2575 – gdb: can not show code

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2575 - gdb: can not show code
Summary: gdb: can not show code
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 major
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks: 3207
Show dependency tree / graph
Reported: 2009年01月10日 16:28 UTC by Jason House
Modified: 2015年06月09日 01:21 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Jason House 2009年01月10日 16:28:53 UTC
The URL shows how this bug typically manifests itself. GDB seems to look for .s files for assembly code and can't seem to find them. This behavior exhibits itself with all D2 programs I've tried, including void main(){}
Comment 1 Jason House 2009年01月24日 11:16:01 UTC
After a lot of help from volodya on irc #gdb, it looks like the issue is that the low_pc and high_pc attributes are missing.
GDB can try to compensate for this (as if it was some legacy producer of debug info) by walking the children, but it only looks at "namespace" and "subprogram". D has "module" which stops it.
Comment 2 Mihail Zenkov 2009年01月24日 16:09:34 UTC
Break points don't work with demangled name. Not sure but imho problem in incorrect DW_AT_name and/or not provided DW_AT_MIPS_linkage by DMD.
DMD put mangled name to DW_AT_name:
 <2><91>: Abbrev Number: 6 (DW_TAG_subprogram)
 DW_AT_sibling : <c8>
 DW_AT_name : _D5crash3fooFZv
 DW_AT_decl_file : 1
 DW_AT_decl_line : 12
 DW_AT_low_pc : 0
 DW_AT_high_pc : 0x16
 DW_AT_frame_base : 1 byte block: 55 (DW_OP_reg5)
GDC/GCC put mangled name to DW_AT_MIPS_linkage_name and demandled to DW_AT_name:
 <1><bd>: Abbrev Number: 6 (DW_TAG_subprogram)
 DW_AT_external : 1
 DW_AT_name : foo
 DW_AT_decl_file : 1
 DW_AT_decl_line : 12
 DW_AT_MIPS_linkage_name: _D5crash3fooFZv
 DW_AT_low_pc : 0x3b
 DW_AT_high_pc : 0x51
 DW_AT_frame_base : 0x43 (location list)
After fix DW_TAG_module you can try use mangled name, for example main - _Dmain
Comment 3 Mihail Zenkov 2009年02月07日 20:56:12 UTC
GDB also work fine with LDC debug info.
 <1><a7>: Abbrev Number: 3 (DW_TAG_subprogram)
 DW_AT_name : crash.foo
 DW_AT_MIPS_linkage_name: _D5crash3fooFZv
 DW_AT_external : 1
 DW_AT_prototyped : 1
 DW_AT_decl_file : 1
 DW_AT_decl_line : 11
 DW_AT_low_pc : 0x20
 DW_AT_high_pc : 0x21
 DW_AT_frame_base : 1 byte block: 54 (DW_OP_reg4)
Comment 4 Jason House 2009年02月15日 10:00:38 UTC
It looks like the URL showing the problem has expired. Here's a sample session. I upped the severity because this is a really painful bug in dmd for me. I'm forced to place tons of writefln statements into the code instead of being able to step through it in the debugger
jhouse@jhouse-laptop:~/housebot/0.8$ gdb ./housebot-0.8 
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) break main
Breakpoint 1 at 0x8059e87
(gdb) run
Starting program: /home/jhouse/housebot/0.8/housebot-0.8 
[Thread debugging using libthread_db enabled]
[New Thread 0xb7c3eb00 (LWP 23503)]
[Switching to Thread 0xb7c3eb00 (LWP 23503)]
Breakpoint 1, 0x08059e87 in main ()
Current language: auto; currently asm
(gdb) list
1	/tmp/ccPssJzP.s: No such file or directory.
	in /tmp/ccPssJzP.s
(gdb) quit
The program is running. Exit anyway? (y or n) y
jhouse@jhouse-laptop:~/housebot/0.8$ 
Comment 5 Walter Bright 2009年02月20日 04:42:07 UTC
But dmd does emit the low_pc and high_pc data. Compile:
int foo(int i) { return i * i; }
with:
dmd -c -g foo.d
Then run dumpobj on it:
dumpobj -p foo.o
which will pretty-print the dwarf debug into. The attributes are there.
Comment 6 Jason House 2009年02月20日 07:54:59 UTC
D'oh, if only I reported more information when I remembered it.
Trying now, I'm doing "objdump -Wgs <executable>" and then searching for module.
What I see right before it is DW_TAG_compile_unit. I don't see DW_AT_high_pc and DW_AT_low_pc in that section, but I don't know if it's supposed to be there. The impression I got from my chats on #gdb was that the debug data was stored in somewhat of a hierarchical structure. In order to figure out the offsets for the source file, it wanted to find the high and low attributes but did not. There's a workaround inside gdb that will walk the children in order to get around the behavior of old compilers, but it's fragile. Having modern stuff such as DW_TAG_module stops it from operating (since it doesn't match what old compilers did).
That's all I can remember/reproduce with some experimentation with objdump. Can you reproduce the problem? Maybe chat with someone on #gdb? I had to wait ~12 hours to get a response. Once I did, they were very helpful. I'll guess the compile_unit should have high_pc and low_pc, but I'm only guessing. If you can reproduce the issue, then it should be easy to see if what you did works or not. Sorry for the lack of detail :(
Comment 7 Walter Bright 2009年02月25日 00:30:08 UTC
Looks like DW_AT_MIPS_linkage_name is an undocumented vendor extension to Dwarf.
Comment 8 Mihail Zenkov 2009年02月25日 20:46:19 UTC
It undocumented but widely used. IMHO better use them for mangled name than DW_AT_name. Current way violates DWARF:
"Because the names of program objects described by DWARF are the names as they appear in the source program, implementations of language translators that use some form of mangled name (as do many implementations of C++) should use the unmangled form of the name in the DWARF DW_AT_name attribute, including the keyword operator (in names such as "operator +"), if present. Sequences of multiple whitespace characters may be compressed."
Comment 9 Walter Bright 2009年08月05日 01:21:42 UTC
I'll add the MIPS_linkage tag and change the name tag. We'll see how far that gets us.
Comment 10 Walter Bright 2009年09月03日 13:24:21 UTC
Fixed dmd 1.047 and 2.032
Comment 11 Leandro Lucarella 2009年10月12日 16:16:19 UTC
This is not entirely fixed for DMD 2, see bug 3368.
Comment 12 Leandro Lucarella 2009年10月12日 16:23:21 UTC
Woops! Closing it again since it doesn't look like the same problem. The bug I meant to reopen was bug 1079.


AltStyle によって変換されたページ (->オリジナル) /