On Friday, 5 June 2020 at 17:03:40 UTC, Luis wrote:
So I actually managed to "debug" my unittests but It requires that I run previsuly "dub test" on console, so the executable is update. As I understand, I need to setup a task to be prelaunched by debug to generate the unittest executable, but I don't know how setup it correctly. I only manage to build the library, but not the unittest executable.

Also, how hell I can see the content of a array on the debugger? I only see the length and "pointer" property. I try to add a watch expression to these pointer with the "@" but the show content, don't matches the real stuff on the array... This it's forcing me to use the old classic "debug with printfs" with it's annoying if you have pure @nogc nothrow annotated code.


I have the impression that debugging D has get worse in this last years. I remember debuging with "ddd" with zero issues like five years ago, and now I keep hitting all kind of troubles with anything that I try.

To build before running the debugger, add the following task to your task definitions file (Ctrl-Shift-B):

{
        "label": "dub build", // <-- add a good name here
        "type": "dub",
        "run": false,
        "buildType": "unittest", // <-- this makes it build the unittests
        "problemMatcher": [
                "$dmd"
        ],
        "group": "build"
}

And in the debug configuration add the preLaunchTask with the given label:

{
        "version": "0.2.0",
        "configurations": [
                {
                        ...,
                        "preLaunchTask": "dub build"
                }
        ]
}

For more information consult the User Guide (F1 -> code-d User Guide / Documentation) and see the Debugging section.



Directly debugging the unittests from code-d is not supported yet, but is in planning.

About the debugging printing: pretty printers might make it look worse than it would be with the plain GDB formatter. But definitely this could be improved. If you use the Native Debug extension it should default to the plain value printer, which in turn might make other stuff not look so good. If you use the C/C++ extension, you might be able to have better support if you add a Natvis file. Void-995 wrote a D natvis file like 2 years ago, which was never fully finished (DL: https://www.dropbox.com/s/t5yejma3w7cbna9/dlang.natvis?dl=1 ; mirror: https://wfr.moe/f6xBDC/dlang.natvis), so I'm not sure how well that works now.


Btw if you use the latest serve-d version (release channel "nightly") you will have snippets to insert debug printf statements like

debug { import std.stdio : writeln; try { writeln(""); } catch (Exception) {} } debug { import std.stdio : writefln; try { writefln!""(); } catch (Exception) {} }
debug { import core.stdc.stdio : printf; printf("\n"); }

which work in @nogc @safe nothrow pure

Reply via email to