<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Author: enrico<br class="">Date: Wed Oct  1 16:53:32 2014<br class="">New Revision: 218835<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=218835&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=218835&view=rev</a><br class="">Log:<br class="">Add documentation about the new SBExecutionContext for Python commands feature. This marks the end of <a href="rdar://18142728" class="">rdar://18142728</a><br class=""><br class="">Modified:<br class="">   lldb/trunk/www/python-reference.html<br class=""><br class=""><div>I jotted down a few lines on how this works, and the updated function prototype (since argument order changes when you do this) - but feel free to update my wording</div><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 1, 2014, at 3:32 PM, <a href="mailto:jingham@apple.com" class="">jingham@apple.com</a> wrote:</div><br class="Apple-interchange-newline"><div class="">Excellent!!!  Thanks for adding this, Enrico!  Can you also add something to the Python Tutorial describing this and why it's a good idea to do it this way?<br class=""><br class="">Jim<br class=""><br class=""><blockquote type="cite" class="">On Oct 1, 2014, at 2:47 PM, Enrico Granata <<a href="mailto:egranata@apple.com" class="">egranata@apple.com</a>> wrote:<br class=""><br class="">Author: enrico<br class="">Date: Wed Oct  1 16:47:29 2014<br class="">New Revision: 218834<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=218834&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=218834&view=rev</a><br class="">Log:<br class="">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<br class=""><br class="">Modified:<br class="">   lldb/trunk/include/lldb/API/SBExecutionContext.h<br class="">   lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h<br class="">   lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h<br class="">   lldb/trunk/scripts/Python/python-swigsafecast.swig<br class="">   lldb/trunk/scripts/Python/python-wrapper.swig<br class="">   lldb/trunk/source/API/SBCommandInterpreter.cpp<br class="">   lldb/trunk/source/API/SBExecutionContext.cpp<br class="">   lldb/trunk/source/Commands/CommandObjectCommands.cpp<br class="">   lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp<br class="">   lldb/trunk/test/functionalities/command_script/TestCommandScript.py<br class="">   lldb/trunk/test/functionalities/command_script/py_import<br class="">   lldb/trunk/test/functionalities/command_script/welcome.py<br class=""><br class="">Modified: lldb/trunk/include/lldb/API/SBExecutionContext.h<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBExecutionContext.h?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBExecutionContext.h?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/include/lldb/API/SBExecutionContext.h (original)<br class="">+++ lldb/trunk/include/lldb/API/SBExecutionContext.h Wed Oct  1 16:47:29 2014<br class="">@@ -25,6 +25,8 @@ public:<br class=""><br class="">    SBExecutionContext (const lldb::SBExecutionContext &rhs);<br class=""><br class="">+    SBExecutionContext (lldb::ExecutionContextRefSP exe_ctx_ref_sp);<br class="">+    <br class="">    SBExecutionContext (const lldb::SBTarget &target);<br class=""><br class="">    SBExecutionContext (const lldb::SBProcess &process);<br class=""><br class="">Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)<br class="">+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Wed Oct  1 16:47:29 2014<br class="">@@ -127,7 +127,8 @@ public:<br class="">                                                                 const char *session_dictionary_name,<br class="">                                                                 lldb::DebuggerSP& debugger,<br class="">                                                                 const char* args,<br class="">-                                                                 lldb_private::CommandReturnObject& cmd_retobj);<br class="">+                                                                 lldb_private::CommandReturnObject& cmd_retobj,<br class="">+                                                                 lldb::ExecutionContextRefSP exe_ctx_ref_sp);<br class=""><br class="">    typedef bool            (*SWIGPythonCallModuleInit)         (const char *python_module_name,<br class="">                                                                 const char *session_dictionary_name,<br class="">@@ -502,7 +503,8 @@ public:<br class="">                           const char* args,<br class="">                           ScriptedCommandSynchronicity synchronicity,<br class="">                           lldb_private::CommandReturnObject& cmd_retobj,<br class="">-                           Error& error)<br class="">+                           Error& error,<br class="">+                           const lldb_private::ExecutionContext& exe_ctx)<br class="">    {<br class="">        return false;<br class="">    }<br class=""><br class="">Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)<br class="">+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Wed Oct  1 16:47:29 2014<br class="">@@ -146,7 +146,8 @@ public:<br class="">                          const char* args,<br class="">                          ScriptedCommandSynchronicity synchronicity,<br class="">                          lldb_private::CommandReturnObject& cmd_retobj,<br class="">-                          Error& error);<br class="">+                          Error& error,<br class="">+                          const lldb_private::ExecutionContext& exe_ctx);<br class=""><br class="">    Error<br class="">    GenerateFunction(const char *signature, const StringList &input);<br class=""><br class="">Modified: lldb/trunk/scripts/Python/python-swigsafecast.swig<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-swigsafecast.swig?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-swigsafecast.swig?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/scripts/Python/python-swigsafecast.swig (original)<br class="">+++ lldb/trunk/scripts/Python/python-swigsafecast.swig Wed Oct  1 16:47:29 2014<br class="">@@ -126,3 +126,10 @@ SBTypeToSWIGWrapper (lldb::SBCommandRetu<br class="">{<br class="">    return SWIG_NewPointerObj((void *) cmd_ret_obj_sb, SWIGTYPE_p_lldb__SBCommandReturnObject, 0);<br class="">}<br class="">+<br class="">+template <><br class="">+PyObject*<br class="">+SBTypeToSWIGWrapper (lldb::SBExecutionContext* ctx_sb)<br class="">+{<br class="">+    return SWIG_NewPointerObj((void *) ctx_sb, SWIGTYPE_p_lldb__SBExecutionContext, 0);<br class="">+}<br class=""><br class="">Modified: lldb/trunk/scripts/Python/python-wrapper.swig<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/scripts/Python/python-wrapper.swig (original)<br class="">+++ lldb/trunk/scripts/Python/python-wrapper.swig Wed Oct  1 16:47:29 2014<br class="">@@ -770,13 +770,15 @@ LLDBSwigPythonCallCommand<br class="">    const char *session_dictionary_name,<br class="">    lldb::DebuggerSP& debugger,<br class="">    const char* args,<br class="">-    lldb_private::CommandReturnObject& cmd_retobj<br class="">+    lldb_private::CommandReturnObject& cmd_retobj,<br class="">+    lldb::ExecutionContextRefSP exe_ctx_ref_sp<br class="">)<br class="">{<br class=""><br class="">    lldb::SBCommandReturnObject cmd_retobj_sb(&cmd_retobj);<br class="">    SBCommandReturnObjectReleaser cmd_retobj_sb_releaser(cmd_retobj_sb);<br class="">    lldb::SBDebugger debugger_sb(debugger);<br class="">+    lldb::SBExecutionContext exe_ctx_sb(exe_ctx_ref_sp);<br class=""><br class="">    bool retval = false;<br class=""><br class="">@@ -791,7 +793,12 @@ LLDBSwigPythonCallCommand<br class="">        // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you<br class="">        // see comment above for SBCommandReturnObjectReleaser for further details<br class="">        PyObject* pvalue = NULL;<br class="">-        pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));<br class="">+<br class="">+        PyCallable::argc argc = pfunc.GetNumArguments();<br class="">+        if (argc.num_args == 5 || argc.varargs == true)<br class="">+            pvalue = pfunc(debugger_sb, args, exe_ctx_sb, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));<br class="">+        else<br class="">+            pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));<br class=""><br class="">        Py_XINCREF (session_dict);<br class="">        Py_XDECREF (pvalue);<br class=""><br class="">Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)<br class="">+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Wed Oct  1 16:47:29 2014<br class="">@@ -479,7 +479,8 @@ LLDBSwigPythonCallCommand (const char *p<br class="">                           const char *session_dictionary_name,<br class="">                           lldb::DebuggerSP& debugger,<br class="">                           const char* args,<br class="">-                           lldb_private::CommandReturnObject &cmd_retobj);<br class="">+                           lldb_private::CommandReturnObject &cmd_retobj,<br class="">+                           lldb::ExecutionContextRefSP exe_ctx_ref_sp);<br class=""><br class="">extern "C" bool<br class="">LLDBSwigPythonCallModuleInit (const char *python_module_name,<br class=""><br class="">Modified: lldb/trunk/source/API/SBExecutionContext.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBExecutionContext.cpp?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBExecutionContext.cpp?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/source/API/SBExecutionContext.cpp (original)<br class="">+++ lldb/trunk/source/API/SBExecutionContext.cpp Wed Oct  1 16:47:29 2014<br class="">@@ -29,6 +29,11 @@ m_exe_ctx_sp(rhs.m_exe_ctx_sp)<br class="">{<br class="">}<br class=""><br class="">+SBExecutionContext::SBExecutionContext (lldb::ExecutionContextRefSP exe_ctx_ref_sp) :<br class="">+m_exe_ctx_sp(exe_ctx_ref_sp)<br class="">+{<br class="">+}<br class="">+<br class="">SBExecutionContext::SBExecutionContext (const lldb::SBTarget &target) :<br class="">m_exe_ctx_sp(new ExecutionContextRef())<br class="">{<br class=""><br class="">Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)<br class="">+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Wed Oct  1 16:47:29 2014<br class="">@@ -1366,7 +1366,8 @@ protected:<br class="">                                                         raw_command_line,<br class="">                                                         m_synchro,<br class="">                                                         result,<br class="">-                                                         error) == false)<br class="">+                                                         error,<br class="">+                                                         m_exe_ctx) == false)<br class="">        {<br class="">            result.AppendError(error.AsCString());<br class="">            result.SetStatus(eReturnStatusFailed);<br class=""><br class="">Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)<br class="">+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Oct  1 16:47:29 2014<br class="">@@ -2510,7 +2510,8 @@ ScriptInterpreterPython::RunScriptBasedC<br class="">                                               const char* args,<br class="">                                               ScriptedCommandSynchronicity synchronicity,<br class="">                                               lldb_private::CommandReturnObject& cmd_retobj,<br class="">-                                               Error& error)<br class="">+                                               Error& error,<br class="">+                                               const lldb_private::ExecutionContext& exe_ctx)<br class="">{<br class="">    if (!impl_function)<br class="">    {<br class="">@@ -2525,6 +2526,7 @@ ScriptInterpreterPython::RunScriptBasedC<br class="">    }<br class=""><br class="">    lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().shared_from_this();<br class="">+    lldb::ExecutionContextRefSP exe_ctx_ref_sp(new ExecutionContextRef(exe_ctx));<br class=""><br class="">    if (!debugger_sp.get())<br class="">    {<br class="">@@ -2548,7 +2550,8 @@ ScriptInterpreterPython::RunScriptBasedC<br class="">                                             m_dictionary_name.c_str(),<br class="">                                             debugger_sp,<br class="">                                             args,<br class="">-                                             cmd_retobj);<br class="">+                                             cmd_retobj,<br class="">+                                             exe_ctx_ref_sp);<br class="">    }<br class=""><br class="">    if (!ret_val)<br class=""><br class="">Modified: lldb/trunk/test/functionalities/command_script/TestCommandScript.py<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/TestCommandScript.py?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/TestCommandScript.py?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/test/functionalities/command_script/TestCommandScript.py (original)<br class="">+++ lldb/trunk/test/functionalities/command_script/TestCommandScript.py Wed Oct  1 16:47:29 2014<br class="">@@ -40,6 +40,7 @@ class CmdPythonTestCase(TestBase):<br class="">            self.runCmd('command script delete tell_async', check=False)<br class="">            self.runCmd('command script delete tell_curr', check=False)<br class="">            self.runCmd('command script delete bug11569', check=False)<br class="">+            self.runCmd('command script delete takes_exe_ctx', check=False)<br class=""><br class="">        # Execute the cleanup function during test case tear down.<br class="">        self.addTearDownHook(cleanup)<br class="">@@ -108,6 +109,9 @@ class CmdPythonTestCase(TestBase):<br class="">                    substrs = ['running async'])<br class="">        self.expect("tell_curr",<br class="">                    substrs = ['I am running sync'])<br class="">+                    <br class="">+# check that the execution context is passed in to commands that ask for it<br class="">+        self.expect("takes_exe_ctx", substrs = ["a.out"])<br class=""><br class="">        # Test that a python command can redefine itself<br class="">        self.expect('command script add -f foobar welcome -h "just some help"')<br class=""><br class="">Modified: lldb/trunk/test/functionalities/command_script/py_import<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/py_import?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/py_import?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/test/functionalities/command_script/py_import (original)<br class="">+++ lldb/trunk/test/functionalities/command_script/py_import Wed Oct  1 16:47:29 2014<br class="">@@ -9,3 +9,4 @@ command script import mysto.py --allow-r<br class="">command script add tell_sync --function welcome.check_for_synchro --synchronicity sync<br class="">command script add tell_async --function welcome.check_for_synchro --synchronicity async<br class="">command script add tell_curr --function welcome.check_for_synchro --synchronicity curr<br class="">+command script add takes_exe_ctx --function welcome.takes_exe_ctx<br class=""><br class="">Modified: lldb/trunk/test/functionalities/command_script/welcome.py<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/welcome.py?rev=218834&r1=218833&r2=218834&view=diff" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/welcome.py?rev=218834&r1=218833&r2=218834&view=diff</a><br class="">==============================================================================<br class="">--- lldb/trunk/test/functionalities/command_script/welcome.py (original)<br class="">+++ lldb/trunk/test/functionalities/command_script/welcome.py Wed Oct  1 16:47:29 2014<br class="">@@ -30,3 +30,6 @@ def check_for_synchro(debugger, args, re<br class="">    if debugger.GetAsync() == False:<br class="">        print >>result,  ('I am running sync')<br class=""><br class="">+def takes_exe_ctx(debugger, args, exe_ctx, result, dict):<br class="">+    print >>result, str(exe_ctx.GetTarget())<br class="">+<br class=""><br class=""><br class="">_______________________________________________<br class="">lldb-commits mailing list<br class=""><a href="mailto:lldb-commits@cs.uiuc.edu" class="">lldb-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits<br class=""></blockquote><br class=""></div></blockquote></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thanks,</div><div class=""><i class="">- Enrico</i><br class="">📩 egranata@<font color="#ff2600" class=""></font>.com ☎️ 27683</div><div class=""><br class=""></div></div></div></div></div></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>
<br class=""></body></html>