简体   繁体   English

跨过Emacs GDB

[英]Stepping Over in Emacs GDB

I'm having some trouble stepping over in GDB. 我在GDB中遇到了一些麻烦。 I've built an example program from the ffmpeg library with debug symbols on and stripping off. 我已经在ffmpeg库中构建了一个示例程序,其中包含调试符号并将其剥离。 Although I configured the ffmpeg library to static and explicitly disabled shared, it looks like the program I'm debugging is linking dynamically, since its file size is only 99kB. 虽然我将ffmpeg库配置为静态并显式禁用了共享,但看起来我正在调试的程序是动态链接的,因为它的文件大小只有99kB。 I don't know that this is the issue but thought to mention it. 我不知道这是问题,但想提一下。

After I set and hit a breakpoint in av_seek_frame, I use the 'next' command to step over. 在av_seek_frame中设置并命中断点后,我使用'next'命令跳过。 However, this steps into the first function within av_seek_frame(), as you can see below. 但是,这将进入av_seek_frame()中的第一个函数,如下所示。 Furthermore if a do a second 'next', the backtrace looses track of where it is. 此外,如果做第二个“下一个”,则回溯将无法跟踪它的位置。 Am I set up wrong? 我设置错了吗? How can I step over? 我怎么能跨过去? I should note I double checked that 'set step-mode off' is off as the default (as I believe this will break at the first piece of code without debug info.) 我应该注意,我仔细检查了'set step-mode off'是默认关闭的(因为我相信这会在没有调试信息的第一段代码中断开。)

Breakpoint 1, av_seek_frame (s=0x16429000, stream_index=0, timestamp=29727438, flags=0) at l
(gdb) list
1648
1649        return 0;
1650    }
1651
1652    int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags
1653    {
1654        int ret;
1655        AVStream *st;
1656
1657        ff_read_frame_flush(s);
(gdb) next
ff_read_frame_flush (s=0x16429000) at libavformat/utils.c:1248
(gdb) list
1243
1244    /**
1245     * Flush the frame reader.
1246     **/
1247    void ff_read_frame_flush(AVFormatContext *s)
1248    {
1249        AVStream *st;
1250        int i, j;
1251
1252        flush_packet_queue(s);
(gdb) next
ff_read_frame_flush (s=0x16429000) at libavformat/utils.c:1252
(gdb) where
#0  ff_read_frame_flush (s=0x16429000) at libavformat/utils.c:1252
#1  0x00000000 in ?? ()

If you're not sure whether or not your binary is statically linked, you can check it with ldd and see a message like this: 如果您不确定您的二进制文件是否是静态链接的,可以使用ldd进行检查并查看如下消息:

% ldd ffmpeg
        not a dynamic executable

Next, make sure that you give gdb the full path to the executable so that you're not accidentally picking up a binary installed elsewhere on the system that happens to be in your PATH. 接下来,请确保为gdb提供可执行文件的完整路径,这样您就不会意外地在系统中的其他位置安装二进制文件。

Most likely you're loading the wrong binary. 很可能你加载了错误的二进制文件。 Even without using --disable-stripping and --disable-optimizations I can use gdb fine using both step and next commands. 即使使用--disable-stripping和--disable-optimizations,我也可以使用stepnext命令来使用gdb。 You don't need to use --disable-stripping because inside gdb you can use the ffmpeg_g binary (or if you happen to run the ffmpeg binary you can load the symbols from it using file ffmpeg_g ). 您不需要使用--disable-stripping,因为在gdb中您可以使用ffmpeg_g二进制文件(或者如果您碰巧运行ffmpeg二进制file ffmpeg_g ,则可以使用file ffmpeg_g从中加载符号)。

For debugging purposes it is nice to use the --disable-optimizations so that you don't get value optimized out when inspecting variables, but strictly speaking you don't need to use the option to get emacs/gdb to behave... I have no problems stepping through the code when optimizations are used. 出于调试目的,最好使用--disable-optimizations,以便在检查变量时不会对value optimized out ,但严格来说,您不需要使用该选项来获取emacs / gdb的行为......在使用优化时,我没有遇到问题。

There is one things to keep in mind, though, when setting breakpoints with gud/gdb inside of Emacs that might lead to confusion: the gud-break command uses only the base part of the filename for setting breakpoints, not the absolute path to it, which in the case of ffmpeg means that if, for example, you set a breakpoint in utils.c it might not work correctly depending on the value of the source code search paths that you have set in gdb because ffmpeg has multiple files named utils.c in different paths (in fact, there are a total of 5 utils.c files, one in each of the lib* subdirectories) . 但是,有一件事要记住,当在Emacs中使用gud / gdb设置断点时可能会导致混淆: gud-break命令仅使用文件名的基本部分来设置断点,而不是它的绝对路径,在ffmpeg的情况下意味着,例如,如果你在utils.c中设置断点,它可能无法正常工作,具体取决于你在gdb中设置的源代码搜索路径的值,因为ffmpeg有多个名为utils的文件.c在不同的路径中(实际上,总共有5个utils.c文件,每个lib *子目录中有一个)。 By default the search path is set to $cdir:$cwd, but if you have it set to something like /path/to/ffmpeg:$cdir:$cwd and you try to set a breakpoint in the utils.c of libavformat, it might find the one in libavutil-- in which case if you're lucky it will complain that the line where you want to set a breakpoint does not exist (because the one in libavutil is shorter), or it might set a breakpoint on the line you want, but in the wrong utils.c. 默认情况下,搜索路径设置为$ cdir:$ cwd,但是如果你将它设置为类似/ path / to / ffmpeg:$ cdir:$ cwd并尝试在libavformat的utils.c中设置断点,它可能会在libavutil中找到它 - 在这种情况下,如果你很幸运,它会抱怨你想要设置断点的行不存在(因为libavutil中的那个更短),或者它可能设置一个断点你想要的那一行,但在错误的utils.c中。

This issue with gud/gdb should be considered a bug. gud / gdb的这个问题应该被视为一个bug。 When I get a moment I'll submit a patch for gud-break/gud-format-command to fix the problem. 当我得到片刻时,我将提交gud-break / gud-format-command的补丁来解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM