GDB调试中的问题
我使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它实际上并没有执行相同的代码两次。编译器优化可以导致机器指令重新排序,使得为第二源行生成的一些指令被放置在第一源行的最后一条指令之前。当与指令对应的源代码行发生更改时,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.
尝试在不进行任何优化的情况下进行编译(-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.