LLDB: List source code

前端 未结 2 1556
盖世英雄少女心
盖世英雄少女心 2021-02-07 11:14

My single most used gdb command is l followed by n followed by l -.

How can I get the same in lldb?

I am

相关标签:
2条回答
  • 2021-02-07 11:35

    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.

    0 讨论(0)
  • 2021-02-07 11:37

    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
    
    0 讨论(0)
提交回复
热议问题