[lldb-dev] Various questions about lldbinit and python scripts.

Jean-Yves Avenard jyavenard at gmail.com
Fri Oct 4 19:40:37 PDT 2013


Hi.

Being forced to move from gdb to lldb thanks to XCode 5 dropping
support for gdb, I find myself having to re-implement several commands
I had up and running within gdb.

I use the Qt framework, and in gdb, I had various macros to print the
content of Qt objects such as QString, QMap, QList etc...

I tried to follow the tutorials found there:
http://lldb.llvm.org/tutorial.html

and scripting:
http://lldb.llvm.org/scripting.html

In the python reference documentation:
http://lldb.llvm.org/python-reference.html

there's a link to a template example:
http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/cmdtemplate.py

which according to the documentation should be invoked from lldb with:

command script import /path/to/cmdtemplate.py

When doing so, the module gets properly imported and you see in the
lldb console:

The "framestats" command has been installed, type "help framestats" or
"framestats --help" for detailed help.

However trying to use the command
(lldb) framestats --help

yield:
error: unable to execute script function

I'm just putting this as an example... I've been unable to load *any*
python script within lldb:

(lldb) version
lldb-300.2.47

it always yield the same error "unable to execute script function"..

I tried setting the PYTHONPATH variable to:
/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python

which is where it's located, to no available...

So I'm looking at some pointers on how to use python scripts within lldb.

Ultimately, what I'm trying to achieve is printing the content of a QString.
A QString object has a private member QString::Data* d; where d->size
contains the number of UTF-16 characters
and d->data is an array of ushort (the UTF-16) characters.

In gdb I would "simply" have:

define printqstringdata
    set $d = ('QString::Data'*) $arg0
    set $i = 0
    # abort after a '-1' character, to avoid going on forever when
printing a garbage string
    while $i < $d->size && ($i == 0 || (char)$d->data[$i-1] != -1)
        printf "%c", (char)($d->data[$i++] & 0xff)
    end
    printf "\n"
end

to print the content of the QString, I would call printqstringdata variable.d

doing such loop would be easy in python; provided I managed to get the
script to load and provide and retrieve the QString variable argument.

Any pointers or link to some tutorials will be welcome...

Googling lldb python scripting hasn't provided much help at this stage
unfortunately... It seems no one has bothered writing much python
scripts for lldb yet.... probably too new or not popular enough.

Kind regards
Jean-Yves



More information about the lldb-dev mailing list