什么是clang 选项,以便在GDB中我可以使用std :: cout作为函数参数
What is clang++ option so that inside GDB I can use std::cout as function parameter
我首先在这里提出问题。现在,我在使用clang时遇到了同样的问题,因此再次询问。
我尝试了clang 3.8和3.9,命令选项是" -g -o0"。
GDB版本为7.11.1-0ubuntu1〜16.04。
这是代码:
#include <iostream>
using namespace std;
class D
{
int n;
public:
D(int _n):n(_n){}
void dump(ostream &os);
};
void
D::dump(ostream &os)
{
os << "n=" << n << std::endl;
}
int main() {
D d(200);
std::cout << "hello" << std::endl;
return 0;
}
运行到"返回0"时,调用命令失败:
(gdb) call d.dump(std::cout)
A syntax error in expression, near `)'.
使用相同选项编译G 时,相同的代码和相同的GDB命令正常工作。
有解决方法吗?
这可能是由于经历的问题。该程序工作正常。我执行了
~/c++practise> g++ stackoverflow1.cpp
~/c++practise> ./a.out
hello
~/c++practise> gdb --version
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-90.el6)
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b std::cout
"std::cout" is not a function
(gdb) b D::dump(ostream &os)
Breakpoint 1 at 0x400865: file stackoverflow1.cpp, line 15.
(gdb) b main
Breakpoint 2 at 0x4008a2: file stackoverflow1.cpp, line 19.
(gdb) run
Starting program: /home/e1211797/c++practise/outputtrail
Breakpoint 2, main () at stackoverflow1.cpp:19
19 D d(200);
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.x86_64 libgcc-4.4.7-17.el6.x86_64 libstdc++-4.4.7-17.el6.x86_64
(gdb) s
D::D (this=0x7fffffffe0a0, _n=200) at stackoverflow1.cpp:8
8 D(int _n):n(_n){}
(gdb) s
main () at stackoverflow1.cpp:21
21 std::cout << "hello" << std::endl;
(gdb) s
hello
22 return 0;
(gdb) s
23 }
(gdb) s
0x0000003788c1ed1d in __libc_start_main () from /lib64/libc.so.6
(gdb) s
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited normally.
(gdb)
相关文章:
- 是否可以使C++类成为Objc类的委托
- 是否可以使一个类成为两个不同层次结构的子类?
- 是否有编译器标志可以使较新的 gcc 版本像旧版本一样构建
- C 可以使destuructor不称为班级成员和基类攻击方的灾难
- 为什么std :: string使wsagetlasterror返回零
- 可以使未命名的结构静态
- 是否可以使整数仅收到一个单个数字而不是两个接收输入
- C++:有哪些常规方法可以使代码更有效地用于大数字
- 是否可以使 std 容器使用默认运算符为新?
- LD_BIND_NOW可以使可执行文件运行得更慢?
- 是否可以使头文件使文本居中?- 在控制台中
- 在Ostream上使用std :: endl使我的文件二进制
- 有什么方法可以使核心忙碌等待
- 有没有一种技术可以使虚函数在所有派生类中强制重写?
- 有没有一种方法可以使全局函数/静态成员函数一次可呼出
- 是否有一种方法可以使此C 14递归模板在C 17中短
- 编写一个可以使二维数组平坦的函数
- 有哪些优化技巧可以使我的代码运行得更快
- 传递给std::basic_string的分配器是否可以使其方法为虚拟的
- 是否可以使std::string始终包含一个小写字符串