Complete the behavior of the set Next statement similar to VS in gdb

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.