[lldb-dev] lldb type summary provider - SBProcess is invalid

Lei Kong via lldb-dev lldb-dev at lists.llvm.org
Tue Sep 13 21:50:04 PDT 2016


Thanks!
SBValue.process works!

I have another script that I run manually to search process memory for certain patterns, not a type summary provider, there is no SBValue passed to my script, in such a case, how do I get current process?

From: Enrico Granata<mailto:egranata at apple.com>
Sent: Tuesday, September 13, 2016 10:31 AM
To: Lei Kong<mailto:leikong at msn.com>
Cc: lldb-dev at lists.llvm.org<mailto:lldb-dev at lists.llvm.org>
Subject: Re: [lldb-dev] lldb type summary provider - SBProcess is invalid


> On Sep 13, 2016, at 10:02 AM, Lei Kong via lldb-dev <lldb-dev at lists.llvm.org> wrote:
>
> 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?
>
>

Good hunch :-)
Maybe we should do a better job at documenting this, but http://lldb.llvm.org/python-reference.html <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:

value.GetProcess()

That's the SBProcess object you want to use

>
> Thanks much
>
>
>
>
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org <mailto:lldb-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev>

Thanks,
- Enrico
📩 egranata@.com ☎️ 27683

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20160913/24db1eeb/attachment.html>


More information about the lldb-dev mailing list