diff options
-rw-r--r-- | lldb/include/lldb/API/SBExecutionContext.h | 2 | ||||
-rw-r--r-- | lldb/include/lldb/Interpreter/ScriptInterpreter.h | 6 | ||||
-rw-r--r-- | lldb/include/lldb/Interpreter/ScriptInterpreterPython.h | 3 | ||||
-rw-r--r-- | lldb/scripts/Python/python-swigsafecast.swig | 7 | ||||
-rw-r--r-- | lldb/scripts/Python/python-wrapper.swig | 11 | ||||
-rw-r--r-- | lldb/source/API/SBCommandInterpreter.cpp | 3 | ||||
-rw-r--r-- | lldb/source/API/SBExecutionContext.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectCommands.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 7 | ||||
-rw-r--r-- | lldb/test/functionalities/command_script/TestCommandScript.py | 4 | ||||
-rw-r--r-- | lldb/test/functionalities/command_script/py_import | 1 | ||||
-rw-r--r-- | lldb/test/functionalities/command_script/welcome.py | 3 |
12 files changed, 46 insertions, 9 deletions
diff --git a/lldb/include/lldb/API/SBExecutionContext.h b/lldb/include/lldb/API/SBExecutionContext.h index dac04b30f6d..e5cac1afe91 100644 --- a/lldb/include/lldb/API/SBExecutionContext.h +++ b/lldb/include/lldb/API/SBExecutionContext.h @@ -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); diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h index bc7c7a0e57a..2fbc57a7a32 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h @@ -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; } diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h index 483cb090cd5..92fc0328959 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h @@ -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); diff --git a/lldb/scripts/Python/python-swigsafecast.swig b/lldb/scripts/Python/python-swigsafecast.swig index 4813c4f8c4d..fee57cb75f3 100644 --- a/lldb/scripts/Python/python-swigsafecast.swig +++ b/lldb/scripts/Python/python-swigsafecast.swig @@ -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); +} diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index 0c6382482c3..bf22198f4e4 100644 --- a/lldb/scripts/Python/python-wrapper.swig +++ b/lldb/scripts/Python/python-wrapper.swig @@ -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); diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp index 397ee61839a..aa1ff55bc73 100644 --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -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, diff --git a/lldb/source/API/SBExecutionContext.cpp b/lldb/source/API/SBExecutionContext.cpp index 6a8dd2e33f1..d1c21eccb72 100644 --- a/lldb/source/API/SBExecutionContext.cpp +++ b/lldb/source/API/SBExecutionContext.cpp @@ -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()) { diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 6061a1d7620..836d2a18e35 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -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); diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 945e869a794..42a7640f348 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -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) diff --git a/lldb/test/functionalities/command_script/TestCommandScript.py b/lldb/test/functionalities/command_script/TestCommandScript.py index 6efda1c46aa..27ce4a7c6f1 100644 --- a/lldb/test/functionalities/command_script/TestCommandScript.py +++ b/lldb/test/functionalities/command_script/TestCommandScript.py @@ -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"') diff --git a/lldb/test/functionalities/command_script/py_import b/lldb/test/functionalities/command_script/py_import index 8cb112d884d..afc8c82340e 100644 --- a/lldb/test/functionalities/command_script/py_import +++ b/lldb/test/functionalities/command_script/py_import @@ -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 diff --git a/lldb/test/functionalities/command_script/welcome.py b/lldb/test/functionalities/command_script/welcome.py index b6340990e78..c444934012f 100644 --- a/lldb/test/functionalities/command_script/welcome.py +++ b/lldb/test/functionalities/command_script/welcome.py @@ -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()) + |