summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Interpreter/ScriptInterpreterPython.cpp127
1 files changed, 64 insertions, 63 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index c8dfec513cc..10b9792f009 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -28,22 +28,13 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Target/Thread.h"
-// This function is in the C++ output file generated by SWIG after it is
-// run on all of the headers in "lldb/API/SB*.h"
-extern "C" void init_lldb (void);
-
-extern "C" bool
-LLDBSWIGPythonBreakpointCallbackFunction
-(
- const char *python_function_name,
- const char *session_dictionary_name,
- lldb::SBFrame& sb_frame,
- lldb::SBBreakpointLocation& sb_bp_loc
-);
-
using namespace lldb;
using namespace lldb_private;
+
+static ScriptInterpreter::SWIGInitCallback g_swig_init_callback = NULL;
+static ScriptInterpreter::SWIGBreakpointCallbackFunction g_swig_breakpoint_callback = NULL;
+
const char embedded_interpreter_string[] =
"import readline\n\
import code\n\
@@ -212,7 +203,7 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
if (!g_initialized)
{
g_initialized = true;
- ScriptInterpreterPython::Initialize ();
+ ScriptInterpreterPython::InitializePrivate ();
}
bool safe_to_run = false;
@@ -1288,38 +1279,40 @@ ScriptInterpreterPython::BreakpointCallbackFunction
&& python_function_name[0] != '\0')
{
Thread *thread = context->exe_ctx.thread;
- const StackFrameSP stop_frame_sp = thread->GetStackFrameSPForStackFramePtr (context->exe_ctx.frame);
+ const StackFrameSP stop_frame_sp (thread->GetStackFrameSPForStackFramePtr (context->exe_ctx.frame));
BreakpointSP breakpoint_sp = target->GetBreakpointByID (break_id);
- const BreakpointLocationSP bp_loc_sp = breakpoint_sp->FindLocationByID (break_loc_id);
-
- SBFrame sb_frame (stop_frame_sp);
- SBBreakpointLocation sb_bp_loc (bp_loc_sp);
-
- if (sb_bp_loc.IsValid() || sb_frame.IsValid())
+ if (breakpoint_sp)
{
- bool ret_val = true;
- FILE *tmp_fh = (python_interpreter->m_dbg_stdout ? python_interpreter->m_dbg_stdout : stdout);
- if (CurrentThreadHasPythonLock())
- {
- python_interpreter->EnterSession ();
- ret_val = LLDBSWIGPythonBreakpointCallbackFunction(python_function_name,
- python_interpreter->m_dictionary_name.c_str(),
- sb_frame, sb_bp_loc);
- python_interpreter->LeaveSession ();
- }
- else
+ const BreakpointLocationSP bp_loc_sp (breakpoint_sp->FindLocationByID (break_loc_id));
+
+ if (stop_frame_sp && bp_loc_sp)
{
- while (!GetPythonLock (1))
- fprintf (tmp_fh,
- "Python interpreter locked on another thread; waiting to acquire lock...\n");
- python_interpreter->EnterSession ();
- ret_val = LLDBSWIGPythonBreakpointCallbackFunction(python_function_name,
- python_interpreter->m_dictionary_name.c_str(),
- sb_frame, sb_bp_loc);
- python_interpreter->LeaveSession ();
- ReleasePythonLock ();
+ bool ret_val = true;
+ FILE *tmp_fh = (python_interpreter->m_dbg_stdout ? python_interpreter->m_dbg_stdout : stdout);
+ if (CurrentThreadHasPythonLock())
+ {
+ python_interpreter->EnterSession ();
+ ret_val = g_swig_breakpoint_callback (python_function_name,
+ python_interpreter->m_dictionary_name.c_str(),
+ stop_frame_sp,
+ bp_loc_sp);
+ python_interpreter->LeaveSession ();
+ }
+ else
+ {
+ while (!GetPythonLock (1))
+ fprintf (tmp_fh,
+ "Python interpreter locked on another thread; waiting to acquire lock...\n");
+ python_interpreter->EnterSession ();
+ ret_val = g_swig_breakpoint_callback (python_function_name,
+ python_interpreter->m_dictionary_name.c_str(),
+ stop_frame_sp,
+ bp_loc_sp);
+ python_interpreter->LeaveSession ();
+ ReleasePythonLock ();
+ }
+ return ret_val;
}
- return ret_val;
}
}
// We currently always true so we stop in case anything goes wrong when
@@ -1447,7 +1440,15 @@ ScriptInterpreterPython::RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton)
void
-ScriptInterpreterPython::Initialize ()
+ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
+ SWIGBreakpointCallbackFunction python_swig_breakpoint_callback)
+{
+ g_swig_init_callback = python_swig_init_callback;
+ g_swig_breakpoint_callback = python_swig_breakpoint_callback;
+}
+
+void
+ScriptInterpreterPython::InitializePrivate ()
{
Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
@@ -1506,9 +1507,9 @@ ScriptInterpreterPython::Initialize ()
}
- // This function is in the C++ output file generated by SWIG after it is
- // run on all of the headers in "lldb/API/SB*.h"
- init_lldb ();
+ // Initialize SWIG after setting up python
+ assert (g_swig_init_callback != NULL);
+ g_swig_init_callback ();
// Update the path python uses to search for modules to include the current directory.
@@ -1536,20 +1537,20 @@ ScriptInterpreterPython::Initialize ()
stdin_tty_state.Restore();
}
-void
-ScriptInterpreterPython::Terminate ()
-{
- // We are intentionally NOT calling Py_Finalize here (this would be the logical place to call it). Calling
- // Py_Finalize here causes test suite runs to seg fault: The test suite runs in Python. It registers
- // SBDebugger::Terminate to be called 'at_exit'. When the test suite Python harness finishes up, it calls
- // Py_Finalize, which calls all the 'at_exit' registered functions. SBDebugger::Terminate calls Debugger::Terminate,
- // which calls lldb::Terminate, which calls ScriptInterpreter::Terminate, which calls
- // ScriptInterpreterPython::Terminate. So if we call Py_Finalize here, we end up with Py_Finalize being called from
- // within Py_Finalize, which results in a seg fault.
- //
- // Since this function only gets called when lldb is shutting down and going away anyway, the fact that we don't
- // actually call Py_Finalize should not cause any problems (everything should shut down/go away anyway when the
- // process exits).
- //
-// Py_Finalize ();
-}
+//void
+//ScriptInterpreterPython::Terminate ()
+//{
+// // We are intentionally NOT calling Py_Finalize here (this would be the logical place to call it). Calling
+// // Py_Finalize here causes test suite runs to seg fault: The test suite runs in Python. It registers
+// // SBDebugger::Terminate to be called 'at_exit'. When the test suite Python harness finishes up, it calls
+// // Py_Finalize, which calls all the 'at_exit' registered functions. SBDebugger::Terminate calls Debugger::Terminate,
+// // which calls lldb::Terminate, which calls ScriptInterpreter::Terminate, which calls
+// // ScriptInterpreterPython::Terminate. So if we call Py_Finalize here, we end up with Py_Finalize being called from
+// // within Py_Finalize, which results in a seg fault.
+// //
+// // Since this function only gets called when lldb is shutting down and going away anyway, the fact that we don't
+// // actually call Py_Finalize should not cause any problems (everything should shut down/go away anyway when the
+// // process exits).
+// //
+//// Py_Finalize ();
+//}
OpenPOWER on IntegriCloud