View Issue Details

IDProjectCategoryView StatusLast Update
0035566FPCCompilerpublic2019-10-13 18:09
ReporterMartin FriebeAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionreopened 
Platform64bit IntelOSwin 10OS Version10
Product VersionProduct Build42039 
Target VersionFixed in Version3.3.1 
Summary0035566: dwarf-3 for widestring (rev 42039, 42038) is wrong
DescriptionFor windows style widestring the size is always stored in a 4 byte field.

The dwarf expression now correctly subtracts 4. But then uses DW_OP_deref, with for 64 bit apps, loads a 64bit value.

The correct expression should be DW_OP_deref_size, 4

See Patch.
TagsNo tags attached.
Fixed in Revision42087,43182
FPCOldBugId
FPCTarget-
Attached Files
  • widestring_fix_deref_size.patch (2,248 bytes)
    Index: dbgdwarf.pas
    ===================================================================
    --- dbgdwarf.pas	(revision 42039)
    +++ dbgdwarf.pas	(working copy)
    @@ -4268,7 +4268,7 @@
                   if not (is_widestring(def) and (tf_winlikewidestring in target_info.flags)) then
                     upperopcodes:=13
                   else
    -                upperopcodes:=15;
    +                upperopcodes:=16;
                   { lower bound is always 1, upper bound (length) needs to be calculated }
                   append_entry(DW_TAG_subrange_type,false,[
                     DW_AT_lower_bound,DW_FORM_udata,1,
    @@ -4287,16 +4287,21 @@
                   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 }
    -              if upperopcodes=15 then
    +              if upperopcodes=16 then
                     { for Windows WideString the size is always a DWORD }
                     current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit4)))
                   else
                     current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizesinttype.size));
                   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)));
    +              if upperopcodes=16 then begin
    +                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref_size)));
    +                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
    +			  end
    +			  else
    +                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
     
                   { for widestrings, the length is specified in bytes, so divide by two }
    -              if (upperopcodes=15) then
    +              if (upperopcodes=16) then
                     begin
                       current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit1)));
                       current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_shr)));
    
  • dwarf3_widestring_skip_correction.diff (1,376 bytes)
    *** y:/Temp/mtmp/dbgdwarf.pas-revBASE.svn001.tmp.pas	Sun May 19 00:59:31 2019
    --- B:/FPC/SVN/fixes_3_2/compiler/dbgdwarf.pas	Sat Oct 12 20:37:27 2019
    ***************
    *** 4279,4285 ****
                    { yes -> length = 0 }
                    current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)));
                    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 }
                    if upperopcodes=16 then
                      { for Windows WideString the size is always a DWORD }
    --- 4279,4288 ----
                    { yes -> length = 0 }
                    current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)));
                    current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
    !               if upperopcodes=16 then
    !                 current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(6))
    ! 			  else
    !                 current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
                    { no -> load length }
                    if upperopcodes=16 then
                      { for Windows WideString the size is always a DWORD }
    

Relationships

related to 0035386 closedSven Barth Wrong dwarf-3 info for ansistring when cross compiling to 32 bit 

Activities

Martin Friebe

2019-05-12 13:25

manager  

widestring_fix_deref_size.patch (2,248 bytes)
Index: dbgdwarf.pas
===================================================================
--- dbgdwarf.pas	(revision 42039)
+++ dbgdwarf.pas	(working copy)
@@ -4268,7 +4268,7 @@
               if not (is_widestring(def) and (tf_winlikewidestring in target_info.flags)) then
                 upperopcodes:=13
               else
-                upperopcodes:=15;
+                upperopcodes:=16;
               { lower bound is always 1, upper bound (length) needs to be calculated }
               append_entry(DW_TAG_subrange_type,false,[
                 DW_AT_lower_bound,DW_FORM_udata,1,
@@ -4287,16 +4287,21 @@
               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 }
-              if upperopcodes=15 then
+              if upperopcodes=16 then
                 { for Windows WideString the size is always a DWORD }
                 current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit4)))
               else
                 current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)+sizesinttype.size));
               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)));
