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.
The standard LLDB installation provides you with an extensive set of commands designed to be compatible with familiar GDB commands. In addition to using the standard configuration, you can easily customize LLDB to suit your needs. Both GDB and LLDB are of course excellent debuggers without doubt.
Definition. LLDB is the debugger component of the LLVM project. But, GDB is a portable debugger that runs on many UNIX like systems and works for many programming languages. Thus, this is the main difference between LLDB and GDB.
In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )
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.
LLDB: [How to] List source code
ie: For anyone looking for "How do I make lldb show which line I am on again? (since my recent commands have covered it up)", it is simply f
. Type f
to see where you are at in the code again.
f
OR
frame select
Source: LLDB: List source code
See also the help menu in lldb
:
help f
shows the following:
(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'
The bottom of that help menu shows that "f
is an abbreviation for frame select
".
Note that in gdb
, the equivalent command is simply:
f
OR
frame
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With