I am having trouble with using GDB on my c++ program. I want to set up a break point for my class member function and I'm not sure on the syntax of how to do it. My program is working find right now and I'm just trying to learn to use GDB. My problem is all the information I find on line only really deals with just a main() file and no other functions or classes and if they involve classes its only using a function with a void return statement.
I have a binary search tree class. I want to set a break point at a function in my program. here's the section of my header file.
class BST { BST() ... private: int add((BST * root, BST *src); }
I am telneting into a command line linux server for school. I can get GDB running with my program just fine with g++ -g *.cpp (there are other files that are working fine) and the file is saved as a.out. I run GDB with
gdb ./a.out
and I get into GDB. I can get a break point for the void display function just fine with
b BST::disp_block()
but how do I do it with the add function I have tried
b BST::int add(BST*, BST *) b int BST::add(BST*, BST *) b BST::add(BST*, BST *)
and I even tried with the argument names
b BST::int add(BST * root, BST * src) b int BST::add(BST * root, BST * src) b BST::add(BST * root, BST * src)
and I keep getting the error
Function "____" not defined. Make break point pending on future shared library load? (y or [n])
How do I set up a break point for a member function like this one? Im assuming watch points would be the same format, if not could you explain that too.
You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.
You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.
A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.
c file listed in Example 7.1, “Compiling a C Program With Debugging Information” with debugging information, you can set a new breakpoint at line 7 by running the following command: (gdb) break 7 Breakpoint 2 at 0x4004e3: file fibonacci.
As Dark Falcon said, break BST::add
should work if you don't have overloads.
You can also type:
(gdb) break 'BST::add(<TAB>
(note the single quote). This should prompt GDB to perform tab-completion, and finish the line like so:
(gdb) break 'BST::add(BST*, BST*)
and which point you can add the terminating '
' and hit Enter to add the breakpoint.
I can get a break point for the void display function
Function return type is not part of its signature and has nothing to do with what's happening.
You may need to specify the namespace if any defined for the class. If it other than the standard namespace std. The file name is optional, if you are executing the correct binary. You can verify if the symbol exists on the executable via. "nm -C" command, where -C handles name mangling for C++.
So to summarise with an Example: If the namespace is "mySpace" and the class is "X" whose member is "Y", then the breakpoint should be like the one below, "(gdb) b mySpace::X::Y"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With