LLDB Alaises

Hi! I just started working with lldb and I was planning to add some aliases to LLDB as I realized that some commands are longer and more complex to write. e.g.,
breakpoint set -f example.c -n main
This is going to set a breakpoint at main function in example.c
But same could be done like this:
break example.c:main
in gdb, which is much more convenient and easy to write.
Also this breakpoint was just an example. I want to ask the community which set of complex longer commands do they think are more frequently used and adding an alias for them would make sense?

1 Like

You might want to look at help _regexp-break - by default lldb defines a command alias for b to _regexp-break which handles many of the most common shortcuts, although I don’t think there is a regular expression that would match filename:funcname. Do you think this is a commonly used combination? Of course it’s possible to have multiple functions with the same name, particularly across multiple solibs/dylibs in a process, and filename may disambiguate but I think normally people specify the binary name that they want the function name to be searched in.

1 Like

Hi @Ameerhamza! @junior-jl is almost done working on a new command option to launch the process in main [lldb] add stop-at-user-entry option to process launch by junior-jl · Pull Request #67019 · llvm/llvm-project · GitHub. You should take a look.

1 Like

One of the things that’s great about the design of b and _regexp-break, is that you can augment it very easily! I have personally overloaded b with custom patterns, and your case of <file>:<function> is a good example of a custom pattern.

First, lldb has command regex, a handy tool for quick and easy custom commands. It lets you define a command by rewriting inputs to be used by some existing command.

Although b is not defined using command regex, if it were defined as a regex, it would look like this:

command regex b
s/(.*)/_regexp-break %1/

This uses a sed-like syntax, convert one command invocation, into another. In this contrived example, all input is matched with (.*) and is passed on to _regexp-break (via %1, which matches the first regex group).

The flexibility with this approach is that command regex accepts multiple substitution patterns, trying them in order. To add your <file>:<function> case, let’s construct a pattern, and rewrite it. A simple pattern that would work is (.+):(\D.*). That is, any characters, a colon, a non-digit, and then any characters. The non-digit is to prevent matching a common use case: <file>:<line>, ex example.c:26.

command regex b
s/(.+):(\D.*)/breakpoint set -f %1 -n %2/
s/(.*)/_regexp-break %1/

With this in place, the command b example.c:main will be rewritten to breakpoint set -f example.c -n main.