<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Thanks!</p>
<p class="MsoNormal">SBValue.process works!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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?</p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p> </o:p></span></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:egranata@apple.com">Enrico Granata</a><br>
<b>Sent: </b>Tuesday, September 13, 2016 10:31 AM<br>
<b>To: </b><a href="mailto:leikong@msn.com">Lei Kong</a><br>
<b>Cc: </b><a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
<b>Subject: </b>Re: [lldb-dev] lldb type summary provider - SBProcess is invalid</p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p> </o:p></span></p>
</div>
<div class="" style="word-wrap:break-word"><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Sep 13, 2016, at 10:02 AM, Lei Kong via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div dir="ltr" class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<div class="" style="margin:0px; padding:0px; border:0px currentcolor; font-size:13px">
<div class="x_post-text" itemprop="text" style="margin:0px 0px 5px; padding:0px; border:0px currentcolor; width:660px; line-height:1.3; font-size:15px">
<p class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
I wrote a lldb type summary provider for wstring with 16bit wchar on Ubuntu 16.04.</p>
<p class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
Things work fine if I manually do the following in lldb:</p>
<pre class="" style="margin:0px 0px 1em; padding:5px; border:0px currentcolor; width:auto; overflow:auto; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif; font-size:13px; max-height:600px; background-color:rgb(239,240,241)"><code class="" style="margin:0px; padding:0px; border:0px currentcolor; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif; font-size:13px; white-space:inherit; background-color:rgb(239,240,241)">(lldb) script import mytypes
(lldb) type summary add -F mytypes.wstring_SummaryProvider "std::__1::wstring"
</code></pre>
<p class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
I tried to make things easier with auto-loading by adding the following to .lldbinit:</p>
<pre class="" style="margin:0px 0px 1em; padding:5px; border:0px currentcolor; width:auto; overflow:auto; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif; font-size:13px; max-height:600px; background-color:rgb(239,240,241)"><code class="" style="margin:0px; padding:0px; border:0px currentcolor; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif; font-size:13px; white-space:inherit; background-color:rgb(239,240,241)">script import mytypes
type summary add -F mytypes.wstring_SummaryProvider "std::__1::wstring"
</code></pre>
<p class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
Then I got a failure of "SBProcess is invalid" when printing a wstring variable.</p>
<p class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
My type summary function has the following, which I believe is where the error is encountered:</p>
<pre class="" style="margin:0px 0px 1em; padding:5px; border:0px currentcolor; width:auto; overflow:auto; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif; font-size:13px; max-height:600px; background-color:rgb(239,240,241)"><code class="" style="margin:0px; padding:0px; border:0px currentcolor; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif; font-size:13px; white-space:inherit; background-color:rgb(239,240,241)">content = lldb.process.ReadMemory(bufferAddr, byteCount, error)
</code></pre>
<p class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
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?</p>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>Good hunch :-)</div>
<div>Maybe we should do a better job at documenting this, but <a href="http://lldb.llvm.org/python-reference.html" class="">http://lldb.llvm.org/python-reference.html</a> reads</div>
<div><br class="">
</div>
<div>"<span class="" style="">While extremely convenient, these variables (<i class=""><b class="">lldb.process</b></i> 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.</span><span class="" style=""> </span></div>
<p class="" style="">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."</p>
<div>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:</div>
<div><br class="">
</div>
<div>value.GetProcess()</div>
<div><br class="">
</div>
<div>That's the SBProcess object you want to use</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div dir="ltr" class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<div class="" style="margin:0px; padding:0px; border:0px currentcolor; font-size:13px">
<div class="x_post-text" itemprop="text" style="margin:0px 0px 5px; padding:0px; border:0px currentcolor; width:660px; line-height:1.3; font-size:15px">
<div class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
 <br class="x_webkit-block-placeholder">
</div>
<p class="" style="margin:0px 0px 1em; padding:0px; border:0px currentcolor; clear:both; font-size:15px">
Thanks much</p>
</div>
</div>
 <br class="">
<table class="" style="margin:0px; padding:0px; border:0px currentcolor; text-align:left; color:rgb(36,39,41); text-transform:none; line-height:16.9px; text-indent:0px; letter-spacing:normal; font-family:Arial,'Helvetica Neue',Helvetica,sans-serif; font-size:13px; font-style:normal; font-weight:normal; word-spacing:0px; white-space:normal; border-collapse:collapse; border-spacing:0px; orphans:2; widows:2; background-color:rgb(255,255,255)">
<tbody class="" style="margin:0px; padding:0px; border:0px currentcolor; font-size:13px">
<tr class="" style="margin:0px; padding:0px; border:0px currentcolor; font-size:13px">
<td class="x_votecell" style="margin:0px; padding:0px 15px 0px 0px; border:0px currentcolor; font-size:13px; vertical-align:top">
<div class="x_vote" style="margin:0px; padding:0px; border:0px currentcolor; text-align:center; font-size:13px; min-width:46px">
<div class="x_favoritecount" style="margin:0px; padding:0px; border:0px currentcolor; text-align:center; font-size:13px">
 </div>
</div>
</td>
<td class="x_postcell" style="margin:0px; padding:0px; border:0px currentcolor; font-size:13px; vertical-align:top">
<div class="" style="margin:0px; padding:0px; border:0px currentcolor; font-size:13px">
 </div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; float:none; display:inline!important">_______________________________________________</span><br class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<span class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; float:none; display:inline!important">lldb-dev
 mailing list</span><br class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<a href="mailto:lldb-dev@lists.llvm.org" class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">lldb-dev@lists.llvm.org</a><br class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" class="" style="font-family:Calibri; font-size:16px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a></div>
</blockquote>
</div>
<br class="">
<div class="">
<div class="" style="color:rgb(0,0,0); font-family:Helvetica; font-size:12px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<br class="x_Apple-interchange-newline">
Thanks,</div>
<div class="" style="color:rgb(0,0,0); font-family:Helvetica; font-size:12px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<i class="">- Enrico</i><br class="">
📩 egranata@<font color="#ff2600" class=""></font>.com ☎️ 27683</div>
</div>
<br class="">
</div>
</body>
</html>