Skip to content

emit DWARF debug info #170

@pointbazaar

Description

@pointbazaar

To support source level debugging, source level stepping, inspecting the stack frame, ...

Implementation idea:

Extend struct Instr (array of which is stored in struct IBuffer) with line number information.
Then the ibuffer instance will have complete line number information for every instruction.

When writing instructions to the .asm file, a label can be emitted every time the line number changes,
and then later refer to that label in the line number program.

Example for introspecting the .debug_line section of a simple program compiled with gcc -g main.c:

readelf --debug-dump=decodedline a.out 
Contents of the .debug_line section:

main.c:
File name                        Line number    Starting address    View    Stmt
main.c                                     3              0x1119               x
main.c                                     5              0x111d               x
main.c                                     7              0x1124               x
main.c                                     8              0x1127               x
main.c                                     -              0x1129

Listing sections

readelf --sections a.out 

Looking at another gcc-compiled program with dwarfdump (part of libdwarf)

[alex@odroid test-dwarf]$ dwarfdump --print-lines a.out 

.debug_line: line number info for a single cu
Source lines (from CU-DIE at .debug_info offset 0x0000000c):

            NS new statement, BB new basic block, ET end of text sequence
            PE prologue end, EB epilogue begin
            IS=val ISA number, DI=val discriminator value
<pc>        [lno,col] NS BB ET PE EB IS= DI= uri: "filepath"
0x00001119  [   3,12] NS uri: "/tmp/test-dwarf/main.c"
0x0000111d  [   5, 6] NS
0x00001124  [   5,17] NS
0x0000112b  [   5,28] NS
0x00001132  [   7,11] NS
0x0000113a  [   8, 1] NS
0x0000113c  [   8, 1] NS ET

To avoid passing through the line number information through every struct Instr creation,
can have something like ibu_set_line_no(ibu, line_no) to set it and when jmp(...) macro calls ibu_branch(...) which calls ibu_push4(...) that can then retrieve the line number information frum the struct IBuffer and insert into struct Instr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerissues related to the compilerenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions