Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Forums
  - IRC
  - Community Discord
  - Wiki
  - GitHub
  - Issues
  - Get involved
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

# Debugging D on Windows

The D reference compiler DMD and the LLVM-based LDC compiler can both output symbolic debug information that can be used by most Windows debuggers. With the exception of generating OMF object files when using -m32 with dmd, the linker will generate a PDB file containing the debug information of the executable.

To prepare a program for symbolic debugging, compile with the -gf switch:

    dmd -gf -m64 myprogram.d

How to start debugging the program depends on debugger being used. For example debugging with Visual Studio can be invoked by opening the "Developer Command Prompt for VS" and executing:

    devenv myprogram.exe

If you want to pass arguments to the debuggee you have to use the /debugexe switch:

    devenv /debugexe myprogram.exe args...

where args... are the command line arguments to myprogram.exe.

When the debugger comes up, load myprogram.d and set a breakpoint at the beginning of your main() function. Running the program will stop at your breakpoint in main(). The debugger should then allow you to step through the program, show local variables and watch expressions.

If you have Visual D installed as an extension to Visual Studio, the debugger understands D expressions in watch expressions and is able to inspect D-specific language constructs like dynamic and associative arrays. This functionality might also be available in other debuggers if they support it through mago-mi.

Debuggers without these extensions will interpret your code as C/C++. Most debug information maps naturally to C data structures, but the respective syntax has to be used, e.g. -> must be used instead of . to display a class member in a watch expression.

When compiling the program with dmd without specifying an architecture (i.e. using the default -m32), the Digital Mars linker optlink.exe is used to produce the executable. The debug information format used is an ancient version of CodeView that is only partially supported by more recent debuggers. You can use cv2pdb to convert the debug information to the ubiquitous PDB format.

Copyright © 1999-2023 by the D Language Foundation | Page generated by Ddoc on Sun Jul 2 00:31:16 2023