My single most used gdb
command is l
followed by n
followed by l -
.
How can I get the same in lldb?
I am not satisfied with having to type some line number just to see the code somewhere. I want to see where I am in the code, after dumping a ton of variables out to the terminal. And I used to use l -
to go back to look at where I am, since subsequent calls to l
will scroll me down (lldb also does this, but crucially does not respond to l -
).
Perhaps I am missing something and there is some sort of "mode" i can put it in, which will show the corresponding source location in a separate buffer all the time. That would be nice, but I'm not even asking for that.
In Xcode 4.6, lldb's l
alias is a simple shortcut for source list
.
In the top of tree sources, this has been improved to behave more like gdb. If you look at source/Interpreter/CommandInterpreter.cpp
over at http://lldb.llvm.org/ you'll see that l
is now a regular expression command alias with these cases:
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"))
With these cases, you will get behavior like this:
Show current frame:
(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 }
show previous ten lines:
(lldb) l -
5
6
7
8
9 puts ("hi"); // line 9
10
11
You can also use the stop-line-count-after
and stop-line-count-before
settings to control how much source context is displayed at frame stops.
Note that you can create your own regular expression command alias in your ~/.lldbinit
file with the same behavior as the top-of-tree lldb's l
. See help command regex
for the syntax and an example.