Let me back up a little - I'm running this from lldb, not python.
Ah, gotcha.
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.
Got it.
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.
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).
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.
That shouldn't happen if you have a valid debugger handle.
If I create a new debugger instead, I get "error: invalid frame".
Each debugger has a target list:
debugger
target = 0x11110000
target = 0x22220000
Each target may or may not have a process
debugger
target = 0x11110000
process = 0x12340000
target = 0x22220000
process = 0x00000000
Then each process, if valid might have one or more threads and one or more frames within each thread:
debugger
target = 0x11110000
process = 0x12340000
thread 1 = 0x12310000
thread 2 = 0x12310000
frame[0] = 0x123092302
frame[1] = 0x223092302
target = 0x22220000
process = 0x00000000
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.
How do I start up a new thread, but access the debugger on the main thread, which is attached to the remote gdb server?
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:
(lldb) script print lldb.debugger
Debugger (instance: "debugger_1", id: 1)
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.
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?
Greg