Solved

Debugging using gdb or dbx

Posted on 1998-02-07
6
962 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

746 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now