<div dir="ltr">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.  <div><br></div><div>Any chance you want to just try fixing this python stuff on Windows instead?  :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 11, 2014 at 2:25 PM, Ted Woodward <span dir="ltr"><<a href="mailto:ted.woodward@codeaurora.org" target="_blank">ted.woodward@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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 class="HOEnZb"><font color="#888888"><br>
Ted<br>
</font></span><span class="im HOEnZb"><br>
-----Original Message-----<br>
From: Greg Clayton [mailto:<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>]<br>
</span><div class="HOEnZb"><div class="h5">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><br>
</div></div></blockquote></div><br></div>