gdb command


 
Thread Tools Search this Thread
Top Forums Programming gdb command
# 1  
Old 10-15-2003
Question gdb command

I'm having problem understanding the how to use gdb command to debug my program. Can anyone give me some suggestion how to start, and examples. I read the manual in unix...I'm still confuse.
# 2  
Old 10-15-2003
Well ... I don't usually read the GDB manual because its command line help is already quite good. To use GDB properly you should compile your C program with the -g switch. Then simply

gdb ./executable

Then you will be asked to enter the commands. I usually just type 'help' then you will see

Quote:
List of classes of commands:

aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
tui -- Text User Interface commands
user-defined -- User-defined commands
For example, to get a list of commands associated with running the program you type 'help running'.

To run the program, enter 'run'. Usually you may want to insert some breakpoints before starting the program. I forgot the command to use. You may type 'help breakpoints' for a list of commands that you will find useful.
# 3  
Old 10-16-2003
Question how do you generate an executable file ?

this is what i did to get an executable file before i use gdb command


i type :

gcc -g text2.c

it did not work.
# 4  
Old 10-16-2003
Then it's your text2.c that does not work. If your program is correct, it should be compilable. It is possible for some special conditions that a program compiled with -g may cause it not functioning as expected but that only affects runtime.

Can you specify what do you mean by "it did not work"? Any error messages?
# 5  
Old 10-16-2003
my program(text2.c) did compile and run. I tested my code. It did give me the right output and so on.

but i couldn't find any executable file in my directory. This is what i did..and what happened :


[confuse@enlnxs ~]$ gcc -g text2.c
[confuse@enlnxs ~]$ ls
a.out file33.c file4new.c mail text2.c text3.c
file2.c file4.c file.c test.c text2.out

[confuse@enlnxs ~]$ gdb text2.c
GNU gdb Red Hat Linux (5.2-2)
Copyright 2002 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"..."/ennfs/csc/cscund/confuse/text2.c": not in executable format: File format not recognized

(gdb)
# 6  
Old 10-16-2003
Oh dear. When you use gcc/g++ to compile a program and if you don't specify the -o switch, the output is written to the file named "a.out".

Either you

gcc text2.c -o text2 -g
gdb ./text2

or

gcc text2.c -g
gdb ./a.out
# 7  
Old 10-16-2003
Bug thanks

thank you. : )
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Gdb backtrace

Hi, all I try to understand the output from gdb Program received signal SIGABRT, Aborted. *** glibc detected *** /home/sys_cbo/dev/zif/bin/Debug/zifd: free(): invalid pointer: 0x00007fffac04d3d0 *** how should i read this? (gdb) backtrace #0 0x0000003015e32925 in raise () from... (1 Reply)
Discussion started by: huvcbo
1 Replies

2. Programming

Qemu + gdb

Hi, I got: host machine: RedHat (RHEL6) virtual machine: RedHat (RHEL6) I run (on host machine): qemu-system-x86_64 ...... -S -s after that i run (on host machine): gdb target remote localhost:1234 set architecture i386:x86-64 and then i can use (on host machine) 'ctrl + c' to... (2 Replies)
Discussion started by: Chrisdot
2 Replies

3. Programming

gdb help

i have created some break points in gdb. let's say.... b sqlcxt how can i know the breakpoint name of sqlcxt ??? (1 Reply)
Discussion started by: lipun4u
1 Replies

4. Programming

gdb not found

Hello, I am having problem with debugging my code. I am writing a C code and then I compile it with the Makefile. I make a target file and then copy it in my Robot(Khepera III) and then run the program over there. I compile it ofcorse on my machine and then copy the compiled file in the... (10 Replies)
Discussion started by: mind@work
10 Replies

5. UNIX for Advanced & Expert Users

Using Gdb

Hi All, I am trying to execute a binary and it is giving Segmentation Fault. Can I use gdb to debug this error? Secondly there is no core file generated , so when I an trying to run gdb with the binary only I am not able to set any breakpoints. When I am running the gdb and the I am... (1 Reply)
Discussion started by: shubhranshu
1 Replies

6. UNIX for Advanced & Expert Users

Gdb

Hi All, I wanted to know if there is a core file generated and I am not sure for which Binary it is generated . Can I use gdb to debug the core file ? Thanks. (1 Reply)
Discussion started by: shubhranshu
1 Replies

7. UNIX for Advanced & Expert Users

Gdb:

Hi, This is a simple question on GDB. Given a core file, how can you check which process has dumped the core? Regards - Krishna (1 Reply)
Discussion started by: krishnamurthig
1 Replies

8. Programming

gdb: how to debug an executable file with a few command line papameters

If an executalbe file has several parameters, gdb can not pass parameters correctly. Let us see: run: ./executablefile1 agr1 arg2 arg3 debug: gdb executablefile1 run executalbefile1 arg1 arg2 arg3 then argv : executablefile1 argv : executablefile argv : arg1 ... (3 Replies)
Discussion started by: cdbug
3 Replies

9. Programming

gdb Tutorials

Can anyone give me the link to a website having gdb tutorials (for advanaced debugging & shortcuts) http://www.burneddowndays.com/talk/YaBBImages/rolleyes.gif (1 Reply)
Discussion started by: wojtyla
1 Replies

10. Programming

GDB or DBX??

Which is better?? I have always been a gdb fan.. But ppl say dbx is beter better for debugging the core.. Do all GDB lovers agree to it??? :cool: (1 Reply)
Discussion started by: jyotipg
1 Replies
Login or Register to Ask a Question