Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么是叮当声++;选项,以便在GDB中我可以使用std::cout作为函数参数_C++_Gdb_Clang_Clang++ - Fatal编程技术网

C++ 什么是叮当声++;选项,以便在GDB中我可以使用std::cout作为函数参数

C++ 什么是叮当声++;选项,以便在GDB中我可以使用std::cout作为函数参数,c++,gdb,clang,clang++,C++,Gdb,Clang,Clang++,我首先问了这个问题。现在我在使用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

我首先问了这个问题。现在我在使用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;
}
当使用具有相同选项的g++编译时,相同的代码和相同的gdb命令可以很好地工作


有解决办法吗?

可能是因为verison问题。程序运行良好。我执行了它

     ~/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++Practice>g++堆栈溢出1.cpp
~/c++练习>/a.out
你好
~/c++练习>gdb--版本
GNU gdb(gdb)Red Hat Enterprise Linux(7.2-90.el6)
g++(GCC)4.4.7 20120313(红帽4.4.7-17)
是否在将来加载共享库时使断点挂起?(y或[n])n
(gdb)b标准::cout
“std::cout”不是一个函数
(gdb)bd::dump(ostream&os)
0x400865处的断点1:文件stackoverflow1.cpp,第15行。
(gdb)b干管
0x4008a2处的断点2:文件stackoverflow1.cpp,第19行。
(gdb)运行
启动程序:/home/e1211797/c++练习/输出轨道
stackoverflow1.cpp处的断点2,main():19
19天(200);
缺少单独的调试信息,请使用:debuginfo安装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
在stackoverflow1处的D::D(this=0x7fffffffe0a0,_n=200)。cpp:8
8d(int):n({}n)
(gdb)s
stackoverflow1处的main().cpp:21

21 std::cout这不能回答为什么
(gdb)call d.dump(std::cout)
失败。仍然不能回答这个问题。请阅读我的答案说明。这是由于gdb版本造成的问题。由于gdb版本7.2对抗lcang,所以面临很多问题:你也可以参考链接
     ~/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)