www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - gdb seg fault

reply Chris <central_p hotmail.com> writes:
Does anybody know why when trying to debug a "Hello world" program with 
gdb under cygwin, it causes a segmentation fault? But it runs fine, when 
it is not debugged.

Here is the program:

import std.stdio;

void main()
{
     int i = 1;
     i++;
     printf("Good bye");
     writefln("\n%d", i);
}
Feb 18 2006
parent reply John Demme <me teqdruid.com> writes:
I bet you're using the -g flag with dmd.  If you disable that, gdb doesn't
crash. (Right?)

If the above is true, then this happens because gdb uses the DWARF2
debugging information standard, whereas the little information that DMD
outputs is in DWARF3... The only practical difference is that D has a
language tag in DWARF3, so gdb can know what language the program is in. 
Unpatched versions of gdb, however, don't have a clue about D and when they
read the tag, just crash.  I have a patch for GDB on dsource.org that adds
the tag to GDB as well as adds symbol demangling.  I'd suggest you give it
a try.

Alternatively, compile with the -gc flag instead to tell DMD to lie and
output C's debugging tag.

~John Demme

Chris wrote:

 Does anybody know why when trying to debug a "Hello world" program with
 gdb under cygwin, it causes a segmentation fault? But it runs fine, when
 it is not debugged.
 
 Here is the program:
 
 import std.stdio;
 
 void main()
 {
      int i = 1;
      i++;
      printf("Good bye");
      writefln("\n%d", i);
 }
Feb 18 2006
next sibling parent reply Chris <central_p hotmail.com> writes:
Sorry,

I've forgot to mention that I was using gdc.

Files compiled with dmd are not recognized by GDB.

Here is the message:
$ gdb d.exe
GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you 
arewelcome to change it and/or distribute copies of it under certain 
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-cygwin"..."/cygdrive/e/home/My 
Documents/CodeBlocks Projects/d/d.exe": not in executable format: File 
format not recognized

John Demme wrote:
 I bet you're using the -g flag with dmd.  If you disable that, gdb doesn't
 crash. (Right?)
 
 If the above is true, then this happens because gdb uses the DWARF2
 debugging information standard, whereas the little information that DMD
 outputs is in DWARF3... The only practical difference is that D has a
 language tag in DWARF3, so gdb can know what language the program is in. 
 Unpatched versions of gdb, however, don't have a clue about D and when they
 read the tag, just crash.  I have a patch for GDB on dsource.org that adds
 the tag to GDB as well as adds symbol demangling.  I'd suggest you give it
 a try.
 
 Alternatively, compile with the -gc flag instead to tell DMD to lie and
 output C's debugging tag.
 
 ~John Demme
 
 Chris wrote:
 
 Does anybody know why when trying to debug a "Hello world" program with
 gdb under cygwin, it causes a segmentation fault? But it runs fine, when
 it is not debugged.

 Here is the program:

 import std.stdio;

 void main()
 {
      int i = 1;
      i++;
      printf("Good bye");
      writefln("\n%d", i);
 }
Feb 19 2006
parent John Demme <me teqdruid.com> writes:
Chris wrote:
 Here is the message:
 $ gdb d.exe
 GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special)
 Copyright 2004 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and you
 arewelcome to change it and/or distribute copies of it under certain
 conditions.
 Type "show copying" to see the conditions.
 There is absolutely no warranty for GDB.  Type "show warranty" for
 details. This GDB was configured as
 "i686-pc-cygwin"..."/cygdrive/e/home/My Documents/CodeBlocks
 Projects/d/d.exe": not in executable format: File format not recognized
 
I don't think GDB supports windows executables.
Feb 19 2006
prev sibling parent reply Chris <central_p hotmail.com> writes:
Sorry for asking this but how do I apply this patch? I'm not used to 
compiling OSS. Where should I look for more info?

Thank you for the tips

  Chris


John Demme wrote:
 I bet you're using the -g flag with dmd.  If you disable that, gdb doesn't
 crash. (Right?)
 
 If the above is true, then this happens because gdb uses the DWARF2
 debugging information standard, whereas the little information that DMD
 outputs is in DWARF3... The only practical difference is that D has a
 language tag in DWARF3, so gdb can know what language the program is in. 
 Unpatched versions of gdb, however, don't have a clue about D and when they
 read the tag, just crash.  I have a patch for GDB on dsource.org that adds
 the tag to GDB as well as adds symbol demangling.  I'd suggest you give it
 a try.
 
 Alternatively, compile with the -gc flag instead to tell DMD to lie and
 output C's debugging tag.
 
 ~John Demme
 
 Chris wrote:
 
 Does anybody know why when trying to debug a "Hello world" program with
 gdb under cygwin, it causes a segmentation fault? But it runs fine, when
 it is not debugged.

 Here is the program:

 import std.stdio;

 void main()
 {
      int i = 1;
      i++;
      printf("Good bye");
      writefln("\n%d", i);
 }
Feb 19 2006
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Chris wrote:

 Sorry for asking this but how do I apply this patch? I'm not used to 
 compiling OSS. Where should I look for more info?
RTFM :-) http://www.gnu.org/software/diffutils/manual/html_node/index.html Usually invoked something like: "patch -p1 -i whatever.patch" You can use the GNU --dry-run flag first, for a practice run... --anders
Feb 19 2006