Solved

Debugging using gdb or dbx

Posted on 1998-02-07
6
968 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

828 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