Re: [fpc-devel] Peephole issue in 3.2.3

2024-06-02 Thread Martin Frb via fpc-devel

On 02/06/2024 21:06, J. Gareth Moreton via fpc-devel wrote:

I admit I'm not overly sure how to handle Thaddy sometimes:

"They fixed it in the wrong way. It is fixed in a way to solve a 
single - rare - problem by an OP that seems to have more infuence than 
me and the fixer(s) would not listen."


Not sure what problem he's referring to exactly.  Hopefully not my 
aforementioned commit, because I think making sure the flag register 
is properly allocated so the peephole optimizer can make the correct 
informed choices is pretty important!


Thaddy is talking about another issue, to which he supplied a link. No 
idea why (or if) he thought they were related.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Peephole issue in 3.2.3

2024-06-02 Thread Martin Frb via fpc-devel
While not sure how 3.2.4 preparation are going, nor what is still 
outstanding for merging, I just wanted to quickly check if the following 
is know (and hopefully making the list)

https://forum.lazarus.freepascal.org/index.php/topic,67448.0.html

From what I can tell
- present in today's 3.2.3
- probably peephole

Merely from the commit message, possibly
https://gitlab.com/freepascal.org/fpc/source/-/commit/6f24c8b4efccea67d092062009f413cc789a052c 


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Potentially wrong line info with dwarf 4

2024-05-23 Thread Martin Frb via fpc-devel

On 23/05/2024 22:55, Florian Klämpfl via fpc-devel wrote:

On 23.05.24 14:51, Martin Frb via fpc-devel wrote:

If I am not missing any detail

Using -gw 4 it seems fpc writes the same header for line info as it 
does for dwarf 3.


However, when the line info version is set to 4 (at least if all 
units are dwarf 4 / if some are dwarf 3 this may not be the case)


Dwarf 4 has a new field in the header, and that is not written.

objdump in this case delivers trash for the filenames (as they are 
not in the correct location)



Afaik, the line info version can be set to 3, even if other dwarf 
info is version 4


I fixed the header. This was an easier one :)


Which versions of Fpc will that apply?

3.3.1 and up
and/or also 3.2.3?

Did 3.2.2 have -gw4?

I ask because FpDebug will look at the producer to decide if it should 
read the broken info.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Potentially wrong line info with dwarf 4

2024-05-23 Thread Martin Frb via fpc-devel

If I am not missing any detail

Using -gw 4 it seems fpc writes the same header for line info as it does 
for dwarf 3.


However, when the line info version is set to 4 (at least if all units 
are dwarf 4 / if some are dwarf 3 this may not be the case)


Dwarf 4 has a new field in the header, and that is not written.

objdump in this case delivers trash for the filenames (as they are not 
in the correct location)



Afaik, the line info version can be set to 3, even if other dwarf info 
is version 4

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Dwarf Standard - implementing...

2024-05-19 Thread Martin Frb via fpc-devel

Anyone any feedback, please?

Or, who would be knowledgeable, and might at least tell me when there 
might be time, if too busy right now?



On 17/05/2024 13:49, Martin Frb wrote:

On 09/05/2024 19:53, Martin Frb via fpc-devel wrote:

It's now an issue for the Dwarf standard.
https://dwarfstd.org/issues/240507.1.html


Looking at the time other proposals have taken, I think it is 
reasonable to implement properties as custom extension now. And then 
later make any amendments (best case, just change the numeric 
constants for the DW_TAG/_AT... ).


I have done some experiments on Joost's work. But I now reached the 
point were I do need feedback and help:

https://gitlab.com/martin_frb/fpc-src/-/compare/main...martin-dwarf-prop-2?from_project_id=28644964=false

Joost's code had some of the "tai" sizes hard-coded in dbgdwarf.pas. I 
moved that into each of the "tai" classes.

https://gitlab.com/freepascal.org/fpc/source/-/commit/6623ccd6245bb0b8d2d46453ac680c18d6c6aad1#1666e6c01f5086b3630dcd10a1b24557a1c178f6_2741_2831

begin
{ write dummy for now }
AddConstToAbbrev(ord(DW_FORM_string));
append_to_al_dwarf_info(tai_string.create(''),1);




Joost's code did write labels to the "tai" list, where the location of 
the label was unknown, and later
See "|TPendingOffsetConst" in 
|https://gitlab.com/freepascal.org/fpc/source/-/commit/6623ccd6245bb0b8d2d46453ac680c18d6c6aad1#1666e6c01f5086b3630dcd10a1b24557a1c178f6


I tried to use (local) labels for that. This only happens if the Dwarf 
target DIE is in the same CU.

However, I encountered some issues
- On Linux, I think I get global labels.
- I needed labels for TSym
- for code like
    TFoo = record a: integer; property b: integer read a; end;
    TBar = type TFoo;
  TBar is written using the same symbol (same instance). So I can't 
get 2 labels (currently the same label gets written twice, leading to 
an error)


So what is the best way to proceed there?


I also did not yet manage to create a link to the static variable that 
is written for static fields, when it is referred by a class property. 
But maybe that can be done, when static fields are moved inside the 
class  DWARF-5 "5.7.7 Class Variable Entries" allows 
DW_TAG_Variable in a structure.



Btw, while writing the dwarf, is there a way to tell from the data, if 
a property is written because setter/getter are declared here, or 
because it changes only visibility?


Other comments/suggestions?



A lazarus proof of concept counter part.
(To view properties, each watch still must have "function calling" 
enabled)

https://gitlab.com/martin_frb/lazarus
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Dwarf Standard - implementing...

2024-05-17 Thread Martin Frb via fpc-devel

On 09/05/2024 19:53, Martin Frb via fpc-devel wrote:

It's now an issue for the Dwarf standard.
https://dwarfstd.org/issues/240507.1.html


Looking at the time other proposals have taken, I think it is reasonable 
to implement properties as custom extension now. And then later make any 
amendments (best case, just change the numeric constants for the 
DW_TAG/_AT... ).


I have done some experiments on Joost's work. But I now reached the 
point were I do need feedback and help:

https://gitlab.com/martin_frb/fpc-src/-/compare/main...martin-dwarf-prop-2?from_project_id=28644964=false

Joost's code had some of the "tai" sizes hard-coded in dbgdwarf.pas. I 
moved that into each of the "tai" classes.

https://gitlab.com/freepascal.org/fpc/source/-/commit/6623ccd6245bb0b8d2d46453ac680c18d6c6aad1#1666e6c01f5086b3630dcd10a1b24557a1c178f6_2741_2831

begin
{ write dummy for now }
AddConstToAbbrev(ord(DW_FORM_string));
append_to_al_dwarf_info(tai_string.create(''),1);




Joost's code did write labels to the "tai" list, where the location of 
the label was unknown, and later
See "|TPendingOffsetConst" in 
|https://gitlab.com/freepascal.org/fpc/source/-/commit/6623ccd6245bb0b8d2d46453ac680c18d6c6aad1#1666e6c01f5086b3630dcd10a1b24557a1c178f6


I tried to use (local) labels for that. This only happens if the Dwarf 
target DIE is in the same CU.

However, I encountered some issues
- On Linux, I think I get global labels.
- I needed labels for TSym
- for code like
    TFoo = record a: integer; property b: integer read a; end;
    TBar = type TFoo;
  TBar is written using the same symbol (same instance). So I can't get 
2 labels (currently the same label gets written twice, leading to an error)


So what is the best way to proceed there?


I also did not yet manage to create a link to the static variable that 
is written for static fields, when it is referred by a class property. 
But maybe that can be done, when static fields are moved inside the 
class  DWARF-5 "5.7.7 Class Variable Entries" allows DW_TAG_Variable 
in a structure.



Btw, while writing the dwarf, is there a way to tell from the data, if a 
property is written because setter/getter are declared here, or because 
it changes only visibility?


Other comments/suggestions?



A lazarus proof of concept counter part.
(To view properties, each watch still must have "function calling" enabled)
https://gitlab.com/martin_frb/lazarus___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] class property - should this work - static field in nested field

2024-05-15 Thread Martin Frb via fpc-devel

The below fails to compile.

However "b" is a class var. The fact that it is reached via a normal 
field, does not change that. The address/value of TBar.f.b can be known 
without on instance of TBar required.


Mind, this is a theoretical question, I don't actually need it, just 
came across the idea and wanted to know.



program Project1;
type

  TFoo = object
    a: integer;
    class var b: integer;
  end;

  TBar = class
    f: TFoo;
    class property fb: integer read f.b;   // Error: Illegal symbol for 
property access

  end;

begin
end.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Dwarf Standard - support for properties

2024-05-09 Thread Martin Frb via fpc-devel

It's now an issue for the Dwarf standard.
https://dwarfstd.org/issues/240507.1.html
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] {$i ascdef.inc} / stdcall

2024-05-06 Thread Martin Frb via fpc-devel

Maybe of interest?

The include file {$i ascdef.inc} is used from unit Windows with
{$calling stdcall}
in effect.

Most functions in it therefore don't have "stdcall". But some do. Is 
that known/wanted/...?


Similar in some other includes.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] apple properties // Re: Help/Guidance please: Dwarf support for properties

2024-05-03 Thread Martin Frb via fpc-devel

On 03/05/2024 14:17, Sven Barth via fpc-devel wrote:
Martin Frb via fpc-devel  schrieb am 
Fr., 3. Mai 2024, 12:13:


In case it goes ahead, I am trying to thing of what would be
needed
Can anyone think of any feature for Pascal properties that is not
covered by the below?


A property can be marked "default". Currently only array properties, 
but there is still the idea to implement "hoisting" of sub members 
through single properties.

Right. I will add a "default" flag.

Out of interest (I recall having seen the discussion, but I don't recall 
the details), how would that be accessed?
a := MyObj; // will a be assigned the object or the default properties 
value?



Will that also mean multiple default properties, if the index signature 
differs?





Properties of type interface or class can have an "implements" clause 
that redirects the implementation of an interface implemented by the 
class (note: class type properties are not yet supported by FPC, but 
are on the ToDo list for Delphi compatibility).



Right. Is that relevant for the debugger though?

Or would that be the other way round? I.e. if we implemented debug info 
for interfaces, then an interface would in the debug info be a structure 
with lots of functions.

Those functions then point to the correct functions in the object.
And through the self param, would reveal the object, or in this case 
the  "implements" interface as object (allowing the debugger to forward 
resolve).


Actually, I don't think that the class debug info even includes which 
interfaces the class implements?


The Borland extension seems to have had it: 
https://github.com/llvm-mirror/llvm/blob/master/include/llvm/BinaryFormat/Dwarf.def#L390



Oxygene introduced per setter/getter visibility and since I had need 
of this here and then in the past I might still be inclined to 
implement that in the future, so this might not only be for C# then.




Good to know, I will amend that.

-
I was also thinking if it might help to have a link to an inherited 
property, if only visibility is changed.
But that does not exist for functions either (though actually indirectly 
yes, through the vmt pointer).


That way the debugger could use that to avoid double listing it.

E.g. currently there is already the problem that with "strict private" 
(or private across units) an object can have several fields "MyField". 
Of the same or different type. (which I still haven't 100% dealt with in 
fpdebug).
With fields though, they are always different. With properties they may 
be a newly introduced, or a visibility change. But then the absence of 
any setter/getter would indicate that too.___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] apple properties // Re: Help/Guidance please: Dwarf support for properties

2024-05-03 Thread Martin Frb via fpc-devel

On 02/05/2024 20:59, Jonas Maebe via fpc-devel wrote:



---

I don't have background on the Apple properties.


It's not Apple, but Objective-C.


Does FPC create such Objective-C code / properties?

If yes, how does it decide on how to translate "property Foo..."?

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] apple properties // Re: Help/Guidance please: Dwarf support for properties

2024-05-03 Thread Martin Frb via fpc-devel

In case it goes ahead, I am trying to thing of what would be needed
Can anyone think of any feature for Pascal properties that is not 
covered by the below?




# Proposal to implement "properties" for Pascal

## Background

Pascal has a property construct, that allows a "variable like" 
identifier, which can either point to a field (member variable) or a 
getter/setter function.

They can be read/write, read only, write only.
  TFoo = class
    FField: integer;
    function GetProp: integer;
    procedure SetProp(AVal: Integer);
    property MyProp: integer read GetProp write SetProp;
    property MyOtherProp: integer read FField;
  end;

Properties can exist in a structure, interface, or on a global level.

Properties can have one or more array like indexes.
  TFoo = class
    function GetProp(AIdx:word; AIdx2: boolean): integer;
    procedure SetProp(AIdx:word; AIdx2: boolean; AVal: Integer);
    property MyProp[AIdx:word; AIdx2: boolean]: integer read GetProp 
write SetProp;

  end;

Properties can share a method, and provide an index (constant) to 
identify which property called the method.

  TFoo = class
    function GetProp(AIndex: Integer): integer;
    procedure SetProp(AIndex: Integer; AValue: integer);
    property MyProp1: integer index 1 read GetProp write SetProp;
    property MyProp2: integer index 2 read GetProp write SetProp;
  end;

Properties can be streamed and therefore can have a default value 
(constant or via function). They can also have a "stored" value 
(function) indicating if they need to be stored in the stream.


Properties can be elevated to a higher visibility (private/public) in 
inherited classes.


There may be partial overlaps with properties in Objective-C and C#

## Proposed Changes

Introducing a new tag

DW_TAG_PROPERTY or DW_TAG_PROPERTY_PASCAL
This tag can occur anywhere where DW_TAG_MEMBER can occur. It can also 
occur on a global scope.


It can have
  DW_AT_NAME
  DW_AT_TYPE
  DW_AT_ACCESSIBILITY
  DW_AT_decl_column, DW_AT_decl_file and DW_AT_decl_line.

It can then contain any of
  DW_TAG_PROPERTY_SETTER
  DW_TAG_PROPERTY_READER
  DW_TAG_PROPERTY_DEFAULT
  DW_TAG_PROPERTY_STORED

Each of them can have

  DW_AT_PROPERTY_FORWARD  reference/constant
    refernce to the field or function
  DW_AT_PROPERTY_OBJECT  reference/expression/constant
    the object on which the value is stored (value for 
DW_OP_push_object_address)
    can be omitted for inherited classes, if it computes to the same as 
the current class


A getter (also "default" and "stored" should be a function returning the 
same type as the property. It should either take no arguments or only 
DW_AT_object_pointer
A setter should be a procedure, it should take optional 
DW_AT_object_pointer and one argument of the same type as the property.


Instead of having attributes grouped in DW_TAG_PROPERTY_SETTER/... all 
attribute could exist top level, in 4 versions. That would be shorter if 
no object needs to be specified. But it is less flexible for later 
additions.



For indexed properties the DW_TAG_PROPERTY also has
  DW_TAG_PROPERTY_INDEX_LIST
containing one or more
  DW_TAG_PROPERTY_INDEX

  DW_AT_NAME
  DW_AT_TYPE
  DW_AT_VALUE  reference or constant or expression (returning value)
  DW_AT_IS_PROPERTY_VALUE  flag

DW_AT_NAME and  DW_AT_TYPE can be optional. They can be gotten from the 
linked procedure

DW_AT_VALUE is optional. It is used when properties share a getter.

DW_AT_IS_PROPERTY_VALUE is optional. It can be used to specify the 
position of the "assigned value" in a setter. If not specified the 
assigned value will be passed as the last parametr.



To change visibility of an inherited property,
DW_TAG_PROPERTY
  DW_AT_NAME
  DW_AT_ACCESSIBILITY


OFF TOPIC:
  For C# it may be of interest to allow DW_TAG_PROPERTY_SETTER/... to 
have their own   DW_AT_ACCESSIBILITY
  For C# it may be of interest to allow an inlined function declaration 
instead of DW_AT_PROPERTY_VALUE



## References

FreePascal property doc 
https://www.freepascal.org/docs-html/ref/refse27.html
APPLE extension for Objective-C 
https://github.com/llvm/llvm-project/blob/main/llvm/docs/SourceLevelDebugging.rst#debugging-information-format-1



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] apple properties // Re: Help/Guidance please: Dwarf support for properties

2024-05-02 Thread Martin Frb via fpc-devel

On 02/05/2024 20:59, Jonas Maebe via fpc-devel wrote:




---

I don't have background on the Apple properties.


It's not Apple, but Objective-C.

property goes from the member to the property strikes me as odd. 
(first example of dwarf)
It indicates, that the property is only meant to be found when 
starting at the member?


Objective-C also knows the concept of "computed properties", which are 
not tied to a particular field. I don't immediately see how the 
proposal deals/would deal with that.
Ok, I don't know how to read that, but potentially many fields could 
link to the same property.


Do those properties need a field at all?




Also the Apple spec uses strings (names) to refer to the getter/setter.
I don't know if there is a particular underlying need. It's more 
costly than a reference. Also It gets problematic if the getter is in 
an embedded record, or if there are overloaded functions, 


It doesn't use a symbol name, but a selector name. Objective-C method 
dispatching mostly does not happen using a VMT, but by looking up a 
(hash of a) selector in a table. "Calling a method" is called "sending 
a message to" in Objective-C lingo; it's also how it can fairly 
transparently support working with remote objects.


ok. Explains maybe half...

I am not immediately sure if dwarf has anything to describe dispatching. 
Or if this is just left for the debugger to know. Which is ok, with 
custom tags that are for Objective-C only.
I don't know if that table is precomputed / I.e. get completely created 
at compile time => in which case the location of the looked up hash 
would be known in the table, and the address of the method could be 
gotten via a dwarf expression?


The other part that I really don't understand is, why you find the 
property from the field, and not the other way round (above)?
Does that mean the code/user would not start with "object.my_property" 
but rather do "object.field as property"?


I am trying to understand if there is any common ground with properties 
in Pascal.


I've ask if they (dwarf makers) see potential for our properties 
https://lists.dwarfstd.org/pipermail/dwarf-discuss/2024-May/thread.html
So, I am trying to figure out were those Apple tags fit into it, and 
how/if I treat them in that discussion. (the Borland ones, have no docs 
to be found)


