免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2411 | 回复: 2
打印 上一主题 下一主题

[C++] gdb如何打印函数的内部输出? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-03-02 13:16 |只看该作者 |倒序浏览
我使用gdb调试,
假设有一个函数:
int func()
{
    cout<<"hello";
return 1;
}

运行如下的命令:
(gdb)print func()
这样,只是打印出了函数的返回值,
但是函数内部的hello却没有打印出来,
请问如何能够调用一个函数,并且打印这个函数内部执行的输出语句呢?
谢谢回答!!!

论坛徽章:
0
2 [报告]
发表于 2010-03-02 13:55 |只看该作者
@debian:~$ gdb ./a.out
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) break cout.cc : 8
Breakpoint 1 at 0x80485ea: file cout.cc, line 8.
(gdb) run
Starting program: /home/smith/a.out

Breakpoint 1, func () at cout.cc:8
8                   cout<<"hello\n";
(gdb) n
hello
9                               return 1;
(gdb) q
The program is running.  Exit anyway? (y or n) y


你在你的hello后面加了个换行。

论坛徽章:
0
3 [报告]
发表于 2010-03-02 18:02 |只看该作者
谢谢,

但是,我的意思是使用gdb里面的call命令或者print命令强制调用函数,这时候函数内部的打印语句都输出不来。有没有什么办法把函数里面的打印语句也输出来。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP