[lldb-dev] issues with python scripting in LLDB

Enrico Granata granata.enrico at gmail.com
Fri Nov 4 14:00:28 CDT 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.uiuc.edu/pipermail/lldb-dev/attachments/20111104/14fe8ab1/attachment-0001.html 


More information about the lldb-dev mailing list