3

So I've been writing a program in C and debugging to solve the problems I had. After I solved those problems, I could not watch the values of the variables since debugging session just quits because there are no errors or breakpoints after I solved the problems occurred previously.

My editor is Visual Studio Code, running it on macOS, GCC.

1
  • 2
    Did you mark a breakpoint? try with F5 button to access the debug. Commented Apr 22, 2020 at 7:22

2 Answers 2

3

You should basicely put breakpoints at the end of your code, for example on the return line.

If you just want to know which values your variables have at the end of the execution, you can put printf("%x", your_variable); //DEBUG for the variables you want to see, and remove these lines when you finished debugging.

Moreover, if you're familiar with prompt commands, I recommand you to install gdb, this debugger is very powerful and easy to use ! Here is a little tutorial if you're interested ;)

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

1 Comment

Thank you for this. Is there a more efficient way to keep the debug session running without setting arbitrary breakpoints? I want to keep the debug session active while working on a single file and watch what happens to my objects.
3

Set your breakpoint on the code then press F5 to run the app in VSCode. Once the breakpoint hit, you can see local variables by selecting Run and Debug button (Red). You alse can add variables into Watch...

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.