1# Line number information23Line number information maps between machine code instructions and the source level location.45## Encoding67The line number information is stored in the `.debug_line` section for ELF and `__debug_line`8section of the `__DWARF` segment for Mach-O object files. The line number information contains a9header followed by the line program. The line program is a program for a virtual machine with10instructions like set line number for the current machine code instruction and advance the current11machine code instruction.1213## Tips1415You need to set either `DW_AT_low_pc` and `DW_AT_high_pc` **or** `DW_AT_ranges` of a16`DW_TAG_compilation_unit` to the range of addresses in the compilation unit. After that you need17to set `DW_AT_stmt_list` to the `.debug_line` section offset of the line program. Otherwise a18debugger won't find the line number information. On macOS the debuginfo relocations **must** be19section relative and not symbol relative.20See [#303 (comment)](https://github.com/bjorn3/rustc_codegen_cranelift/issues/303#issuecomment-457825535)21for more information.2223# Function debuginfo2425## Tips2627`DW_TAG_subprogram` requires `DW_AT_name`, `DW_AT_low_pc` and `DW_AT_high_pc` **or** `DW_AT_ranges`.28Otherwise gdb will silently skip it. When `DW_AT_high_pc` is a length instead of an address, the29DWARF version must be at least 4.3031<details>32<summary>IRC log of #gdb on irc.freenode.org at 2020-04-23</summary>3334```35(13:46:11) bjorn3: i am writing a backend for a compiler that uses DWARF for debuginfo. for some reason gdb seems to completely ignore all DW_TAG_subprogram, while lldb works fine. any idea what the problem could be?36(13:47:49) bjorn3: this is the output of llvm-dwarfdump: https://gist.github.com/bjorn3/8a34e333c80f13cb048381e94b4a375637(13:47:50) osa1: luispm: why is that problem not exists in 'commands'? (the target vs. host)38(13:52:16) luispm: osa1, commands is a bit more high level. It executes isolated commands. Breakpoint conditions need to be evaluated in the context of a valid expression. That expression may involve variables, symbols etc.39(13:52:36) luispm: osa1, Oh, i see your point now. Commands is only executed on the host.40(13:53:18) luispm: osa1, The commands are not tied to the execution context of the debugged program. The breakpoint conditions determine if execution must stop or continue etc.41(13:55:00) luispm: bjorn3, Likely something GDB thinks is wrong. Does enabling "set debug dwarf*" show anything?42(13:56:01) bjorn3: luispm: no43(13:56:12) bjorn3: for more context: https://github.com/bjorn3/rustc_codegen_cranelift/pull/97844(13:58:16) osa1 verliet de ruimte (quit: Quit: osa1).45(13:58:28) bjorn3: luispm: wait, for b m<TAB> it shows nothing, but when stepping into a new function it does46(13:58:45) bjorn3: it still doesn't show anything for `info args` though47(13:58:50) bjorn3: No symbol table info available.48(14:00:50) luispm: bjorn3, Is that expected given the nature of the binary?49(14:01:17) bjorn3: b main<TAB> may show nothing as I only set DW_AT_linkage_name and not DW_AT_name50(14:01:24) bjorn3: info args should work though51(14:03:26) luispm: Sorry, I'm not sure what's up. There may be a genuine bug there.52(14:03:41) luispm: tromey (not currently in the channel, but maybe later today) may have more input.53(14:04:08) bjorn3: okay, thanks luispm!54(14:04:27) luispm: In the worst case, reporting a bug may prompt someone to look into that as well.55(14:04:48) luispm: Or send an e-mail to the gdb@sourceware.org mailing list.56(14:05:11) bjorn3: I don't know if it is a bug in gdb, or just me producing (slightly) wrong DWARF57(14:39:40) irker749: gdb: tom binutils-gdb.git:master * 740480b88af / gdb/ChangeLog gdb/darwin-nat.c gdb/inferior.c gdb/inferior.h: Remove iterate_over_inferiors58(15:22:45) irker749: gdb: tromey binutils-gdb.git:master * ecc6c6066b5 / gdb/ChangeLog gdb/dwarf2/read.c gdb/unittests/lookup_name_info-selftests.c: Fix Ada crash with .debug_names59(15:23:13) bjorn3: tromey: ping60(15:23:29) tromey: bjorn3: hey61(15:24:16) bjorn3: I am writing a backend for a compiler which uses DWARF for debuginfo. I unfortunately can't get gdb to show arguments. lldb works fine.62(15:25:13) bjorn3: it just says: No symbol table info available.63(15:25:21) bjorn3: any idea what it could be?64(15:25:34) bjorn3: dwarfdump output: https://gist.github.com/bjorn3/8a34e333c80f13cb048381e94b4a375665(15:26:48) bjorn3: more context: https://github.com/bjorn3/rustc_codegen_cranelift/pull/97866(15:28:05) tromey: offhand I don't know, but if you can send me an executable I can look67(15:28:17) bjorn3: how should I send it?68(15:29:26) tromey: good question69(15:29:41) tromey: you could try emailing it to tromey at adacore.com70(15:29:47) tromey: dunno if that will work or not71(15:30:26) bjorn3: i will try72(15:37:27) bjorn3: tromey: i sent an email with the subject "gdb args not showing"73(15:38:29) tromey: will check now74(15:38:40) bjorn3: thanks!75(15:42:51) irker749: gdb: tdevries binutils-gdb.git:master * de82891ce5b / gdb/ChangeLog gdb/block.c gdb/block.h gdb/symtab.c gdb/testsuite/ChangeLog gdb/testsuite/gdb.base/decl-before-def-decl.c gdb/testsuite/gdb.base/decl-before-def-def.c gdb/testsuite/gdb.base/decl-before-def.exp: [gdb/symtab] Prefer def over decl (inter-CU case)76(15:42:52) irker749: gdb: tdevries binutils-gdb.git:master * 70bc38f5138 / gdb/ChangeLog gdb/symtab.c gdb/testsuite/ChangeLog gdb/testsuite/gdb.base/decl-before-def.exp: [gdb/symtab] Prefer def over decl (inter-CU case, with context)77(15:43:36) tromey: bjorn3: sorry, got distracted. I have the file now78(15:45:35) tromey: my first thing when investigating was to enable complaints79(15:45:37) tromey: so I did80(15:45:40) tromey: set complaints 100081(15:45:42) tromey: then82(15:45:51) tromey: file -readnow mini_core_hello_world83(15:46:00) tromey: gdb printed just one style of complaint84(15:46:07) tromey: During symbol reading: missing name for subprogram DIE at 0x3f785(15:46:18) tromey: (which is really pretty good, most compilers manage to generate a bunch)86(15:46:29) tromey: and then the gdb DWARF reader says87(15:46:34) tromey: /* Ignore functions with missing or empty names. These are actually88(15:46:34) tromey: illegal according to the DWARF standard. */89(15:46:34) tromey: if (name == NULL)90(15:46:34) tromey: {91(15:46:37) tromey: complaint (_("missing name for subprogram DIE at %s"),92(15:46:40) tromey: sect_offset_str (die->sect_off));93(15:46:47) tromey: I wonder if that comment is correct though94(15:47:34) tromey: I guess pedantically maybe it is, DWARF 5 3.3.1 says95(15:47:43) tromey: The subroutine or entry point entry has a DW_AT_name attribute whose value is96(15:47:43) tromey: a null-terminated string containing the subroutine or entry point name.97(15:48:14) bjorn3: i tried set complaints, but it returned complaints for system files. i didn't know about file -readnow.98(15:48:21) tromey: cool99(15:48:26) bjorn3: i will try adding DW_AT_name100(15:48:45) tromey: without readnow unfortunately you get less stuff, because for whatever reason gdb has 2 separate DWARF scanners101(15:49:02) tromey: sort of anyway102(15:49:43) tromey: this seems kind of pedantic of gdb, like if there's a linkage name but no DW_AT_name, then why bail?103(15:50:01) tromey: also what about anonymous functions104(15:50:17) tromey: but anyway this explains the current situation and if you don't mind adding DW_AT_name, then that's probably simplest105(15:51:47) bjorn3: i added DW_AT_name.106(15:51:54) bjorn3: now it says cannot get low and high bounds for subprogram DIE at ...107(15:52:01) tromey: ugh108(15:52:10) bjorn3: i will add DW_AT_low_pc and DW_AT_high_pc109(15:52:15) tromey: /* Ignore functions with missing or invalid low and high pc attributes. */110(15:52:37) tromey: you can also use DW_AT_ranges111(15:52:55) tromey: if you'd prefer112(15:53:08) bjorn3: already using DW_AT_ranges for DW_TAG_compilation_unit113(15:53:19) bjorn3: for individual functions, there are no gaps114(15:57:07) bjorn3: still the same error with DW_AT_low_pc and DW_AT_high_pc115(15:57:24) bjorn3: tromey: ^116(15:58:08) tromey: hmmm117(15:58:30) bjorn3: should i send the new executable?118(15:58:31) tromey: send me another executable & I will debug119(15:58:33) tromey: yep120(15:59:23) bjorn3: sent as repy of the previous mail121(16:03:23) tromey: the low PC has DW_FORM_addr, but the high PC has DW_FORM_udata, which seems weird122(16:03:50) mjw: no123(16:03:54) tromey: no?124(16:04:00) mjw: I suggested that for the DWARF standard...125(16:04:05) mjw: sorry126(16:04:58) mjw: The idea was that instead of two relocations and two address wide fields, you have one address and a constant offset.127(16:05:05) tromey: ahh, I see the code now128(16:05:07) tromey: I forgot about this129(16:05:18) tromey: if (cu->header.version >= 4 && attr_high->form_is_constant ())130(16:05:18) tromey: high += low;131(16:05:36) mjw: that second offset doesn't need a relocation and can often be packed in something small, like an uleb128132(16:05:51) mjw: using udata might not be ideal though, but is allowed133(16:05:51) tromey: bjorn3: the problem is that this CU claims to be DWARF 3 but is using a DWARF 4 feature134(16:05:58) mjw: aha135(16:05:59) bjorn3: which one?136(16:06:03) ryoshu: hi137(16:06:08) tromey: high_pc (udata) 107 (+0x00000000000011b0 <_ZN21mini_core_hello_world5start17hec55b7ca64fc434eE>)138(16:06:08) tromey:139(16:06:12) ryoshu: just soft ping, I have a queue of patches :)140(16:06:22) tromey: using this as a length requires DWARF 4141(16:06:36) tromey: for gdb at least it's fine to always emit DWARF 4142(16:06:44) bjorn3: trying dwarf 4 now143(16:06:48) tromey: I think there are some DWARF 5 features still in the works but DWARF 4 should be solid AFAIK144(16:07:03) tromey: fini145(16:07:08) tromey: lol wrong window146(16:07:56) mjw: Maybe you can accept it for DWARF < 4. But if I remember correctly it might be that people might have been using udata as if it was an address...147(16:08:13) tromey: yeah, I vaguely recall this as well, though I'd expect there to be a comment148(16:08:21) mjw: Cannot really remember why it needed version >= 4. Maybe there was no good reason?149(16:08:32) bjorn3: tromey: it works!!!! thanks for all the help!150(16:08:41) tromey: my pleasure bjorn3151```152153</details>
Findings
✓ No findings reported for this file.