However from what I have seen so far, I do think there are fundamental 
differences.

Pascal properties should have
- the property as a declaration that is a start point (except for being 
owned by a class / but also exists without)
- links to other entities starting at the property (or no links, and 
duplication of accessor declarations)


Maybe there is still stuff that could be proposed as share-able?
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] apple properties // Re: Help/Guidance please: Dwarf support for properties

2024-05-02 Thread Martin Frb via fpc-devel

https://github.com/llvm/llvm-project/blob/main/llvm/docs/SourceLevelDebugging.rst#debugging-information-format-1

Objective C properties exist separately from class members.  A 
property can be
defined only by "setter" and "getter" selectors, and be calculated 
anew on each

access.  Or a property can just be a direct access to some declared ivar.


I don't know if in Apple terms "ivar" has any special meaning?

Nor if there is more to "calculated anew on each access"?

---

I don't have background on the Apple properties.

But the fact that the link between a "field" (tag_member) and the 
property goes from the member to the property strikes me as odd. (first 
example of dwarf)
It indicates, that the property is only meant to be found when starting 
at the member?


For FPC properties that is the other way round.
The property would have to point to the field. (or function)


Also the Apple spec uses strings (names) to refer to the getter/setter.
I don't know if there is a particular underlying need. It's more costly 
than a reference. Also It gets problematic if the getter is in an 
embedded record, or if there are overloaded functions, 




-
There do exist Borland properties
https://android.googlesource.com/platform//prebuilts/clang/host/linux-x86/+/b669748458572622ed716407611633c5415da25c/clang-r416183d/include/llvm/BinaryFormat/Dwarf.def

But I could not find any details at all



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Help/Guidance please: Dwarf support for properties

2024-04-28 Thread Martin Frb via fpc-devel

On 27/04/2024 22:10, Jonas Maebe via fpc-devel wrote:

On 27/04/2024 21:40, Martin Frb via fpc-devel wrote:
First, telling the asm to store  ".l99 - .ldebuginfo" or telling the 
asm to store 733 (having done the math already) will result in the 
same dwarf info.

Of course this only works for local labels.

The big question here is, if it is ok to use labels (potentially many 
labels) for this purpose.


Sure. The current DWARF writer also does this.


So on Windows (and presumingly Mac) that will all be local labels.

On Linux (I just checked) the current Dwarf writer generates global 
labels (with relocations).
The change in question would add quite a few more of them. As any field 
or method in a class can be referred to by a property (even from another 
unit (except private), it would need to add a label to each and every 
field and method.

[[ see below ]]


So, if that is OK, then I would appreciate some pointers how I can best 
generate those labels.
Some of the code does not have a TDef - Which is needed for 
"get_def_dwarf_labs()".


Then again, I might have another look at Joost's code and try to 
rebase/fix it for current trunk


But then before I do, is there any feedback on it?
What would be the requirements to get it accepted?

Would there be preferences between the 2 approaches?

At least on macOS there's no support for storing the difference 
between two labels in s/uleb128 in DWARF.


That should be (from dwarf point of view) the same as on Windows? On 
Windows the generated dwarf does only have references within each 
compilation unit.
I don't have a Mac at hand right now, but I assume that an Mac any 
declaration from another unit (such as e.g.  base classes) will have a 
copy written to any unit in which they need to be referenced.



---
Off topic to properties, but looking at what currently happens on Linux

The compiler is smart enough to only add exported-labels for types in an 
"interface section".


Types private to the unit, well... It seems they were meant to get local 
labels, but do get exported too?

They get (on linux) labels like (on windows that is just .ld20):
    _$UNIT1$_Ld20

And that label is present in the .o file.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Help/Guidance please: Dwarf support for properties

2024-04-27 Thread Martin Frb via fpc-devel

On 27/04/2024 20:29, Jonas Maebe via fpc-devel wrote:

On 27/04/2024 17:18, Martin Frb via fpc-devel wrote:


One of the posts also brings up the idea of avoiding labels (in asm), 
and keep track of locations by counting the bytes in the generated 
dwarf as part of the compilers work (IMHO duplicate what the asm 
already can do?)


That's not the assembler's, but the linker's job. And on macOS, the 
DWARF info is not processed by the linker and hence can only contain 
relative offsets (differences between two local labels).


Maybe a miss understanding: storing the difference between 2 local 
labels would be the asm?

But if (e.g. on Linux) it is cross units then its the linker.

There are 2 consideration here.

1)
First, telling the asm to store  ".l99 - .ldebuginfo" or telling the asm 
to store 733 (having done the math already) will result in the same 
dwarf info.

Of course this only works for local labels.

The big question here is, if it is ok to use labels (potentially many 
labels) for this purpose.
From the mails at the dwarf list, it seems Joost wanted to avoid this, 
but it is not clear why.


Joost then went on, to count the bytes that are added by each bit of 
dwarf info written (same as the asm would do), and therefore be able to 
write the number directly (or in some cases iirc write it later into the 
gap).
That leads to a very big changeset, as the entire dwarf generating code 
needs to do counting.
(And IMHO, that is very easy to accidentally break / and if just one 
very specific dwarf encoding breaks it, it may be months until found)


But, then again I don't know anything about the impact of such amounts 
of additional labels...



2)
At least on Linux, references for dwarf go across compilation units.

On Windows, if "unit1" has "TForm1 = class(TForm)", that leads to *all* 
base classes being encoded into that unit. Almost every unit will 
therefore have a copy of TObject (if it is oop). On Linux, only one unit 
has this.


I must say, I haven't checked how Joost's code deals with that. (and 
mine would probably still need work for that too, but before doing 
anything, I am trying to find out what is ok).
Afaik that is why there is: tf_dwarf_only_local_labels in 
target_info.flags



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Help/Guidance please: Dwarf support for properties

2024-04-27 Thread Martin Frb via fpc-devel

On 27/04/2024 17:05, Martin Frb via fpc-devel wrote:

On 27/04/2024 15:24, Jonas Maebe via fpc-devel wrote:

On 27/04/2024 13:45, Martin Frb via fpc-devel wrote:
Ok, I would like to start another attempt to support properties when 
using fpdebug as debugger.


I would recommend asking guidance on the DWARF list (dwarf-discuss). 
Maybe there are already standard-supported constructs to do this.





It is not mentioned in the latest draft for dwarf 6. 
https://snapshots.sourceware.org/dwarfstd/dwarf-spec/latest/


Joost actually checked
https://lists.dwarfstd.org/pipermail/dwarf-discuss/2021-May/thread.html
https://lists.dwarfstd.org/pipermail/dwarf-discuss/2021-June/thread.html

And Joost based his implementation on this.


One of the posts also brings up the idea of avoiding labels (in asm), 
and keep track of locations by counting the bytes in the generated dwarf 
as part of the compilers work (IMHO duplicate what the asm already can do?)

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Help/Guidance please: Dwarf support for properties

2024-04-27 Thread Martin Frb via fpc-devel

On 27/04/2024 15:24, Jonas Maebe via fpc-devel wrote:

On 27/04/2024 13:45, Martin Frb via fpc-devel wrote:
Ok, I would like to start another attempt to support properties when 
using fpdebug as debugger.


I would recommend asking guidance on the DWARF list (dwarf-discuss). 
Maybe there are already standard-supported constructs to do this.





It is not mentioned in the latest draft for dwarf 6. 
https://snapshots.sourceware.org/dwarfstd/dwarf-spec/latest/



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Help/Guidance please: Dwarf support for properties

2024-04-27 Thread Martin Frb via fpc-devel
Ok, I would like to start another attempt to support properties when 
using fpdebug as debugger.


The idea is to add custom tags in the dwarf info. This can be done by a 
new option -godwarfporperties

Though, it may be better to go with -godwarffpdbg / similar to -godwarfcpp

Making it fpdebug specific will allow to add other info, that would 
benefit debugging Pascal, but isn't in Dwarf...



In 2022 Joost did an attempt:
https://gitlab.com/freepascal.org/fpc/source/-/compare/main...joost%2Fdwarfproperties?from_project_id=28644964=false

I didn't understand the reasons behind (but then I am not familiar with 
the FPC codebase).

I do now get some guesses as to why...

-
But anyway, I started my own attempt based on that.
https://gitlab.com/martin_frb/fpc-src/-/compare/main...martin-dwarf-properties?from_project_id=28644964=false

The first problem is getting labels for items that need to be referenced.

2a267440b240be3aa99d0c14fd6c8dcf90a27f99
For procedures this is explained in the first commit => they currently 
have an (possible intentional) unbalanced dbg_state_writing.

Requiring them to have a label, conflicts with that.
I welcome feedback on the suggestions in my commit message.

19e6b4fea54b85df1ad8df221947231d01d98bb9
Just completing the above, and write the labels.

959566d705d6a464b3076a97ddaa8213c9d9ec9f
Same problem for DW_TAG_MEMBER
My "workaround" is certainly wrong.  But currently there is no SYM.
How can I get labels for it?
Such as that they also work, if the field is in the parent, in a diff 
unit => which on linux requires a global label, since the declaration is 
NOT copied into the current unit.


50f7d0d53a20cef541f87b474a7b8cc39558808d
Write the basic info.
Currently only works if the property field/getter is in the same object 
(or base class), but not if it is in a record belonging to the object.
The latter requires the structure address to be also written, and 
resolving the record to the field...


But before I go and spent time on that, I would like to first resolve 
all the issues that already exist.


-
Using -godwarffpdbg would also allow for this:
https://gitlab.com/martin_frb/fpc-src/-/compare/main...martin-entry-pc?from_project_id=28644964=false

Which makes sure there is an address for each of the functions that need 
to be called.


-
Test implementation in Lazarus
https://gitlab.com/martin_frb/lazarus/-/commits/fpdebug-godwarfproperties

properties with getters aren't called yet. It shows the getter, as if it 
was an event variable.


But if the getter has an address, it can be called by adding "()" (and 
enabling function eval).

At least for datatypes supported in function calls.

Looking forward to some feedback.
Martin

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] wrong result for abs(low(int64))

2024-04-04 Thread Martin Frb via fpc-devel

On 04/04/2024 16:39, J. Gareth Moreton via fpc-devel wrote:
Essentially, an arithmetic overflow is happening.  Since the largest 
Int64 possible is 9,223,372,036,853,775,807, going one above that (the 
result to abs(low(int64))) wraps back around to 
-9,223,372,036,853,775,808.


Internally, you can think about negating (positing?) a negative number 
as inverting the bits and then adding one (aka. two's complement), so 
low(int64) is 1000...000, which inverted becomes 0111...111, and then 
adding one results in 1000...000 again.


I got that bit...

Initially I was surprised to find "abs" to return a signed number. After 
all, it will never be negative.


But, in the meantime I recalled that unsigned numbers will cause other 
issues when used in expressions.

"abs(-1)-2" would behave different.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] wrong result for abs(low(int64))

2024-04-04 Thread Martin Frb via fpc-devel

The below writes:  -9223372036854775808

Shouldn't absolute return a positive number?

program Project1;
begin
  writeln( abs(low(int64)) );
end.



Seems
writeln( abs(low(longint)) );

also returns negative...

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] fpc 3.3.1 fails in fpjwarsa

2024-03-20 Thread Martin Frb via fpc-devel

On 20/03/2024 10:14, Michael Van Canneyt via fpc-devel wrote:
I just did the same for 55 platforms (cross-compile), on ubuntu. All 
work without errors ?


Apologies, probably my fault. I export the sources from git before 
build, but did not remove old files. Starting without any old files in 
the sources, and it works.


Thanks for the feedback.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] fpc 3.3.1 fails in fpjwarsa

2024-03-19 Thread Martin Frb via fpc-devel

Older Ubuntu, trying to update (starting compiler is 3.2.2)


make clean
make all  OPT=" -O-1 -gw3 "
make install INSTALL_PREFIX=/home/m/fpc/


Compiling ./fcl-web/src/fcm/fpfcmstrings.pp
Writing Resource String Table file: fpfcmstrings.rsj
Compiling ./fcl-web/src/jwt/fpjwarsa.pp
fpjwarsa.pp(21,35) Error: Identifier not found "TJWTSigner"
fpjwarsa.pp(21,35) Error: Class type expected, but got ""
fpjwarsa.pp(25,64) Error: Identifier not found "TJWTKey"
fpjwarsa.pp(26,62) Error: Identifier not found "TJWTKey"
fpjwarsa.pp(23,20) Error: There is no method in an ancestor class to be 
overridden: "class AlgorithmName:System.AnsiString;"
fpjwarsa.pp(25,14) Error: There is no method in an ancestor class to be 
overridden: "CreateSignature(TJWT;):System.AnsiString;"
fpjwarsa.pp(26,14) Error: There is no method in an ancestor class to be 
overridden: "Verify(const AnsiString;):System.Boolean;"

fpjwarsa.pp(56,38) Error: Identifier not found "TJWTSigner"
fpjwarsa.pp(56,38) Error: Class type expected, but got ""
fpjwarsa.pp(60,64) Error: Identifier not found "TJWTKey"
fpjwarsa.pp(61,62) Error: Identifier not found "TJWTKey"
fpjwarsa.pp(58,20) Error: There is no method in an ancestor class to be 
overridden: "class AlgorithmName:System.AnsiString;"
fpjwarsa.pp(60,14) Error: There is no method in an ancestor class to be 
overridden: "CreateSignature(TJWT;):System.AnsiString;"
fpjwarsa.pp(61,14) Error: There is no method in an ancestor class to be 
overridden: "Verify(const AnsiString;):System.Boolean;"

fpjwarsa.pp(89,1) Fatal: There were 14 errors compiling module, stopping
Fatal: Compilation aborted

The installer encountered the following error:
Compilation of "BuildUnit_fcl_web.pp" failed
  $00542579
  $0054C7E2
  $0054B87E
  $0054CADB
  $0054FEAA
  $00540F3B
  $005415C0
  $0047868F
  $004A5AF9

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Failing Lazarus Codetools Pas2JS-related tests - again

2024-03-19 Thread Martin Frb via fpc-devel

On 19/03/2024 15:41, Mattias Gaertner via fpc-devel wrote:



On 19.03.24 14:58, Maxim Ganetsky via fpc-devel wrote:

[...]
#7 944.7 fpmake.pp(228,5) Error: Identifier not found "T"


Ah, you are using fpc 3.3.1 to compile it.

Fixed.

But I get strange linker errors compiling webidl2pas:

(9015) Linking bin/x86_64-linux/webidl2pas
/usr/bin/ld.bfd: 
/path/compiler/utils/pas2js/units/x86_64-linux/webidl2pas.o:(.fpc.n_links+0x50): 
undefined reference to `DEBUGSTART_$CUSTAPP'
/usr/bin/ld.bfd: 
/path/compiler/utils/pas2js/units/x86_64-linux/webidl2pas.o:(.fpc.n_links+0x58): 
undefined reference to `DEBUGEND_$CUSTAPP'


It compiles with the ppu files of fpc 3.3.1 and 3.2.2 tough, but not 
with the sources ...


I don't know if it applies.

But I have in some cases seen similar linking issues, if parts of the 
code were compiled with DWARF-2 and other parts with DWARF-3

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Question about "Default()"

2024-02-22 Thread Martin Frb via fpc-devel

https://www.freepascal.org/docs-html/rtl/system/default.html
Default is a compiler intrinsic: it returns for every type T a default 
value. In essence, this is a block of memory that is zeroed out. It 
can be used to correctly initialize any type, and more importantly, a 
managed type. It also works using a generic type template. 


But zero isn't always a valid value => so how can it be used to 
initialize a type where that is invalid.


The below will runtime error "invalid enum value".
(And also, in the past, I saw it pointed out countless times, that 
setting an enum to an ordinal value that is not matching any of its 
members does not have a defined behaviour).


So is that a bug in Default?
Or is the documentation wrong "any type"? (it contradicts itself anyway 
"zeroed" <> "any type")

Or ...?

program Project1;
type
  //tt = 3..5;
  tt = (e1=3, e2=5,e3=7);
var a: tt;
begin
  a := Default(tt);
  writeln(a);
  readln;
end.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Missing documentation for changes in 3.3.1 - visibility of class fields

2024-02-17 Thread Martin Frb via fpc-devel
The code below (avail as download, wrongly reported at 
https://gitlab.com/freepascal.org/fpc/source/-/issues/40634#note_1777253148 
=> gen331_b.zip )

compiles in in 3.2.3, but not in 3.3.1

As for as I am concerned 3.3.1 is right. But should that change be 
mentioned on the user changes 
https://wiki.freepascal.org/User_Changes_Trunk ?


---
program class_nest;
{$mode ObjFPC}{$H+}
uses unit1;

type
  TDataPointDistanceTool = class(TDataPointTool) //   not inheriting 
from the nested class

  strict protected
    function FindRef(ADest: TDataPointTool.TPointRef): Boolean;
  end;

function TDataPointDistanceTool.FindRef(ADest: 
TDataPointTool.TPointRef): Boolean;

begin
  ADest.FGraphPos := 1;
end;

begin
end.

---
unit Unit1;
{$mode ObjFPC}{$H+}
interface
uses
  Classes, SysUtils;

type

  TDataPointTool = class
  public
  type
    TPointRef = class
    private
    protected
  FGraphPos: integer; // It is protected
    end;
  end;

implementation

end.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Exact rules for "strict protected"

2024-02-14 Thread Martin Frb via fpc-devel

https://www.freepascal.org/docs-html/ref/refse35.html


Strict Protected
Is the same as Protected, except that the members of a Protected
section are also accessible to other classes implemented in the
same unit. Strict protected members are only visible to descendent
classes, not to other classes in the same unit. 




In the below

TSubFoo can see the strict proctected TTest.
So therefore TSubFoo does not count as "not to other classes in the same 
unit."

Well, it is another class, but it is within the class TFoo.

TSubBar is also another class, but it is within TBar. And for TBar we 
have "only visible to descendent classes" => TBar should see TTest.

And since TSubBar is in TBar?

