LLDB:列出源代码

LLDB: List source code

本文关键字:源代码 LLDB      更新时间:2023-10-16

我最常用的一个gdb命令是lnl -

如何在lldb中获得相同的结果?

我不满足于必须键入一些行号才能在某个地方看到代码。在向终端转储了大量变量之后,我想看看我在代码中的位置。我过去常常使用l -返回查看我所在的位置,因为后续对l的调用会向下滚动我(lldb也会这样做,但关键是不会响应l -)。

也许我错过了什么,我可以把它放在某种"模式"中,它会一直在一个单独的缓冲区中显示相应的源位置。那太好了,但我甚至没有要求。

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

在树源的顶部,这已经得到了改进,表现得更像gdb。如果您查看source/Interpreter/CommandInterpreter.cpphttp://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"))

在这些情况下,你会得到这样的行为:

显示当前帧:

(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   }

显示前十行:

(lldb) l -
   5    
   6    
   7    
   8    
   9        puts ("hi"); // line 9
   10   
   11   

还可以使用stop-line-count-afterstop-line-count-before设置来控制在帧停止时显示多少源上下文。

请注意,您可以在~/.lldbinit文件中创建自己的正则表达式命令别名,其行为与树顶部lldb的l相同。有关语法和示例,请参见help command regex

LLDB:[如何]列出源代码

ie:对于任何寻找"如何使lldb再次显示我在上的哪一行?(因为我最近的命令掩盖了这一点)",它就是简单的f。键入f以再次查看代码中的位置。

f

frame select

来源:LLDB:列出源代码

另请参阅lldb:中的帮助菜单

help f

显示以下内容:

(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'

该帮助菜单的底部显示;CCD_ 20是CCD_;。

请注意,gdb中,等效命令只是:

f

frame
user@hostname> lldb -o "image lookup -rvn file" -o "quit" "Name of exec-file" | grep "CompileUnit"
user@hostname> lldb -o "image lookup -rvs file" -o "quit" "Name of exec-file" | grep "CompileUnit"