[Go] GDB Attach

Source: Internet
Author: User

Ext.: http://blog.csdn.net/wangeen/article/details/14230171

Attach is an important debug mode of GDB, which plays an important role in the MPI program Debug.

The following steps are performed:

1) First add the following code to the beginning of the program, note that this is a dead loop, the reason why the death cycle is to keep him waiting attch

{    int i = 0;    Char hostname[256];    GetHostName (hostname, sizeof (hostname));    printf ("PID%d on%s ready for attach\n", Getpid (), hostname);    Fflush (stdout);    while (0 = = i)        sleep (5);}

The startup program will get the following statement

PID 15425 on XXX ready for attach

PID 15426 on XXX ready for attach


2) Start GDB

$gdb

(gdb) Attach 15425

(GDB) up//The up here is very important, see Misc

(GDB) Set Var i=1

This jumps out of the dead loop and continues.


3) Misc

About GDB's use

We used to think that GDB was very difficult to use, and many of the debug messages were not shown, especially in the case of multithreading, when I used GDB attach MPI program to find the reason, because GDB is always trying to pause the program to grab the contents of the stack to frame, If a situation like sleep is encountered, GDB does not get any information, in which case we need to use up to toggle the frame.

[Go] GDB Attach

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.