<html xmlns:v="urn:schemas-microsoft-com:vml" 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 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.hoenzb
{mso-style-name:hoenzb;}
span.im
{mso-style-name:im;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I think it’s more than just “script print”:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Windows:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>>> result = lldb.SBCommandReturnObject()<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>>> lldb.debugger.GetCommandInterpreter().HandleCommand('help gdb-remote', result)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>6<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>>> result.GetOutput()<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>''<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>>> result.GetError()<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>'error: SBCommandInterpreter or the command line is not valid\n'<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Linux:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>>> result = lldb.SBCommandReturnObject()<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>>> lldb.debugger.GetCommandInterpreter().HandleCommand('help gdb-remote', result)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>1<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>>> result.GetOutput()<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>" Connect to a remote GDB server. If no hostname is provided, localhost is\n assumed. This command takes 'raw' input (no need to quote stuff).\n\nSyntax: gdb-remote [<hostname>:]<portnum>\n"<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If I create a command, I can use the passed in debugger to run HandleCommand() on Windows, but can’t do it using lldb.debugger, interactively or in a script.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Zachary Turner [mailto:zturner@google.com] <br><b>Sent:</b> Thursday, September 11, 2014 5:45 PM<br><b>To:</b> Ted Woodward<br><b>Cc:</b> Greg Clayton; lldb-dev@cs.uiuc.edu<br><b>Subject:</b> Re: [lldb-dev] Call python script on stop?<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>lldb.debugger should work on Windows, but python still has some kinks to work out on Windows, definitely. For starters, "script print" doesn't work on Windows. I know how to fix it, but I'm just not there yet and it's a large fix. <o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Any chance you want to just try fixing this python stuff on Windows instead? :)<o:p></o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Thu, Sep 11, 2014 at 2:25 PM, Ted Woodward <<a href="mailto:ted.woodward@codeaurora.org" target="_blank">ted.woodward@codeaurora.org</a>> wrote:<o:p></o:p></p><p class=MsoNormal>I think I found the problem. I'm running on Windows. :-)<br><br>OK, the real problem:<br>(lldb) script print lldb.debugger<br>No value<br><br>I tried passing the debugger as a variable, but that crashes on both Windows and Linux.<br><br>My code looks like:<br><br>def __lldb_init_module(debugger, dict):<br> debugger.HandleCommand('command script add -f vregwin.vrs vrs')<br><br>def vrs(debugger, command, result, dict):<br> foo = thread.start_new_thread(vregwin, (debugger,))<br><br>def vregwin(debugger):<br> result = lldb.SBCommandReturnObject()<br> debugger.GetCommandInterpreter().HandleCommand('help gdb-remote', result)<br> print result.GetOutput()<br> print result.GetError()<br><br><br>A "print debugger" in there gives:<br>Debugger (instance: "HÄ]ÃåHì@", id: 140736691407232)<br><br>So I need to use lldb.debugger, which doesn't work on Windows. I guess I'll switch to Linux.<br><span style='color:#888888'><br><span class=hoenzb>Ted</span><br></span><br><span class=im>-----Original Message-----</span><br><span class=im>From: Greg Clayton [mailto:<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>]</span><o:p></o:p></p><div><div><p class=MsoNormal>Sent: Wednesday, September 10, 2014 3:25 PM<br>To: Ted Woodward<br>Cc: Jim Ingham; <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>Subject: Re: [lldb-dev] Call python script on stop?<br><br><br>> On Sep 10, 2014, at 1:00 PM, Ted Woodward <<a href="mailto:ted.woodward@codeaurora.org">ted.woodward@codeaurora.org</a>> wrote:<br>><br>> Let me back up a little - I'm running this from lldb, not python.<br><br>Ah, gotcha.<br><br>> Ultimately I want to have lldb run from eclipse, connected to a gdb server, but use python to pop up TK windows so we can enhance the gui without having to write eclipse java code.<br><br>Got it.<br><br>> I've got my script creating the TK window, and I can populate the window by reading registers. Then I moved the window code to another thread, but now I can't read registers.<br><br>Many windowing frameworks require UI updates happen on a specific thread. I am not sure if you are running into such a problem here. There should be nothing stopping you from being able to read registers from another thread. You will need to make sure your target is stopped (otherwise the register read will fail saying the process is running).<br><br>> I'm connected to the gdb server, and can read registers from the command line. I pass the debugger in to my handler code in the other thread, and lldb crashes when I try to access it.<br><br>That shouldn't happen if you have a valid debugger handle.<br><br>> If I create a new debugger instead, I get "error: invalid frame".<br><br>Each debugger has a target list:<br><br>debugger<br> target = 0x11110000<br> target = 0x22220000<br><br>Each target may or may not have a process<br><br>debugger<br> target = 0x11110000<br> process = 0x12340000<br> target = 0x22220000<br> process = 0x00000000<br><br>Then each process, if valid might have one or more threads and one or more frames within each thread:<br><br>debugger<br> target = 0x11110000<br> process = 0x12340000<br> thread 1 = 0x12310000<br> thread 2 = 0x12310000<br> frame[0] = 0x123092302<br> frame[1] = 0x223092302<br> target = 0x22220000<br> process = 0x00000000<br><br><br>So there is no reason to create a new debugger, it won't contain anything. You need to access the current debugger. If you are running through the embedded python interpreter, you can just use "lldb.debugger". That will always be correct for your current session.<br><br>><br>> How do I start up a new thread, but access the debugger on the main thread, which is attached to the remote gdb server?<br><br>All LLDB code is multi-theaded so you should be able to read registers on any thread. You need to make sure you have good instances:<br><br>(lldb) script print lldb.debugger<br>Debugger (instance: "debugger_1", id: 1)<br><br><br>When you print the debugger, you get valid text. You should also validate that you have valid target, process, thread, and frame objects before you use them.<br><br>Maybe you can post the code that is using the debugger to get the current target, and how you are getting the thread and frame that you are getting registers from?<br><br>Greg<br>><br>> -----Original Message-----<br>> From: Greg Clayton [mailto:<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>]<br>> Sent: Tuesday, September 09, 2014 7:08 PM<br>> To: Ted Woodward<br>> Cc: Jim Ingham; <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>> Subject: Re: [lldb-dev] Call python script on stop?<br>><br>> You would use two python threads.<br>><br>> Info on python threads:<br>><br>> <a href="http://www.tutorialspoint.com/python/python_multithreading.htm" target="_blank">http://www.tutorialspoint.com/python/python_multithreading.htm</a><br>><br>> You would make one thread run your command prompt code, and one thread just consuming events. You would make a function in python:<br>><br>><br>> def lldb_event_thread():<br>> ....<br>><br>><br>> And the code inside lldb_event_thread would be consuming the events (copy code from process_events.py).<br>><br>> You actually might want 3 thread:<br>> 1 - main thread that waits for anything from the two other threads<br>> 2 - command prompt thread<br>> 3 - event thread<br>><br>><br>><br>>> On Sep 9, 2014, at 4:43 PM, Ted Woodward <<a href="mailto:ted.woodward@codeaurora.org">ted.woodward@codeaurora.org</a>> wrote:<br>>><br>>> Can I do that from inside lldb, or are we talking another python process? If inside lldb, how do I do that?<br>>><br>>> -----Original Message-----<br>>> From: Greg Clayton [mailto:<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>]<br>>> Sent: Tuesday, September 09, 2014 6:35 PM<br>>> To: Ted Woodward<br>>> Cc: Jim Ingham; <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>>> Subject: Re: [lldb-dev] Call python script on stop?<br>>><br>>> You will need to launch another python thread, and in that thread, handle all events just like the process_events.py script.<br>>><br>>><br>>>> On Sep 9, 2014, at 4:31 PM, Ted Woodward <<a href="mailto:ted.woodward@codeaurora.org">ted.woodward@codeaurora.org</a>> wrote:<br>>>><br>>>> Is there a way to launch another lldb thread, so I have the command prompt and a python script running at the same time?<br>>>><br>>>> -----Original Message-----<br>>>> From: <a href="mailto:jingham@apple.com">jingham@apple.com</a> [mailto:<a href="mailto:jingham@apple.com">jingham@apple.com</a>]<br>>>> Sent: Tuesday, September 09, 2014 5:38 PM<br>>>> To: Greg Clayton<br>>>> Cc: Ted Woodward; <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>>>> Subject: Re: [lldb-dev] Call python script on stop?<br>>>><br>>>> Yes, you definitely want to handle events yourself. The target stop hooks are fine for printing some variables and threads, etc, but I wouldn't try to update your GUI, etc, from there.<br>>>><br>>>> Jim<br>>>><br>>>>> On Sep 9, 2014, at 3:22 PM, Greg Clayton <<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>> wrote:<br>>>>><br>>>>><br>>>>>> On Sep 9, 2014, at 1:36 PM, Ted Woodward <<a href="mailto:ted.woodward@codeaurora.org">ted.woodward@codeaurora.org</a>> wrote:<br>>>>>><br>>>>>> I’m working on a simple python gui proof-of-concept. I’m going to use the Tkinter module to open a Tk window that displays registers. I’d like to have it auto-update when the target stops.<br>>>>>><br>>>>>> Is there a way to automatically call a python script when a target stops, and to call another (to clean up) when the target is killed?<br>>>>><br>>>>> Why not just consume the events yourself?<br>>>>><br>>>>> See the following sample python code:<br>>>>><br>>>>> svn cat <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py" target="_blank">http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py</a><br>>>>><br>>>>> There is a "target stop-hook" command you could use:<br>>>>><br>>>>> (lldb) help target stop-hook<br>>>>><br>>>>> But I would suggest consuming the events on another thread from python, or just making a polling loop where you want for events for a specified amount of time.<br>>>>><br>>>>> Greg<br>>>>><br>>>>><br>>>>> _______________________________________________<br>>>>> lldb-dev mailing list<br>>>>> <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>>>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>>>><br>>>><br>>><br>>><br>><br>><br><br><br><br>_______________________________________________<br>lldb-dev mailing list<br><a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><o:p></o:p></p></div></div></div><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>