www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D2 and gdb

reply vnm <green_ tut.by> writes:
Hi!

Is there any support of D2 in gdb 7.2 ?

Little example to clarify my question:

------------------------------------------------------------

// file main.d
int glVar = 0xAAAAAAAA;

void main()
{
  glVar = 0xBBBBBBBB;
}

------------------------------------------------------------

I compiled it using command "dmd -gc -debug main.d";
then I load it to gdb and trying to debug application:

------------------------------------------------------------

vnm vnm:~/proj/d_gdb_test$ gdb main
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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 "i686-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /home/vnm/proj/d_gbb_test/main...done.
(gdb) b main
Breakpoint 1 at 0x804b667
(gdb) r
Starting program: /home/vnm/proj/d_gbb_test/main
[Thread debugging using libthread_db enabled]

Breakpoint 1, 0x0804b667 in main ()
(gdb) info line
No line number information available.
(gdb) info variables glVar
All variables matching regular expression "glVar":

File main.d:
int _D4main5glVari;

------------------------------------------------------------

Why gdb can't show line information and why it shows symbols in mangled 
form ? Is this software issues or I'm doing something wrong ?
AFAIK, gdb 7.2 integrated some patch for D support (including symbols 
demangling feature). This patch was D1 only ?
Jan 25 2011
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 25 Jan 2011 15:44:59 -0500, vnm <green_ tut.by> wrote:

 Why gdb can't show line information and why it shows symbols in mangled  
 form ? Is this software issues or I'm doing something wrong ?
 AFAIK, gdb 7.2 integrated some patch for D support (including symbols  
 demangling feature). This patch was D1 only ?
I don't know anything about the symbol mangling, but the symbol of main is actually _Dmain. main() is the runtime's main which ends up calling your main function. I'm pretty sure gdb doesn't know this. Likely, the runtime is compiled without the debug flags, so you won't get any line info there. Try breaking on Dmain instead. -Steve
Jan 25 2011
parent vnm <green_ tut.by> writes:
On 01/26/2011 12:28 AM, Steven Schveighoffer wrote:
 On Tue, 25 Jan 2011 15:44:59 -0500, vnm <green_ tut.by> wrote:

 Why gdb can't show line information and why it shows symbols in
 mangled form ? Is this software issues or I'm doing something wrong ?
 AFAIK, gdb 7.2 integrated some patch for D support (including symbols
 demangling feature). This patch was D1 only ?
I don't know anything about the symbol mangling, but the symbol of main is actually _Dmain. main() is the runtime's main which ends up calling your main function. I'm pretty sure gdb doesn't know this. Likely, the runtime is compiled without the debug flags, so you won't get any line info there. Try breaking on Dmain instead. -Steve
Steve, Robert, thanks for explanations about main/_Dmain. Situation with symbols names demangling stays unclear to me...
Jan 26 2011
prev sibling parent Robert Clipsham <robert octarineparrot.com> writes:
On 25/01/11 20:44, vnm wrote:
 Hi!

 Is there any support of D2 in gdb 7.2 ?

 Little example to clarify my question:

 ------------------------------------------------------------

 // file main.d
 int glVar = 0xAAAAAAAA;

 void main()
 {
 glVar = 0xBBBBBBBB;
 }

 ------------------------------------------------------------

 I compiled it using command "dmd -gc -debug main.d";
 then I load it to gdb and trying to debug application:

 ------------------------------------------------------------

 vnm vnm:~/proj/d_gdb_test$ gdb main
 GNU gdb (GDB) 7.2-ubuntu
 Copyright (C) 2010 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later
 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 "i686-linux-gnu".
 For bug reporting instructions, please see:
 ...
 Reading symbols from /home/vnm/proj/d_gbb_test/main...done.
 (gdb) b main
 Breakpoint 1 at 0x804b667
 (gdb) r
 Starting program: /home/vnm/proj/d_gbb_test/main
 [Thread debugging using libthread_db enabled]

 Breakpoint 1, 0x0804b667 in main ()
 (gdb) info line
 No line number information available.
 (gdb) info variables glVar
 All variables matching regular expression "glVar":

 File main.d:
 int _D4main5glVari;

 ------------------------------------------------------------

 Why gdb can't show line information and why it shows symbols in mangled
 form ? Is this software issues or I'm doing something wrong ?
 AFAIK, gdb 7.2 integrated some patch for D support (including symbols
 demangling feature). This patch was D1 only ?
As Steven has already stated, you need to use 'b _Dmain', then it will work as expected. When you do 'b main' it breaks at the runtime main() function, which handles things like uncaught exceptions, runtime initialisation, static constructors and destructors, unittest running etc. As the version of druntime that dmd is linking to has no debugging information, you end up with the above issues. Hope this helps. -- Robert http://octarineparrot.com/
Jan 25 2011