Welcome Guest ( Log In | Register )




                Web Hosting

 
Reply to this topicNew Topic
C/c++ -gdb Linux Debug Tool, Simple Gdb tutorial
kanade
post May 30 2008, 09:48 AM
Post #1


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 37
Joined: 15-May 08
Member No.: 30,356


To run the C/C++ file use

$ gcc –g –o test sample.cpp

To debug the code use following command

$ gdb test --- you will get following messages

GNU gdb Red Hat Linux (6.3.0.0-1.122rh) Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) b 4 -- Set the break point for your code, here I have set for 4th line of the code

Breakpoint 1 at 0x8048384: file test2.c, line 4.

(gdb) r -- once the break point is set use “r “ to run the code

Starting program: /home/tests/test
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x8b5000
Breakpoint 1, main () at test2.c:5
5 {

(gdb) n -----press “n” to go to next line

main () at test2.c:7
7 max=MAX(5,4,3);

(gdb) n -----press “n” to go to next line

8 printf("\n%d",max);

(gdb) print max -----use “print” command to print any variables

$1 = 5

(gdb)

will add some more command to this at later stage.......
Go to the top of the page
 
+Quote Post
ml01172
post Oct 8 2008, 03:21 PM
Post #2


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 6
Joined: 8-October 08
Member No.: 33,294


It would be great if you added some info on debugging programs with threads. I'll take your turn now smile.gif

Typing:
info threads

will result in displaying which threads exist in the moment. The numbers in the first column (1, 2 etc.) represent the threads' ids. Once you know these ids, you can switch to corresponding threads like this:

thread 2

GDB will now be executing that thread in the front, while other threads will continue working in the background. You can use the usual techniques described above (next, quit, step, continue etc.) in this thread.

Debugging with threads tends to be complicated since multiple things happen at the same time. One might consider using sleep() in a thread so it doesn't "run away" before you switch to it in the debugger.

Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   10 ganeshn11 1,718 7th January 2009 - 10:07 AM
Last post by: wutske
No New Posts 5 rahid 277 1st January 2009 - 02:31 PM
Last post by: sakmac
No New Posts   4 jlhaslip 924 30th December 2008 - 08:50 PM
Last post by: iG-
No new   63 snutz411 5,451 30th December 2008 - 12:18 AM
Last post by: xboxrulz
No New Posts   7 liveblue 353 19th December 2008 - 03:26 AM
Last post by: laniczech
No New Posts   8 laniczech 284 12th December 2008 - 06:25 AM
Last post by: Darasen
No New Posts 4 www.jbi.in 370 12th December 2008 - 02:03 AM
Last post by: quack
No new   21 drogus 2,259 6th December 2008 - 12:43 AM
Last post by: The_Fury
No New Posts   18 liquidsparxx 4,962 2nd December 2008 - 01:47 AM
Last post by: xboxrulz
No New Posts   12 drogus 1,505 26th November 2008 - 10:13 PM
Last post by: xboxrulz
No New Posts   5 docduke 490 21st November 2008 - 03:27 AM
Last post by: Guest
No New Posts 16 kanade 1,119 18th November 2008 - 09:58 AM
Last post by: liod
No New Posts 4 borejk 486 5th November 2008 - 11:14 AM
Last post by: Guest
No New Posts   4 phdex 238 17th October 2008 - 05:06 AM
Last post by: Lancer
No New Posts 9 jamesleon 899 27th September 2008 - 02:45 AM
Last post by: Habble