summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-03-22 01:14:58 +0000
committerGreg Clayton <gclayton@apple.com>2011-03-22 01:14:58 +0000
commitfc36f79170a2e462697f00529f1df92c53dae505 (patch)
treec5da4eda43626cba1b396ec0aa3a475d6f30d7e0 /lldb/source/Interpreter
parent348a54838144c0b5525edf33be457c50a9257628 (diff)
downloadbcm5719-llvm-fc36f79170a2e462697f00529f1df92c53dae505.tar.gz
bcm5719-llvm-fc36f79170a2e462697f00529f1df92c53dae505.zip
Abtracted the innards of lldb-core away from the SB interface. There was some
overlap in the SWIG integration which has now been fixed by introducing callbacks for initializing SWIG for each language (python only right now). There was also a breakpoint command callback that called into SWIG which has been abtracted into a callback to avoid cross over as well. Added a new binary: lldb-platform This will be the start of the remote platform that will use as much of the Host functionality to do its job so it should just work on all platforms. It is pretty hollowed out for now, but soon it will implement a platform using the GDB remote packets as the transport. llvm-svn: 128053
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r--lldb/source/Interpreter/ScriptInterpreter.cpp10
-rw-r--r--lldb/source/Interpreter/ScriptInterpreterPython.cpp127
2 files changed, 70 insertions, 67 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp
index fd1e10abfbc..7011c2e7f2b 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -91,14 +91,16 @@ ScriptInterpreter::LanguageToString (lldb::ScriptLanguage language)
}
void
-ScriptInterpreter::Initialize ()
+ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
+ SWIGBreakpointCallbackFunction python_swig_breakpoint_callback)
{
-// ScriptInterpreterPython::Initialize ();
+ ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback,
+ python_swig_breakpoint_callback);
}
void
-ScriptInterpreter::Terminate ()
+ScriptInterpreter::TerminateInterpreter ()
{
-// ScriptInterpreterPython::Terminate ();
+ ScriptInterpreterPython::TerminateInterpreter ();
}
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