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

What is clang++ option so that inside GDB I can use std::cout as function parameter

本文关键字:std 可以使 cout 参数 函数 我可以 选项 clang GDB 什么      更新时间:2023-10-16

我首先在这里提出问题。现在,我在使用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)