?
Solved

Debugging using gdb or dbx

Posted on 1998-02-07
6
Medium Priority
?
980 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 320 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

764 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