So the below code have that error, or is it a bug?
An if it should, what is the correct exact description of "Strict 
protected"?



program Project1;
type
  TFoo = class
  strict protected type
    TTest = record end;
  private type
    TSubFoo = class
  a: TTest;
    end;
  end;

  TBar = class(TFoo)
  private type
    TSubBar = class
  a: TTest;  // project1.lpr(15,10) Error: Identifier not found "TTest"
    end;
  end;

begin
end.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Default-max-precision for different float types?

2024-02-13 Thread Martin Frb via fpc-devel

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40768

Are there any defaults, with which precision each float type 
(single/double/extended) should be printed?

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] debug info and TAlphaColor = Cardinal;

2024-02-10 Thread Martin Frb via fpc-devel

The below leads to debug info reporting TAlphaColor as Cardinal.

Maybe it could be changed (like TColor is a distinct type)?


unit System.UITypes;
Type
...
    TAlphaColor = Cardinal;

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] inc(QWORD, BYTE) -> range check

2024-01-31 Thread Martin Frb via fpc-devel

https://www.freepascal.org/docs-html/rtl/system/inc.html
- says it operates on pointers
- also gives examples for unsigned types such as word

But can it be used to increment a QWORD?


  Inc(FAddress, (Opcode div FOwner.FLineInfo.LineRange) * 
FOwner.FLineInfo.MinimumInstructionLength);


FAddress: QWord = $02B6

All values in the expression are of type Byte. Though the question to 
ask may be what the result is cast too

I know the result of the expression is 0 (zero).
From the assembler I can see that I passed the div and the multiplication.

And then I got
000100CBEC93 48B8FF7F mov rax,$7FFF
000100CBEC9D 4839C2   cmp rdx,rax
000100CBECA0 7605 jbe +$05    # 
$000100CBECA7 NEXTLINE+1815 fpdbgdwarfdataclasses.pas:4556
000100CBECA2 E8998535FF   call -$00CA7A67    # 
$000100017240 $fpc_rangeerror system.inc:801



which calls range check.

For all I can tell it checks the value of FAddress.
But why does it check it against High(Int64) ?

It is a QWord.


FPC 3.2.3 from Dec 2023
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Modifiers...

2024-01-24 Thread Martin Frb via fpc-devel

https://www.freepascal.org/docs-html/ref/refsu3.html

Is this list complete/correct?

1)
It lists bitpacked, but
    program foo; var  bitpacked: integer;  begin end;
gives an error.

I thought modifiers can be used as var names?

2)
Is there, or has there once been?
(found in the synedit highlighter)
  final
  automated
  optional


3)
Not on the list, but suspected the should?
Some are on https://www.freepascal.org/docs-html/ref/refse100.html
  sealed
  inline
  mwpascal
  noinline
  weakexternal
  compilerproc
  vectorcall




___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] defines by the compiler... / linux, LIBC, SysCall

2024-01-11 Thread Martin Frb via fpc-devel

On 11/01/2024 17:30, Marco van de Voort via fpc-devel wrote:


Let me state it more clearly:

The point is that given a precompiled Linux RTL, to my best knowledge  
you can't test any define outside the FPC build environment to see if 
the RTL was compiled with FPC_USE_LIBC or not. Maybe there is some 
workaround testing for some symbol inside the system unit with{$if 
defined(symbol}, but there is no supported global define to test.


Ok, kind of expected that




Targets that enable libc by default (darwin, sunos and openbsd 
apparently) by default make this work by locally enabling 
FPC_USE_LIBC, usually both in rtl/$target or by other hacks in various 
packages/ dirs for shared code, and simply not providing any 
alternative in the target specific code.


And to my best knowledge the "LIBC" in the extradefines of Slowaris 
(below) means zip, nada, zilch. It is an artifact of 1.0.x times, 
which is so old EVEN Lazarus doesn't support it :-)


Ok. ...

Now what I was hoping for, but

- Darwin isn't a problem. As I test for that anyway.
- I can add {$IFDEF SUNOS} too
- Not sure which others...

Sadly however the list can change. So without "LIBC" or other such 
define, this is going to be tricky




___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] defines by the compiler... / linux, LIBC, SysCall

2024-01-11 Thread Martin Frb via fpc-devel

On 11/01/2024 16:34, Marco van de Voort via fpc-devel wrote:


Op 11-1-2024 om 15:48 schreef Martin Frb via fpc-devel:

- Can (on any linux/unix)  "uses SysCall" be compiled  (without error)


You can test that yourself on a Linux system by compiling a cycle with 
-dFPC_USE_LIBC and then compiling a test program (without defines)   
Since there was a bugfix necessary, I assume not.


Not necessary. (as far as I understand the comments that had been made 
already)
-dFPC_USE_LIBC  would not change the os target to sunos.  And therefore 
FPC would not look at the tsysteminfo containing

     extradefines : 'UNIX;LIBC;SUNOS;HASUNIX';

-dFPC_USE_LIBC   would just affect the "uses SysCall" (and that 
hopefully in *exactly* the same manner as compiling on sunos)






- Does it need to be guarded {$IFnDEF LIBC} ?


That define would be FPC_USE_LIBC.  But afaik that is only defined ad 
hoc on spots where it is needed during the FPC compilation. I.e. it is 
set in the build system rather than being a compiler built in. So no.


Sure?

-dFPC_USE_LIBC    would be specified be the user or Makefile when the 
fpc/rtl is build.


But when an fpc (that had been build with -dFPC_USE_LIBC ) is used to 
compile a random project, will then this fpc by tiself define 
-dFPC_USE_LIBC    (without the user needing to do so?)


--

I have 2 different concerns

1) What happens on sunos?
(Where the compiler defaults to LIBC)

That is the case I wont to cover.

2) What happens, if the user "tampers" with settings building a non 
default fpc.


That 2nd part is not that important in respect to my questions in this mail.
If the user does that, then  (when compiling lazarus or any project)
-  no special define may be set by FPC (and that is ok)
- the user may have to set a define according to the project (lazarus 
could offer a workaround define)



-
as for point 1
To make sure it compiles with
- normal build fpc on linux/darwin
- normal build fpc on sunos


{$ifdef linux}
  uses   SysCall;
{$endif}

{$ifdef darwin}
  {$DEFINE FPDEBUG_USE_LIBC}  // darwin: always libc
{$else}
  {$IF not declared(Do_SysCall)}  // Linux, but no Do_SysCall

    {$IFDEF LIBC}    // Does this define ever exist (by fpc)
  {$DEFINE FPDEBUG_USE_LIBC} // no DoSysCall ==> use libc
    {$ELSE}
  {$DEFINE FPDEBUG_USE_DUMMY}  // no DoSysCall ==> empty dummy proc
    {$ENDIF}

  {$ENDIF}

     // ELSE: Do_Syscall exists and can be used
{$endif}



Will that work?
==>> Will (on linux, including sunos)
  "uses SysCall"
compile (not throw an error during compilation). (that is for NORMAL / 
non-tampered FPC)


If yes, then that should work. (even if LIBC isn't defined)
If yes, then I can check if "DoSysCall" can be used

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] defines by the compiler... / linux, LIBC, SysCall

2024-01-11 Thread Martin Frb via fpc-devel

Is this page up to date?
https://www.freepascal.org/docs-html/prog/progap7.html

Maybe I am wrong, but looking at the tsysteminfo does the value in 
extradefines specify values that will be defined during compilation 
(such as those given on that page)?


If the do then "sunos" has
    extradefines : 'UNIX;LIBC;SUNOS;HASUNIX';


But neither LIBC nor HASUNIX are listed on that page.

---
I don't have sunos for testing.
But https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40575

The primary target is to avoid compilation errors.

All the below guarded by {$ifdef linux}


1) I can add "uses SysCall".
There is a comment this will work in 3.3.1 / not sure if 3.2.x will 
abort compile, or just use some unit without the expected symbol.


So the question is (for compilers starting at 3.2.0  // that is one 
version back)


- Can (on any linux/unix)  "uses SysCall" be compiled  (without error)
- Does it need to be guarded {$IFnDEF LIBC} ?


2) If it can always be used, I can then check
  {$IF declared(Do_SysCall)}

3) If Do_SysCall is not avail
Does FPC then provide the define LIBC?

So could I do
  {$IF declared(Do_SysCall)}
 // code uses Do_SysCall
  {$ELSE}
    {$IFDEF LIBC}
   // code imports ptrace from libc
    {$ELSE}
  // code defines empty dummy "raise Exception.create('not 
supported');"

  // compiles, but wont work
    {$ENDIF}
  {$ENDIF}


Thanks for any help/feedback.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] WordBool or SmallInt ?

2023-12-29 Thread Martin Frb via fpc-devel

fpc 3.2.3
The below prog prints 3 times: 11, -1   (signed values)

https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-250003.1.1
Free Pascal also supports the ByteBool, WordBool, LongBool and 
QWordBool types. These are of type Byte, Word, Longint or Int64, 


Besides the fact that a "QWordBool" should be "Int64", they all seem to 
be treated as signed.


Yet at least the first two of them are documented as unsigned.



program Project1;
var
b1,b2 : wordbool;
b3,b4 : longbool;
b5,b6 : qwordbool;

begin
b1 := wordBool(11);
b2 := wordBool(-1);
writeln(ord(b1));
writeln(ord(b2));

writeln;
b3 := LongBool(11);
b4 := LongBool(-1);
writeln(ord(b3));
writeln(ord(b4));

writeln;
b5 := qwordBool(11);
b6 := qwordBool(-1);
writeln(ord(b5));
writeln(ord(b6));

readln;
end.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Ascending order of enum vals

2023-12-29 Thread Martin Frb via fpc-devel

Enums must be ascending. Otherwise a compiler note will be issued... Or not.

Below prog gives
project1.lpr(4,32) Note: Values in enumeration types have to be ascending

But if the values are cast first, then no warning.

The 2nd line will print 255, 0,-2 => which is not ascending.

program Project1;
type

TMyEnum = (e1:=-1,e2:=0, e3:=-2);
//TMyEnum = (e1:=byte(-1),e2:=0, e3:=-2);
//TMyEnum = (e1:=-1,e2:=0, e3:=qword(-2));

var
xa: TMyEnum;


begin
writeln(ord(e1));
writeln(ord(e2));
writeln(ord(e3));
readln;
end.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] TProcess and redirection of StdIn/Out (e.g. from/to files)

2023-12-14 Thread Martin Frb via fpc-devel

On 14/12/2023 21:33, Marco van de Voort via fpc-devel wrote:


Op 14-12-2023 om 21:27 schreef Martin Frb via fpc-devel:


I am actually pretty sure, on Linux, I can get what I want by doing 
it in the "OnFork" event of TProcess.
But on Windows it is well hidden away in the "Execute" method, 
nothing virtual that could be intercepted.


Change the input handle and use popassinput ?
As I said, not possible (unless I make a copy of the entire TProcess 
code).  There is no way to intercept "Execute", and it must be done 
before the Windows API is called to create the process.




But I wonder if this is not too specialistic. It depends on how well 
you can abstract it into TProcess, and preferably in a somewhat 
similar way for all OSes.


Well Michael's answer looks like he is about to have what I need. 
Depends on the when...

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] TProcess and redirection of StdIn/Out (e.g. from/to files)

2023-12-14 Thread Martin Frb via fpc-devel

On 14/12/2023 20:54, Marco van de Voort via fpc-devel wrote:


Op 14-12-2023 om 20:29 schreef Martin Frb via fpc-devel:

 Op 14-12-2023 om 17:30 schreef Martin Frb via fpc-devel:
If I am right the TProcess currently does not allow redirection of 
StdOut/In to/from a file (or other handle provided).


It does, if you need a runcommandloop like routine that writes to 
file. Partially this can be even simplified by inheriting TProcess 
and overriding readinputstream
But that means the parent process has to read the data (from the 
file) and forward it.


Without a shell that always needs to happen. How else ? Keep in mind 
that TProcess is a kernel and not a shell level concept.


At least on Windows you can give a handle that is to be used as StdIn.

And on Linux that handle is currently setup after the fork event, in the 
new process => and currently it either is a pipe or (I think) a copy of 
the parent stdin. But nothing stops it to be a filehandle.
But afaik StdIn is just a handle. This handle can be a tty (usually if 
there is a shell), but it can be /dev/nil or a file or ...


I am actually pretty sure, on Linux, I can get what I want by doing it 
in the "OnFork" event of TProcess.
But on Windows it is well hidden away in the "Execute" method, nothing 
virtual that could be intercepted.







Also not sure how to simulate an EOF in that case


Probably close the pipe.

Anyway the full project is here: 
http://www.stack.nl/~marcov/files/processmemodemo.zip


It is slightly different, a TProcess based application that tries to 
instrument a secondary binary.




Thanks, but I consider that a worst case work around.

I'd rather copy the entire TProcess, so I can make a few tiny changes in 
TProcess.Execute.

I already done a proof of concept on win:
- get the handle to the file
- pass it to the WinAPI for creating the process
=> works.

Haven't yet looked at Linux. But should be even easier.

-

The reason I ask is, that if there is a chance of a future solution in 
FPC, then I like to avoid my own solution now until I can at least do my 
own solution in a compatible manner.

For that I would have to know enough details on that future solution.

Well depending on the amount of changes, I may still do my own 
incompatible


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] TProcess and redirection of StdIn/Out (e.g. from/to files)

2023-12-14 Thread Martin Frb via fpc-devel

On 14/12/2023 18:13, Marco van de Voort via fpc-devel wrote:


Op 14-12-2023 om 17:30 schreef Martin Frb via fpc-devel:
If I am right the TProcess currently does not allow redirection of 
StdOut/In to/from a file (or other handle provided).


It does, if you need a runcommandloop like routine that writes to 
file. Partially this can be even simplified by inheriting TProcess and 
overriding readinputstream
But that means the parent process has to read the data (from the file) 
and forward it.

Also not sure how to simulate an EOF in that case






Is this something that should be added? (I.e. a feature request to be 
added)
If yes, should there just be 3 properties for the handles? A callback 
to create/provide them? A virtual method?

Should there be a flag?

Maybe you can create a predefined derivative that does this with less 
additional code, but this should already be possible.




Afaik, only if the parent process does the forwarding.

If the parent process is busy the child process will need to wait... If 
the parent process wants to launch the child, and the parent then exits


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] TProcess and redirection of StdIn/Out (e.g. from/to files)

2023-12-14 Thread Martin Frb via fpc-devel

On 14/12/2023 18:06, Michael Van Canneyt via fpc-devel wrote:



Actually, I already started an implementation of an extension half a 
year ago.




Is there an accessible branch for that? (maybe in a fork?)
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] TProcess and redirection of StdIn/Out (e.g. from/to files)

2023-12-14 Thread Martin Frb via fpc-devel
If I am right the TProcess currently does not allow redirection of 
StdOut/In to/from a file (or other handle provided).


If it does, and I have been missing the "how to", then please enlighten 
me and disregard the remainder of the mail.



The code for setting up redirection to pipes (to be read/write by the 
parent process) already exists. So this is mainly a call to add 
properties to explicitly set those handles.

Or provide some other method.

Is this something that should be added? (I.e. a feature request to be added)
If yes, should there just be 3 properties for the handles? A callback to 
create/provide them? A virtual method?

Should there be a flag?

What should be the resolving order if handles are give, but other flags 
(pipes/input) are set?


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] ""make clean" builds ppc1 [[Re: Getting error building fpc for clang 16]]

2023-12-09 Thread Martin Frb via fpc-devel

On 09/12/2023 17:03, Martin Frb via fpc-devel wrote:

Anyway, I changed the make
 make install INSTALL_PREFIX=/home/m/fpc/$INSTPATH/gw3  OPT=" 
-Clv16.0 " LLVM=1


Then next it fails, with the same error on
    make clean

Yes, it tries to compile a file while doing "make clean"



Even stranger, if I do  delete the ppc1 before "make clean"
rm /home/m/fpc/$INSTSRC/source/compiler/ppc*

Then "make clean" will build a new ppc1. Why?



make cycleclean
make[5]: Entering directory '/home/m/fpc/rel_3.3.1/source/compiler'
/usr/bin/rm -f x86_64/bin/x86_64-linux/pp x86_64/bin/x86_64-linux/pp.o 
x86_64/bin/x86_64-linux/pp.bclibppp.a x86_64/bin/x86_64-linux/libimppp.a

/usr/bin/rm -rf units
/usr/bin/rm -rf bin
/usr/bin/rm -f *.o *.bc *.ppu *.rst *.s *.a *.so *.ppl
/usr/bin/rm -rf *.sl
/usr/bin/rm -f fpcmade.* Package.fpc *.fpm
/usr/bin/rm -f   script*.res link*.res *_script.res *_link.res
/usr/bin/rm -f ./ppas.sh *_ppas.sh ppas.sh ppaslink.sh
make -C utils cleanall
make[6]: Entering directory '/home/m/fpc/rel_3.3.1/source/compiler/utils'
/usr/bin/rm -f fpc ppufiles ppudump ppumove mka64ins mkarmins mkx86ins 
msg2inc mkx86inl mkz80ins fpc.o ppufiles.o ppudump.o ppumove.o 
mka64ins.o mkarmins.o mkx86ins.o msg2inc.o mkx86inl.o mkz80ins.o fpc.bc 
ppufiles.bc ppudump.bc ppumove.bc mka64ins.bc mkarmins.bc mkx86ins.bc 
msg2inc.bc mkx86inl.bc mkz80ins.bclibpfpc.a libpppufiles.a libpppudump.a 
libpppumove.a libpmka64ins.a libpmkarmins.a libpmkx86ins.a libpmsg2inc.a 
libpmkx86inl.a libpmkz80ins.a libimpfpc.a libimpppufiles.a 
libimpppudump.a libimpppumove.a libimpmka64ins.a libimpmkarmins.a 
libimpmkx86ins.a libimpmsg2inc.a libimpmkx86inl.a libimpmkz80ins.a

