c++ - 什么是 clang++ 选项以便在 GDB 中我可以使用 std::cout 作为函数参数

标签 c++ gdb clang clang++

我首先问了这个问题here .现在用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;
}

运行到“return 0”时,调用命令失败:

(gdb) call d.dump(std::cout)
A syntax error in expression, near `)'.

当使用具有相同选项的 g++ 编译时,相同的代码和相同的 gdb 命令工作正常。

有解决办法吗?

最佳答案

这可能是因为 verizon 问题。该程序运行良好。我执行了

     ~/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++ - 什么是 clang++ 选项以便在 GDB 中我可以使用 std::cout 作为函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42431224/

相关文章:

C++ 相同的字符串不相等(实际上是 char*)

c++ - 发现逻辑错误 c++

c - Linux,如何在 GDB 中运行 c 代码之前等待几秒钟

LLVM 相当于命令行上的 gcc -D 宏定义

c++ - 使用 libclang 检查通用属性

c++ - clang 与 gcc CRTP : constexpr variable cannot have non-literal type

c++ - 在 "template"和函数声明之间使用:template<typename trait> using tr = base_trait<trait> void fn(tr::type arg) { ... }

c - 如何检测堆栈溢出点

gdb - 如何在gdb中打印wstring

c++ - 解析 C++ 以生成代码的最简单方法是什么?