Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Programming ➜ General ➜ Debugging with GDB and winsock

Debugging with GDB and winsock

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by ThomasWatts   USA  (66 posts)  Bio
Date Wed 14 Nov 2007 10:35 AM (UTC)
Message
The previous post was closed, but relevant to the subject.
Previous post: http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=3653

I am using WindowsXP, and my dev platform is MingW32.
GDB version is 6.3 native to MingW32.

I recently decided to try and use said program to find out why my program was crashing with no useful information (turned out to be bad char* management).
GDB barfs on the winsock listen function returning a SIGSEGV. This makes debugging absolutely impossible. Or not so I later found out (after much superlative frustration).

The 'attach' command comes to the rescue!
Step 1: Run the target program as normal.
Step 2: Run GDB in a separate command prompt window.
Step 3: Using the task manager (CTRL-Shift-Esc), find the process ID (PID) of the target program.
Step 4: in GDB type 'attach <name> <pid>' to attach GDB to the already running process.
Name is the executable name relative to the path that GDB was run from excluding '.exe'
Step 5: in GDB type 'continue', this allows the attached program to run as normal again.

Now when the bugs fly free, GDB comes to the rescue and outputs some useful information about the problem. As for exiting GDB as well as your program, I just hit (CTRL-C) several times in both command windows.
I hope this will be helpful to anyone having the same problems as I did. As usual however, Your Mileage May Vary.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 15 Nov 2007 07:29 PM (UTC)
Message
Thanks for the tip. I mentioned on that page you should be able to attach to a running process in a single step like this:


gdb <file-name> <pid>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,450 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.