Skip to content

[AVR] Object type method debug information missing

Summary

DWARF debug information for object type method is missing when the object is declared in unit.

System Information

  • Operating system: Embedded
  • Processor architecture: AVR
  • Compiler version: main 2bf37774 , 3.2.3 ea5c84dc, 3.2.2 0d122c49
  • Device: Microcontroller

Steps to reproduce

Example Project

Compile :

<AVRFPC> -Tembedded -Pavr -MObjFPC -Sai -CirotR -O1 -gw3 -Xg -a -al -Xe -Xm -Sm -WpATMEGA328P -CpAVR5 -godwarfsets -dF_CPU:=16000000 avr_object_debug_test.pas

program avr_object_debug_test;

uses
  utestobj;

var
  TestObj: TTestObj;
  TestRec: TTestRec;

begin
  DoSomething;
  TestObj.DoSomething;
  TestRec.DoSomething;
end.
unit utestobj;

{$modeswitch advancedrecords}

interface

type
  TTestObj = object
    procedure DoSomething;
  end;

  TTestRec = record
    procedure DoSomething;
  end;

procedure DoSomething;

implementation

procedure TTestObj.DoSomething;
var
  i, x: SizeInt;
begin
  x := 5;
  i := 0;
  Inc(i);
  x := i;
end;

procedure TTestRec.DoSomething;
var
  i, x: SizeInt;
begin
  x := 5;
  i := 0;
  Inc(i);
  x := i;
end;

procedure DoSomething;
var
  i, x: SizeInt;
begin
  x := 5;
  i := 0;
  Inc(i);
  x := i;
end;

end.

What is the current bug behavior?

There is no debug information.

( Using windows avr-gdb 8.3 patched by MiR from here )

$main () at avr_object_debug_test.pas:12
12        TestObj.DoSomething;
(gdb) s
UTESTOBJs_sTTESTOBJ_s__ss_DOSOMETHING () at utestobj.pas:24
24        x := 5;
(gdb) s
25        i := 0;
(gdb) print x
No symbol "x" in current context. 

What is the expected (correct) behavior?

Emit debug information for method of object type declared in units.

Relevant logs and/or screenshots

Debug info from avr_object_debug_test project builded with main (2bf37774) on Windows 10 using:

avr-embedded-objdump.exe -Wi avr_object_debug_test.elf .

avr_object_debug_test.elf:     file format elf32-avr

Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0xc3 (32-bit)
   Version:       3
   Abbrev Offset: 0x0
   Pointer Size:  4
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_name        : avr_object_debug_test.pas
    <26>   DW_AT_producer    : Free Pascal 3.3.1 2022/09/24
    <43>   DW_AT_comp_dir    : G:/Programming/dimitris/Projects/fpc_avr_bugs/debug_objects/
    <80>   DW_AT_language    : 9    (ANSI Pascal)
    <81>   DW_AT_identifier_case: 3    (case_insensitive)
    <82>   DW_AT_stmt_list   : 0x0
    <86>   DW_AT_low_pc      : 0x9e
    <8a>   DW_AT_high_pc     : 0xc0
 <1><8e>: Abbrev Number: 2 (DW_TAG_variable)
    <8f>   DW_AT_name        : TestObj
    <97>   DW_AT_location    : 5 byte block: 3 40 1 80 0 (DW_OP_addr: 800140)
    <9d>   DW_AT_type        : <0x118c>
 <1><a1>: Abbrev Number: 2 (DW_TAG_variable)
    <a2>   DW_AT_name        : TestRec
    <aa>   DW_AT_location    : 5 byte block: 3 41 1 80 0 (DW_OP_addr: 800141)
    <b0>   DW_AT_type        : <0x11ab>
 <1><b4>: Abbrev Number: 3 (DW_TAG_subprogram)
    <b5>   DW_AT_name        : $main
    <bb>   DW_AT_prototyped  : 1
    <bc>   DW_AT_external    : 1
    <bd>   DW_AT_low_pc      : 0x9e
    <c1>   DW_AT_high_pc     : 0xbc
 <2><c5>: Abbrev Number: 0
 <1><c6>: Abbrev Number: 0
  Compilation Unit @ offset 0xc7:
   Length:        0xff5 (32-bit)
   Version:       3
   Abbrev Offset: 0x30
   Pointer Size:  4
 <0><d2>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <d3>   DW_AT_name        : avr/atmega328p.pp
    <e5>   DW_AT_producer    : Free Pascal 3.3.1 2022/09/24
    <102>   DW_AT_comp_dir    : G:/Programming/dimitris/tools/laz-2.2.2_fpc-3.2.2/fpc/3.3.1/source/rtl/embedded/
    <153>   DW_AT_language    : 9    (ANSI Pascal)
    <154>   DW_AT_identifier_case: 3    (case_insensitive)
    <155>   DW_AT_stmt_list   : 0x5e
    <159>   DW_AT_low_pc      : 0x214
    <15d>   DW_AT_high_pc     : 0x21a

