LLDB:列出源代码

问题描述 投票:0回答:3

我最常用的

gdb
命令是
l
,然后是
n
,然后是
l -

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

满意于必须键入一些行号才能在某处查看代码。在将大量变量转储到终端后,我想查看代码中的位置。我曾经使用

l -
返回查看我所在的位置,因为后续调用
l
将使我向下滚动(lldb 也这样做,但关键的是不响应
l -
)。

也许我遗漏了一些东西,并且我可以将其放入某种“模式”,它将在单独的缓冲区中显示相应的源位置始终。那就太好了,但我什至都没有要求。

c++ debugging gdb lldb
3个回答
28
投票

在 Xcode 4.6 中,lldb 的

l
别名是
source list
的简单快捷方式。

在树源代码的顶部,它已得到改进,使其行为更像 gdb。如果您查看

http://lldb.llvm.org/
上的 source/Interpreter/CommandInterpreter.cpp,您会发现
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-after
stop-line-count-before
设置来控制在帧停止时显示多少源上下文。

请注意,您可以在

~/.lldbinit
文件中创建自己的正则表达式命令别名,其行为与树顶 lldb 的
l
相同。请参阅
help command regex
了解语法和示例。


10
投票

LLDB:[如何]列出源代码

即:对于任何寻找 “如何让 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'

该帮助菜单的底部显示:

f
frame select

的缩写

请注意,

gdb
中,等效命令很简单:

f

frame

0
投票
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"
© www.soinside.com 2019 - 2024. All rights reserved.