[lldb-dev] issues with python scripting in LLDB
Jim Ingham
jingham at apple.com
Fri Nov 4 13:59:14 PDT 2011
I think the idea of having a flag to "command script add" is the best way to do it, with "synchronous" the default. That way people who want to get fancy could, but by default things would work as you naively expected them to... If you have some time to work on this, that would be excellent!
Jim
On Nov 4, 2011, at 12:00 PM, Enrico Granata wrote:
> Jim,
>
> an easy way to have commands run synchronous would be to change ScriptInterpreterPython::RunScriptBasedCommand() to run "debugger.SetAsync(False)" before actually invoking the target function, and "debugger.SetAsync(True)" immediately after.
>
> Of course, one could add a --asynchronous flag to "command script add" and have all commands added *without* this flag run synchronous through the above trick.
> If you want, I can try to work on this in the coming days and let you have a patch for this.
>
> Otherwise, if the preferred idea is to leave it to the individual scripted commands to pick their synchronicity, I guess it is safer to have the code in a try-finally block, as in:
>
>> def StepOver(debugger, args, result, dict):
>> arg_split = args.split(" ")
>> print type(arg_split)
>> count = int(arg_split[0])
>> try:
>> debugger.SetAsync(False)
>> for i in range(0,count):
>> lldb.thread.StepOver(lldb.eOnlyThisThread)
>> debugger.HandleCommand("fr var")
>> print "step<%d>"%i
>> finally:
>> debugger.SetAsync (True)
>
>
> Sincerely,
> - Enrico Granata
>
> On Nov 4, 2011, at 6:18 PM, Jim Ingham wrote:
>
>> gdbrulez:lldb-clean/build/Debug > cat ~/Desktop/script.py
>> #########################
>> import lldb
>> import sys
>> import os
>> import time
>>
>> def StepOver(debugger, args, result, dict):
>> arg_split = args.split(" ")
>> print type(arg_split)
>> count = int(arg_split[0])
>> debugger.SetAsync(False)
>> for i in range(0,count):
>> lldb.thread.StepOver(lldb.eOnlyThisThread)
>> debugger.HandleCommand("fr var")
>> print "step<%d>"%i
>>
>> debugger.SetAsync (True)
>>
>> def __lldb_init_module(debugger, session_dict):
>> debugger.HandleCommand("command script add -f script.StepOver mysto")
>> return None
>>
>> Be sure to set the debugger back to Async mode in the script when you're done. My guess is that the most useful way to run lldb "script" commands is to set them to synchronous mode by default. Or maybe this should be a flag on the "command script add"?
>>
>> Hope this helps,
>>
>> Jim
More information about the lldb-dev
mailing list