Vscode-cpptools: can't stop at the breakpoint

Created on 19 Dec 2016  路  13Comments  路  Source: microsoft/vscode-cpptools

_From @andychen2016 on December 19, 2016 8:17_

  • VSCode Version: Code 1.7.2 (7ba55c5860b152d999dda59393ca3ebeb1b5c85f, 2016-11-21T22:14:18.217Z)
  • OS Version: Linux x64 4.4.0-53-generic
  • Extensions:

|Extension|Author|Version|
|---|---|---|
|makeRunner|alexnesnes|0.1.1|
|code-gnu-global|austin|0.2.1|
|vscode-instant-markdown|dbankier|0.2.1|
|python|donjayamanne|0.5.5|
|CppSnippets|hars|0.0.5|
|MagicPython|magicstack|0.6.1|
|vscode-clang|mitaki28|0.2.1|
|cpptools|ms-vscode|0.9.3|
|Spell|seanmcbreen|0.9.1|
|python|tht13|0.2.3|


Steps to Reproduce:

1.launch.json set as below:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/build/tools/caffe.bin",
"args": ["train","--solver=examples/mnist/lenet_solver.prototxt"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "build",
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
2.make caffe project there is no error;
3.Add break point in main function, press "F5" run caffe.bin, but VS code not stop at the breakpoint!

_Copied from original issue: Microsoft/vscode#17518_

debugger

Most helpful comment

@Sendoushi @andychen2016 Please confirm when you are compiling that you are compiling with the -g flag. This is necessary for debugging.

All 13 comments

@andychen2016 Can you enable trace logging in the launch.json and try again and send me the logs?

to do this, please add "logging": { "trace": true, "traceResponse": true }

Also had the same issue trying to breakpoint a C code.

Here is my hello.c code:

#include <stdio.h>

// Method declarations
void foo();

// Main project method
int main(void) {
    foo();
}

void foo() {
    int i = 0;
    // DEV: Setting breakpoint on the next line
    printf("Foo! %i", i);
}

Here is my launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C Launch",
            "type": "cppdbg",
            "request": "launch",
            "preLaunchTask": "make",
            "program": "${workspaceRoot}/hello",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false,
            "logging": { "trace": true, "traceResponse": true },
            "linux": {
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            },
            "osx": {
                "MIMode": "lldb"
            },
            "windows": {
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        },
        {
            "name": "C Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "enter program name, for example ${workspaceRoot}/a.out",
            "processId": "${command.pickProcess}",
            "linux": {
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            },
            "osx": {
                "MIMode": "lldb"
            },
            "windows": {
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        }
    ]
}

And finally here is the full log you requested:

E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/Launch","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.31115.1","VS.Diagnostics.Debugger.HostVersion":"1.0.21122.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Launch.Duration":2157,"VS.Diagnostics.Debugger.Launch.IsCoreDump":false},"type":"output"}
 R: {"success":true,"message":null,"request_seq":2,"command":"launch","body":null,"running":false,"refs":null,"seq":0,"type":"response"}
