gdb调试程序乱跳问题

ncubrian 2014-08-19 10:15:40
我单步调试redis-cli,断点设的718行,然后run却停在别的地方,感觉gdb显示的代码和程序正在执行的代码行数对不上,然后后面就是一会执行后面一会执行前面,完全搞不懂。。。
有人知道这是咋回事吗?Thanks in advance!

(gdb) break linenoise.c:718
Breakpoint 1 at 0x414347: file linenoise.c, line 718.
(gdb) run
Starting program: /root/redis-2.8.13/src/redis-cli
[Thread debugging using libthread_db enabled]

Breakpoint 1, linenoiseRaw (prompt=0x655780 "127.0.0.1:6379> ") at linenoise.c:933
933 if (enableRawMode(STDIN_FILENO) == -1) return -1;
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000414347 in linenoise at linenoise.c:718
breakpoint already hit 1 time
(gdb) s
linenoiseEdit (prompt=0x655780 "127.0.0.1:6379> ") at linenoise.c:718
718 l.ofd = stdout_fd;
(gdb)
716 * specific editing functionalities. */
(gdb)
717 l.ifd = stdin_fd;
(gdb)
719 l.buf = buf;
(gdb)
720 l.buflen = buflen;
(gdb)
721 l.prompt = prompt;
(gdb)
718 l.ofd = stdout_fd;
(gdb)
721 l.prompt = prompt;
(gdb)
724 l.len = 0;
...全文
642 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你们这是想让我们跟着提高英语还是咋的
ncubrian 2014-08-19
  • 打赏
  • 举报
回复
引用 5 楼 micropentium6 的回复:
[quote=引用 3 楼 ncubrian 的回复:] [quote=引用 2 楼 micropentium6 的回复:] also, are sure this is the right source tree for the binary? You will have to disable all optimization options during compilation. Jumping around could also happen if -O is enabled.
yes, -O is enabled. I'm gonna remove -O and try again. BTW, how to know which thread is currently running and how many thread are there in execution?[/quote] info threads Display a summary of all threads currently in your program. GDB displays for each thread (in this order): the thread number assigned by GDB the target system's thread identifier (systag) the current stack frame summary for that thread An asterisk `*' to the left of the GDB thread number indicates the current thread. For example, (gdb) info threads 3 process 35 thread 27 0x34e5 in sigpause () 2 process 35 thread 23 0x34e5 in sigpause () * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8) at threadtest.c:68[/quote]I've tried your suggestion. There's only one thread and it turns out the -O option is what makes the program jump around. Thanks a lot.
  • 打赏
  • 举报
回复
引用 3 楼 ncubrian 的回复:
[quote=引用 2 楼 micropentium6 的回复:] also, are sure this is the right source tree for the binary? You will have to disable all optimization options during compilation. Jumping around could also happen if -O is enabled.
yes, -O is enabled. I'm gonna remove -O and try again. BTW, how to know which thread is currently running and how many thread are there in execution?[/quote] info threads Display a summary of all threads currently in your program. GDB displays for each thread (in this order): the thread number assigned by GDB the target system's thread identifier (systag) the current stack frame summary for that thread An asterisk `*' to the left of the GDB thread number indicates the current thread. For example, (gdb) info threads 3 process 35 thread 27 0x34e5 in sigpause () 2 process 35 thread 23 0x34e5 in sigpause () * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8) at threadtest.c:68
  • 打赏
  • 举报
回复
info threads Display a summary of all threads currently in your program. GDB displays for each thread (in this order): the thread number assigned by GDB the target system's thread identifier (systag) the current stack frame summary for that thread An asterisk `*' to the left of the GDB thread number indicates the current thread. For example, (gdb) info threads 3 process 35 thread 27 0x34e5 in sigpause () 2 process 35 thread 23 0x34e5 in sigpause () * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8) at threadtest.c:68
ncubrian 2014-08-19
  • 打赏
  • 举报
回复
引用 2 楼 micropentium6 的回复:
also, are sure this is the right source tree for the binary? You will have to disable all optimization options during compilation. Jumping around could also happen if -O is enabled.
yes, -O is enabled. I'm gonna remove -O and try again. BTW, how to know which thread is currently running and how many thread are there in execution?
  • 打赏
  • 举报
回复
also, are sure this is the right source tree for the binary? You will have to disable all optimization options during compilation. Jumping around could also happen if -O is enabled.
  • 打赏
  • 举报
回复
is this a multi-threading program? If so, that explains why the code execution kept jumping around. when you fire up gdb, try -tui option, it will give u a text window for source. Of course, it will be messy if you debug multi-threading app...

23,215

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