[lldb-dev] Call python script on stop?

Ted Woodward ted.woodward at codeaurora.org
Wed Sep 10 13:00:29 PDT 2014


Let me back up a little - I'm running this from lldb, not python. 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.

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. 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. If I create a new debugger instead, I get "error: invalid frame".

How do I start up a new thread, but access the debugger on the main thread, which is attached to the remote gdb server?

-----Original Message-----
From: Greg Clayton [mailto:gclayton at apple.com] 
Sent: Tuesday, September 09, 2014 7:08 PM
To: Ted Woodward
Cc: Jim Ingham; lldb-dev at cs.uiuc.edu
Subject: Re: [lldb-dev] Call python script on stop?

You would use two python threads.

Info on python threads:

http://www.tutorialspoint.com/python/python_multithreading.htm

You would make one thread run your command prompt code, and one thread just consuming events. You would make a function in python:


def lldb_event_thread():
    ....


And the code inside lldb_event_thread would be consuming the events (copy code from process_events.py). 

You actually might want 3 thread:
1 - main thread that waits for anything from the two other threads
2 - command prompt thread
3 - event thread



> On Sep 9, 2014, at 4:43 PM, Ted Woodward <ted.woodward at codeaurora.org> wrote:
> 
> Can I do that from inside lldb, or are we talking another python process? If inside lldb, how do I do that?
> 
> -----Original Message-----
> From: Greg Clayton [mailto:gclayton at apple.com] 
> Sent: Tuesday, September 09, 2014 6:35 PM
> To: Ted Woodward
> Cc: Jim Ingham; lldb-dev at cs.uiuc.edu
> Subject: Re: [lldb-dev] Call python script on stop?
> 
> You will need to launch another python thread, and in that thread, handle all events just like the process_events.py script.
> 
> 
>> On Sep 9, 2014, at 4:31 PM, Ted Woodward <ted.woodward at codeaurora.org> wrote:
>> 
>> Is there a way to launch another lldb thread, so I have the command prompt and a python script running at the same time?
>> 
>> -----Original Message-----
>> From: jingham at apple.com [mailto:jingham at apple.com] 
>> Sent: Tuesday, September 09, 2014 5:38 PM
>> To: Greg Clayton
>> Cc: Ted Woodward; lldb-dev at cs.uiuc.edu
>> Subject: Re: [lldb-dev] Call python script on stop?
>> 
>> 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.
>> 
>> Jim
>> 
>>> On Sep 9, 2014, at 3:22 PM, Greg Clayton <gclayton at apple.com> wrote:
>>> 
>>> 
>>>> On Sep 9, 2014, at 1:36 PM, Ted Woodward <ted.woodward at codeaurora.org> wrote:
>>>> 
>>>> 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.
>>>> 
>>>> 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?
>>> 
>>> Why not just consume the events yourself?
>>> 
>>> See the following sample python code:
>>> 
>>> svn cat http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py
>>> 
>>> There is a "target stop-hook" command you could use:
>>> 
>>> (lldb) help target stop-hook 
>>> 
>>> 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.
>>> 
>>> Greg
>>> 
>>> 
>>> _______________________________________________
>>> lldb-dev mailing list
>>> lldb-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
>> 
>> 
> 
> 






More information about the lldb-dev mailing list