Closed HolyBlackCat closed 3 years ago
This trips me up all the time, but it seems to be a gcc specific thing. First make sure you compile your debug build with -g & -Og (don't use any other optimizer flag in debug). Next you have to be aware of this limitation:
https://code.visualstudio.com/docs/languages/cpp#_known-limitations
GDB on Cygwin and MinGW cannot break a running process. To set a breakpoint when the application is running (not stopped under the debugger), or to pause the application being debugged, press Ctrl-C in the application's terminal.
So for instance if you're writing a game and have a game loop that updates/draws every frame, you have to either start debugging with existing breakpoints (and set new ones during those breaks) or hit Ctrl+C in the external console/windows command prompt after you've set new breakpoints on the fly.
@andrew-r-king I'm already using -g
with no other flags, as the issue says.
Thanks for the Ctrl+C trick! It looks like a reasonable workaround.
But if sending SIGINT manually works, couldn't VS code send it automatically when I place breakpoint while a program is running?
Also, in CodeBlocks placing a breakpoint somehow works as expected. Maybe they're doing just that?
@HolyBlackCat We have tried to work around this on Windows and haven't found a good way to send SIGINT to MinGW (or CYGWIN). The only way to set the breakpoint is what @andrew-r-king has mentioned, to send SIGINT yourself and stop and then set breakpoints OR set a breakpoint ahead of time (or use stopAtEntry
) and set your other breakpoints. If we could send SIGINT to the debugger during this process, it would be easier to deal with.
I don't know how CodeBlocks is doing it.
@pieandcakes I've rummaged in CB sources a bit, and found a part where they're sending the interrupt.
Here it is, function DebuggerGDB::DoBreak
:
http://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/debuggergdb/debuggergdb.cpp
Code::Block break by using DebugBreakProcess() to send breakpoint exception to debuggee on Windows.
This issue has been closed automatically because it has not had recent activity.
@pieandcakes is it possible to reopen this important issue? It's essential to be able to debug with GDB on Windows. Without it, breakpoints and pausing don't work, and debugging non-console apps is not possible.
This issue has been closed automatically because it has not had recent activity.
How is it possible this was never resolved?!
Issue Type: Bug
Pretty much what the title says.
If I add a breakpoint after starting the debugger, it becomes grayed out, with 'unverified breakpoint' tooltip. The application doesn't seem to hit it.
How to reproduce:
Create
test.cpp
with following contentsCompile it with
g++ -g test.cpp -o out.exe
.In the same directory, create
.vscode/launch.json
with following contents:Open this directory in VS Code, then open
test.cpp
. PressDEBUG: (gdb) Launch
button.Try adding a breakpoint on
std::cout ...
line. Boom, it immediately goes unverified.Some observations:
If I add a breakpoint before starting an application, it works properly. When application is paused on a such breakpoint, I can add a new breakpoint, and it will work properly as well. But if I press
Continue
and then add a breakpoint, it doesn't work.I can't execute any commands in the debug console. If the application is paused on a breakpoint, I get this:
If the application is already running, I get this:
My compiler identification is:
It's the last stable MinGW-w64 build, with default installation settings. Its
bin
directory is added toPATH
.There are no non-ASCII symbols neither in MinGW path, not in project path. The
gdb
that comes with MinGW works correctly in this scenario outside of VS Code (e.g. in CodeBlocks).The contents of the debug console after performing the minimal repro steps described above are
Extension version: 0.20.1 VS Code version: Code - Insiders 1.29.0-insider (bdfe4fd41f6a5fe538197b3cba937230249a563a, 2018-11-04T13:04:20.759Z) OS version: Windows_NT x64 6.1.7601
System Info
|Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz (4 x 3093)| |GPU Status|2d_canvas: enabledchecker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled| |Memory (System)|3.98GB (1.09GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|