I wrote a lldb type summary provider for wstring with 16bit wchar on Ubuntu 16.04.
Things work fine if I manually do the following in lldb:
(lldb) script import mytypes
(lldb) type summary add -F mytypes.wstring_SummaryProvider "std::__1::wstring"
I tried to make things easier with auto-loading by adding the following to .lldbinit:
script import mytypes
type summary add -F mytypes.wstring_SummaryProvider "std::__1::wstring"
Then I got a failure of “SBProcess is invalid” when printing a wstring variable.
My type summary function has the following, which I believe is where the error is encountered:
content = lldb.process.ReadMemory(bufferAddr, byteCount, error)
Maybe this is because “process” is not assigned yet when the type summary is added during auto-loading? Or this is a bug in lldb? Does anyone know how to work around this issue?
Maybe we should do a better job at documenting this, but http://lldb.llvm.org/python-reference.html reads
"While extremely convenient, these variables (lldb.process et alia) have a couple caveats that you should be aware of. First of all, they hold the values of the selected objects on entry to the embedded interpreter. They do not update as you use the LLDB API’s to change, for example, the currently selected stack frame or thread.
Moreover, they are only defined and meaningful while in the interactive Python interpreter. There is no guarantee on their value in any other situation, hence you should not use them when defining Python formatters, breakpoint scripts and commands (or any other Python extension point that LLDB provides). As a rationale for such behavior, consider that lldb can run in a multithreaded environment, and another thread might call the “script” command, changing the value out from under you."
As part of a formatter, you get passed an SBValue. One of the things you can ask of an SBValue is the process it came from, thusly:
That’s the SBProcess object you want to use
lldb-dev mailing list