Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to filter LLDB output?

Tags:

xcode

lldb

When I call, for example image list, I have huge number if them. Currently, I just copy it out and then work with it. But is there really no other way? I'd like to be able to do something like image list | grep ...

like image 336
Lishmael Avatar asked Oct 16 '14 07:10

Lishmael


2 Answers

So first off, "image list" takes an module name as an argument, so if you know the module you are looking for, you can do:

(lldb) image list Foundation
[  0] 18EDD673-A010-3E99-956E-DA594CE1FA80 0x00007fff8e357000 /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation 

However, the lldb command line itself doesn't have support for piping or filtering operations beyond what the commands themselves offer. We off-load that sort of task to the script interpreter, since then we can take advantage of the whole ecosystem provided by the scripting language. So far, we only support Python, so you would do:

(lldb) script
>>> for module in lldb.target.modules:
...     if module.file.basename == "Foundation":
...         print module.file
... 
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation

or whatever it was you really wanted to do... LLDB's Python help is pretty good, so to find out what you have available to you in Python, do:

(lldb) script
>>> help (lldb.SBModule)
Help on class SBModule in module lldb:
etc...

And there's an introductory web page for the Python scripting at:

http://lldb.llvm.org/python-reference.html

like image 185
Jim Ingham Avatar answered Oct 19 '22 04:10

Jim Ingham


I put together a little script that allows piping the output of LLDB commands through any shell utility:

https://github.com/ihnorton/lldb.sh

With that script installed, any (hopefully!) lldb command(s) may be prefixed with sh, and then followed by | and a shell command. For example, the following pipes the output of image list through wc -c and returns the number of characters:

(lldb) sh image list | wc -c
    3898

Or

(lldb) sh image list | grep <your library>
...

It also works with pagers like less:

(lldb) sh image list | less
...
like image 30
Isaiah Norton Avatar answered Oct 19 '22 04:10

Isaiah Norton