Post

LLDB notes

Working with LLDB, I often come across new things like commands, additional tools, and more. I’d like to use this post as a sort of notebook where I can jot down important things and notes about LLDB and LLVM in general that I’ve stumbled upon and wouldn’t want to lose. I hope that in the future, this post will grow into something valuable.

Commands

Enable logging:

1
(lldb) log enable -f /LOG/FILE/PATH -v lldb all

Run python code from the debugger:

1
(lldb) script import time; print(f"Time: {time.time()}");

Measure the command evaluation time:

1
(lldb) script import time; s = time.time(); lldb.debugger.HandleCommand("""<COMMAND>"""); time.time() - s

But this long command can be aliased:

1
echo "command regex measure 's/(.+)/script import time; s = time.time(); lldb.debugger.HandleCommand(\"\"\"%1\"\"\"); time.time() - s;/'" >> ~/.lldbinit

And then just

1
(lldb) measure expr -- demo()

Multiline expressions (### << is a comment beginning, no need to write it):

1
2
3
4
(lldb) expr -- ### << press enter to start the multiline expression from a new line
int x = 1;
x + 2;
### << after this empty line, the expression will be evaluated

Tools

Tool for parsing, dumping, and performing other operations on PDB files:

1
llvm-pdbutil -h
This post is licensed under CC BY 4.0 by the author.