How to use a debugger in DEV C++? I am finding problems resolving run-time errors in my C code written in DEV C++. How can the debugger help me resolve the run-time errors?
First, make sure you are using a project.
Then go to Project Options - Compiler - Linker and set Generate debugging information to "yes", and make sure you are not using any optimization options (they're not good for debug mode). Also check the Parameters tab, make sure you don't have any optimization options (like -O2 or -O3, but -O0 is ok because it means no optimization) or strip option (-s).
After that, do a full rebuild (Ctrl-F11), then set breakpoint(s) where you want the debugger to stop (otherwise it will just run the program). To set a breakpoint on a line, just click on the gutter (the gray band on the left), or press Ctrl-F5.
Now you are ready to launch the debugger, by pressing F8 or clicking the debug button. If everything goes well, the program will start, and then stop at the first breakpoint. Then you can step through the code, entering function calls, by pressing Shift-F7 or the "step into" button, or stepping over the function calls, by pressing F7 or the "next step" button. You can press Ctrl-F7 or the "continue" button to continue execution till the next breakpoint. At any time, you can add or remove breakpoints.
When the program stopped at a breakpoint and you are stepping through the code, you can display the values of various variables in your program by putting your mouse over them, or you can display variables and expressions by pressing F4 or the "add watch" button and typing the expression.
I got the same issue Although selecting the break points and select debug, debugging not working. I solved the problem as below:
Be sure that project is opened.
Display the project panel:
View>Project /Class Browser, Select Debug tab from the project panel
Set the base compiler:
Project > Project Options > Compiler > Linker
select the base compiler as “TDM-GCC 4.9.2 64 bit Debug”
Set the “Generate debugging information” as YES
Execute > Rebuild
To debug:
Execute > Toggle Breakpoint, then set the breakpoints.
Execute > Debug
Also check that at the menu bar base compiler is displayed as “TDM-GCC 4.9.2 64 bit Debug”
After selecting rebuild if directly breakpoints are set without selecting Toggle BreakPoints debugging is not started. Before selecting debug, selecting Toggle Breakpoint and then setting breakpoints solved the debug problem in my case.
Related
I can see my code being executed in the terminal window but the output screen does not pop up when I hit run . The output window on the console shows running and then done but the black screen with the result does not pop up like it used to before.I might have changed some settings in vscode but now I can't find the right one to change.
There can be many reasons. I'm afraid the changes you've applied caused this but no worries I suggest going over your project settings and VSCode's settings.
Check out these two links:
VS Code settings
C / CPP Config
P.S. I'm suggesting the second link based on your C tag.
Check your debug window too:
Menu -> Debug Console
or
Ctrl+Shift+Y.
First off, I know that segfaults are raised no matter if you like them or not. However, I would like to ignore them in debugging.
For a class, I am deliberately raising segfaults and handling them in a handler. I would like to ignore the ones that I am handling (or all of them) as they make debugging difficult.
In settings, in Debug (On Task Errors) , there is a drop down menu to select, "control what to do when errors are encountered" . Select "Debug Anyway" option: Please see the screen shot:
I am using VS Code version 1.49.2
You can go to the debug (or Run) tab on the left side of your VS code, and go down to where it says breakpoint.
![The breakpoint]]1
And if you want your VS code to catch the unhandled exception, you can disable this All Exceptions.
I'm debugging a C application using eclipse CDT. Generally I can go up in breakpoints and also step by step. But the problem is that I have problem to see the variable in steps. But if I want to see the content of a char** variable called path_list, I see in the variables window this error:
Failed to execute MI command:
-data-evaluate-expression *(*(path_list))
Error message from debugger back end:
value has been optimized out
So I tried to see the memory content of the variable path_list but I got an error popup:
Has someone an idea about this problem and how I can see the content of path_list?
Make sure you compiled your code with -g and -O0 options. By default compiler not uses -O0.
I'm using lldb from the command line to debug a simple C program.
On my machine at work, I was able to use tab completion for symbol names. For example, if I type "b ma" then Tab, it'll tab-complete to "b main". The same goes for other functions.
However, I cannot get this feature to work on my laptop, where an actual tab (ASCII value 9) is inserted after the cursor. Both machines are running 10.8.4 and have the latest Xcode.
Any ideas?
I think you're running gdb on one of your two systems.
lldb can do tab completion -- it can do more sophisticated tab completion than gdb -- but you have to use the canonical form of the lldb commands for it to work. The b command you're using is an alias (a regular expression alias - a list of regular expressions that try to parse your breakpoint command and do the right thing) which doesn't give the lldb tab completion engine enough information about context to do anything.
Instead, if you were to do
(lldb) br s -n ma<TAB>
it would autocomplete. This is the short form of breakpoint set --name, of course.
The cleverness of lldb comes in to effect when you realize that lldb can tab complete lots of different arguments -- breakpoint set --filefileTab will complete "file" as a filename. breakpoint set --selector will autocomplete selector names. breakpoint set --shlib (which limits the breakpoint to only set in a specific dylib/framework/binary) will autocomplete with the list of dylibs/frameworks/binaries.
At some point in the future we want to get tab completion working with alias commands like b but no one has had time to tackle that one yet.
I need to print some structure for debugging purposes.Since the code base is huge i am having difficulty locating the exact member I need to look into.Is there some way I could print out the entire structure? or atleast know what type of structure it is so that I can go back and look into it's definition?
Use a debugger. Most debuggers give you an option to see the contents of an entire structure whenever you hit a breakpoint. On *nix the most popular debugger is gdb, and on Windows the most popular IDE (which includes a debugger) is Visual Studio. Both the sited I linked to have free-as-in-beer download links.
In gdb, you can set a breakpoint with the break command, and once you reach the breakpoint you can print the contents of the struct with the print command. More specifically, you can compile with debugging data included (the -g flag in gcc), and then use
$ gdb debugging_executable
Some basic information about GDB gets printed here
> break main.c:100
> run
> print struct_variable
It's also worth looking into the step and continue commands.
In Visual Studio, you can set a breakpoint by double-clicking just to the left of the source line (there is a gray bar on the left side of the editor), and mouse over the variable name to inspect the contents once you reach the breakpoint.