Debugging windows exe built with bazel using visual studio debugger

458 views
Skip to first unread message

Matthias Buehlmann

unread,
Oct 22, 2021, 7:14:14 AM10/22/21
to bazel-discuss

I'm building a windows exe using bazel (release 4.1.0). I'm building by first opening the "x64 Native Tools Command Prompt For VS 2019" in order to set the environment to use VS 2019 build tools and then use that command prompt to compile via

bazel --bazelrc windows.rc build --verbose_failures -c opt myproject:mytarget

in my windows.rc I added the following lines:

#embed debug symbols
build --copt /Z7
build --strip=never

and this causes the resulting exe to get significantly bigger. But when I then attach the Visual Studio 2019 Debugger to the process, Visual Studio nevertheless tells me "Binary was not built with debug information."

What else do I need to do to be able to attach the debugger and have debugging symbols loaded?

Matthias Buehlmann

unread,
Oct 25, 2021, 2:28:41 AM10/25/21
to bazel-discuss
I probably should add that I specifically want to be able to attach the debugger to a release build (-c opt) that was compiled with all optimizations enabled

Konstantin

unread,
Nov 5, 2021, 1:59:36 PM11/5/21
to bazel-discuss
Hi Matthias,

The short answer to your question: you need to add "build --linkopt /debug" to your .bazelrc file.

This page says "It is not possible to create an .exe or .dll that contains debug information. Debug information is always placed in a .obj or .pdb file.", so to get debuggable binary you have to create .PDB. In dbg build it is created by default, but for opt build it is not, so you have to request it explicitly.

Konstantin
Reply all
Reply to author
Forward
0 new messages