E initialized: {"type":"initialized"}
C setBreakpoints: {"source":{"path":"/Users/sendoushi/work/src/local/harvard_cs50/week_1/hello.c","name":"hello.c"},"lines":[14],"breakpoints":[{"line":14}],"sourceModified":false}
 R: {"success":true,"message":null,"request_seq":3,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":true,"line":14,"message":null}]},"running":false,"refs":null,"seq":0,"type":"response"}
E breakpoint: {"reason":"changed","breakpoint":{"id":1,"verified":false,"line":14,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained."},"type":"breakpoint"}
C setFunctionBreakpoints: {"breakpoints":[]}
 R: {"success":true,"message":null,"request_seq":4,"command":"setFunctionBreakpoints","body":{"breakpoints":[]},"running":false,"refs":null,"seq":0,"type":"response"}
C configurationDone: null

@Sendoushi @andychen2016 Please confirm when you are compiling that you are compiling with the -g flag. This is necessary for debugging.

You're right. On my end, after using this:

clang -ggdb3 -O0 -std=c99 foo.c -o bin/foo

It worked like a charm. Thanks!

If this is still an issue, please comment/reopen.

@Sendoushi save my ass, really thank you

in Linux ubuntu - i was not able to debug cpp program until i changed int main() to int main(int argc, char ** argv)

in Linux ubuntu - i was not able to debug cpp program until i changed int main() to int main(int argc, char ** argv)

this is extremely helpful. The debugger just won't stop at the breakpoint if the main() is written as
int main().
@pieandcakes Can you explain why this happens?

Thank you all for the useful comments in this issue! Here is what I had to do with an existing project with a cmake build:

  1. I had to change the CMakeLists.txt file:
    set(CMAKE_BUILD_TYPE Debug)
  2. Then use the newly created executables with suffix '_d' in the launch.json
  3. Change the main() to main(int argc, char ** argv) in the target file.

Thank you all for the useful comments in this issue! Here is what I had to do with an existing project with a cmake build:

  1. I had to change the CMakeLists.txt file:
    set(CMAKE_BUILD_TYPE Debug)
  2. Then use the newly created executables with suffix '_d' in the launch.json
  3. Change the main() to main(int argc, char ** argv) in the target file.

@eyesfree thanks so much for the tip!

For stepping through code that uses GTest and doesn't have the main function exposed, simply adding the set(CMAKE_BUILD_TYPE Debug) line and rebuilding worked.

Hello,I debug the linux arm board through Ethernet, and encountered the same issue. But I use other PC with same environment and configurations, it works well.

It can step through debugging, but it cannot set breakpoints.
When I set the breakpoints, here is the log info.
<-- C (setBreakpoints-10): {"command":"setBreakpoints","arguments":{"source":{"name":"main.cpp","path":"/////////////*/src/main.cpp","sources":[],"checksums":[]},"lines":[44],"breakpoints":[{"line":44}],"sourceModified":false},"type":"request","seq":10}
--> R (setBreakpoints-10): {"type":"response","request_seq":10,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":true,"line":44}]},"seq":126}
--> E (breakpoint): {"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":1,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":44}},"seq":128}

I hava set set(CMAKE_BUILD_TYPE Debug) in CMakeLists.txt. The log is:

Thread 1 "****" received signal SIGINT, Interrupt.
0x0000ffffad4055d8 in pthread_cond_wait () from /usr/lib64/libpthread.so.0
[Switching to thread 89 (LWP 288079)](running)
=thread-selected,id="89"
<--   C (setBreakpoints-15): {"command":"setBreakpoints","arguments":{"source":{"name":"*******.cpp","path":"/*****/*******.cpp"},"lines":[116,118,119,120,123,124,125,127,128,137,331,332],"breakpoints":[{"line":116},{"line":118},{"line":119},{"line":120},{"line":123},{"line":124},{"line":125},{"line":127},{"line":128},{"line":137},{"line":331},{"line":332}],"sourceModified":false},"type":"request","seq":15}
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"\nThread "},"seq":2511}

Thread 
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"1 \"***\" received signal SIGINT, Interrupt.\n"},"seq":2513}
1 "MyProgram" received signal SIGINT, Interrupt.
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"0x0000ffff9cea65d8 in pthread_cond_wait () from /usr/lib64/libpthread.so.0\n"},"seq":2515}
0x0000ffff9cea65d8 in pthread_cond_wait () from /usr/lib64/libpthread.so.0
--> R (setBreakpoints-15): {"type":"response","request_seq":15,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":116},{"id":2,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":118},{"id":8,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":119},{"id":3,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":120},{"id":4,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":123},{"id":11,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":124},{"id":12,"verified":true,"line":125},{"id":9,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":127},{"id":10,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":128},{"id":5,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":137},{"id":6,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":331},{"id":7,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":332}]},"seq":2517}
--> E (breakpoint): {"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":12,"verified":false,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.","line":125}},"seq":2519}
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"[Switching to thread 150 (LWP 196820)](running)\n"},"seq":2521}
[Switching to thread 150 (LWP 196820)](running)
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"=thread-selected,id=\"150\"\n"},"seq":2523}
=thread-selected,id="150"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donfiguerres picture donfiguerres  路  56Comments

agauniyal picture agauniyal  路  82Comments

TurboTim picture TurboTim  路  77Comments

atilimcetin picture atilimcetin  路  182Comments

bobbrow picture bobbrow  路  70Comments