Can I get Visual Studio to break on any Debug.WriteLine?
I have a Debug.WriteLine that is just writing a number and I cannot find it to turn it off.
I have it down to one method call but even holding F11 for 20 minutes did not get to the mutant Debug.WriteLine
Use Debug > New Breakpoint > Break at Function. Enter "System.Diagnostics.Debug.WriteLine" for the function name. That sets 5 breakpoints, one for each overload.
Do consider that it might not be generated by managed code, the default trace listener that normally displays Debug.WriteLine() output uses a debugger function (OutputDebugString) to produce output. That function may also be used by native code.
Related
I have a "problem" about my debugger.
When I debug, I usually use the command step into, to go forward, and everything was going smooth. Then some day, when I stepped into a function like printf(), or fscanf(), the debugger started taking me into the actual library, <stdio.h>...
I know I can avoid this just using the command step over, but I'm really used to debug my code easily and fast, just by pressing constantly the same button, and I don't want to switch every 3 seconds from step into to step over, because I want to focus on my code flow...
Can anyone help me please?
If you need other info, of course I'm going to give them to you.
As you have tagged Visual Studio Code, I am answering for the debugger in that IDE. To execute and then leave a function you have entered while debugging, you can press SHIFT F11. (This would in effect be "the opposite" of entering a function, which is F11.) From the Microsoft documentation a description of Step Out can be found:
"Click Step Out on the Debug menu to resume running on the target.
This command executes the rest of the current function and breaks when
the function return is completed."
You can use ~/.gdbinit configuration file, see man gdbinit
skip file /usr/include/stdio.h
You can check it in gdb using info skip:
(gdb) info skip
Num Enb Glob File RE Function
1 y n /usr/include/stdio.h n <none>
(gdb)
You can skip a whole file skip file /what/ever.c or a function : skip printf
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.
I am using GDB to debug my msp430. I connect the target and then load the binary of program and then "continue".
My program is working fine however I want to see certain values of variables in real time. Actually I want to check the time stamp of my start of code and end of code which will give me total duration.
As I am totally new to GDB, currently I have placed this line in my code
printf("Hello World\n");
However nothing is printed but my code is working fine which is actually blinking LEDs.
Please guide me how to view values of variables in GDB in debug mode.
Thanks
To print a variable in gdb you can use the print command
(gdb) print counter
You can set a breakpoint on line 10 with break 10. And then attach a sequence of commands to be run every time the program stops at breakpoint 1 with commands 1. An example is below:
(gdb) break 10
Breakpoint 1 at 0x1c4d: file example.c, line 10.
(gdb) commands 1
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>print counter
>continue
>end
(gdb) continue
So this will break at line 10, print the value of counter and then continue the program.
For timestamps, what you probably want to do is set two breakpoints, one at the start of the code, and one at the end. Have each breakpoint record the time, say by calling the appropriate function. You can make a breakpoint do things by using the commands feature.
However, if this is something you want to do frequently, you might consider just adding code to your program to do it.
For real-time (-ish) access to variables when debugging remotely, you might be interested in the gdb "tracepoint" feature. Currently this feature only works when debugging remotely, and it relies on the remote debug server having the needed features. Tracepoints let you record some selected variables at selected points, and then examine them later. The recording is done with reasonably minimal overhead.
I have stage server which I use it with Xmanager. In the stage sever,after whatever I choose using the mouse,a "^C" will appear automatically after $.For example ,I choose "system/" with mouse,and a "^C" soon appears in the command line.
It never happened before until yesterday I tried "Shift+Ctrl+V" which means "copy" after I choosing the command line which I wanted to copy, but it didn't work although I tried several times.And then the problem I described existed.
It's really confusing,and I don't whether "^C" has any bad effect.
How to resolve this problem?Anyone knows why it happened?
The reason causing this problem is that I opened youdao dictionary simultaneously with its function of catching words on the screen on. Just close it and the problem won't happen again. I don't know why maybe it has something to do with the software's compatibility.
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.