GDB调试中的问题

发布于 2024-11-04 01:46:05 字数 907 浏览 2 评论 0原文

我使用GDB来调试C程序,但我发现GDB执行了一些代码两次。

例如

 ....
    stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
    stream_sys_t *p_sys;
    if( !s )
    return NULL;
    s->p_input = p_access->p_input;
    s->psz_path = strdup( p_access->psz_path );
  ....

GDB调试,

292     stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
Missing separate debuginfos, use: debuginfo-install dbus-libs-1.2.16-9.fc12.i686 libcap-ng-0.6.2-3.fc12.i686
(gdb) next
295     if( !s )
(gdb) 
292     stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
(gdb) 
295     if( !s )
(gdb) 
298     s->p_input = p_access->p_input;
(gdb) 
299     s->psz_path = strdup( p_access->psz_path );
(gdb) 
298     s->p_input = p_access->p_input;
(gdb) 
299     s->psz_path = strdup( p_access->psz_path );

我很困惑。你能解释一下为什么吗?

谢谢

I use GDB to debug a C program, but I find GDB execute some codes twice.

For example,

 ....
    stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
    stream_sys_t *p_sys;
    if( !s )
    return NULL;
    s->p_input = p_access->p_input;
    s->psz_path = strdup( p_access->psz_path );
  ....

GDB Debugging,

292     stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
Missing separate debuginfos, use: debuginfo-install dbus-libs-1.2.16-9.fc12.i686 libcap-ng-0.6.2-3.fc12.i686
(gdb) next
295     if( !s )
(gdb) 
292     stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
(gdb) 
295     if( !s )
(gdb) 
298     s->p_input = p_access->p_input;
(gdb) 
299     s->psz_path = strdup( p_access->psz_path );
(gdb) 
298     s->p_input = p_access->p_input;
(gdb) 
299     s->psz_path = strdup( p_access->psz_path );

I am confused. Could you explain why?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-11-11 01:46:05

它实际上并没有执行相同的代码两次。编译器优化可以导致机器指令重新排序,使得为第二源行生成的一些指令被放置在第一源行的最后一条指令之前。当与指令对应的源代码行发生更改时,Gdb 的“next”命令会停止,即使它实际上可能只是执行尚未完成的源代码行的其余部分。

It is not actually executing the same code twice. Compiler optimizations can cause machine instructions to be reordered, such that some instructions that were generated for the second source line are placed before the last instruction for the first source line. Gdb's "next" command stops when the source line corresponding to the instruction changes, even though it may actually just be executing the rest of a source line that was not finished yet.

就是爱搞怪 2024-11-11 01:46:05

尝试在不进行任何优化的情况下进行编译(-O0)并再次运行。
另一个想法,就是对 s->p_input 进行监视,看看这个结构体字段是否被修改了两次。

Try to compile without any optimization (-O0) and run again.
Another idea, it is to put a watch on s->p_input and see if this structure field is modified twice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文