Complete the behavior of the set Next statement similar to VS in gdb
In Visual Studio, with the right mouse button in the source code at the specified location, select Set Next statement to quickly control the program to the specified location to start execution. This allows careless programmers to see how the previous program was run without repeating the previous steps.
In GdB, this line is done by two instructions.
1. Break point
2. Jump Point
Attention
1, if the pointer is set to a position other than the current execution function, it will cause a variety of unknown consequences (interested can try it yourself)
2, if the code run logic, the execution of the uninitialized code, or do not repeat the execution of code, it will also cause unknown consequences
Example
Source
#include <iostream>
using namespace Std;
int main ()
{
cout << "line1" << Endl;
cout << "line2" << Endl;
cout << "Line3" << Endl;
cout << "Line4" << Endl;
cout << "Line5" << Endl;
cout << "Line6" << Endl;
cout << "Line7" << Endl;
return 0;
}
Compile
g++-G Gdbjump.cpp-o gdbjump
Debugging
GDB Gdbjump
Debugging operations
(GDB) B main
Breakpoint 1 at 0x400848:file Gdbjump.cpp, line 7.
(GDB) R
Starting program: ~/temp/gdbjump
Warning:no loadable sections found in added Symbol-file system-supplied DSO at 0x2aaaaaaab000
Breakpoint 1, Main () at Gdbjump.cpp:7
7 cout << "line1" << Endl;
(GDB) B 9
Breakpoint 2 at 0x400880:file Gdbjump.cpp, line 9.
(GDB) Jump 9
Continuing at 0x400880.
Breakpoint 2, Main () at Gdbjump.cpp:9
9 cout << "Line3" << Endl;
(GDB) n
Line3
Ten cout << "Line4" << Endl;
(GDB) n
Line4
cout << "Line5" << Endl;
(GDB) n
Line5
cout << "Line6" << Endl;
(GDB) n
Line6
cout << "Line7" << Endl;
(GDB) n
Line7
return 0;
(GDB) n
15}
(GDB) C
Continuing.
Program exited normally.
Description: Line1 and line2 will not be printed out