我如何设置一个断点on operator&与GDB [英] How do I set a breakpoint on operator< with GDB
问题描述
基本上是什么标题说。我有一个函数:
bool操作符< (... lhs,... rhs)
'b operator<(...)'给我错误:
命令中的格式化模板规范
如何停止GDB的思考<是模板开放?我试图设置一个断点的行号,以及,但这个定义是在头文件,并且由于某种原因,GDB认为行号不存在于头文件中。
GDB 6.8
你可以先打印所有出现的
.h
或 .cpp
文件, code> g ++ 使用 -g
$ gdb test
(gdb)p'operator<'
$ 1 = {bool(MyClass& MyClass&)} 0x4009aa< operator<(MyClass& MyClass&)>
(gdb)b * 0x4009aa
断点1在0x4009aa:文件test.h,第5行。
(gdb)r
启动程序: /home/agururaghave/.scratch/gdb-test/test
断点1,operator< (obj1 = ...,obj2 = ...)at test.cpp:6
6 friend bool operator< (MyClass& obj1,MyClass& obj2){
我测试了以下代码: / p>
/ * test.h * /
#include< iostream>
class MyClass {
public:
friend bool operator< (MyClass& obj1,MyClass& obj2){
std :: cout< operator< << \\\
;
return true;
}
};
/ * test.cpp * /
#includetest.h
int main(){
MyClass myObj1;
MyClass myObj2;
bool result = myObj1< myObj2;
std :: cout<<结果< \\\
;
return 0;
}
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
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;
}
这篇关于我如何设置一个断点on operator&与GDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!