Allow Python commands to optionally take an SBExecutionContext argument in case they need to handle 'where they want to act' separately from the notion of 'currently-selected entity' that is associated to the debugger. Do this in an (hopefully) non-breaking way by running an argcount check before passing in the new argument. Update the test case to also check for this new feature. www update to follow
llvm-svn: 218834
This commit is contained in:
parent
ebcf42cdec
commit
06be059ad9
12 changed files with 46 additions and 9 deletions
|
|
@ -25,6 +25,8 @@ public:
|
|||
|
||||
SBExecutionContext (const lldb::SBExecutionContext &rhs);
|
||||
|
||||
SBExecutionContext (lldb::ExecutionContextRefSP exe_ctx_ref_sp);
|
||||
|
||||
SBExecutionContext (const lldb::SBTarget &target);
|
||||
|
||||
SBExecutionContext (const lldb::SBProcess &process);
|
||||
|
|
|
|||
|
|
@ -127,7 +127,8 @@ public:
|
|||
const char *session_dictionary_name,
|
||||
lldb::DebuggerSP& debugger,
|
||||
const char* args,
|
||||
lldb_private::CommandReturnObject& cmd_retobj);
|
||||
lldb_private::CommandReturnObject& cmd_retobj,
|
||||
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
|
||||
|
||||
typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name,
|
||||
const char *session_dictionary_name,
|
||||
|
|
@ -502,7 +503,8 @@ public:
|
|||
const char* args,
|
||||
ScriptedCommandSynchronicity synchronicity,
|
||||
lldb_private::CommandReturnObject& cmd_retobj,
|
||||
Error& error)
|
||||
Error& error,
|
||||
const lldb_private::ExecutionContext& exe_ctx)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,8 @@ public:
|
|||
const char* args,
|
||||
ScriptedCommandSynchronicity synchronicity,
|
||||
lldb_private::CommandReturnObject& cmd_retobj,
|
||||
Error& error);
|
||||
Error& error,
|
||||
const lldb_private::ExecutionContext& exe_ctx);
|
||||
|
||||
Error
|
||||
GenerateFunction(const char *signature, const StringList &input);
|
||||
|
|
|
|||
|
|
@ -126,3 +126,10 @@ SBTypeToSWIGWrapper (lldb::SBCommandReturnObject* cmd_ret_obj_sb)
|
|||
{
|
||||
return SWIG_NewPointerObj((void *) cmd_ret_obj_sb, SWIGTYPE_p_lldb__SBCommandReturnObject, 0);
|
||||
}
|
||||
|
||||
template <>
|
||||
PyObject*
|
||||
SBTypeToSWIGWrapper (lldb::SBExecutionContext* ctx_sb)
|
||||
{
|
||||
return SWIG_NewPointerObj((void *) ctx_sb, SWIGTYPE_p_lldb__SBExecutionContext, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -770,13 +770,15 @@ LLDBSwigPythonCallCommand
|
|||
const char *session_dictionary_name,
|
||||
lldb::DebuggerSP& debugger,
|
||||
const char* args,
|
||||
lldb_private::CommandReturnObject& cmd_retobj
|
||||
lldb_private::CommandReturnObject& cmd_retobj,
|
||||
lldb::ExecutionContextRefSP exe_ctx_ref_sp
|
||||
)
|
||||
{
|
||||
|
||||
lldb::SBCommandReturnObject cmd_retobj_sb(&cmd_retobj);
|
||||
SBCommandReturnObjectReleaser cmd_retobj_sb_releaser(cmd_retobj_sb);
|
||||
lldb::SBDebugger debugger_sb(debugger);
|
||||
lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp);
|
||||
|
||||
bool retval = false;
|
||||
|
||||
|
|
@ -791,7 +793,12 @@ LLDBSwigPythonCallCommand
|
|||
// pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
|
||||
// see comment above for SBCommandReturnObjectReleaser for further details
|
||||
PyObject* pvalue = NULL;
|
||||
pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
|
||||
|
||||
PyCallable::argc argc = pfunc.GetNumArguments();
|
||||
if (argc.num_args == 5 || argc.varargs == true)
|
||||
pvalue = pfunc(debugger_sb, args, exe_ctx_sb, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
|
||||
else
|
||||
pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
|
||||
|
||||
Py_XINCREF (session_dict);
|
||||
Py_XDECREF (pvalue);
|
||||
|
|
|
|||
|
|
@ -479,7 +479,8 @@ LLDBSwigPythonCallCommand (const char *python_function_name,
|
|||
const char *session_dictionary_name,
|
||||
lldb::DebuggerSP& debugger,
|
||||
const char* args,
|
||||
lldb_private::CommandReturnObject &cmd_retobj);
|
||||
lldb_private::CommandReturnObject &cmd_retobj,
|
||||
lldb::ExecutionContextRefSP exe_ctx_ref_sp);
|
||||
|
||||
extern "C" bool
|
||||
LLDBSwigPythonCallModuleInit (const char *python_module_name,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@ m_exe_ctx_sp(rhs.m_exe_ctx_sp)
|
|||
{
|
||||
}
|
||||
|
||||
SBExecutionContext::SBExecutionContext (lldb::ExecutionContextRefSP exe_ctx_ref_sp) :
|
||||
m_exe_ctx_sp(exe_ctx_ref_sp)
|
||||
{
|
||||
}
|
||||
|
||||
SBExecutionContext::SBExecutionContext (const lldb::SBTarget &target) :
|
||||
m_exe_ctx_sp(new ExecutionContextRef())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1366,7 +1366,8 @@ protected:
|
|||
raw_command_line,
|
||||
m_synchro,
|
||||
result,
|
||||
error) == false)
|
||||
error,
|
||||
m_exe_ctx) == false)
|
||||
{
|
||||
result.AppendError(error.AsCString());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
|
|
|
|||
|
|
@ -2510,7 +2510,8 @@ ScriptInterpreterPython::RunScriptBasedCommand(const char* impl_function,
|
|||
const char* args,
|
||||
ScriptedCommandSynchronicity synchronicity,
|
||||
lldb_private::CommandReturnObject& cmd_retobj,
|
||||
Error& error)
|
||||
Error& error,
|
||||
const lldb_private::ExecutionContext& exe_ctx)
|
||||
{
|
||||
if (!impl_function)
|
||||
{
|
||||
|
|
@ -2525,6 +2526,7 @@ ScriptInterpreterPython::RunScriptBasedCommand(const char* impl_function,
|
|||
}
|
||||
|
||||
lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().shared_from_this();
|
||||
lldb::ExecutionContextRefSP exe_ctx_ref_sp(new ExecutionContextRef(exe_ctx));
|
||||
|
||||
if (!debugger_sp.get())
|
||||
{
|
||||
|
|
@ -2548,7 +2550,8 @@ ScriptInterpreterPython::RunScriptBasedCommand(const char* impl_function,
|
|||
m_dictionary_name.c_str(),
|
||||
debugger_sp,
|
||||
args,
|
||||
cmd_retobj);
|
||||
cmd_retobj,
|
||||
exe_ctx_ref_sp);
|
||||
}
|
||||
|
||||
if (!ret_val)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class CmdPythonTestCase(TestBase):
|
|||
self.runCmd('command script delete tell_async', check=False)
|
||||
self.runCmd('command script delete tell_curr', check=False)
|
||||
self.runCmd('command script delete bug11569', check=False)
|
||||
self.runCmd('command script delete takes_exe_ctx', check=False)
|
||||
|
||||
# Execute the cleanup function during test case tear down.
|
||||
self.addTearDownHook(cleanup)
|
||||
|
|
@ -108,6 +109,9 @@ class CmdPythonTestCase(TestBase):
|
|||
substrs = ['running async'])
|
||||
self.expect("tell_curr",
|
||||
substrs = ['I am running sync'])
|
||||
|
||||
# check that the execution context is passed in to commands that ask for it
|
||||
self.expect("takes_exe_ctx", substrs = ["a.out"])
|
||||
|
||||
# Test that a python command can redefine itself
|
||||
self.expect('command script add -f foobar welcome -h "just some help"')
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@ command script import mysto.py --allow-reload
|
|||
command script add tell_sync --function welcome.check_for_synchro --synchronicity sync
|
||||
command script add tell_async --function welcome.check_for_synchro --synchronicity async
|
||||
command script add tell_curr --function welcome.check_for_synchro --synchronicity curr
|
||||
command script add takes_exe_ctx --function welcome.takes_exe_ctx
|
||||
|
|
|
|||
|
|
@ -30,3 +30,6 @@ def check_for_synchro(debugger, args, result, dict):
|
|||
if debugger.GetAsync() == False:
|
||||
print >>result, ('I am running sync')
|
||||
|
||||
def takes_exe_ctx(debugger, args, exe_ctx, result, dict):
|
||||
print >>result, str(exe_ctx.GetTarget())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue