Skip to content
systemcoding.dev
Debugging

Set breakpoints on functions matching a regex with breakpoint set -r

Break on every function whose name matches a regular expression in LLDB with breakpoint set -r, abbreviated br s -r.

1 min read
Summarize in AI

LLDB's counterpart of rbreak is breakpoint set -r, where -r takes a regular expression matched against function names. One breakpoint with many locations is created, rather than many breakpoints, which makes it easy to delete in one go.

Text
(lldb) breakpoint set -r '^parse_'
Breakpoint 1: 3 locations.
(lldb) breakpoint list
1: regex = '^parse_', locations = 3, resolved = 3, hit count = 0
  1.1: where = app`parse_header + 4 at parse.c:20:5, address = 0x0000000100003f20, resolved, hit count = 0
  1.2: where = app`parse_body + 4 at parse.c:41:5, address = 0x0000000100003f70, resolved, hit count = 0
  1.3: where = app`parse_footer + 4 at parse.c:63:5, address = 0x0000000100003fd0, resolved, hit count = 0

The same command exists in short form as br s -r parse_. Limit the search to a file with -s, naming the shared library or module, as in br s -r parse_ -s app, so a loose pattern does not match thousands of functions in system libraries and make the program slow to start. -f file -l line is the line form, and -n name the plain function name.

Individual locations are controlled as breakpoint disable 1.2. Matching is an unanchored regex search, so parse_ also matches reparse_all; add the ^ anchor if you mean a prefix. The syntax follows the LLDB tutorial, written against LLDB 19, and -r also covers C++ and Objective-C names.

Share

More snippets

Systems Programming

Get the page size with sysconf(_SC_PAGESIZE)

Read the memory page size at run time with sysconf(_SC_PAGESIZE) instead of hard-coding 4096, which is wrong on arm64 kernels built with 16K or 64K pages.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.