2017-08-17 20 views
3

私は20のコンストラクタを持つC++オブジェクトを持っており、どのコンストラクタが呼び出されているのか知りたい。C++オブジェクトのgdbのすべてのコンストラクタでブレークポイントを同時に設定する方法は?

+2

。または、デザインの実装は次のとおりです。 –

+0

なぜ 's'コマンドを使ってctorに入ることができないのですか? – dlmeetei

+0

呼び出し元のコードからどのコンストラクターが呼び出されているかを把握できるはずです。それでもブレークポイントを設定したい場合は、20個のコンストラクタすべてからダミーメソッドを呼び出してブレークポイントを設定することができます。 – VTT

答えて

2

documentationを参照してください:

rbreak regex

Set breakpoints on all functions matching the regular expression regex. This command sets an unconditional breakpoint on all matches, printing a list of all breakpoints it set. Once these breakpoints are set, they are treated just like the breakpoints set with the break command. You can delete them, disable them, or make them conditional the same way as any other breakpoint.

例:

class Foo { 
public: 
    Foo() {} 
    Foo(int) {} 
}; 

int main() { 
    Foo f1; 
    Foo f2(1); 
    return 0; 
} 

GDBセッション:あなたは多くのコンストラクタは、私はあなたのデザインが欠陥があると言うだろうとしている場合

[ ~]$ gdb -q a.out 
Reading symbols from a.out...done. 
(gdb) rbreak Foo::Foo 
Breakpoint 1 at 0x4004dc: file so-rbr.cpp, line 3. 
void Foo::Foo(); 
Breakpoint 2 at 0x4004eb: file so-rbr.cpp, line 4. 
void Foo::Foo(int); 
(gdb) i b 
Num  Type   Disp Enb Address   What 
1  breakpoint  keep y 0x00000000004004dc in Foo::Foo() at so-rbr.cpp:3 
2  breakpoint  keep y 0x00000000004004eb in Foo::Foo(int) at so-rbr.cpp:4 
(gdb) 
0

break myNamespace::myClass::myClassを実行すると、すべてのコンストラクタでgdbが破損します。

たとえば、少なくとも2つのコンストラクタを持つruntime_errorの作成を中断する場合は、break std::runtime_error::runtime_errorを実行します。

Breakpoint 4 at 0xaf20 (4 locations) 

このブレークポイントは複数のコンストラクタに設定されていることを、示している:gdbの出力は次のようなものになります。このような出力を提供しますinfo breakpointsを実行しているブレークポイントの位置を確認するには:あなたはrbreakを使用することができます

Num  Type   Disp Enb Address   What 
1  breakpoint  keep y <MULTIPLE>   
1.1       y  0x000000000000af20 <std::runtime_error::runtime_error(char const*)@plt> 
1.2       y  0x000000000000b300 <std::runtime_error::runtime_error(std::runtime_error const&)@plt> 
1.3       y  0x000000000000b460 <std::runtime_error::runtime_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@plt> 
1.4       y  0x000000000000b5e0 <std::runtime_error::runtime_error(char const*)@plt> 
+0

何らかの理由で、break_stop :: runtime_error :: runtime_errorのためにただ1つのコンストラクタでブレークポイントを取得しています – avimonk

+0

'break std :: runtime_error :: runtime_error'または' break std :: runtime_error :: runtime_error() 'を実行しましたか? – OutOfBound

+0

b std :: runtime_error :: runtime_error。あなただけを貼り付けてコピーしてください。たぶん古いGDBのバージョンやコードがデバッグでコンパイルされていないのでしょうか? – avimonk

関連する問題