www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.debugger - Basic expressions in GDB

reply Valentino Giudice <valentino.giudice96 gmail.com> writes:
Hi all.
I am a newbie and this is my first time posting on a D forum.

I am using GDB on Linux, from Windows, trough WSL.
I am compiling using DMD (in debug mode), as this seems to give 
better results than using GDC.

So far, I have failed to do the following:

- Create, from the debugger, a string. A sequence of characters 
between quote is evaluated as a C-style array of chars.
- Call a function from the debugger with its name. Only 
unintuitive mangled names can be used and the output has to be 
cast in the proper type.

If I compile using GDC or LDC, then global variables inside a 
module will have two names: "module.variable" and a mangled name.
They have to be cast when read and the "module.variable" name 
needs to be accessed using single quotes around it, or it crashes.

When compiling with DMD this doesn't happen: global variables 
only have the "module.variable" name, which can be read without 
any cast and with or without single quotes.

What should I consider when writing expressions in the debugger?
Is there any way to write expression closer to the D syntax?

Thank you all in advance.
Jul 31
parent user1234 <user1234 12.de> writes:
On Thursday, 1 August 2024 at 03:24:30 UTC, Valentino Giudice 
wrote:
 Hi all.
 I am a newbie and this is my first time posting on a D forum.

 I am using GDB on Linux, from Windows, trough WSL.
 I am compiling using DMD (in debug mode), as this seems to give 
 better results than using GDC.

 So far, I have failed to do the following:

 - Create, from the debugger, a string. A sequence of characters 
 between quote is evaluated as a C-style array of chars.
 - Call a function from the debugger with its name. Only 
 unintuitive mangled names can be used and the output has to be 
 cast in the proper type.

 If I compile using GDC or LDC, then global variables inside a 
 module will have two names: "module.variable" and a mangled 
 name.
 They have to be cast when read and the "module.variable" name 
 needs to be accessed using single quotes around it, or it 
 crashes.

 When compiling with DMD this doesn't happen: global variables 
 only have the "module.variable" name, which can be read without 
 any cast and with or without single quotes.

 What should I consider when writing expressions in the debugger?
 Is there any way to write expression closer to the D syntax?

 Thank you all in advance.
AFAIK with LDC (so debug info are generated with LLVM) there's no way to evaluate globals using expressions. The names somewhat look like expressions but it's actually just a full name, hence the need to had quotes, whereas for non-static member, it's really an expression. I have the same problem with static members ([0], onhe has to use "s.a" to see the value of the static member). Note that the LLVM API used to generate DWARF info is not even official (it's still at the "metadata" stage). "Not a so usefull answer" you might think. Well it's because initially I wanted to share that old blog post [1]. Essentially it's about linking your program with `extern(C)` functions, which allows better pretty printing (as you can call the function with a plain name since `extern(C)` stuff are not mangled). [0]: https://github.com/ldc-developers/ldc/issues/4567 [1]: https://medium.com/dunnhumby-data-science-engineering/how-to-simplify-debugging-unit-tests-in-d-a2b52c5c1fa
Sep 04