2017-02-24 4 views
0

私は最初に質問hereを求めました。今私はclangを使用するときに同じ問題に遭遇するので、再度尋ねる。clang ++オプションとは何ですか?GDB内部でstd :: coutを関数パラメータとして使用できます

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 `)'. 

を同じコードと同じGDBコマンドは正常に動作して++グラムでコンパイルしたとき同じオプション。

回避策はありますか?

答えて

1

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) 
+0

これは '(gdb)call d.dump(std :: cout)'が失敗する理由には答えません。 – ks1322

+0

通常のデバッグは正常に動作しています。 – venky513

+0

まだ質問に全く答えません。 – ks1322

関連する問題