LLDB:列出源代码

Ste*_* Lu 9 c++ debugging gdb lldb

我的一个最常用的gdb命令是l由跟随n后面l -.

我如何在lldb中获得相同的内容?

不是不满意不必键入一些行号刚在某处看到代码.在将大量变量转储到终端之后,我想看看我在代码中的位置.我曾经习惯l -回去看看我在哪里,因为随后的调用l将滚动我(lldb也这样做,但关键是没有响应l -).

也许我错过了一些东西,并且我可以将它放入某种"模式",它将始终在单独的缓冲区中显示相应的源位置.那会很好,但我甚至都没有要求.

Jas*_*nda 17

在Xcode 4.6中,lldb的l别名是一个简单的快捷方式source list.

在树源的顶部,这已经改进,表现得更像gdb.如果你看一下source/Interpreter/CommandInterpreter.cpp在在http://lldb.llvm.org/你会看到,l现在是一个正则表达式命令别名这些情况:

if (list_regex_cmd_ap->AddRegexCommand("^([0-9]+)[[:space:]]*$", "source list --line %1") &&
    list_regex_cmd_ap->AddRegexCommand("^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*$", "source list --file '%1' --line %2") &&
    list_regex_cmd_ap->AddRegexCommand("^\\*?(0x[[:xdigit:]]+)[[:space:]]*$", "source list --address %1") &&
    list_regex_cmd_ap->AddRegexCommand("^-[[:space:]]*$", "source list --reverse") &&
    list_regex_cmd_ap->AddRegexCommand("^-([[:digit:]]+)[[:space:]]*$", "source list --reverse --count %1") &&
    list_regex_cmd_ap->AddRegexCommand("^(.+)$", "source list --name \"%1\"") &&
    list_regex_cmd_ap->AddRegexCommand("^$", "source list"))
Run Code Online (Sandbox Code Playgroud)

在这些情况下,您将获得如下行为:

显示当前帧:

(lldb) f
#0: 0x0000000100000f2b a.out`main + 27 at a.c:15
   12   
   13   
   14   
-> 15       puts ("hi"); // line 15
   16   
   17       puts ("hi"); // line 17
   18   }
Run Code Online (Sandbox Code Playgroud)

显示前十行:

(lldb) l -
   5    
   6    
   7    
   8    
   9        puts ("hi"); // line 9
   10   
   11   
Run Code Online (Sandbox Code Playgroud)

您还可以使用stop-line-count-afterstop-line-count-before设置来控制帧停止时显​​示的源上下文数量.

请注意,您可以在~/.lldbinit文件中创建自己的正则表达式命令别名,其行为与top-of-tree lldb相同l.请参阅参考资料help command regex以获取语法和示例.

  • 我正在玩一个玩具源文件,我注意到如果我在源文件的末尾重复使用`l`,`l -`似乎没有再次倒退.如果您接近源文件的末尾,您可能已经看到过. (3认同)

Gab*_*les 9

LLDB:[如何]列出源代码

即:对于任何寻找“如何让 lldb 显示我再次所在的行?(因为我最近的命令已覆盖它)”的人,这很简单f。再次键入f以查看您在代码中的位置。

f
Run Code Online (Sandbox Code Playgroud)

或者

frame select
Run Code Online (Sandbox Code Playgroud)

来源:LLDB:列出源代码

另请参阅以下位置的帮助菜单lldb

help f
Run Code Online (Sandbox Code Playgroud)

显示以下内容:

(lldb) help f
     Select the current stack frame by index from within the current thread (see 
     'thread backtrace'.)

Syntax: f <cmd-options> [<frame-index>]

Command Options Usage:
  f [-r <offset>] [<frame-index>]

       -r <offset> ( --relative <offset> )
            A relative frame index offset from the current frame index.
     
     This command takes options and free-form arguments.  If your arguments resemble option 
     specifiers (i.e., they start with a - or --), you must use ' -- ' between the end of 
     the command options and the beginning of the arguments.

'f' is an abbreviation for 'frame select'
Run Code Online (Sandbox Code Playgroud)

该帮助菜单的底部显示“f是”的缩写frame select

请注意,在 中gdb,等效命令很简单:

f
Run Code Online (Sandbox Code Playgroud)

或者

frame
Run Code Online (Sandbox Code Playgroud)