Solved

Debugging using gdb or dbx

Posted on 1998-02-07
6
969 Views
Last Modified: 2008-03-10
I need help using either dbx, gdb, or xxgdb. Please be specific.

Here is what I have already did and I was so confused.

1. I have put -g flag when compiled my C++ source
2. % dbx executable_file
3. I typed 'next' and got error message like this
    dbx: can't continue execution -- no active process

4. I tried to put a break point at line 8 using
    'stop at 8' command and I got another message:
   dbx: No current source file
5. Well, I scratched my head and typed 'quit'

Same story happened when I tried using both gdb and xxgdb.

Please help! I need to know how you debug your C++ codes in Unix, STEP by STEP!

Thanks!!!

PS: I use all my points and hope that I would get a very brilliant answer :)
0
Comment
Question by:v5
  • 4
  • 2
6 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 80 total points
ID: 1181088
You can't step until you start running.

Try this:

gdb a.out
(gdb)l

this will list out your program...

(gdb)break 12

Set a breakpoint at one of the lines in your program.  I've used 12 as an example, yours will vary.

(gdb)run

Now when it hits the breakpoint, it will stop.  You can now:

(gdb)next
0
 

Author Comment

by:v5
ID: 1181089
My output file is not a.out, I use -o a a.o. So, the executeable file is "a", not "a.out".

I try % gdb a

then (gdb)l

and I got an error msg
dbx: No current source file

0
 
LVL 32

Expert Comment

by:jhance
ID: 1181090
I don't understand "-o a a.o".  When you compile with gcc the command should be:

gcc sourcefile.c -g -o a

This will give an executable "a" that contains debugging information.  Now you can say:

gdb a

If I understand what you wrote, you are giving it:

gcc source.c -g -o a a.o


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:jhance
ID: 1181091
www:~$ gcc test.c -g -o a
www:~$ gdb a
GDB is free software and you are welcome to 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.
GDB 4.14 (i486-slackware-linux), Copyright 1995 Free Software Foundation, Inc...
(gdb) l
1       #include <stdio.h>
2
3       int main(void)
4       {
5               int i;
6
7               printf("<HTML>\n");
8               printf("<BODY>\n");
9               for(i=0; i<50000; i++){
10
(gdb) break 7
Breakpoint 1 at 0x80004a6: file test.c, line 7.
(gdb) run
Starting program: /users/joe/a

Breakpoint 1, main () at test.c:7
7               printf("<HTML>\n");
(gdb) n
<HTML>
8               printf("<BODY>\n");
(gdb)
0
 

Author Comment

by:v5
ID: 1181092
I forgot -g

One more question, when I set break point at line 6, how can I display the value of the variable at that line?

Another question, in your opinion, which debugging tool is the greatest? dbx, gdb, X version of gdb, or purecov?

Thanks!!
0
 
LVL 32

Expert Comment

by:jhance
ID: 1181093
To get the value of a location, use the inspect command:

(gdb) inspect i

In my opinion, dbx and gdb are about the same.  xgdb is maybe a little easier to use but you can't always count on having it available.  I've never used purecov.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 97
Would like to move button in a function 3 83
How to split this in C++ 4 117
How do I get Window Title of all opened process? 4 32
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question