Thread: gdb drive me crazy!!!!

  1. #1
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92

    Wink gdb drive me crazy!!!!

    When you just make program from single source file, debug is easy. When you make a typical c++ program from three files ( header file, implementation class, main program ), it is still easy to debug with gdb. Just set breakpoint in main source code, then step, step, step, step. Although you don't set breakpoint in implementation file, it will bring you into it because you just step step step from main file.

    But if you make a GUI--C++ based program like qt, or gtk applications, it become complicated. Right now I am making C++ program using gtkmm library. The main file is so simple that put breakpoint in this file is unneccessary. Look my main program:

    Code:
    #include <config.h>
    #include <gtkmm/main.h>
    
    #include "window1.hh"
    
    int main(int argc, char **argv)
    {  
       
       Gtk::Main m(&argc, &argv);
    
       window1 *window1 = new class window1();
       m.run(*window1);
       delete window1;
       return 0;
    }
    Nothing usefull here for our debugging process. What I want to watch is the functions in implementation file, let's said it window1.cc:
    Code:
    .............
    //Here's the stuff I want to keep my eye on
    void on_button_click() {
             int blabla;
             float blablabla();
             switch(blablaba) {
                  case blabla1: doing_blabla();          //I want to set my breakpoint here
    ............
    How can I set breakpoint in implementation file?
    $ gdb the_binary
    gdb> list

    This will list my main program file, so nothing useful.
    If I set breakpoint in this line:
    m.run(*window1);
    Hopefully, after stop in this breakpoint I will step, step, step until I come in implementation file. But I got this error/warning if I step from there:
    Gtk::Main::run (window=Internal: global symbol `Window' found in window.cc psymtab but not in symtab.
    Window may be an inlined function, or may be a template function
    (if a template, try specifying an instantiation: Window<type>).
    ) at main.cc:422
    422 main.cc: No such file or directory.
    in main.cc
    Step again, got this:
    Gtk::Widget::show (this=0x807f4d0) at widget.h:312
    312 widget.h: No such file or directory.
    in widget.h
    And so on.....................

    I know if I use IDE like Anjuta, it will set my debugger option automatically. But unfortunately, the editor in Anjuta sucks. I use Vim as my text editor, Glade to make user interface, and console to compile this program.

    I have used something so called gdb frontend:
    ddd ------------> I got the same problem...... no main.cc, no blablabla......
    insight -------------> This is almost perfect........ It set up the option for debugger automatically so I can put breakpoint in implementation file...... Unfortunately, because maybe I make a serious bug in my program, the debugger hang up when I continue after breakpoint in m.run(*window1);.
    Kdbg -------------> My program has very very serious bug because I got this message after I load the executable: gdb: Using host libthread_db library "/lib/libthread_db.so.1".

    So I want to try gdb console alternative to debug my buggy program. Help me, buddies!!!!
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    I think you'll get more help if you provide a consise description of the main problem.

  3. #3
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92
    Ok, I make my problem simple. Assume you have three files. Main.cpp, Implementation.cpp, and Header.cpp. Assume Main.cpp is like code above.
    Code:
    #include <config.h>
    #include <gtkmm/main.h>
    
    #include "window1.hh"
    
    int main(int argc, char **argv)
    {  
       
       Gtk::Main m(&argc, &argv);
    
       window1 *window1 = new class window1();
       m.run(*window1);             //assume this is line 9
       delete window1;
       return 0;
    }
    You have compiled them. And the binary's name is blabla. So you want to debug it.
    $ gdb blabla

    Assume you want to put breakpoint in m.run(window1); statement. So you say in gdb session like this:
    (gdb) break 9

    Assume the implementation file is like this:
    Code:
    void blablablabla::kill_me_honey() {
           int i;
           smile();        //this is where I want to put breakpoint 
    }
    And I want to put breakpoint in smile(); statement. How? I am newbie in gdb world. A lot of tutorial in internet is discussing debug one file only. Learning gdb from manual ( I think ) is like learning English from dictionary. So I am not familiar.

    Is that clear?

    There are only 3 files in my simple example. What about if windows application that generate a lot of files, and object files ( the ones with .o ). HOw can I tell to gdb that I want to put breakpoints in a lot of files not just main files?

    Thank you.

    ----------------------


    Sorry bothering you guyz! I found the temporary ( hopefully permanent ) solution. Ignore this thread. Thank you.
    Last edited by gandalf_bar; 04-07-2004 at 04:16 AM.
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Are you compiling with the -g option?

  5. #5
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92

    Talking

    Quote Originally Posted by rotis23
    Are you compiling with the -g option?
    The Makefile already did for me.

    http://www.cprogramming.com/gdbtutorial.html

    Go to the page above then I think the page need to be updated.


    Looking Around
    There are two main kinds of commands you can use at the GDB prompt. One kind of command tells GDB how to act; the other kind just tells it to give you information. In this section we'll discuss the latter kind of command. You can use GDB to tell you the values of variables by typing print <variable>. This kind of command works just as it would within C or C++; for example, you can look at a particular element in an array with print myarray[5] or a field in a structure with print struct.label. List is another useful command to let you know where you are; it will show you the surrounding lines of code.The next time you type list, you will be shown the next 10 lines. You can look at a particular area of code by typing list <line number>. For example, if you want to look at the area of line 20, type list 20. If your program has multiple source files, you can specify which one you want to look at by typing list:<filename><line number>. You can also choose to examine the beginning of a function using list:<function>. A third command, backtrace, is used for looking at the stack of your program. When you type backtrace, you will see a listing of all the functions that have not yet returned and where those functions were called. If you want to look at a frame above or below your current frame in the stack, use up and down to change your scope, so that you can see the state of the caller function.


    list:<filename><line number>

    That is wrong. The one right is list <filename>:<line number>

    Correct me if I am mistaken.

    That's one I m looking around for this this long time. This is the answer for my thread. I am stupid not to read the tutorial from this website first. Ok, thank you, rotis23! Time to shut up and write the code, baby!!!!
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You could try 'ddd', which is the GUI front end to gdb
    Setting breakpoints, examining variables etc is all pointy-clicky
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. buffered vs unbuffered question
    By Overworked_PhD in forum Linux Programming
    Replies: 6
    Last Post: 07-04-2008, 04:57 PM
  2. Memory allocation error
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 01-25-2008, 04:24 PM
  3. Contiguous Array version of Linked List
    By ampersand11 in forum C Programming
    Replies: 19
    Last Post: 10-07-2007, 03:05 AM
  4. Too much output in GDB
    By MacNilly in forum Tech Board
    Replies: 0
    Last Post: 09-13-2006, 12:45 PM
  5. does gdb lie?
    By dinjas in forum C Programming
    Replies: 8
    Last Post: 03-10-2005, 05:17 PM