"Disclaimer: Copyright, welcome reprint, please do not use for commercial purposes. Contact mailbox: feixiaoxing @163.com "
Software debugging is an important lesson in our software development process. In the front, we also discussed the program debugging, for example here. Today, we can also talk about software debugging more content. such as conditional breakpoints, data breakpoints, multi-threaded breakpoints and so on.
[CPP]View PlainCopy
- #include <stdio.h>
- int value = 0;
- void Test ()
- {
- int total;
- int index;
- Total = 0;
- For (index = 0; index <; index + +)
- Total + = index * INDEX;
- Value = Total;
- return;
- }
- int main ()
- {
- Test ();
- return 1;
- }
(1) Data breakpoint
The so-called data breakpoint, which is the process of calculating the number in a global variable or function, triggers a breakpoint if the data value itself has changed. There are two kinds of data here, one is the global data, and the data inside the function.
Take global data value as an example:
A) press F10, run the program, get the address of value;
b) alt+f9, select "DATA", "Advanced";
c) Enter DW (0x0043178) in "Expression" and "OK" to enter;
D) F5 continue to run the program, the program will stop when value changes.
Take the local data total as an example,
A) press F10, run the program, get the address of value;
b) alt+f9, select "DATA", "Advanced";
c) Enter total in "Expression", enter Test in "Function", "OK" to enter;
D) F5 continue to run the program, the program will also stop when total changes.
(2) Conditional breakpoint
Conditional breakpoints are about the same as data breakpoints. However, the data breakpoint will be broken when the data changes, and the conditional breakpoint will be broken only if it satisfies certain conditions. For example, we can have the Test subroutine break in index==5.
A) press F10, run the program, get the address of value;
b) alt+f9, select "DATA", "Advanced";
c) Enter index==5 in "Expression", enter Test in "Function", "OK" to enter;
D) F5 continue to run the program, the program will also stop at the time of index==5.
(3) Multi-threaded debugging
On the VC above the debugging of multiple programs is relatively simple. If you want to debug the program, first F10, start running the program. Second, we need to wait for the thread to be created before we can set a breakpoint, or we see a program that only has a thread in the main function.
A) Click "Debug", select "Threads", then we can start multi-threaded debugging;
b) If you need to suspend a thread, click on the corresponding thread and select "Suspend";
c) If a thread needs to be re-dispatched, click on the corresponding thread, select "Resume";
D) If you need to see the stack for a particular thread, then select that thread, then "Set Focus", Close the Threads dialog box and see it in the Stack window;
e) If a thread is suspended, then all threads are suspended, and if you step, all threads will run;
f) If you need to debug a thread, you need to suspend the other thread.
Summarize:
1) Look at the memory, look at the stack, conditional breakpoints, data breakpoints need to use comprehensive,
2) The sooner the program is debugged, the better
3) First write a single-threaded program, and then write a good multi-threaded programs,
4) for multithreading, module design > Programming prevention > Debugging > Post-mortem remediation.
Multithreading that little Thing (the multi-threaded debugging)