( Removed atmega328p.pp debug info for space )

 <1><10bf>: Abbrev Number: 0
  Compilation Unit @ offset 0x10c0:
   Length:        0x2c1 (32-bit)
   Version:       3
   Abbrev Offset: 0x88
   Pointer Size:  4
 <0><10cb>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <10cc>   DW_AT_name        : utestobj.pas
    <10d9>   DW_AT_producer    : Free Pascal 3.3.1 2022/09/24
    <10f6>   DW_AT_comp_dir    : G:/Programming/dimitris/Projects/fpc_avr_bugs/debug_objects/
    <1133>   DW_AT_language    : 9    (ANSI Pascal)
    <1134>   DW_AT_identifier_case: 3    (case_insensitive)
    <1135>   DW_AT_stmt_list   : 0x1b8
    <1139>   DW_AT_low_pc      : 0x21a
    <113d>   DW_AT_high_pc     : 0x32a
 <1><1141>: Abbrev Number: 2 (DW_TAG_subprogram)
    <1142>   DW_AT_name        : DoSomething
    <114e>   DW_AT_prototyped  : 1
    <114f>   DW_AT_external    : 1
    <1150>   DW_AT_low_pc      : 0x2d2
    <1154>   DW_AT_high_pc     : 0x32a
 <2><1158>: Abbrev Number: 3 (DW_TAG_variable)
    <1159>   DW_AT_name        : i
    <115b>   DW_AT_location    : 2 byte block: 8c 2 (DW_OP_breg28 (r28): 2)
    <115e>   DW_AT_type        : <0x116d>
 <2><1162>: Abbrev Number: 3 (DW_TAG_variable)
    <1163>   DW_AT_name        : x
    <1165>   DW_AT_location    : 2 byte block: 8c 4 (DW_OP_breg28 (r28): 4)
    <1168>   DW_AT_type        : <0x116d>
 <2><116c>: Abbrev Number: 0
 <1><116d>: Abbrev Number: 4 (DW_TAG_typedef)
    <116e>   DW_AT_name        : SmallInt
    <1177>   DW_AT_type        : <0x117b>
 <1><117b>: Abbrev Number: 5 (DW_TAG_base_type)
    <117c>   DW_AT_name        : SmallInt
    <1185>   DW_AT_encoding    : 5    (signed)
    <1186>   DW_AT_byte_size   : 2
 <1><1187>: Abbrev Number: 6 (DW_TAG_reference_type)
    <1188>   DW_AT_type        : <0x116d>
 <1><118c>: Abbrev Number: 4 (DW_TAG_typedef)
    <118d>   DW_AT_name        : TTestObj
    <1196>   DW_AT_type        : <0x119a>
 <1><119a>: Abbrev Number: 7 (DW_TAG_structure_type)
    <119b>   DW_AT_name        : TTestObj
    <11a4>   DW_AT_byte_size   : 0
 <2><11a5>: Abbrev Number: 0
 <1><11a6>: Abbrev Number: 6 (DW_TAG_reference_type)
    <11a7>   DW_AT_type        : <0x118c>
 <1><11ab>: Abbrev Number: 4 (DW_TAG_typedef)
    <11ac>   DW_AT_name        : TTestRec
    <11b5>   DW_AT_type        : <0x11b9>
 <1><11b9>: Abbrev Number: 7 (DW_TAG_structure_type)
    <11ba>   DW_AT_name        : TTESTREC
    <11c3>   DW_AT_byte_size   : 0
 <2><11c4>: Abbrev Number: 2 (DW_TAG_subprogram)
    <11c5>   DW_AT_name        : DoSomething
    <11d1>   DW_AT_prototyped  : 1
    <11d2>   DW_AT_external    : 1
    <11d3>   DW_AT_low_pc      : 0x276
    <11d7>   DW_AT_high_pc     : 0x2d2
 <3><11db>: Abbrev Number: 8 (DW_TAG_formal_parameter)
    <11dc>   DW_AT_name        : this
    <11e1>   DW_AT_location    : 3 byte block: 8c 2 6 (DW_OP_breg28 (r28): 2; DW_OP_deref)
    <11e5>   DW_AT_artificial  : 1
    <11e6>   DW_AT_type        : <0x11ab>
 <3><11ea>: Abbrev Number: 3 (DW_TAG_variable)
    <11eb>   DW_AT_name        : i
    <11ed>   DW_AT_location    : 2 byte block: 8c 4 (DW_OP_breg28 (r28): 4)
    <11f0>   DW_AT_type        : <0x116d>
 <3><11f4>: Abbrev Number: 3 (DW_TAG_variable)
    <11f5>   DW_AT_name        : x
    <11f7>   DW_AT_location    : 2 byte block: 8c 6 (DW_OP_breg28 (r28): 6)
    <11fa>   DW_AT_type        : <0x116d>
 <3><11fe>: Abbrev Number: 0
 <2><11ff>: Abbrev Number: 0
 <1><1200>: Abbrev Number: 6 (DW_TAG_reference_type)
    <1201>   DW_AT_type        : <0x11ab>
 <1><1205>: Abbrev Number: 4 (DW_TAG_typedef)
    <1206>   DW_AT_name        : $rttidef$INIT_$UTESTOBJ_$$_TTESTOBJ
    <122a>   DW_AT_type        : <0x122e>
 <1><122e>: Abbrev Number: 7 (DW_TAG_structure_type)
    <122f>   DW_AT_name        : $RTTIDEF$INIT_$UTESTOBJ_$$_TTESTOBJ
    <1253>   DW_AT_byte_size   : 26
 <2><1254>: Abbrev Number: 0
 <1><1255>: Abbrev Number: 6 (DW_TAG_reference_type)
    <1256>   DW_AT_type        : <0x1205>
 <1><125a>: Abbrev Number: 4 (DW_TAG_typedef)
    <125b>   DW_AT_name        : $rttidef$RTTI_$UTESTOBJ_$$_TTESTOBJ
    <127f>   DW_AT_type        : <0x1283>
 <1><1283>: Abbrev Number: 7 (DW_TAG_structure_type)
    <1284>   DW_AT_name        : $RTTIDEF$RTTI_$UTESTOBJ_$$_TTESTOBJ
    <12a8>   DW_AT_byte_size   : 22
 <2><12a9>: Abbrev Number: 0
 <1><12aa>: Abbrev Number: 6 (DW_TAG_reference_type)
    <12ab>   DW_AT_type        : <0x125a>
 <1><12af>: Abbrev Number: 4 (DW_TAG_typedef)
    <12b0>   DW_AT_name        : $rttidef$INIT_$UTESTOBJ_$$_TTESTREC
    <12d4>   DW_AT_type        : <0x12d8>
 <1><12d8>: Abbrev Number: 7 (DW_TAG_structure_type)
    <12d9>   DW_AT_name        : $RTTIDEF$INIT_$UTESTOBJ_$$_TTESTREC
    <12fd>   DW_AT_byte_size   : 26
 <2><12fe>: Abbrev Number: 0
 <1><12ff>: Abbrev Number: 6 (DW_TAG_reference_type)
    <1300>   DW_AT_type        : <0x12af>
 <1><1304>: Abbrev Number: 4 (DW_TAG_typedef)
    <1305>   DW_AT_name        : $rtti_header$8
    <1314>   DW_AT_type        : <0x1318>
 <1><1318>: Abbrev Number: 7 (DW_TAG_structure_type)
    <1319>   DW_AT_name        : $RTTI_HEADER$8
    <1328>   DW_AT_byte_size   : 10
 <2><1329>: Abbrev Number: 0
 <1><132a>: Abbrev Number: 6 (DW_TAG_reference_type)
    <132b>   DW_AT_type        : <0x1304>
 <1><132f>: Abbrev Number: 4 (DW_TAG_typedef)
    <1330>   DW_AT_name        : $rttidef$RTTI_$UTESTOBJ_$$_TTESTREC
    <1354>   DW_AT_type        : <0x1358>
 <1><1358>: Abbrev Number: 7 (DW_TAG_structure_type)
    <1359>   DW_AT_name        : $RTTIDEF$RTTI_$UTESTOBJ_$$_TTESTREC
    <137d>   DW_AT_byte_size   : 22
 <2><137e>: Abbrev Number: 0
 <1><137f>: Abbrev Number: 6 (DW_TAG_reference_type)
    <1380>   DW_AT_type        : <0x132f>
 <1><1384>: Abbrev Number: 0 

Possible fixes

Edited by d.ioannidis
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information