2

When I debug my application through a terminal and gdb, everything works as expected, however if I try to use gdb as the debugger for vs code, it exists immediately with output:

Breakpoint 1, main (argc=1, argv=0x7fffffffe638) at /home/kronos/Desktop/voxel-world/source/main.cpp:60
60  {
[Inferior 1 (process 7771) exited with code 01]
The program '/home/kronos/Desktop/voxel-world/build/voxel-world' has exited with code 1 (0x00000001).

This is my configuration file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/build/voxel-world",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

2 Answers 2

5

First I would make sure that the program is not exiting with return code 1 by design (e.g., due to sanity checks etc.). You could start by setting

"stopOnEntry": true

in config file launch.json, then proceed by debugging stepwise through main().

Sign up to request clarification or add additional context in comments.

1 Comment

this does not work, main is unknown, no break points work. My issue is similar to OP's
0

The solution that worked for me was to recompile everything with no optimization -O0 and with debugging symbols included -g. This is what my Makefile looks like:

all: main

main: main.o flash_simulator.o flash_simulator.h
    cc -O0 -g -o main main.o flash_simulator.o

%.o : %.c
    cc -O0 -g -c $< -o $@

clean:
    rm -f *.o

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.