Reputation: 14656
Basically what the title says. I have a function:
bool operator< (... lhs, ... rhs)
that I would like to break on. 'b operator<(...)' gives me the error:
malformed template specification in command
How can I stop GDB from thinking the < is a template opener? I've tried to set a breakpoint by line number as well, but this definition is in a header file, and for some reason, GDB thinks that line number doesn't exist in the header file.
GDB 6.8
Upvotes: 3
Views: 2592
Reputation: 49583
You could first print all occurrences of operator <
, grab the address of the function you're interested and set a breakpoint on it.
NOTE: This technique would work irrespective of your function definition is in .h
or .cpp
file as long as you have compiled with g++
using -g
$ gdb test
(gdb) p 'operator <'
$1 = {bool (MyClass &, MyClass &)} 0x4009aa <operator<(MyClass&, MyClass&)>
(gdb) b *0x4009aa
Breakpoint 1 at 0x4009aa: file test.h, line 5.
(gdb) r
Starting program: /home/agururaghave/.scratch/gdb-test/test
Breakpoint 1, operator< (obj1=..., obj2=...) at test.cpp:6
6 friend bool operator < ( MyClass &obj1, MyClass &obj2 ) {
I tested out with the following code:
/* test.h */
#include <iostream>
class MyClass {
public:
friend bool operator < ( MyClass &obj1, MyClass &obj2 ) {
std::cout << "operator <" << "\n";
return true;
}
};
/* test.cpp */
#include "test.h"
int main() {
MyClass myObj1;
MyClass myObj2;
bool result = myObj1 < myObj2;
std::cout << result << "\n";
return 0;
}
Upvotes: 7
Reputation: 171413
Try putting it in single-quotes:
break 'operator<(Blah, Blah)'
You can also use TAB-completion to get GDB to help you
If that doesn't help you'll need to be more specific about the operator's signature instead of saying "...", since you're omitting the important part of the question!
Oh, I've just seen you're using GDB 6.8 which is about to celebrate its 5th birthday ... upgrade. GDB 7 is much better at parsing C++ declarations.
Upvotes: 2