2

I have a simple project just with one main.c file and info.h file. I am using makefile for building purpose

myprog1 : main.o
    gcc -g main.o -Wall -ansi -pedantic -o myprog1
main.o : main.c info.h
    gcc -c main.c -Wall -ansi -pedantic -o main.o

I am clicking Debug -> Start debugging -> C++ (GDB/LLDB), then I get generated file (I edited my prog name added -g flag and stopAtEntry = true)

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/myprog1",
            "args": [
               "-g"
            ],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

And when I click Run Debug it just ignores my debug points with message

module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained

I have already read a lot of possible issues, but any help me...

What am I doing wrong?

P.S. I am new in C language and in VS code. Could you please advise me what exactly I have to change in order to make it work?

EDIT

I also tried to launch debug on my macOS and there is a main() method

enter image description here

As you can see I put two debug points, but anyway when I start to debug, it doesn't stop at any of these two points.

You can see log output on the screenshot...

What is the problem?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121

3 Answers3

3

One thing to note is you are passing the -g flag to LLDB as well as through the compiler. IIRC, LLDB does not have a -g option, so there's most likely a problem with that. Unless there are no declarations externally defined in "info.h", there could also be a problem with your makefile not including all necessary object files although you would have been unable to compile the appropriate executable (I'm mentioning this solely because you can still proceed with debugging even when tasks in vscode return errors) Based on your edit, it seems your main.c file doesn't include info.h, so this is not an issue.

I've read from here that the way you write the main function header can cause problems with breakpoints, too. Try writing your main function header as int main(int argc, char** argv)

Side note: althought LLDB should be able to debug GCC-compiled code, I'd suggest you use Clang to compile your code instead since it is also part of the LLVM toolchain. More about that here: Is it possible to debug a gcc-compiled program using lldb, or debug a clang-compiled program using gdb?

Here's some other places you should look if you still can't fix it (from what I can tell this could actually be a bug):

https://github.com/microsoft/vscode-cpptools/issues/3829

https://lldb.llvm.org/use/troubleshooting.html

https://github.com/Microsoft/vscode-cpptools/issues/416

https://74th.github.io/vscode-debug-specs/cpp/

NaShBe
  • 306
  • 2
  • 8
0

well, for a start, it is a C program, not a C++ program, so using the wrong debugger. The C++ debugger is expecting 'name mangling' but GCC does not perform 'name mangling'

user3629249
  • 16,402
  • 1
  • 16
  • 17
0

I'm note sure if it's of any help but I use CodeLLDB Extension (https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) Then just run make and start the debugger.

Example of the launch.json i use:

"version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "launch", "program": "${workspaceFolder}/a.out", "args": [], "cwd": "${workspaceFolder}" } ] }

Axenth
  • 73
  • 2
  • 6