Solved

Debugging using gdb or dbx

Posted on 1998-02-07
6
974 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 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
Technology Partners: 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

Independent Software Vendors: 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

707 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