Results 1 to 3 of 3

Thread: how to put a break point in another file in gdb

  1. #1
    Join Date
    Jan 2011
    Beans
    20

    how to put a break point in another file in gdb

    Hi all!

    I'm trying to debug a program which has 3 files.

    There is one .h file, one .cc file and one main file.

    Suppose the code is as follows:

    Code:
    //class1.h
    #include "class1.h"
    #include <stdio>
    #include <iostream>
    using namespace std;
    
    class class1
    {
       class1();
       function1();
    };
    Code:
    //class1.cc
    #include "class1.h"
    #include <stdio>
    #include <iostream>
    using namespace std;
    
    class1::class1()
    {
    
    }
    
    
    class1::function1()
    {
       cout << "this is class one"<< endl;
    }

    Code:
    //the main code
    //main.cc
    include "class1.h"
    
    int main(int argc, char* argv[])
    {
        class1 *obj1 = new class1();
        obj1->function1();
    }
    What I'm asking is how can I put a break point in the line

    cout << "this is class one"<< endl;

    in class1.cc. (please, check the red line above)

    Any kind of help is kindly appreciated.

    Regards.

  2. #2
    Join Date
    Sep 2010
    Location
    41.2898°S, 174.768°E
    Beans
    2
    Distro
    Ubuntu

    Re: how to put a break point in another file in gdb

    Code:
    break class1.cc:15
    Unless I've miscounted the line number

  3. #3
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,274
    Distro
    Kubuntu

    Re: how to put a break point in another file in gdb

    Or
    Code:
    b class1::function1
    If you have multiple overloaded function1() functions, then be more specific when setting the breakpoint by specifying the parameter types that the function accepts; for example:
    Code:
    b class1::function1(int)
    Or you can list the function using the directive "list" and then set the breakpoint as quick-dudley indicated.

    IMHO, interfacing with gdb became obsoleted with the advent of X11 for Linux. You should use ddd, for it has a more intuitive interface.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •