gpt4 book ai didi

c++ - LLDB:列出源代码

转载 作者:可可西里 更新时间:2023-11-01 17:25:59 25 4
gpt4 key购买 nike

我最常用的 gdb 命令是 l,然后是 n,然后是 l -

我怎样才能在 lldb 中得到相同的东西?

满足于必须键入一些行号才能看到某处的代码。在将大量变量转储到终端后,我想看看我在代码中的位置。我曾经使用 l - 返回查看我在哪里,因为随后调用 l 会向下滚动(lldb 也这样做,但关键不是响应 l -)。

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

最佳答案

在 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-afterstop-line-count-before 设置来控制在帧停止时显​​示多少源上下文。

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

关于c++ - LLDB:列出源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17480107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com