Debugging D code with GDB

Luís Ferreira contact at lsferreira.net
Mon Nov 29 14:48:21 UTC 2021


On Sun, 2021-11-28 at 21:59 +0000, Iain Buclaw via Digitalmars-d-learn
wrote:
> On Saturday, 27 November 2021 at 14:17:11 UTC, Eduard Staniloiu 
> wrote:
> > Hello,
> > 
> > I'm trying to use `gdb` to debug D binaries, but I'm having 
> > trouble accessing the methods of a struct or class. It seems 
> > that `gdb` doesn't see them.
> > 
> > Given the following simple example
> > ```
> > // test.d
> > struct S
> > {
> >     int x;
> > 
> >     void myPrint() { writefln("x is %s\n", x); }
> > }
> > 
> > void main(string[] args)
> > {
> >     S s;
> > }
> > ```
> > Compile the source file with debug simbols (`dmd -g test.d 
> > -of=test`) and open the binary with gdb (`gdb test`) and run 
> > the following
> > 
> > ```
> > > break _Dmain # break at D entry point
> > > run
> > > ptype s
> > type = struct test.S {
> >     int x;
> > }
> > > print s.myPrint()
> > Structure has no component named myPrint.
> > ```
> > 
> > As you can see, when I try to access the `myPrint()` method I 
> > get the error
> > "Structure has no component named myPrint."
> > 
> 
> DMD doesn't emit this information. GDB can't work miracles when 
> the compiler isn't pulling its own weight.

I confirm this is an issue with DMD. I filed a bug in the issue
tracker, in case you want to follow:
https://issues.dlang.org/show_bug.cgi?id=22551

Anyway, DMD exports the symbol, it should work if you do something like
`myPrint(&s)`, but I think there is another problem on calling it, due
to defective calling convention on both DMD and LDC implementations.

LDC exports the symbol correctly, although.

-- 
Sincerely,
Luís Ferreira @ lsferreira.net

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20211129/4888e898/attachment.sig>


More information about the Digitalmars-d-learn mailing list