/usr/bin/rm -f units/x86_64-linux/ppu.ppu units/x86_64-linux/crc.ppu
/usr/bin/rm -rf units
/usr/bin/rm -rf bin
/usr/bin/rm -f *.o *.bc *.ppu *.rst *.s *.a *.so *.ppl
/usr/bin/rm -rf *.sl
/usr/bin/rm -f fpcmade.* Package.fpc *.fpm
/usr/bin/rm -f   script*.res link*.res *_script.res *_link.res
/usr/bin/rm -f ./ppas.sh *_ppas.sh ppas.sh ppaslink.sh
make[6]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler/utils'
/usr/bin/rm -rf x86_64/units
/usr/bin/rm -rf x86_64/bin
/usr/bin/rm -f x86_64/*.o x86_64/*.ppu x86_64/*.rst x86_64/*.s 
x86_64/*.a x86_64/*.so x86_64/*.ppl
/usr/bin/rm -f x86_64/ppc386 x86_64/ppc68k x86_64/ppcppc x86_64/ppcsparc 
x86_64/ppcarm x86_64/ppcarmeb x86_64/ppcx64 x86_64/ppcppc64 
x86_64/ppcmips x86_64/ppcmipsel x86_64/ppcmips64 x86_64/ppcmips64el 
x86_64/ppcavr x86_64/ppcjvm x86_64/ppc8086 x86_64/ppca64 
x86_64/ppcsparc64 x86_64/ppcrv32 x86_64/ppcrv64 x86_64/ppcxtensa 
x86_64/ppcz80 x86_64/ppcwasm32 x86_64/ppcloongarch64

/usr/bin/rm -f ppcx64
make[5]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler'
make compiler
make[5]: Entering directory '/home/m/fpc/rel_3.3.1/source/compiler'
/usr/bin/mkdir -p x86_64/units/x86_64-linux
/usr/bin/mkdir -p x86_64/bin/x86_64-linux
/home/m/fpc/svn/ppcx64_3_2_2 -Ur -Xs -O2 -n -Fux86_64 -Fusystems 
-Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -Fix86_64 
-FEx86_64/bin/x86_64-linux -FUx86_64/units/x86_64-linux -Cg 
-Fl/usr/lib/gcc/x86_64-redhat-linux/13 -dRELEASE -O-1 -gw3  -dx86_64 
-dGDB -dllvm -Fullvm -Fux86 -Fix86 
-o/home/m/fpc/rel_3.3.1/source/compiler/ppc1 pp.pas

make[5]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler'
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Getting error building fpc for clang 16

2023-12-09 Thread Martin Frb via fpc-devel

On 09/12/2023 10:50, Jonas Maebe via fpc-devel wrote:

On 07/12/2023 13:52, Martin Frb via fpc-devel wrote:

I also looked for msg2inc. And msg2inc was compiled before


Maybe check the timestamps of compiler/msg*.inc, 
compiler/utils/msg2inc.pp and compiler/msg/errore.msg. Perhaps some of 
those have timestamps far in the future?


The seem ok to me. Either checkout date, or build date.

Anyway, I changed the make
 make install INSTALL_PREFIX=/home/m/fpc/$INSTPATH/gw3  OPT=" 
-Clv16.0 " LLVM=1


Then next it fails, with the same error on
    make clean

Yes, it tries to compile a file while doing "make clean"

Interestingly, "make clean" refuses to start, unless it has a compiler 
in path (ok, even if it should not need it, as it should not compile 
anything...), but then it uses  source/compiler/ppc1


make[8]: '/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux' is up to 
date.

make[8]: Leaving directory '/home/m/fpc/rel_3.3.1/source/rtl/linux'
as --64 -o /home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux/abitag.o 
x86_64/abitag.as
/home/m/fpc/rel_3.3.1/source/compiler/ppc1 -Ur -Ur -Xs -O2 -n -Fi../inc 
-Fi../x86_64 -Fi../unix -Fix86_64 -FE. 
-FU/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -Cg 
-Fl/usr/lib/gcc/x86_64-redhat-linux/13 -O-1 -gw3 -dx86_64 -dRELEASE -Us 
-Sg system.pp
/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux/system.ll:9990:76: 
error: expected '('
define void @"\01SYSTEM_$$_STRPAS$PANSICHAR$$SHORTSTRING"([256 x i8]* 
sret noalias nocapture %p.$result, i8* %p.p) inlinehint nobuiltin 
"null-pointer-is-valid"="true" strictfp !dbg !1643 {

^
1 error generated.

--
the files with date, after "make all" before "make install" got started:

[m@fedora fpc]$ find rel_3.3.1/source/ -name '*msg2inc*' | xargs ls -la
-rwxr-xr-x. 1 m m 341048 Dec  9 12:12 
rel_3.3.1/source/compiler/utils/msg2inc
-rw-r--r--. 1 m m  20180 Dec  6 23:07 
rel_3.3.1/source/compiler/utils/msg2inc.pp
-rw-r--r--. 1 m m  63416 Dec  9 12:12 
rel_3.3.1/source/compiler/utils/units/x86_64-linux/msg2inc.o


[m@fedora fpc]$ ls -la rel_3.3.1/source/compiler/msg*inc*
-rw-r--r--. 1 m m  47096 Dec  6 23:07 rel_3.3.1/source/compiler/msgidx.inc
-rw-r--r--. 1 m m 112167 Dec  6 23:07 rel_3.3.1/source/compiler/msgtxt.inc

[m@fedora fpc]$ ls -la rel_3.3.1/source/compiler/msg/*
-rw-r--r--. 1 m m 139307 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorct.msg
-rw-r--r--. 1 m m 244571 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorda.msg
-rw-r--r--. 1 m m 304534 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errord.msg
-rw-r--r--. 1 m m 305647 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errordu.msg
-rw-r--r--. 1 m m 291024 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errore.msg
-rw-r--r--. 1 m m 246429 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errores.msg
-rw-r--r--. 1 m m 250649 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorfi.msg
-rw-r--r--. 1 m m 105908 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorf.msg
-rw-r--r--. 1 m m 151642 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorhe.msg
-rw-r--r--. 1 m m 258978 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorheu.msg
-rw-r--r--. 1 m m 248955 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorid.msg
-rw-r--r--. 1 m m 188895 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/erroriu.msg
-rw-r--r--. 1 m m 241199 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorn.msg
-rw-r--r--. 1 m m 136463 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorpli.msg
-rw-r--r--. 1 m m 136451 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorpl.msg
-rw-r--r--. 1 m m 220070 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorpt.msg
-rw-r--r--. 1 m m 255864 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorptu.msg
-rw-r--r--. 1 m m 177521 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorr.msg
-rw-r--r--. 1 m m 347094 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorru.msg
-rw-r--r--. 1 m m 246714 Dec  6 23:07 
rel_3.3.1/source/compiler/msg/errorues.msg


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Getting error building fpc for clang 16

2023-12-07 Thread Martin Frb via fpc-devel

On 07/12/2023 13:52, Martin Frb via fpc-devel wrote:

On 07/12/2023 12:19, Jonas Maebe via fpc-devel wrote:



On 2023-12-07 01:09, Martin Frb via fpc-devel wrote:

But I am getting

make[8]: '/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux' is up 
to date.

make[8]: Leaving directory '/home/m/fpc/rel_3.3.1/source/rtl/linux'
as --64 -o 
/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux/abitag.o 
x86_64/abitag.as
/home/m/fpc/rel_3.3.1/source/compiler/ppc1 -Ur -Ur -Xs -O2 -n 
-Fi../inc -Fi../x86_64 -Fi../unix -Fix86_64 -FE. 
-FU/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -Cg 
-Fl/usr/lib/gcc/x86_64-redhat-linux/13 -dx86_64 -dRELEASE  -Us -Sg 
system.pp


The -Clv parameter is missing here for some reason, so the compiler 
is generating code for LLVM 7.0 rather than 16.0.


It seems to happen during "make install". Strange, why does it compile 
during installation?


Starting compiler is 3.2.2

I should mention that the compiler is not installed to /usr/ , nor 
anywhere in a global available place. (As I have several versions on 
that machine, I made sure non of them has anything in a place where it 
could be found by others.  (that includes no /etc/fpc.cfg, nor fpc.cfg 
in my home dir. / each fpc has an fpc.cfg inside its install dir)


But before the make is called the PATH is set to include the 3.2.2 fpc.

I use identical setup on several Linux boxes, including the one that 
successfully build with clang 11

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Getting error building fpc for clang 16

2023-12-07 Thread Martin Frb via fpc-devel

On 07/12/2023 12:19, Jonas Maebe via fpc-devel wrote:



On 2023-12-07 01:09, Martin Frb via fpc-devel wrote:

But I am getting

make[8]: '/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux' is up 
to date.

make[8]: Leaving directory '/home/m/fpc/rel_3.3.1/source/rtl/linux'
as --64 -o 
/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux/abitag.o 
x86_64/abitag.as
/home/m/fpc/rel_3.3.1/source/compiler/ppc1 -Ur -Ur -Xs -O2 -n 
-Fi../inc -Fi../x86_64 -Fi../unix -Fix86_64 -FE. 
-FU/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -Cg 
-Fl/usr/lib/gcc/x86_64-redhat-linux/13 -dx86_64 -dRELEASE  -Us -Sg 
system.pp


The -Clv parameter is missing here for some reason, so the compiler is 
generating code for LLVM 7.0 rather than 16.0.


It seems to happen during "make install". Strange, why does it compile 
during installation?


My script issues the following commands:
(I am using the same on another machine with clang 11)

make clean
make all  OPT=" " OPTNEW=" -Clv16.0 " FPCMAKEOPT=" -Clv16.0 " LLVM=1
make install INSTALL_PREFIX=/home/m/fpc/$INSTPATH/def  LLVM=1

The captured output does not have the commands itself, only the output
The "100%" should still be from the "make all" (there is no install in 
the text before that)


I assume "installbase" is the start of the output of above make install.

And then it starts the compiler Why?

Before that there are 10 other occurrences of
   "Entering directory '/home/m/fpc/rel_3.3.1/source/compiler/utils'"


[100%] Compiled package utils-wasmbin
make[2]: Leaving directory '/home/m/fpc/rel_3.3.1/source/utils'
make[1]: Leaving directory '/home/m/fpc/rel_3.3.1/source'
/usr/bin/echo Build > build-stamp.x86_64-linux
/usr/bin/echo Build > base.build-stamp.x86_64-linux
make installbase FPC=/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 
ZIPDESTDIR=/home/m/fpc/rel_3.3.1/source 
FPCMAKE=/home/m/fpc/rel_3.3.1/source/utils/fpcm/bin/x86_64-linux/fpcmake

make[1]: Entering directory '/home/m/fpc/rel_3.3.1/source'
/usr/bin/install -m 755 -d /home/m/fpc/rel_3.3.1/clang64/def/lib/fpc/3.3.1
/usr/bin/install -m 755 -d /home/m/fpc/rel_3.3.1/clang64/def/bin
make compiler_distinstall 
FPC=/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 
ZIPDESTDIR=/home/m/fpc/rel_3.3.1/source 
FPCMAKE=/home/m/fpc/rel_3.3.1/source/utils/fpcm/bin/x86_64-linux/fpcmake

make[2]: Entering directory '/home/m/fpc/rel_3.3.1/source'
make -C compiler distinstall
make[3]: Entering directory '/home/m/fpc/rel_3.3.1/source/compiler'
make quickinstall auxfilesinstall
make[4]: Entering directory '/home/m/fpc/rel_3.3.1/source/compiler'
make -C utils install
make[5]: Entering directory '/home/m/fpc/rel_3.3.1/source/compiler/utils'
/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 -Ur -Xs -O2 -n -Fu.. 
-Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -FE. 
-FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-redhat-linux/13 
-dx86_64 -dRELEASE msg2inc.pp

units/x86_64-linux/msg2inc.ll:663:71: error: expected '('
    invoke  void (i8**, i8*, i64, i64) @"\01fpc_ansistr_copy" (i8** 
sret %reg.1_276, i8* %reg.1_275, i64 %reg.1_274, i64 %reg.1_270) to 
label %.Lj88 unwind label %.Lj9

^
1 error generated.
Error: Error while assembling exitcode 1


=
I also looked for msg2inc. And msg2inc was compiled before

msg2inc.pp is only twice in the log. As below, and as in the error above

Without the pp extension it is present in a few "rm". All above the 
below snippet


make[5]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler/utils'
/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 -Clv16.0 -Ur -Xs -O2 -n 
-Fu.. -Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -FE. 
-FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-redhat-linux/13 
-dx86_64 -dRELEASE mka64ins.pp
/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 -Clv16.0 -Ur -Xs -O2 -n 
-Fu.. -Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -FE. 
-FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-redhat-linux/13 
-dx86_64 -dRELEASE mkarmins.pp
/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 -Clv16.0 -Ur -Xs -O2 -n 
-Fu.. -Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -FE. 
-FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-redhat-linux/13 
-dx86_64 -dRELEASE mkx86ins.pp
/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 -Clv16.0 -Ur -Xs -O2 -n 
-Fu.. -Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -FE. 
-FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-redhat-linux/13 
-dx86_64 -dRELEASE msg2inc.pp
/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 -Clv16.0 -Ur -Xs -O2 -n 
-Fu.. -Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -FE. 
-FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-redhat-linux/13 
-dx86_64 -dRELEASE mkx86inl.pp
/home/m/fpc/rel_3.3.1/source/compiler/ppcx64 -Clv16.0 -Ur -Xs -O2 -n 
-Fu.. -Fu/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -FE. 
-FUunits/x86_64-linux -Cg -Fl/usr/lib/gcc/x86_64-redhat-linux/13 
-dx86_64 -dRELE

[fpc-devel] Getting error building fpc for clang 16

2023-12-06 Thread Martin Frb via fpc-devel
I was trying to build an fpc for clang 16 (same commands worked on a 
diff machine for clang 11)


I changed the version in the make line:
  make all  OPT=" " OPTNEW=" -Clv16.0 " FPCMAKEOPT=" -Clv16.0 " LLVM=1

I also tried version 16.0.6

fpc 49cb7b256476409924c581145a760b863b9e755d
(I had tried earlier with an older fpc on that machine. I don't know if 
the error was the same)


clang --version
clang version 16.0.6 (Fedora 16.0.6-3.fc38)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

But I am getting

make[8]: '/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux' is up to 
date.

make[8]: Leaving directory '/home/m/fpc/rel_3.3.1/source/rtl/linux'
as --64 -o /home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux/abitag.o 
x86_64/abitag.as
/home/m/fpc/rel_3.3.1/source/compiler/ppc1 -Ur -Ur -Xs -O2 -n -Fi../inc 
-Fi../x86_64 -Fi../unix -Fix86_64 -FE. 
-FU/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux -Cg 
-Fl/usr/lib/gcc/x86_64-redhat-linux/13 -dx86_64 -dRELEASE  -Us -Sg system.pp
/home/m/fpc/rel_3.3.1/source/rtl/units/x86_64-linux/system.ll:9713:76: 
error: expected '('
define void @"\01SYSTEM_$$_STRPAS$PANSICHAR$$SHORTSTRING"([256 x i8]* 
sret noalias nocapture %p.$result, i8* %p.p) inlinehint nobuiltin 
"null-pointer-is-valid"="true" strictfp {

^
1 error generated.
system.pp(747,1) Error: Error while assembling exitcode 1
system.pp(747,1) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
make[7]: *** [Makefile:2870: system.ppu] Error 1
make[7]: Leaving directory '/home/m/fpc/rel_3.3.1/source/rtl/linux'
make[6]: *** [Makefile:2367: linux_all] Error 2
make[6]: Leaving directory '/home/m/fpc/rel_3.3.1/source/rtl'
make[5]: *** [Makefile:5486: rtl] Error 2
make[5]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler'
make[4]: *** [Makefile:5319: next] Error 2
make[4]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler'
make[3]: *** [Makefile:5327: ppc2] Error 2
make[3]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler'
make[2]: *** [Makefile:5337: cycle] Error 2
make[2]: Leaving directory '/home/m/fpc/rel_3.3.1/source/compiler'
make[1]: *** [Makefile:3256: compiler_cycle] Error 2
make[1]: Leaving directory '/home/m/fpc/rel_3.3.1/source'
make: *** [Makefile:3288: build-stamp.x86_64-linux] Error 2

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Wrong debug info when using clang backend

2023-12-06 Thread Martin Frb via fpc-devel

On 06/12/2023 21:58, Martin Frb via fpc-devel wrote:

On 06/12/2023 21:05, Jonas Maebe via fpc-devel wrote:

On 06/12/2023 17:37, Martin Frb via fpc-devel wrote:

Not suer if the issue is within Fpc or clang...

Should this be reported against Fpc?


FPC defines the variables' debug info at the start of the function 
and defines their lifetime as starting at the beginning of the 
function and continuing until the end. But LLVM is free to modify 
these if it notices these are too pessimistic


My guess is that even without optimisations, LLVM notices these 
variables' values are not really used later on and reduces the 
variables' live range.


Strange, then clang has a serious issue.


But, yes it probably is clang.

If I have enough code, so clang does not optimize the entire function 
away in -O1, then clang writes info for some of the lines.

Actually the variable is in a (or several?) registers.
And clang misses some lines too.
But it covers some lines in the procedure.


With -O- it never is in a register...
Well it gets loaded sometimes, but it' always also on the stack.
Seems like clang doesn't see it while it is on the stack.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Wrong debug info when using clang backend

2023-12-06 Thread Martin Frb via fpc-devel

On 06/12/2023 21:05, Jonas Maebe via fpc-devel wrote:

On 06/12/2023 17:37, Martin Frb via fpc-devel wrote:

Not suer if the issue is within Fpc or clang...

Should this be reported against Fpc?


FPC defines the variables' debug info at the start of the function and 
defines their lifetime as starting at the beginning of the function 
and continuing until the end. But LLVM is free to modify these if it 
notices these are too pessimistic


My guess is that even without optimisations, LLVM notices these 
variables' values are not really used later on and reduces the 
variables' live range.


Strange, then clang has a serious issue.

I changed the code, so they are used. Still clang only defines the 
location list for the "end" keyword.

(I also removed the nested aspect)

Which in this case is
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:17  end;
0040143A 4883C448 add rsp,$48
0040143E C3   ret

And the location list covers those 2 statements.

Maybe it's the version of clang (if anyone has a newer one setup...)

Is there a way to see what fpc tells clang? (in human readable form)


program clang_nested_proc_1;
{$mode objfpc}

  procedure Bar(a, b: integer);
  var
    c,d: integer;
  begin
    c:=Random(99);
    d:=Random(99);
    writeln(a,b,c,d);
    d:=d+a;
    c:=c+b;
    writeln(a,b,c,d);
  end;

procedure Foo;
begin
  Bar(1,2);
end;

begin
  Foo;
end.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Wrong debug info when using clang backend

2023-12-06 Thread Martin Frb via fpc-devel

Not suer if the issue is within Fpc or clang...

Should this be reported against Fpc?

- Fedora 33
- Fpc 3.3.1  from Sept 26th
- make all  OPT=" " OPTNEW=" -Clv11.0 " FPCMAKEOPT=" -Clv11.0 " LLVM=1
- clang --version
  clang version 11.0.0 (Fedora 11.0.0-3.fc33)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  InstalledDir: /usr/bin


Program at the end of this mail was compiled with -O-

Assembler for nested procedure Bar
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:8 begin
004012D0 897424F8 mov [rsp-$08],esi
004012D4 895424F0 mov [rsp-$10],edx
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:9  a := 1;
004012D8 C74424F80100 mov [rsp-$08],$0001
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:10  b := 1;
004012E0 C74424F00100 mov [rsp-$10],$0001
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:11  c:=2;
004012E8 C74424E40200 mov [rsp-$1C],$0002
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:12  d:=2;
004012F0 C74424E00200 mov [rsp-$20],$0002
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:13  d:=2;
004012F8 C74424E00200 mov [rsp-$20],$0002
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:14  end;
00401300 C3   ret

Variables d and c are encoded using a location list
 <2><9c>: Abbrev Number: 3 (DW_TAG_variable)
    <9d>   DW_AT_location    : 0x24 (location list)
       DW_AT_name    : (indirect string, offset: 0xab): D
       DW_AT_decl_file   : 1
       DW_AT_decl_line   : 7
       DW_AT_type    : <0xdb>
 <2>: Abbrev Number: 3 (DW_TAG_variable)
       DW_AT_location    : 0x48 (location list)
       DW_AT_name    : (indirect string, offset: 0xad): C
       DW_AT_decl_file   : 1
       DW_AT_decl_line   : 7
       DW_AT_type    : <0xdb>

Contents of the .debug_loc section:
    Offset   Begin    End  Expression
     004012c3 004012c5 (DW_OP_breg7 (rsp): 0)
    0014 
    0024 00401300 00401301 (DW_OP_breg7 (rsp): -32)
    0038 
    0048 00401300 00401301 (DW_OP_breg7 (rsp): -28)
    005c 

Both location lists specify the variable is only available from 
00401300 00401301

- That covers exactly the asm "ret" statement.
- Yet the variables are stored on the frame ([rsp-$1C] / [rsp-$20]) => 
so they are available before.




program clang_nested_proc_1;
{$mode objfpc}

procedure Foo;
  procedure Bar(a, b: integer);
  var
    c,d: integer;
  begin
    a := 1;
    b := 1;
    c:=2;
    d:=2;
    d:=2;
  end;
begin
  Bar(1,2);
end;

begin
  Foo;
end.



line info confirms the addresses from the asm.

Contents of the .debug_line section:
CU: clang_nested_proc_1.lpr:
File name    Line number    Starting address    
View    Stmt

clang_nested_proc_1.lpr   15 0x4012b0   x
clang_nested_proc_1.lpr   16 0x4012b4   x
clang_nested_proc_1.lpr   17 0x4012c3   x
clang_nested_proc_1.lpr    8 0x4012d0   x
clang_nested_proc_1.lpr    8 0x4012d0   1   x
clang_nested_proc_1.lpr    9 0x4012d8   x
clang_nested_proc_1.lpr   10 0x4012e0   x
clang_nested_proc_1.lpr   11 0x4012e8   x
clang_nested_proc_1.lpr   12 0x4012f0   x
clang_nested_proc_1.lpr   13 0x4012f8   x
clang_nested_proc_1.lpr   14 0x401300   x
clang_nested_proc_1.lpr   19 0x401310   x
clang_nested_proc_1.lpr   19 0x401311   x
clang_nested_proc_1.lpr   20 0x401316   x
clang_nested_proc_1.lpr   21 0x40131b   x
clang_nested_proc_1.lpr   21 0x401322   x




___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] vargars vs array of const for WinAPI

2023-11-10 Thread Martin Frb via fpc-devel

On 09/11/2023 22:19, Marco van de Voort via fpc-devel wrote:


Op 9-11-2023 om 20:47 schreef Martin Frb via fpc-devel:
I saw that in some places (I think gtk2) "varargs" is used for open 
arrray API calls.


Any reason that is not adapted for Windows (overloaded)?


It probably is newer (kylix). I'm not sure anyway what the problem is? 
Why would varargs be better




Not a big deal... Just in case of porting stuff from (newer?) Delphi.

Probably only of interrest if both syntax can live as overloads.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Bug #38492

2023-11-10 Thread Martin Frb via fpc-devel

On 10/11/2023 10:49, Adriaan van Os via fpc-devel wrote:
Sorry, but I am looking for a diff for fpc bug #38492. Mantis says 
"'Fixed in Revision: 38492" which looks like a mistake, as 38492 is 
the bug number. Also gitlab reports fix #11ef1d17 which is instead a 
register allocation fix.


Is the fix already in fpc-3.2 fixes ?


searching the log messages:


ff3f812d979e57b49463224a814c64e027670d2d

*   * fix conversion of true/false macro definitions to boolean values
    (mantis #38492)
   o since the macro lookups are recursive, "mac" will usually be nil
 afterwards (unless we found an undefined macro)

git-svn-id: trunk@49160 -


And (if this is the correct commit) you can check if this file is in 
fixes (newly added)


\tests\webtbs\tw38492.pp

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] vargars vs array of const for WinAPI

2023-11-09 Thread Martin Frb via fpc-devel
I saw that in some places (I think gtk2) "varargs" is used for open 
arrray API calls.


Any reason that is not adapted for Windows (overloaded)?

function wsprintfA(_para1:LPSTR; _para2:LPCSTR; const args:array of 
const):longint; cdecl; external 'user32' name 'wsprintfA';
function wsprintf(_para1:LPSTR; _para2:LPCSTR; const args:array of 
const):longint; cdecl; external 'user32' name 'wsprintfA';


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] About the var param in CreateConsoleScreenBuffer

2023-11-09 Thread Martin Frb via fpc-devel

On 09/11/2023 14:19, Marco van de Voort via fpc-devel wrote:


Anyway, standard procedure in such cases is to move the pascallized 
declaration to redef.inc and have a pointer value in the original 
place. Which I just commited to GIT.


Thanks. Merge-able?


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] About the var param in CreateConsoleScreenBuffer

2023-11-09 Thread Martin Frb via fpc-devel

Fpc defines
function CreateConsoleScreenBuffer(dwDesiredAccess:DWORD; 
dwShareMode:DWORD; var lpSecurityAttributes:SECURITY_ATTRIBUTES; 
dwFlags:DWORD; lpScreenBufferData:LPVOID):HANDLE; external 'kernel32' 
name 'CreateConsoleScreenBuffer';


`lpSecurityAttributes` is a `var` param in the above. But 
https://learn.microsoft.com/en-us/windows/console/createconsolescreenbuffer 
states that the param is optional and can be null/nil.

var param don't accept nil. So this should be a pointer instead.

Yet,  this was reported in 
https://gitlab.com/freepascal.org/fpc/source/-/issues/5836

That issue got closed "*Fixed in version:* 1.9.9"
Only "git blame" shows no change to that line ever. (Well afaik some 
commits are not in git, so could be).


So the question is: Was it fixed and broken again? Was it fixed but not 
committed?

Or does the cryptic comment


Pascal CONST can be both by reference (thus consuming a *) or by value.

This is the only safe way.


mean its a "wont fix" ?
And if that is the case, then what does this comment mean?___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] make OPT= OPTFPC= NEWOPT=

2023-10-06 Thread Martin Frb via fpc-devel

On 06/10/2023 15:11, Marco van de Voort via fpc-devel wrote:


Op 6-10-2023 om 14:28 schreef Martin Frb via fpc-devel:

What is the difference between those 3?


OPT= always to my best knowledge

NEWOPT is opt only for later cycles and the rest, iow not for the 
first FPC bootstrap cycle (that might be started with an older 
compiler version).  So it is for additional options that are not 
supported by the bootstrap compiler, but are supported by the newer 
compiler.


Thanks.

I may have found why it didn't work. Two OPT for one make. pebkac.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] make OPT= OPTFPC= NEWOPT=

2023-10-06 Thread Martin Frb via fpc-devel

What is the difference between those 3?

I came across OPTNEW here https://wiki.freepascal.org/LLVM

But now I am trying to play with the rather old fpc build script for the 
laz installer.

And it calls

%MAKEEXE% compiler_cycle PP=%RELEASE_PPC% >> %LOGFILE% 2>&1
%MAKEEXE% rtl_clean  PP=%COMPILER% >> %LOGFILE%
%MAKEEXE% rtl packages  PP=%COMPILER% OPT="-Ur -CX" >> %LOGFILE%
%MAKEEXE% utils  PP=%COMPILER% OPT="-CX -XX -Xs" 
DATA2INC=%SOURCE_DIR%\utils\data2inc >>

...

And giving it just OPT= does not seem to do the trick.


Oh, yes of course, ideally rewrite that old script... Well "someday" 
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] ppc3.exe ppc386.exe differ: char 665, line 2

2023-09-26 Thread Martin Frb via fpc-devel

I am getting the error in the subject
ececf26d872c9fdc0a315c6289df864f66a1f69a


make.exe all LINKSMART=1  CREATESMART=1  OPTIMIZE=1  OPT="-CX -gl -O4 
-Ooregvar" FPC=C:\FPC\fpc_3.2.2\32\def\bin\i386-win32\fpc.exe   
OPTNEW="-CX -gl -O4 -Ooregvar"  FPMAKEOPT="-T 6"




c:/FPC/fpc_3.3.1/source/compiler/ppc3.exe -XX -CX -Ur -Xs -O2 -n -O2 
-Fui386 -Fusystems -Fuc:/FPC/fpc_3.3.1/source/rtl/units/i386-win32 
-Fii386 -FEi386/bin/i386-win32 -FUi386/units/i386-win32 -dRELEASE -CX 
-gl -O4 -Ooregvar   -CX -gl -O4 -Ooregvar -di386 -dGDB -Fux86 -Fix86 
-Sew -oc:/FPC/fpc_3.3.1/source/compiler/ppc386.exe pp.pas

make.exe[4]: Leaving directory `c:/FPC/fpc_3.3.1/source/compiler'
make.exe echotime
make.exe[4]: Entering directory `c:/FPC/fpc_3.3.1/source/compiler'
Start  now 12:06:00
make.exe[4]: Leaving directory `c:/FPC/fpc_3.3.1/source/compiler'
make.exe[3]: Leaving directory `c:/FPC/fpc_3.3.1/source/compiler'
B:/FPC/SVN/fpc_build/install/binw32/cmp.exe -i218 ppc3.exe ppc386.exe
ppc3.exe ppc386.exe differ: char 665, line 2
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] DW_AT_declaration

2023-09-04 Thread Martin Frb via fpc-devel
While looking at 
https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/448#note_1540865966


DW_AT_declaration came up.

From the DWARF 5 spec
A debugging information entry that represents a non-defining or 
otherwise 11 incomplete declaration of a program entity has a 
DW_AT_declaration attribute, 12 which is a flag.


From further reading through the spec it seems to refer to
  "the name being declared but not defined"
- the actual definition of the type is not included here (may be in a 
diff scope/unit)

- the implementation of the procedure is not included


Then I found it in debug info generated by FPC:


  TScreen = class(TLCLComponent)
  private const
    crScreen = Low(TCursor); // use with 
Screen.BeginTempCursor/EndTempCursor to add Screen.Cursor into the temp list



 <0>: Abbrev Number: 1 (DW_TAG_compile_unit)
       DW_AT_name    : forms.pp
       DW_AT_producer    : Free Pascal 3.2.3 2023/06/21
       DW_AT_comp_dir    : B:/lazarus_main/lcl/
...
...
 <1><103e29>: Abbrev Number: 20 (DW_TAG_class_type)
    <103e2a>   DW_AT_name    : TScreen
    <103e32>   DW_AT_byte_size   : 376
...
 <2><103e3d>: Abbrev Number: 68 (DW_TAG_member)
    <103e3e>   DW_AT_name    : crScreen
    <103e47>   DW_AT_declaration : 1
    <103e48>   DW_AT_external    : 1
    <103e49>   DW_AT_type    : <0x115cf7>
    <103e4d>   DW_AT_const_value : -32768


But this isn't an "incomplete declaration".

Everything is in place? Why is the tag added?
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Just to confirm, "with" behaviour expected

2023-08-14 Thread Martin Frb via fpc-devel

On 14/08/2023 14:52, Michael Van Canneyt via fpc-devel wrote:


On Mon, 14 Aug 2023, Martin Frb via fpc-devel wrote:



Does "with" take the "address" of the value, and operate on that 
address, even if the address of that value could change within the 
"with" statement.


You may not do this. It is even documented.

See the remark at the end of this page:

https://www.freepascal.org/docs-html/current/ref/refsu62.html#x172-19600013.2.8 



Ups, sorry I didn't research the details first.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Just to confirm, "with" behaviour expected

2023-08-14 Thread Martin Frb via fpc-devel
In the below code, the array is resized (and more important relocated in 
mem) inside the function "bar".


The commented line (without "with") works as expected.

The "with" line has a different behaviour. I guess it is by design. Just 
wanted to confirm.


The version with "with" prints 12345 for  "  writeln(a[i,j].x);"
For all I can tell the return value of "bar" was written to the old 
address of that array-entry.


Does "with" take the "address" of the value, and operate on that 
address, even if the address of that value could change within the 
"with" statement.


- test was performed with
   fpc 3.2.3  -O1
   fpc 3.3.1  -O4


program Project1;
{$mode objfpc}

procedure outer;
  var
    a: array of array of record x:Integer; end;
    i, j: integer;

  function bar(x: integer): integer;
  begin
    Result := random(99) + 2 * x;
    writeln(Result);
    SetLength(a, 3000, 200);
  end;

  procedure foo;
  begin
    i := random(99);
    j := random(99);
    with a[i,j] do x:= bar(x);
    //a[i,j].x := bar(a[i,j].x);
  end;

begin
  SetLength(a, 100, 100);
  for i := 0 to 99 do
    for j := 0 to 99 do
  a[i,j].x := 12345;

  foo;
  writeln(a[i,j].x);
  readln;
end;

begin
  outer;
end.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Maybe room for better documentation? open array as var param

2023-07-23 Thread Martin via fpc-devel

On 20/07/2023 18:41, Martin Frb via fpc-devel wrote:
For const param, it is well documented that the value (that includes 
the variable that is passed) must not be changed.


But for "var param"?


Actually my previous example was not even the generic case.

Passing any variable that is allocated on the Heap (a field of an 
instance, an element of an array) as a "var param" has the danger that 
it can be freed.


And yes, it should be obvious. If you intent to write to a variable, you 
must not destroy it.
However, you must also be aware, that in case of an array, if you just 
resize it, it may move => yet your var param will not follow that move.


I think it may be "interesting" enough to deserve a small note.

--
The below should brinte 200 to 209.
But it does print a 999 in the middle.




program Project1;
{$mode objfpc}

var x,y: array of integer;
  i: Integer;

procedure foo(var a: integer);
var
  j: Integer;
begin
  x := nil;
  SetLength(y, 10);
  for j := 0 to 9 do y[j] := 200+j;

  a := 999;
end;

begin
  SetLength(x, 10);
  for i := 0 to 9 do x[i] := 100+i;
  foo(x[5]);
  for i := 0 to 9 do writeln(y[i]);
  readln;
end.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Maybe room for better documentation? open array as var param

2023-07-20 Thread Martin Frb via fpc-devel

On 20/07/2023 19:24, Michael Van Canneyt via fpc-devel wrote:



It's IMO probably better to outright forbid passing open array by 
reference.


printing length(a) after x:=Nil; gives 10, which is simply wrong.


The open array is not the same as the dyn array.

It is at any point just a slice of the dyn array. (even if the slice has 
all elements of the dyn array).
At no point is it possible to do a SetLength on the open array (and 
therefore the lenght of the dyn array can't be changed either - not via 
the open array).


In otherwise the reference is only a reference to the members.
There is at no point a reference to the dyn array itself, nor to the length.


Of course if the underlaying data goes away, then the "var param" open 
array  (same as "const param") points to some memory


I don't know if it needs to be forbidden (don't mind if).
But I think
- explicit documentation
- a compiler note or warning might be helpful


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Maybe room for better documentation? open array as var param

2023-07-20 Thread Martin Frb via fpc-devel
For const param, it is well documented that the value (that includes the 
variable that is passed) must not be changed.


But for "var param"?

Well maybe, but not explicit
https://www.freepascal.org/docs-html/ref/refsu68.html#x184-20800014.4.5
>> Open parameters can be passed by value, by reference or as a 
constant parameter. In the latter cases the procedure receives a pointer 
to the actual array.


So a user with sufficient experience could detect that if a pointer is 
received, then the value which is pointed to must not be changed.


Maybe that should be mentioned more explicitly.
And maybe it should additionally also be mentioned on 
https://www.freepascal.org/docs-html/ref/refsu65.html



Because the below may be unexpected to quite a few users.

It will (at least on my test on windows / of course depends on mem 
manager) print numbers starting at 300.

Even so 200++ has been assigned.

But (with sufficient luck or lack of luck) "y" will re-use the memory of 
"x". And "a" will then change "y" which may not be expected.



program Project1;
{$mode objfpc}

var x,y: array of integer;
  i: Integer;

procedure foo(var a: array of integer);
var
  j: Integer;
begin
  x := nil;
  SetLength(y, 10);
  for j := 0 to 9 do y[j] := 200+j;

  for j := 0 to 9 do a[j] := 300+j;
end;

begin
  SetLength(x, 10);
  for i := 0 to 9 do x[i] := 100+i;
  foo(x);
  for i := 0 to 9 do writeln(y[i]);
  readln;
end.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] cthreads and fpc.cfg?

2023-07-19 Thread Martin Frb via fpc-devel

On 19/07/2023 10:22, Michael Van Canneyt via fpc-devel wrote:



The error is logical. What is not logical is that it pops up now.

By all logic, we should have seen this error pop up as early as 2016.

Why it pops up only now is a mystery that we need to solve...


I don't have all the details, but maybe there is something buried in the 
following findings.


The early call to threads happens in

#0  InitCriticalSection (cs=...) at ../inc/thread.inc:229
#1  0x0049ae18 in $create () at 
../objpas/sysutils/sysencoding.inc:214

#2  0x004a6749 in $SYSUTILS_$$_init$ () at ../unix/sysutils.pp:1903
#3  0x0041fc27 in $fpc_initializeunits () at ../inc/system.inc:1134
#4  0x004039be in $main () at fpcmkcfg/fpcmkcfg.pp:585


sysencoding.inc:214
class constructor TEncoding.Create;
hasn't changed recently... (according to git blame)
class constructor TEncoding.Create;
var
  E: TStandardEncoding;
begin
  for E := Low(FStandardEncodings) to High(FStandardEncodings) do
    FStandardEncodings[E] := nil;
{$ifdef FPC_HAS_FEATURE_THREADING}
  InitCriticalSection(FLock);
{$endif}
end;

I don't know if FPC_HAS_FEATURE_THREADING has changed?

Also
unix/sysutils.pp 1903
hasn't changed recently...

Initialization
  InitExceptions;   { Initialize exceptions. OS independent }
  InitInternational;    { Initialize internationalization settings }
  SysConfigDir:='/etc'; { Initialize system config dir }
  OnBeep:=@SysBeep;
{$ifdef android}
  InitAndroid;
{$endif android}


But the function uses a string
    SysConfigDir:='/etc';

Disassembly show it call "create" before InitExceptions
This code must have been inserted by the compiler...

So some recent change in string handling,  now inserts calls to encoding 
create ?


  0x4a6740 <$SYSUTILS_$$_init$>:    push   %rbp
   0x4a6741 <$SYSUTILS_$$_init$+1>:    mov    %rsp,%rbp
   0x4a6744 <$SYSUTILS_$$_init$+4>:    call   0x49ade0 <$create>
   0x4a6749 <$SYSUTILS_$$_init$+9>:    call   0x4a14a0 
   0x4a674e <$SYSUTILS_$$_init$+14>:    call   0x4a56a0 


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] cthreads and fpc.cfg?

2023-07-18 Thread Martin Frb via fpc-devel

On 18/07/2023 22:56, Martin via fpc-devel wrote:

Using 33dba315366ec3002e062c3aa6dcb15b88356580 (3.3.1)
My fpc.cfg looks like this / any idea?:

Threading has been used before cthreads was initialized.

Make cthreads one of the first units in your uses clause.


tried 757f65d0e283c9fd33f2f99e794203590711c686
still...
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] cthreads and fpc.cfg?

2023-07-18 Thread Martin via fpc-devel

Using 33dba315366ec3002e062c3aa6dcb15b88356580 (3.3.1)
My fpc.cfg looks like this / any idea?:

Threading has been used before cthreads was initialized.

Make cthreads one of the first units in your uses clause.



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Before 3.4 gets on the road, can anyone help with fpc Dwarf-properties extension (started by Joost)

2023-07-04 Thread Martin Frb via fpc-devel
Currently the debugger can not show properties (even though it can call 
functions).


DWARF does not know properties, but custom tags can be added. Joost 
started this  in the branch fork-gl/joost/dwarfproperties

https://gitlab.com/freepascal.org/fpc/source/-/tree/joost/dwarfproperties

Rebased at 
https://gitlab.com/martin_frb/fpc-src/-/commits/joost-dwarfproperties
I started on reading that info: 
https://gitlab.com/martin_frb/lazarus/-/commits/fpdebug-godwarfproperties


See bottom of the mail for Joost's original explanation.


Unfortunately I can't reach Joost.
And I really want that to be in 3.4 (whenever that will be).

Yet there are some issues (I am still testing, just what I found so far)

*** Issue 1)
Sometimes nhe references to the function/member are wrong.
I reproduced with a small test  (attached) -gw3 -godwarfproperties

In unit 1, all location for the getters are correct.
getter PropGetter at: 0x13c5
getter PropGetter2 at: 0x142f  (0x6a bytes higher)

In dwarf_prop_test.lpr the first property has the correct location for 
the getter.


But then the next property does not.
getter PropGetter at: 0x04b8
getter PropGetter2 at: 0x0522 (wrong, but also 0x6a bytes higher)

The actual GetPropGetter2 is at 4dd (only 0x25 bytes higher)

So somehow a value from the other unit was used? Or maybe this is 
because the address (low_pc) was omitted in the getter before, but the 
size for it was still added to the offset for the next getter?


In unit1
 <1><134e>: Abbrev Number: 4 (DW_TAG_class_type)

 <2><1381>: Abbrev Number: 7 (Unknown TAG value: 4230)
    <1382>   DW_AT_name    : PropGetter
    <138d>   Unknown AT value: 3230: <0x13c5>
 <2><1391>: Abbrev Number: 7 (Unknown TAG value: 4230)
    <1392>   DW_AT_name    : PropGetter2
    <139e>   Unknown AT value: 3230: <0x142f>

in dwarf_prop_test.lpr
 <1><441>: Abbrev Number: 5 (DW_TAG_class_type)
...
 <2><474>: Abbrev Number: 8 (Unknown TAG value: 4230)
    <475>   DW_AT_name    : PropGetter
    <480>   Unknown AT value: 3230: <0x4b8>
 <2><484>: Abbrev Number: 8 (Unknown TAG value: 4230)
    <485>   DW_AT_name    : PropGetter2
    <491>   Unknown AT value: 3230: <0x522>
...
 <2><4b8>: Abbrev Number: 14 (DW_TAG_subprogram)
    <4b9>   DW_AT_name    : GetPropGetter
...
 <2><4dd>: Abbrev Number: 14 (DW_TAG_subprogram)
    <4de>   DW_AT_name    : GetPropGetter2


*** Issue 2:
Nothing to do with Joosts code, but on Windows the entry pc for the 
methods aren't in the DWARF.


Well, the class is copied into each unit (on Linux there is a cross 
compile-units reference).
The copies are without entry_pc, but there is on pointer to were to find 
the original info (which may not be present, if that unit did not have 
debug info)




=
On 02/05/2022 09:56, Joost van der Sluis via Lazarusdev wrote:


Hi Martin, and all others,

Freepascal's joost/dwarfproperties branch has support for encoding 
properties inside the Dwarf debug-info. Properties are basically 
encoded as references to the underlying fields/methods.


Take this dwarfdump for example:

< 2><0x00ff>  DW_TAG_member
    DW_AT_name  FProp
    DW_AT_data_member_location  len 0x0002: 0x2308:
    DW_OP_plus_uconst 8
    DW_AT_type 
< 2><0x010d>  
    DW_AT_name  DoubleProp
     <0x019e>
    DW_AT_accessibility DW_ACCESS_public
< 2><0x011e>  
    DW_AT_name  SingleProp
     <0x00ff>
     <0x00ff>
    DW_AT_accessibility DW_ACCESS_public


0x4230 is a property
0x3230 is a getter
0x3231 is a setter

The SingleProp property references the FProp field.

You can enable this with 'fpc -gw3 -godwarfproperties' using the 
dwarfproperties branch.


I'm wondering how to handle this in fpDebug. I've did an attempt by 
creating a symbol that symply forwards everything. But that does not 
work very well


(https://gitlab.com/jvdsluis/lazarus-propdb/-/commit/d3853c23724ca63e561b82bc357bbf299fc3da1d) 



Whay do you think is the best approach? Introduce a new class that 
represents the property? Or add a lot of trickery to forward what is 
necessary, but not everything (like the accesibility)


Regards,

Joost.
program dwarf_prop_test;
{$Mode objfpc}
uses unit1;

type

  { TBar }

  TBar = class(TFoo)
  private
FBarPropField: byte;
function GetBarPropGetter: byte;
function GetBarPropGetter2: byte;
function GetBarPropGetter3: byte;
  published
property BarPropField:

Re: [fpc-devel] Cocoa and NOT relocatable

2023-06-08 Thread Martin Frb via fpc-devel

On 08/06/2023 19:59, Giuliano Colla via fpc-devel wrote:

Il 08/06/23 18:40, Martin Frb via fpc-devel ha scritto:


It seems that on Cocoa an exe is by default relocatable.
At least a basic test shows that dumping a stack at runtime for each 
run (no new compile) gives new addresses.


Fpc 3.2.2

Is there a way to turn this off? (some flag to pass to the linker?) 


AFAIK there's no way. It's a feature deep in the way the OS handles 
memory. In a multiprogramming environment any executable must be by 
definition relocatable, because at each run it must fit in a free area 
of memory. So the OS has two choices. Either the executable is not 
relocatable, and you trick it by altering the Memory Management Unit 
tables to map its virtual fixed addresses to any free memory area, or 
you make it relocatable, loose a little time when loading to locate 
it, and do not tamper with MMU mapping tables. It's a system design 
choice.


Great... Yes, it is an important security feature. But a show stopper 
for people who need to debug.


https://forum.lazarus.freepascal.org/index.php/topic,63571.0.html

1) Afaik, FPC still can't resolve addresses with -gl (the line info 
unit, that produces nice dumps on other Platforms).

2) Users can't later resolve them either.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Cocoa and NOT relocatable

2023-06-08 Thread Martin Frb via fpc-devel

It seems that on Cocoa an exe is by default relocatable.
At least a basic test shows that dumping a stack at runtime for each run 
(no new compile) gives new addresses.


Fpc 3.2.2

Is there a way to turn this off? (some flag to pass to the linker?)
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] $ZEROBASEDSTRINGS [[Re: DW_AT_external and other additions to FPC generated dwarf]]

2023-03-28 Thread Martin Frb via fpc-devel

On 28/03/2023 15:50, Martin Frb via fpc-devel wrote:

On 28/03/2023 15:03, Sven Barth via fpc-devel wrote:
Martin Frb via fpc-devel  schrieb am 
So., 26. März 2023, 16:50:


It also would fall short, if ever Fpc did what Delphi did:
{$ZEROBASEDSTRINGS }
Though, maybe that is a "wont ever happen".


FPC supports that directive since at least 3.2.0 (though apparently 
it was forgotten to be documented in the New Features page).




It is also missing here 
https://www.freepascal.org/docs-html/prog/progch1.html___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] $ZEROBASEDSTRINGS [[Re: DW_AT_external and other additions to FPC generated dwarf]]

2023-03-28 Thread Martin Frb via fpc-devel

On 28/03/2023 15:03, Sven Barth via fpc-devel wrote:
Martin Frb via fpc-devel  schrieb am 
So., 26. März 2023, 16:50:


It also would fall short, if ever Fpc did what Delphi did:
{$ZEROBASEDSTRINGS }
Though, maybe that is a "wont ever happen".


FPC supports that directive since at least 3.2.0 (though apparently it 
was forgotten to be documented in the New Features page).




I thought I had seen it somewhere... Maybe forum mention. But then I 
could only find it on a Delphi page.___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] DW_AT_external and other additions to FPC generated dwarf

2023-03-28 Thread Martin Frb via fpc-devel

On 26/03/2023 16:50, Martin Frb via fpc-devel wrote:

On 26/03/2023 15:50, Florian Klämpfl via fpc-devel wrote:
What about using DW_TAG_string_type for this? IIRC, when I 
implemented dwarf, it was not available/not supported, but fpdebug 
can do they. I am not sure about the status of GDB about it though :)


 It still needs to be added to fpdebug, but that will be easy.


Whether it will be used or not...
I added a basic version to FpDebug. Without DWARF-5, since I haven't 
even got test data for the basic DWARF 3/4 implementation.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Is this supposed to work (generic)?

2023-03-27 Thread Martin Frb via fpc-devel

On 27/03/2023 22:59, Sven Barth via fpc-devel wrote:

Am 26.03.2023 um 13:30 schrieb Martin Frb via fpc-devel:

  TSome = class;
  TSome = class(specialize GenLinkedList);



The correct way to declare a generic linked list using classes is the 
following:


=== code begin ===

type
  generic TGenLinkedList = class
    Data: D;
    Next: specialize TGenLinkedList;
  end;

  TSome = specialize TGenLinkedList;

=== code end ===


Ok, but the forward declaration (which is the only working one of my 
examples) is also important.
Not sure, why it needs the forward. After all, the forward also comes 
after the generic.



  generic TGenLinkedList = class
    Data: D;
    Next: C;
  end;

  TSome = class;
  TSome = class(specialize TGenLinkedList)
    other: boolean;
    procedure Foo;
  end;

procedure TSome.Foo;
begin
  Next.other := true; // Next must be type TSome, not just the 
specialized generic.

end;

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] DW_AT_external and other additions to FPC generated dwarf

2023-03-26 Thread Martin Frb via fpc-devel

On 26/03/2023 15:50, Florian Klämpfl via fpc-devel wrote:

Am 23.03.23 um 09:45 schrieb Martin Frb via fpc-devel:

It's a little hard to comment all at once, but at least I start with 
one :)



4) "official" marker for string vs pchar vs array



What about using DW_TAG_string_type for this? IIRC, when I implemented 
dwarf, it was not available/not supported, but fpdebug can do they. I 
am not sure about the status of GDB about it though :)


That would work.
But it can't distinguish between strings of char or widechar.  I.e. it 
can only be used for short and long-string(ansi). But not WideString or 
UnicodeString.
Only DWARF 5 introduces a "DW_AT_type" for DW_TAG_string_type that can 
then define the base type for each char.

Ignoring gdb, fpc could add that for lower dwarf versions too.


It also would fall short, if ever Fpc did what Delphi did: 
{$ZEROBASEDSTRINGS }

Though, maybe that is a "wont ever happen".


 It still needs to be added to fpdebug, but that will be easy.
It is present in gdb sources, but I have no idea how well it will then work.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Is this supposed to work (generic)?

2023-03-26 Thread Martin Frb via fpc-devel

3.2.3 and 3.3.1 on Win 64bit

Trying a generic linked list.
So the specialized class must have an entry for the "next" element. And 
that entry is of the same type as the class itself.


Now at first, this seems to be not possible using generics, because 
specialize does not allow to pass in the "partially done" class.

(the 2 commented lines produce "Error: Illegal expression")
Only it does work, if the class is forward declared.

So is it supposed to work?
And if it is in the last case, then what about the other two cases?


program Project1;
type
  generic GenLinkedList = class
    Data: D;
    Next: T;
  end;

  //TBar = specialize GenLinkedList;
  //TFoo = class(specialize GenLinkedList);

  TSome = class;
  TSome = class(specialize GenLinkedList);
begin
end.


Btw, it is the same, if the linked list uses actual pointer.

  generic GenLinkedList = class
    type  PT = ^T;
  public
    Data: D;
    NextPtr: PT;
  end;

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] DW_AT_external and other additions to FPC generated dwarf

2023-03-23 Thread Martin Frb via fpc-devel
After the brief exchange on 
https://gitlab.com/freepascal.org/fpc/source/-/issues/40208


There are various considerations (ideas/requests) to hopefully help 
improve debugging experience.


I have recently added 3 issues, but there is more. And I wanted to add a 
bit of background here, since it is not all black and white.


1) Scoped Enums https://gitlab.com/freepascal.org/fpc/source/-/issues/40208
2) Unit Search order 
https://gitlab.com/freepascal.org/fpc/source/-/issues/40209
3) DW_AT_external for types 
https://gitlab.com/freepascal.org/fpc/source/-/issues/40210

4) "official" marker for string vs pchar vs array
5) Duplicated (artificial) types under Windows
5a) Missing address for class methods
6) "var param" for function calls / managed param
...

---
1) is simple to reason (IMHO)
There is an example in sysutils:
  {$SCOPEDENUMS OFF}
  TUseBoolStrs = (False, True);

If the debugger reads this, before getting to the definition of the 
"True" (boolean), then expressions could fail if they contain the bool 
constants true/false.


---
2) is required for looking up global vars.
A global var of the same name can exist in different units.
If paused on some code
  if GlobalFoo > 5 then

The debugger needs to work out which GlobalFoo that is.

2) May or may not have an impact on type lookups. See 3.

---
3) DW_AT_external (or visibility) for types

After reconsidering, that one is actually more debatable. But IMHO still 
useful.


unit foo;
interface
implementation
type PCHAR = ^widechar; // does not want to be seen outside this unit.

Granted this is not the most likely case to happen. But it may happen.

At first types seem to be save-ish. If a variable is declared in the 
current unit (or otherwise found in the correct unit, according to "unit 
search order", then the debug info of that variable points to the 
correct type.

No ambiguity, not even with global types.

The issue occurs, when a user writes a watch, using type casts with 
global types (that aren't from the current unit).

 pchar(foo)
 pinteger(foo)  // this one can be ^smallint from unit system, 
though that is not a implementation vs interface

    TForm1(Sender)

In each case the debugger needs to find the correct type (if more that 
one exists). And in each case, that is never 100% accurate, unless only 
one type exists.


But imho can still benefit from the difference between implementation 
and interface. Unless fully qualified, the user is unlikely to want the 
above "pchar=^widechar" from some unit (maybe not even known to him).


As a side note, initially I thought that once unit-search-order is 
known, the issue would be solved for good. But it wont. For 
"TForm1(Sender)":  "Sender: TControl"  can be in units that do not use 
"unit1". Yet the user would expect the debugger to find it.


And (on windows) a "uses unit1; var TempForm: TForm1" copies the 
definition of "TForm1" into that unit. In that case the debugger will 
always think as "TForm1" to belong to that unit. Which will likely be 
correct, while paused in that unit, but may not be correct, if paused in 
another unit, and just searching for the global definition of "TForm1".


So in the end the debugger will need to deal with the possibility of 
ambiguity.
=> if that includes "types from implementation" is therefore not so big 
of an issue. (still might be useful).



---
4) "official" marker for string vs pchar vs array

Not sure if that is reported already. Depending on dwarf version 
"string" (ansistring) is a pointer (either TAG pointer/reference or 
location expression) to

- char  (dwarf 2)
- array of char (dwarf 3)

Currently for dwarf 2, the debugger can't tell the difference. If the 
user says:  foo[1]
The debugger does not know, if the first or second char is meant (0 or 1 
based index)


With dwarf 3 the difference would be in the display format "('a', 'b', 
'c') vs 'abc'.
But currently the debugger (fpdebug) can tell the difference, because 
fpc has a tiny difference in how it encodes the "stride".

That is obviously an implementation detail, and not very future proof.

Therefore an "official" marker would be nice.
- it appears there is none in dwarf
- it could be a custom addition to dwarf
- documenting an "implementation detail" (such as the stride), so 
fpdebug can safely rely on it.


---
5) Duplicated (artificial) types under Windows

As mentioned, declaring
   var foo: TStringList

copies the type definition of TStringList to that unit (Windows only), 
on Linux there is a cross compilation unit reference (well at least, if 
the source unit has debug info, otherwise IIRC it also is a copy).


Maybe those copies should be marked DW_AT_artificial ?
From DWARF
>> A compiler may wish to generate debugging information entries for 
objects or types that were not actually declared in the source of the 
application
>> Any debugging information entry representing the declaration of an 
object or type artificially 

Re: [fpc-devel] Bug in 3.2.3 with corba interfaces

2023-03-18 Thread Martin Frb via fpc-devel

So it seems to be that topic
https://forum.lazarus.freepascal.org/index.php?topic=39416.0

>> Is and As operators require that the interface has a GUID defined

Only that in my case the compiler happily compile

(MyObjec as TCorbaWithoutGUID).foo;

Shouldn't that give an error?

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Bug in 3.2.3 with corba interfaces

2023-03-18 Thread Martin Frb via fpc-devel
While I haven't got a simple example, by this time I am sure the issue 
is not in my code. (it's not online avail yet)


I have a class, with 2 corba interfaces

  TIdeLocalsValue = class(TLocalsValue, TWatchAbleResultIntf, 
TWatchAbleDataIntf)

...
end

If I get an interface using
  (SomeVar as TWatchAbleDataIntf).Foo

it either crashes, or calls the wrong method.

If I swap the order of the interfaces in the declaration, then it works 
(but the other interface will fail).


And yes, the object on which I work is of the correct class. And it is 
alive (not a dangling pointer).


-
I have  tried to introduce a Base class, and move one Interface to that 
base class, but no luck 

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Inconsistency in generics ?

2023-03-03 Thread Martin Frb via fpc-devel

On 03/03/2023 14:29, Sven Barth via fpc-devel wrote:


All identifiers must be known when declaring a generic. In this case 
Trec1 is known thanks to the global type. Trec2 is not known (neither 
in its parent (at declaration time TBase1) nor globally) , so that 
will fail.


When you specialize with TBase2 you change the parent thus a 
completely new scoping situation arises and Trec1 will no longer be 
the global Trec1, but that of TBase2.


Considering how generics are implemented this is both as expected and 
as designed. Not to mention that using the generic parameter as parent 
is *not* officially considered a feature. It's simply not forbidden.




I got to this only while generating code to feed code-tools. So it's not 
that I need it to be either way.


I understand there is a set of rules to explain it all (or most of it, 
see "why" in code below).

But the result of those rules are somewhat "interesting"

It still feels strange
It leads to  "TRec1"  being checked as something that it is not.
If the "specialize" allows TRec1 to be something else (and something 
completely unrelated), then why does the generic check at all, that the 
non-specialized code compiles against the one seen by the generic?



type
  generic TGen = class
    procedure x;
 end;
procedure TGen.x;
begin
   B.x := 1;  // works, even so the compiler has no info what B might 
be (only that there is a name B)

//   B.y();  // then again, does not work - why?
end;


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Inconsistency in generics ?

2023-03-03 Thread Martin Frb via fpc-devel

To me the below behaviour appears inconsistent.
But before I file a bug, I want to double check, if maybe this is 
intention


Tested with 3.2.3  and 3.3.1

Apparently
- when the generic TGen is compiled, it does check if a type "TRec1" and 
"TRec2" is in scope at all.

- it verifies that the generic itself compiles with that type
- **but** then it allows that type to be replaced by another, if the 
specialized param contains such another type


So if the specialized class, can have a type of it's own choosing for 
"TRec1" then why insist that a random other type of that name exists 
when the generic is declared.
(And why reject "TRec2" as it too could be available at the time of 
specialization?)


Or should the specialized class "TClass1" use the global TRec1? and 
ignore TBase2.TRec1 ?



program testgen;
{$mode objfpc}{$H+}
type
  TRec1 = record r1: integer; end; // this will be used to check the 
generic itself


  TBase1 = class
  end;

  { TBase2 }

  TBase2 = class(TBase1)
  public type
    TRec1 = record r1_b2: integer; end; // this will be used in specialize
    TRec2 = record r2_b2: integer; end;
  end;

  generic TGen = class(B)
    f1: Trec1;  // here TBase2.Rec is not known
    //f2: Trec2;  //  Error: Identifier not found "Trec2"
    procedure x;
  end;

  TClass1 = class(specialize TGen)
    procedure Bar;
  end;

procedure TGen.x; // neither works...
begin
  //f1.r1 := 2;  // fails when specialized
  //f1.r1_b2 := 2;  // fails for the generic
end;

procedure TClass1.Bar;
begin
  f1.r1_b2 := 1; // This is TBase2.Rec, and compiles with 3.2.3  and 3.3.1
end;

begin
end.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Curious about the effect of all the new optimizations....

2023-03-01 Thread Martin Frb via fpc-devel

On 01/03/2023 14:22, J. Gareth Moreton via fpc-devel wrote:

On 01/03/2023 13:11, Martin Frb via fpc-devel wrote:
Hence testing back to  3.2.3 ( unfortunately 3.2.2 has a bug that 
matters in this code)


Also, I didn't expect any huge diffs, just wanted to see if anything 
can be noted at all. (and if lucky, in that test I run)


I did a test on a more limited scope (testing only a handful of 
functions. That test runs 4 Min 20 sec under 3.2.3.
And 2 extra seconds with 3.3.1.  But then I only had 2 sample runs 
for each fpc version


2 seconds out of 4:20 is not conclusive unfortunately, unless you're 
able to exactly control the machine state each time, which is next to 
impossible in the modern day.  I am curious of the slowdown though, 
even if it is very slight.

It will be to much code to find it

It's looping and setting up different combinations of data/structures...

It is the test in ide/packages/idedebugger
subtest: TestWatchArrayStuct
(I did not check the others subtests, but this test is combining some of 
the others...)


The diff also happened when I did (for some of the involved units / not 
for all)

{$CodeAlign proc=32 loop=32}

But it could still be that some code got to an unfortunate alignment.

---
For more testing I would need to set up scripts, to compile and run 
automatically with lots of settings (and then run over night, when 
nothing else goes on).

Also find other PC with diff CPU 

For now, I just wanted to do a quick test. (balance my interest with the 
time I have...). So I wont set up in depth testing now.



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Curious about the effect of all the new optimizations....

2023-03-01 Thread Martin Frb via fpc-devel

On 01/03/2023 12:25, J. Gareth Moreton via fpc-devel wrote:
My peephole optimisations mostly save only a handful of cycles each 
time which probably won't add up to much for a relatively short test.  
The most major optimisation I can think of, although I'm not quite 
sure when it was merged, is the method of replacing divisions by a 
constant with an equivalent reciprocal multiplication.  You'll see the 
biggest savings there.  There's other difficulties like processors 
being intelligent with caching and out of order execution, for 
example, that are disguising some inefficiencies.  And some seek only 
to reduce code size with no loss of speed.


What are your timings like when compiling with COREAVX or COREAVX2?  A 
couple of recent peephole optimizations make use of BMI1 and BMI2.
I had -CpCOREAVX2 supplied. (my fpc is a good week old, so if recent is 
less than that...)

I don't have many divisions in that code.

Most of the good is going through big data in memory. So its possible 
that any gained processing speed, just has to wait for data to be fetched.




I can't remember the proverb that Florian used, but it essentially 
boils down to very small changes, individually not amounting to much, 
but which accumulate into a noticable difference when in large numbers.
Hence testing back to  3.2.3 ( unfortunately 3.2.2 has a bug that 
matters in this code)


Also, I didn't expect any huge diffs, just wanted to see if anything can 
be noted at all. (and if lucky, in that test I run)


I did a test on a more limited scope (testing only a handful of 
functions. That test runs 4 Min 20 sec under 3.2.3.
And 2 extra seconds with 3.3.1.  But then I only had 2 sample runs for 
each fpc version


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Curious about the effect of all the new optimizations....

2023-03-01 Thread Martin Frb via fpc-devel

On 01/03/2023 11:55, Adriaan van Os via fpc-devel wrote:


That may have been "-Performance Matters- by Emery Berger". By I find 
it a nonsense video.


Only that last year, I had some code where it happened to me. Some code 
(that had no change in itself, other than a routine above it (which was 
not part of the benchmark) had changed, and hence the tested code 
changed alignment. IIRC over 20% speed diff. Matched exactly what he 
described.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Curious about the effect of all the new optimizations....

2023-03-01 Thread Martin Frb via fpc-devel

On 01/03/2023 11:47, Bart via fpc-devel wrote:

On Wed, Mar 1, 2023 at 11:33 AM Martin Frb via fpc-devel
 wrote:


So for a while now fpc 3.3.1 receives new optimizations => which is
great / big fan of it.

And hence I thought, lets see how much of an impact they have. And in my
test, they had none :(

Optimizations beyond O2 (or even O1) most of the times do not make a
difference for the average user.
There is much randomness in the performance of an application caused
by things you cannot control, which have more influence on the
performance of the application
I watched a video about this not so long ago (it was about
optimization levels in gcc), which explained all this, but I'm unable
to find that again and unanble to reproduce what was being said there.


I know the video.

Eyeballing and alignment issues were among the causes. For the latter I 
tried to see if codealign would have an effect. Though of course if it 
had, it be a lucky strike.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Curious about the effect of all the new optimizations....

2023-03-01 Thread Martin Frb via fpc-devel
So for a while now fpc 3.3.1 receives new optimizations => which is 
great / big fan of it.


And hence I thought, lets see how much of an impact they have. And in my 
test, they had none :(

Wondering if any one else has measured them?

My tests:
Win-10 64 bit
3.3.1  905c485ff413cd48f98891e2075c814759d0c6f1
3.2.3  2022-02-04
both compilers with each O2 and O4

Using the testcase for FpDebug (which runs a decent spread of code).
Testcase with O2 and O3

And I got no noticeable difference.
I also tried {$CodeAlign proc=32 loop=32} for O2 (test and fpc), also no 
diff.



O2 / fpc: o2 323
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.406
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.063
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.609
O2 / fpc: o2 331
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.251
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.031
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  21.531


O3 / fpc: o2 323
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.687
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.281
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.469
O3 / fpc: o2 331
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  23.203
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.250
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.140


O3 / fpc: o4 323
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  23.063
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.250
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.875
O3 / fpc: o4 331
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.577
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.094
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.235


{$CodeAlign proc=32 loop=32}
O2 / fpc: def 323
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.453
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.328
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.656
O2 / fpc: def 331
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.079
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  22.234
TestWatchesValue_fpc 264_Dwarf_32Bit_FpDebug   :  21.984

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] FPC 3.3.1 crash when getting interface from object

2023-02-05 Thread Martin Frb via fpc-devel
I don't currently have many details. (The code in question has been 
working on older 3.3.1, and still works on 3.2.3 and before)


I included various details, but in the end it may be a peephole issues 
in "GetInterfaceByStr"

==> So probably skip ahead to the asm code below.

The code call a method expecting an interface, and providing an instance 
as param. The instance is of a class implementing the interface.
The class uses generics as base, including generics (for the interface) 
for the expected param in the called method.


I tested with O2 and O4 (for my code )
===> and for fpc/rtl: -CX -gl -gw3 -O-1

rev e84e0a16e13a4b73192edafd2aa356254dc2ac88

The line that fails is:
  function TObject.GetInterfaceByStr(const iidstr : shortstring;out 
obj) : boolean;

...
  if result and Assigned(IEntry^.IID) and (IEntry^.IType in 
[etStandard, etFieldValue]) then

    IInterface(obj)._AddRef;

At the time
Result = true
IEntry^ =
( IIDREF: ^PGUID(nil);
  VTABLE: $000100719838^: ;
  IOFFSET: 32;
  IOFFSETASCODEPTR: $0020^: ;
  IIDSTRREF: $0001007103E8^^: $0001007103E0^: '';
  ITYPE: ETSTANDARD)

IEntry^.IID gets
    function tinterfaceentry.GetIID: pguid;
      begin
    if Assigned(IIDRef) then
  GetIID:=IIDRef^
    else
  GetIID:=Nil;

The interface for the param is "CORBA". (so IIDRef should be nil, 
according to comments in the code)


Generated asm (as reported by GDB) / Crash line is marked <

=> Something seems strange. There is a "cmp" without any conditional 
after it?


..\inc\objpas.inc:922
000100012293 807de400 cmpb   $0x0,-0x1c(%rbp)
000100012297 7441 je 0x1000122da 

000100012299 488b45d8 mov 
-0x28(%rbp),%rax    // EAX = The address pointing to IEntry

..\inc\objpas.inc:924
00010001229D 31c9 xor    %ecx,%ecx
..\inc\objpas.inc:922
00010001229F 48833800 cmpq   $0x0,(%rax)
0001000122A3 488b00   mov    (%rax),%rax // EAX = 
The first qword in the record. That is RAX = IEntry^.IIDRef


0001000122A6 488b00   mov    (%rax),%rax   // 
<< RAX = 0x0


0001000122A9 488b45d8 mov    -0x28(%rbp),%rax
0001000122AD 480f44c1 cmove  %rcx,%rax
0001000122B1 4885c0   test   %rax,%rax
0001000122B4 7424 je 0x1000122da 


0001000122B6 488b45d8 mov    -0x28(%rbp),%rax
0001000122BA 8b4020   mov    0x20(%rax),%eax
0001000122BD 85c0 test   %eax,%eax
0001000122BF 7405 je 0x1000122c6 


0001000122C1 83f803   cmp    $0x3,%eax
0001000122C4 7514 jne    0x1000122da 


..\inc\objpas.inc:923



#0 TOBJECT.GETINTERFACEBYSTR(TOBJECT($0CF471C0), '', 0) at 
c:\FPC\fpc_3.3.1\source\rtl\inc\objpas.inc:922
#1 TOBJECT.GETINTERFACE(TOBJECT($0CF471C0), '', 0) at 
c:\FPC\fpc_3.3.1\source\rtl\inc\objpas.inc:928
#2 fpc_class_as_corbaintf(POINTER($0CF471C0), '') at 
c:\FPC\fpc_3.3.1\source\rtl\inc\objpas.inc:262
#3 
TINTERNALDBGMONITORBASE$3$CRC97C7D6C3_CRC46A2B365.SETSUPPLIER(TINTERNALDBGMONITORBASE$3$CRC97C7D6C3_CRC46A2B365($0CF471C0), 
Failed to read data from register) at lazdebuggertemplate.pas:112
#4 
TTESTDBGDEBUGGER.INITDEBUGGERMONITORS(TTESTDBGDEBUGGER($0CF471C0), 
Failed to read data from register) at 
B:\lazarus_main\components\lazdebuggers\lazdebugtestbase\ttestdbgexecuteables.pas:399


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] threads vs widestringmanager / crash

2022-12-21 Thread Martin Frb via fpc-devel

On 21/12/2022 11:37, Marc Weustink via fpc-devel wrote:



On 20-12-2022 21:12, Sven Barth via fpc-devel wrote:
So the only logical solution is to stop the offending thread from 
executing or not to have it call InitThread() while the 
initialization section of the System unit is still running. The 
former might have unintended consequences (e.g. not being able to 
debug the unit initialization) while the later might work in most 
cases as long as that remote thread doesn't need to execute code that 
relies on InitThread().


The latter may be the best solution. Skip any rtl call when a thread 
attaches during initialization. In normal cases this will only be 
triggered when a debugger attaches. It usually only forces a 
breakpoint, so no fully initialized rtl is needed.


Ondrey

When you got the issue, did you:
- Use FpDebug?
- Lazarus 2.3
- Run/Debug - But *not* press the "pause" button?

Because if so, the debugger should not have sent any DebugBreak.
Unless Windows itself injects threads, if an exe is started with 
"poDebugProcess".


So maybe something else is injecting threads... And the reason it 
happens (to be observed) only in the debugger is that the timing changes.



Ondrey, if the above (FpDebug, not pressed "pause") applies, can you 
test the following:
Modify the system unit, and in the "initialization" section, insert some 
"sleep(250);" between statements (downto after InitSystemThreads)

Then run without debugger.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] threads vs widestringmanager / crash

2022-12-20 Thread Martin via fpc-devel

Ok, I don't know too much about the whole initialization
But on the off chance of triggering some ideas, I throw in a couple of 
my thoughts


On 19/12/2022 07:42, Sven Barth wrote:

Am 07.07.2018 um 15:04 schrieb Martin:
So (guessing) the original issue may be due to the debugger. The 
debugger interrupts the target early on. And that does create a 
thread in the target.
If such an external thread happens, would fcp execute the code in 
question?


This is likely to be the cause, cause the EXEC_TLS_CALLBACK is 
executed by Windows for every thread that is started for an 
application. And if the debugger triggers the start of a thread...


Maybe, maybe not always? But, yes at least in the case that I documented 
in 2018: 
https://lists.freepascal.org/pipermail/fpc-devel/2018-July/039374.html


Yet in the system unit:

initialization
.
  if not Assigned(CurrentTM.BeginThread) then
  begin
    InitHeap;
    InitSystemThreads;
  end;
  SysInitExceptions;
  initunicodestringmanager;
  InitWin32Widestrings;

So the WS-Mgr is only assigned after InitSystemThreads => which sets up  
RelocateThreadVar => which can call InitThread.


So order may need to be changed there (if that is possible).
Of course, the case where EXEC_TLS_CALLBACK calls InitThread remains.

A lot of the WS-Mgr init is assigning pointers to the correct procedure.
So if InitThread sees that this has not been done yet, InitThread could 
call those.
Even if 2 threads (main and the early thread) both assign values to the 
pointer, they assign the same value, and so that should not do harm.
Of course the thread init must not change the value, once it was set by 
the main thread, in case usercode assigned a diff value (so maybe in 
ThreadInit, use Interlocked)


This may mean to break "InitWin32Widestrings" into 2 parts, because it 
also prepares some tables.

But those are not needed for "GetStandardCodePageProc"

So if the setting of the codepage related proc pointers are moved to a 
separate init-method, then that can be called (if needed) by InitThread.


--
Or maybe if EXEC_TLS_CALLBACK calls InitThread, it can do the (partial) 
init of WidestringMgr before? (if the order in the initialization 
section can be changed to do the same?)


--
I am not sure if this code needs to worry about any of the other WS-Mgr 
functions.
Any thread that early is not started by Pascal code (neither user, nor 
rtl). It will be a thread working some kernel proc. And that shouldn't 
access the WS-Mgr?



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] InitHeap in TLS_Callback [[Re: threads vs widestringmanager / crash]]

2022-12-20 Thread Martin via fpc-devel

On 20/12/2022 15:08, Martin wrote:

Ok, I don't know too much about the whole initialization
But on the off chance of triggering some ideas, I throw in a couple of 
my thoughts


On 19/12/2022 07:42, Sven Barth wrote:


This is likely to be the cause, cause the EXEC_TLS_CALLBACK is 
executed by Windows for every thread that is started for an 
application. And if the debugger triggers the start of a thread...


Maybe, maybe not always? But, yes at least in the case that I 
documented in 2018: 
https://lists.freepascal.org/pipermail/fpc-devel/2018-July/039374.html


While I just looked through that code, I came to think there may be yet 
another issue.


If a thread is started, that can call EXEC_TLS_CALLBACK.
And EXEC_TLS_CALLBACK  can call InitHeap (in DLL_PROCESS_ATTACH) before 
the main thread has run InitHeap.


But InitHeap does not seem to be threadsafe.

InitHeap itself does probably work if it runs overlapping. But, if one 
thread already goes into using the heap (e.g. allocating) while the 
other still is in InitHeap... That likely does not go well.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Experimentation: "Branch stitching"

2022-11-28 Thread Martin Frb via fpc-devel

On 28/11/2022 16:37, Martin Frb via fpc-devel wrote:


"11.3μop cache"


Apart from the qop cache there is the normal loading into the cache.

I must admit I am not sure on the exact workings, but wasn't there 
something like loading entire cachelines?  If that is so (not sure), 
then of course moving other code in between means potentially pushing 
the current code out of the same cache line?


Then the decision needs information which code is executed more 
often/likely.
(Also in that case I don't know if the conditional branch could be 
negated (be vs bne / bg <> ble ...) without affecting the branch 
predictor? (leaving the order, but dropping the the jmp).


Of course there may also be the question of the distance, and which jump 
/ conditional jump takes what byte size for the distance (Again I 
don't know)___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Experimentation: "Branch stitching"

2022-11-28 Thread Martin Frb via fpc-devel

On 28/11/2022 16:19, J. Gareth Moreton via fpc-devel wrote:
I admit I can be disorganised sometimes and lose documents, so I 
apologise if you have sent them already and I mislaid them in my mess 
of a directory tree.  Believe me though, I want to swallow all of this 
up if it means squeezing out every cycle I can out of the generated 
machine code!


Curious to know... at which point did it become favourable to do a 
32-byte align rather than a 16-byte align on x86 processors? Should 
the compiler start favouring 32-byte aligns for loops, say?


https://www.agner.org/optimize/optimizing_assembly.pdf

"11.3μop cache"

I couldn't find the 32byte align in that doc though. I must have picked 
that up elsewhere. (I think).
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Experimentation: "Branch stitching"

2022-11-28 Thread Martin Frb via fpc-devel

On 28/11/2022 14:32, J. Gareth Moreton via fpc-devel wrote:

On 28/11/2022 12:59, Martin Frb via fpc-devel wrote:

Well first of all, you didn't move the balign in front of .Lj732


I do move the alignment hints, but if the label becomes dead (due to 
the zero-distance jump being 'collapsed'), the alignment hint gets 
removed.  It's an experiment in progress.


Ah, yes right.
Anyway this may be more of a 32 byte thing, and the 16 byte align is at 
best a 50/50 game


I once had a better source on the topic (also it might be in the pdf I 
once sent) but for now:

https://superuser.com/questions/1368480/how-is-the-micro-op-cache-tagged


Each 32B window (from the instruction cache) is mapped into the uop cache
(in case of an outer loop) Due to the size of that cache depending what 
else is executed, uops may or may not be cached (also only matters if 
the moved block is (inside a loop) frequently entered).
But ultimately, the 16 bytes align are not meant for that. Though if a 
user used a directive to set a 32byte align => then that may matter.



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Experimentation: "Branch stitching"

2022-11-28 Thread Martin Frb via fpc-devel

On 28/11/2022 07:22, J. Gareth Moreton via fpc-devel wrote:

...
    testb   %al,%al
    je .Lj733
    subb    $1,%al
    je     .Lj734
    jmp    .Lj732
    .balign 16,0x90
.Lj733:
    ...
    jmp    .Lj718
    .balign 16,0x90
.Lj732:
    movl    $2019050530,%ecx
    call    VERBOSE_$$_INTERNALERROR$LONGINT
    jmp    .Lj718

The block with the internal error can be moved and 'stitched' to the 
"jmp .Lj732" instruction.


    ...
    testb    %al,%al
    je    .Lj733
    subb    $1,%al
    je    .Lj734
    movl    $2019050530,%ecx
    call    VERBOSE_$$_INTERNALERROR$LONGINT
    jmp    .Lj718
    .balign 16,0x90
.Lj733:
    ...

I'm still working a few things out, since it can move the function 
epilogue which makes things harder to read.  Currently I'm only moving 
blocks where the label only has a single reference, thereby causing a 
dead label when it's stitched alongside its corresponding jump.  This 
avoids problems where the label is referenced in a data block that's 
distinct from the assembly and where moving it may cause problems.


Well first of all, you didn't move the balign in front of .Lj732

In the above example, that may be an improvement (most likely) because 
if the label really is referred once only (and thereby is also not a 
loop) then it may not be beneficial to align it (except maybe if the 
user specified a non default align?).
If the label is referred only once, but the whole think is inside a loop 
 it may still be relevant to have the align? (not sure, depends on 
how the cpu caches stuff)?


Another thing is, that moving the block can make the other part of the 
loop longer (needing more cache). If this branch-to-be-moved is rarely 
entered, it may want to be after the final "jmp-to-loop-start" of the 
normal branch?
Of course, if the loop is bigger than the block with the branches, and 
we did know that the branch is some sort of exception only, then we 
would want to move it even further away, to get it out of the loop..


--
Btw, .balign N, 0x90 => isn't there an align that uses multibyte nop 
(like) instructions? (I posted some pdf to you a while back, iirc it 
points that out)

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Attn Florian, commit 1b698210 10/10/2022 22:45:31 breaks DWARF info

2022-10-19 Thread Martin Frb via fpc-devel

On 19/10/2022 22:56, Martin Frb via fpc-devel wrote:

On 19/10/2022 21:12, Pierre Muller via fpc-devel wrote:

Hi Martin,

could you tell me if
https://gitlab.com/freepascal.org/fpc/source/-/issues/39928#note_1140122898 



fixes your troubles?

Thanks in advance,


It looks like the right direction. But see my comment on the issue.

It is correct as in that those are the 2 values that need to be 
adjusted (According to code review). Just the 2nd case should be 
adjusted by assigning the correct values to the variable "uppercodes"


I will have to setup a quick test.
I had my findings by code-review only.


Ok, I made a merge request (slightly diff from the patch, but to the 
same effect).

I tested this, and it produces valid dwarf again.


There is the question as to introducing a constant, instead of changing 
several copies of the same number.

On the other hand it happens once every x years.
And I don't know what the preferred style is.

Could also be
   const   EntryLen = array[Boolean] of integer = (14, 17);
and then use a boolean variable instead of "uppercodes".

But that is not part of the issue itself.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Attn Florian, commit 1b698210 10/10/2022 22:45:31 breaks DWARF info

2022-10-19 Thread Martin Frb via fpc-devel

On 19/10/2022 21:12, Pierre Muller via fpc-devel wrote:

Hi Martin,

could you tell me if
https://gitlab.com/freepascal.org/fpc/source/-/issues/39928#note_1140122898 



fixes your troubles?

Thanks in advance,


It looks like the right direction. But see my comment on the issue.

It is correct as in that those are the 2 values that need to be adjusted 
(According to code review). Just the 2nd case should be adjusted by 
assigning the correct values to the variable "uppercodes"


I will have to setup a quick test.
I had my findings by code-review only.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Attn Florian, commit 1b698210 10/10/2022 22:45:31 breaks DWARF info

2022-10-19 Thread Martin Frb via fpc-devel

Revision: 1b6982107f1ac4b4111e37be0a3649d155a2bc1e
Author: florian 
Date: 10/10/2022 22:45:31
Message:
  * TDebugInfoDwarf3.appenddef_object should not write an extra 
finish_entry for objects and C++ classes


This adds extra DW_OP_... statements in 2 places

In
procedure addstringdef(const name: shortstring; chardef: tdef; deref: 
boolean; lensize: aint);


+ 
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_nop)));


However it does not increase the byte count "upperopcodes" in the
  append_entry(DW_TAG_subrange_type,false,[
    DW_AT_lower_bound,DW_FORM_udata,1,
    DW_AT_upper_bound,DW_FORM_block1,upperopcodes
    ]);

Similar in:
    procedure tdebuginfodwarf3.appenddef_array(list: tasmlist; def: 
tarraydef);


--

I am still puzzled at the effect from what I saw in the data I got from 
a reporter.

He send me an objdump (which failed mid way)


 <2><2617>: Abbrev Number: 18 (DW_TAG_subrange_type)
    <2618>   DW_AT_lower_bound : 1
    <2619>   DW_AT_upper_bound : 13 byte block: 97 6 12 28 4 0 30 2f 3 
0 38 1c 6  (DW_OP_push_object_address; DW_OP_deref; >

 <2><2627>: Abbrev Number: 22 (DW_TAG_subprogram)

It should be followed by "Abbrev Number; 0" (end of the nested block)

Of course FPC would now write 14 bytes (while the header still says 13),
bot the 14th byte should be
    DW_OP_nop   = $96

So I am puzzled where the 22 comes from.
Though that could be something that objdump did. (I don't have the exe 
in question / and I haven't reproduced myself)


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Overloading problem in generic class.

2022-09-18 Thread Martin Frb via fpc-devel

On 18/09/2022 14:29, Bart via fpc-devel wrote:

I wonder anyway

TCustomSpinEditEx = class(specialize TSpinEditExBase)

But "SameValue" does not exist for int64 (or any int)?
So I assume the compiler converts the int to a float


(Note:
The base class can have a virtual abstract InternalSameValue function
thet then needs to be implemented in all descendant classes.
This will break all derived classes that are not part of the Lazarus
distribution, e.g. the ExCtrls package
(https://wiki.freepascal.org/ExCtrls).
This may be the cleaner solution though.
)



And if the base class has
    function SameValue(AValue1, AValue2: T): Boolean; virtual; // but 
not abstract


Which implements the old call, without typecast?

It may need to be abstract in case of
{$ifdef fpc_math_samevalue_bug}
because the non-typecast will otherwise fail.
But for that define, there already is an abstract class, that all 
derived classes must have.
Or it could have different bodies, depending on compiler version and OS. 
(that would to the best of abilities help 3rd party code)


And since it is then overridden in the classes in our code => those will 
do the correct calls.





___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Overloading problem in generic class.

2022-09-18 Thread Martin Frb via fpc-devel

On 18/09/2022 11:37, Bart via fpc-devel wrote:

Hi,

The following program will compile for Windows 32 and 64 bit.
It fails to compile for Linix 64 bit (and if I understand correctly,
also for MacOS 64 bit).



Just enable fpc_math_samevalue_bug

{$if FPC_FullVersion=30202}{$ifdef Win64}
  {$define fpc_math_samevalue_bug}
{$endif}{$endif}


Make it
{$if FPC_FullVersion<=30202}
  {$define fpc_math_samevalue_bug}
{$endif}


I wonder anyway

  TCustomSpinEditEx = class(specialize TSpinEditExBase)

But "SameValue" does not exist for int64 (or any int)?
So I assume the compiler converts the int to a float for calling 
SameValue => that seems undesirable.


So we should have a function (in the scope for the generic)

    function SameValue(AValue1, AValue2: Int64): Boolean; overload;
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Insufficient Dwarf info for Interfaces

2022-09-15 Thread Martin Frb via fpc-devel

On 15/09/2022 21:35, Sven Barth via fpc-devel wrote:

Am 15.09.2022 um 14:32 schrieb Martin Frb via fpc-devel:

https://gitlab.com/freepascal.org/fpc/source/-/issues/39904

On top of adding the functions in the interface to the dwarf info, it 
would be great if the compiler could also add some sort of link to 
the underlaying TObject.


So the debugger could (if available) show the user the 
object/instance that implements the interface.


I am not sure how that would best be done (i.e. maybe add some 
internal field, maybe there is some dwarf tag that can be used, maybe 
a dwarf extension)
From what I  understand, this would require the offset between the 
interface table and the class (i.e. the value that is subtracted from 
"self" in the interface's method).
If for a debug build the compiler could write that value in front of 
the interface, then it could point the debugger to it


You are aware that an interface can be implemented by multiple 
different class types and that the offsets for each class that 
implements a specific interface will be different depending on the 
amount of interfaces a class implements? So if you have a given 
interface neither you nor the compiler will know what is on the other 
side.

Yes.

And I am also aware that for each class that implements the interface, 
their is a separate set of jump pads (with code adjusting "self" by that 
offset), and there is a "interface vmt" for those jump pads.


If TFoo implements ISome, then A:ISome = $100010
If TBAr implements ISome, then A:ISome = $102210

So there are 2 options
1) the compiler writes the "offset" at $18 and $102208 (4 or 8 bytes 
before). (only if debug info generation is on)
The the debugger needs to figure out this is implemented by a class (and 
not external)


2) The compiler writes separate dwarf for the 2 version of the 
"interface vmt".

And It says "this is at address "
THen the debugger does a reverse lookup by address => and finds the 
dwarf info for the "interface vmt"
The problem is to find what dwarf info to use. It must include the 
address, and then the offset (or an dwarf expression to calculate the 
object instance).
This dwarf info for the interface can also link to the type of the 
instance (the class that implements the interface)


The compiler already writes stuff to dwarf like
  DW_TAG_structure_type
  with name   $VMTDEF$TBARU2
  and a size
  but no other info.

Unfortunately this is a type declaration, so it does not have an 
address... (which is really required)


This will likely need a custom dwarf entry. Or tweaking an existing, 
such as including an DW_AT_Location

OR a DW_TAG_VARIABLE to hold the address for this type

--
All the info is already there, except really not accessible.

If the debugger has an interface, and it says address=$1002233
=> the debugger can look up the first method of the interface
=> check the code is in one of the compilation units (code generated 
from pascal source)

=> disassemble the code to get the offset
=> calculate the address of the object instance
=> use RTTI to get the classname.
=> find the dwarf for that class, typecast, and voila



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Insufficient Dwarf info for Interfaces

2022-09-15 Thread Martin Frb via fpc-devel

On 15/09/2022 16:17, Michael Van Canneyt via fpc-devel wrote:



On Thu, 15 Sep 2022, Martin Frb via fpc-devel wrote:


https://gitlab.com/freepascal.org/fpc/source/-/issues/39904

On top of adding the functions in the interface to the dwarf info, it 
would be great if the compiler could also add some sort of link to 
the underlaying TObject.


So the debugger could (if available) show the user the 
object/instance that implements the interface.


I believe the whole idea of interfaces is that this info is not 
available :-)

Well yes... From the applications point of view.

From the debuggers (or rather the user doing the debugging) point of 
view, there is only the question of "can it be done/implemented" (IMHO)


When the compiler generates the jump pads for an interface (that is 
implemented by an object in the app), then the compiler knows the object 
exists, and the compiler has all the info. It only needs to make it 
available to the debugger.


The debugger would then need to be able to check, if the address in the 
interface variable points to such a jump table.
Either by checking if it is in the correct memory range, or better by 
finding a dwarf entry describing this address as an "interface vmt". In 
the latter case that dwarf info could hold in some way the offset for 
self, and the pointer to the dwarf info for class type (since the 
interface as a separate jump table at a diff address for each class that 
implements it)


I understand that it may be deemed to much work But it would be helpful.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


  1   2   3   4   5   6   7   8   9   10   >