Steven Lu
Steven Lu

Reputation: 43417

LLDB: List source code

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.

Upvotes: 21

Views: 43825

Answers (3)

Gabriel Staples
Gabriel Staples

Reputation: 52449

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

Upvotes: 12

Michael Kim
Michael Kim

Reputation: 1

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"

Upvotes: 0

Jason Molenda
Jason Molenda

Reputation: 15375

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.

Upvotes: 30

Related Questions