The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 05:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 01:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 06:44 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-15-2003
Registered User
 

Join Date: Sep 2003
Posts: 7
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.
Reply With Quote
Forum Sponsor
  #2  
Old 10-15-2003
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,469
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.
Reply With Quote
  #3  
Old 10-15-2003
Registered User
 

Join Date: Sep 2003
Posts: 7
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.
Reply With Quote
  #4  
Old 10-16-2003
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,469
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?
Reply With Quote
  #5  
Old 10-16-2003
Registered User
 

Join Date: Sep 2003
Posts: 7
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)
Reply With Quote
  #6  
Old 10-16-2003
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,469
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
Reply With Quote
  #7  
Old 10-16-2003
Registered User
 

Join Date: Sep 2003
Posts: 7
Smile thanks

thank you. : )
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0