我正在尝试找出程序的哪些部分打印到标准输出。
我可以使用如下命令设置断点:
b std::ostream::operator<<(int)
但是当我输入:b std::operator<<(std::ostream&, const std::string&)
时,没有创建断点。
所以有两个问题:
operator << (..., cosnt std::string&)
上设置断点?答案 0 :(得分:10)
使用“信息功能&lt;&lt;。* string ”搜索名称中包含&lt;&lt; 和字符串的功能。 info functions 将正则表达式作为参数。
然后从列出的功能中选择您想要的功能。删除声明末尾的; (如果有)并将声明作为参数粘贴到中断命令:
$ gdb -q ./ostream-operator-breakpoint
<...>
(gdb) start
Temporary breakpoint 1 at 0x4006b0: file ostream-operator-breakpoint.cc, line 4.
Starting program: /home/scottt/Dropbox/stackoverflow/ostream-operator-breakpoint
<...>
(gdb) info functions <<.*string
All functions matching regular expression "<<.*string":
File /usr/src/debug/gcc-4.7.2-20121109/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/basic_string.h:
std::basic_ostream<char, std::char_traits<char> > &std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&);
std::basic_ostream<wchar_t, std::char_traits<wchar_t> > &std::operator<< <wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&);
(gdb) break std::basic_ostream<char, std::char_traits<char> > &std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
Breakpoint 2 at 0x3cbfa94640: file /usr/src/debug/gcc-4.7.2-20121109/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/basic_string.h, line 2750.
动态关联程序需要开始(或运行)命令。除非您首先启动劣质流程,否则 info functions 不会列出共享库(如libstdc ++)中的函数。