View Issue Details

IDProjectCategoryView StatusLast Update
0035386FPCCompilerpublic2019-05-18 19:02
ReporterMartin FriebeAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformMacOsOSMacOS Version-
Product Version3.0.4Product Build 
Target VersionFixed in Version3.3.1 
Summary0035386: Wrong dwarf-3 info for ansistring when cross compiling to 32 bit
DescriptionTested on Mac, with fpc 3.0.4 (As supplied by Lazarus)
This fpc can compile for 64 bit and 32 bit.

If compiling for 32 bit

var s: ansistring;

will create incorrect debug info. Ansistring is an array of char. The lower bound is 1, the upper bound is calculated.
The calculation ends with
DW_OP_lit8, DW_OP_minus, DW_OP_deref

However on 32 bit the strings len, is 4 byte before the string. So it should be DW_OP_lit4

A 32bit fpc on windows correctly creates DW_OP_lit4
TagsNo tags attached.
Fixed in Revision42038
FPCOldBugId0
FPCTarget-
Attached Files
  • dbgdwarf-strlen.diff (881 bytes)
    diff --git a/compiler/dbgdwarf.pas b/compiler/dbgdwarf.pas
    index c83ceda7..0a045a04 100644
    --- a/compiler/dbgdwarf.pas
    +++ b/compiler/dbgdwarf.pas
    @@ -4287,7 +4287,7 @@ implementation
                   current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
                   current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
                   { no -> load length }
    -              current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
    +              current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(pint)));
                   current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
                   current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
     
    
    dbgdwarf-strlen.diff (881 bytes)
  • dbgdwarf-array-cross.patch (892 bytes)
    Index: dbgdwarf.pas
    ===================================================================
    --- dbgdwarf.pas	(revision 41932)
    +++ dbgdwarf.pas	(working copy)
    @@ -4215,7 +4215,7 @@
             current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
             current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
             { no -> load length }
    -        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
    +        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(pint)));
             current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
             current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
             append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));

Relationships

related to 0035566 closedSven Barth dwarf-3 for widestring (rev 42039, 42038) is wrong 
related to 0035567 new Wrong dwarf-3 info for dyn-array when cross compiling between 32/64 bit 

Activities

Sven Barth

2019-04-16 11:30

manager   ~0115543

Does the attached patch fix the issue?

Marco van de Voort

2019-04-17 11:36

manager   ~0115584

(patch (here and related unicodestring case) is utf16/ucs-2 btw, and tortoisediff doesn't like them)

Sven Barth

2019-04-18 20:42

manager  

dbgdwarf-strlen.diff (881 bytes)
diff --git a/compiler/dbgdwarf.pas b/compiler/dbgdwarf.pas
index c83ceda7..0a045a04 100644
--- a/compiler/dbgdwarf.pas
+++ b/compiler/dbgdwarf.pas
@@ -4287,7 +4287,7 @@ implementation
               current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
               current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
               { no -> load length }
-              current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
+              current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(pint)));
               current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
               current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
 
dbgdwarf-strlen.diff (881 bytes)

Sven Barth

2019-04-18 20:42

manager   ~0115660

I always forget that PowerShell does that. -.- Thanks!
Reuploaded as UTF8.

Marco van de Voort

2019-04-18 21:10

manager   ~0115662

I'm a compiler nitwit, but to me it seems something like sizeof(ptrint) shouldn't happen in debuginfo. host and target bittiness might not be equal

Martin Friebe

2019-04-24 16:27

manager   ~0115774

I don't see how sizeof(pint) can work. As that always depends on the compiler? The cross compiler itself is still 64 bit with pointer of 8bytes len. The target wants 4 bytes.
I did not test the sizeof(pint) though.

I did a bit of a search and *guess*. This *seems* to work:
              current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+ def.size } ));

Tested with 32 to 64 bit cross compiler on win.

    But that needs to be reviewed.

There are also several other occurrences of sizeof(pint) (and other sizeof). I have not investigated how to trigger them, or if they cause similar issues.

Sven Barth

2019-04-25 00:04

manager   ~0115794

PInt (declared in globtype.pas) is the target specific integer type that corresponds to a pointer and the field that needs to be skipped is a pointer. "def.size" only works by accident, because it's size is the size of a pointer.

Martin Friebe

2019-04-25 16:06

manager   ~0115801

I currently only can test cross compile (with self build fpc) for win32 to win64.
But the issue exists in this direction too, and is fixed with the "pint" patch. (And normal/none-cross results are correct too)

The issue also exists for arrays. And can be fixed the same way.

It be good if this could also be merged in 3.2 (please let me know, if that will be) => would allow me to restrict workarounds (todo) in fpdebug. Thanks

dbgdwarf-array-cross.patch (892 bytes)
Index: dbgdwarf.pas
===================================================================
--- dbgdwarf.pas	(revision 41932)
+++ dbgdwarf.pas	(working copy)
@@ -4215,7 +4215,7 @@
         current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
         current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
         { no -> load length }
-        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(ptrint)));
+        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizeof(pint)));
         current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_minus)));
         current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
         append_labelentry_ref(DW_AT_type,def_dwarf_lab(def.rangedef));

Sven Barth

2019-05-11 17:40

manager   ~0116136

Fixed it in a more correct way.
Please test and close if okay.

Martin Friebe

2019-05-18 19:02

manager   ~0116249

Works, thanks

Issue History

Date Modified Username Field Change
2019-04-16 01:34 Martin Friebe New Issue
2019-04-16 11:30 Sven Barth File Added: dbgdwarf-strlen.diff
2019-04-16 11:30 Sven Barth Note Added: 0115543
2019-04-16 11:30 Sven Barth Assigned To => Sven Barth
2019-04-16 11:30 Sven Barth Status new => feedback
2019-04-17 11:36 Marco van de Voort Note Added: 0115584
2019-04-18 20:42 Sven Barth File Deleted: dbgdwarf-strlen.diff
2019-04-18 20:42 Sven Barth File Added: dbgdwarf-strlen.diff
2019-04-18 20:42 Sven Barth Note Added: 0115660
2019-04-18 21:10 Marco van de Voort Note Added: 0115662
2019-04-24 16:27 Martin Friebe Note Added: 0115774
2019-04-24 16:27 Martin Friebe Status feedback => assigned
2019-04-25 00:04 Sven Barth Note Added: 0115794
2019-04-25 16:06 Martin Friebe File Added: dbgdwarf-array-cross.patch
2019-04-25 16:06 Martin Friebe Note Added: 0115801
2019-05-11 17:40 Sven Barth Status assigned => resolved
2019-05-11 17:40 Sven Barth Resolution open => fixed
2019-05-11 17:40 Sven Barth Fixed in Version => 3.3.1
2019-05-11 17:40 Sven Barth Fixed in Revision => 42038
2019-05-11 17:40 Sven Barth FPCTarget => -
2019-05-11 17:40 Sven Barth Note Added: 0116136
2019-05-12 13:25 Martin Friebe Relationship added related to 0035566
2019-05-12 13:30 Martin Friebe Relationship added related to 0035567
2019-05-18 19:02 Martin Friebe Status resolved => closed
2019-05-18 19:02 Martin Friebe Note Added: 0116249