+              if upperopcodes=16 then begin
+                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref_size)));
+                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(4));
+			  end
+			  else
+                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_deref)));
 
               { for widestrings, the length is specified in bytes, so divide by two }
-              if (upperopcodes=15) then
+              if (upperopcodes=16) then
                 begin
                   current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit1)));
                   current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_shr)));

Sven Barth

2019-05-16 22:57

manager   ~0116225

Slowly, but surely I'm learning how the DWARF debug info is supposed to work. :P (though I did not see any difference in debugger behviour... *shrugs*)

Thank you for the patch. Please test and close if okay.

Martin Friebe

2019-05-18 19:02

manager   ~0116248

Works, thanks

Martin Friebe

2019-10-12 20:43

manager   ~0118525

Unfortunately the patch missed something. And somehow so did my previous testing....

If upperopcodes=16 then there are more (or larger => more bytes) instructions appended to deref the result.

But if the string is nil, all of those bytes must be skipped.
The current value "skip 3" only works for upperopcodes<>16

See Patch

---
Also this was merged to 3.2.
So it would be good if the update could be merged too.

Martin Friebe

2019-10-12 20:44

manager  

dwarf3_widestring_skip_correction.diff (1,376 bytes)
*** y:/Temp/mtmp/dbgdwarf.pas-revBASE.svn001.tmp.pas	Sun May 19 00:59:31 2019
--- B:/FPC/SVN/fixes_3_2/compiler/dbgdwarf.pas	Sat Oct 12 20:37:27 2019
***************
*** 4279,4285 ****
                { yes -> length = 0 }
                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)));
                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 }
                if upperopcodes=16 then
                  { for Windows WideString the size is always a DWORD }
--- 4279,4288 ----
                { yes -> length = 0 }
                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_lit0)));
                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(ord(DW_OP_skip)));
!               if upperopcodes=16 then
!                 current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(6))
! 			  else
!                 current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit_unaligned(3));
                { no -> load length }
                if upperopcodes=16 then
                  { for Windows WideString the size is always a DWORD }

Cyrax

2019-10-13 05:16

reporter   ~0118541

Can we have the patch in unified format, too? Thanks.

Jonas Maebe

2019-10-13 11:31

manager   ~0118554

Thanks for the patch, fixed.

Issue History

Date Modified Username Field Change
2019-05-12 13:25 Martin Friebe New Issue
2019-05-12 13:25 Martin Friebe Status new => assigned
2019-05-12 13:25 Martin Friebe Assigned To => Sven Barth
2019-05-12 13:25 Martin Friebe File Added: widestring_fix_deref_size.patch
2019-05-12 13:25 Martin Friebe Relationship added related to 0035386
2019-05-16 22:57 Sven Barth Status assigned => resolved
2019-05-16 22:57 Sven Barth Resolution open => fixed
2019-05-16 22:57 Sven Barth Fixed in Version => 3.3.1
2019-05-16 22:57 Sven Barth Fixed in Revision => 42087
2019-05-16 22:57 Sven Barth FPCTarget => -
2019-05-16 22:57 Sven Barth Note Added: 0116225
2019-05-18 19:02 Martin Friebe Status resolved => closed
2019-05-18 19:02 Martin Friebe Note Added: 0116248
2019-10-12 20:43 Martin Friebe Status closed => feedback
2019-10-12 20:43 Martin Friebe Resolution fixed => reopened
2019-10-12 20:43 Martin Friebe Note Added: 0118525
2019-10-12 20:44 Martin Friebe File Added: dwarf3_widestring_skip_correction.diff
2019-10-13 05:16 Cyrax Note Added: 0118541
2019-10-13 11:31 Jonas Maebe Status feedback => resolved
2019-10-13 11:31 Jonas Maebe Fixed in Revision 42087 => 42087,43182
2019-10-13 11:31 Jonas Maebe Note Added: 0118554
2019-10-13 18:09 Martin Friebe Status resolved => closed