[Lldb-commits] [lldb] r107287 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/Core/Debugger.h scripts/Python/append-debugger-id.py scripts/Python/build-swig-Python.sh scripts/lldb.swig source/API/SBDebugger.cpp source/Core/Debugger.cpp source/Interpreter/ScriptInterpreterPython.cpp
Caroline Tice
ctice at apple.com
Wed Jun 30 09:22:25 PDT 2010
Author: ctice
Date: Wed Jun 30 11:22:25 2010
New Revision: 107287
URL: http://llvm.org/viewvc/llvm-project?rev=107287&view=rev
Log:
Add a unique ID to each debugger instance.
Add functions to look up debugger by id
Add global variable to lldb python module, to hold debugger id
Modify embedded Python interpreter to update the global variable with the
id of its current debugger.
Modify the char ** typemap definition in lldb.swig to accept 'None' (for NULL)
as a valid value.
The point of all this is so that, when you drop into the embedded interpreter
from the command interpreter (or when doing Python-based breakpoint commands),
there is a way for the Python side to find/get the correct debugger
instance ( by checking debugger_unique_id, then calling
SBDebugger::FindDebuggerWithID on it).
Added:
lldb/trunk/scripts/Python/append-debugger-id.py
Modified:
lldb/trunk/include/lldb/API/SBDebugger.h
lldb/trunk/include/lldb/Core/Debugger.h
lldb/trunk/scripts/Python/build-swig-Python.sh
lldb/trunk/scripts/lldb.swig
lldb/trunk/source/API/SBDebugger.cpp
lldb/trunk/source/Core/Debugger.cpp
lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
Modified: lldb/trunk/include/lldb/API/SBDebugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=107287&r1=107286&r2=107287&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDebugger.h (original)
+++ lldb/trunk/include/lldb/API/SBDebugger.h Wed Jun 30 11:22:25 2010
@@ -129,6 +129,9 @@
void
PushInputReader (lldb::SBInputReader &reader);
+ static SBDebugger
+ FindDebuggerWithID (int id);
+
private:
// Use the static function: SBDebugger::Create();
Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=107287&r1=107286&r2=107287&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Wed Jun 30 11:22:25 2010
@@ -21,6 +21,7 @@
#include "lldb/Core/Listener.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/SourceManager.h"
+#include "lldb/Core/UserID.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/TargetList.h"
@@ -32,7 +33,8 @@
///
/// Provides a global root objects for the debugger core.
//----------------------------------------------------------------------
-class Debugger
+class Debugger :
+ public UserID
{
public:
@@ -139,6 +141,9 @@
void
UpdateExecutionContext (ExecutionContext *override_context);
+ static lldb::DebuggerSP
+ FindDebuggerWithID (lldb::user_id_t id);
+
protected:
static void
@@ -165,7 +170,7 @@
std::stack<lldb::InputReaderSP> m_input_readers;
std::string m_input_reader_data;
-
+
private:
// Use Debugger::CreateInstance() to get a shared pointer to a new
Added: lldb/trunk/scripts/Python/append-debugger-id.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/append-debugger-id.py?rev=107287&view=auto
==============================================================================
--- lldb/trunk/scripts/Python/append-debugger-id.py (added)
+++ lldb/trunk/scripts/Python/append-debugger-id.py Wed Jun 30 11:22:25 2010
@@ -0,0 +1,27 @@
+#
+# append-debugger-id.py
+#
+# This script adds a global variable, 'debugger_unique_id' to the lldb
+# module (which was automatically generated via running swig), and
+# initializes it to 0.
+#
+
+import sys
+
+if len (sys.argv) != 2:
+ output_name = "./lldb.py"
+else:
+ output_name = sys.argv[1] + "/lldb.py"
+
+# print "output_name is '" + output_name + "'"
+
+try:
+ f_out = open (output_name, 'a')
+except IOError:
+ print "Error: Unable to open file for appending: " + output_name
+else:
+ f_out.write ("debugger_unique_id = 0\n");
+ try:
+ f_out.close()
+ except IOError:
+ print "Error occurred while close file."
Modified: lldb/trunk/scripts/Python/build-swig-Python.sh
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=107287&r1=107286&r2=107287&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/build-swig-Python.sh (original)
+++ lldb/trunk/scripts/Python/build-swig-Python.sh Wed Jun 30 11:22:25 2010
@@ -127,3 +127,10 @@
swig -c++ -shadow -python -I"${SRC_ROOT}/include" -I./. -outdir "${CONFIG_BUILD_DIR}" -o "${swig_output_file}" "${swig_input_file}"
+# Append global variable to lldb Python module.
+
+current_dir=`pwd`
+if [ -f "${current_dir}/append-debugger-id.py" ]
+then
+ python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR}
+fi
Modified: lldb/trunk/scripts/lldb.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=107287&r1=107286&r2=107287&view=diff
==============================================================================
--- lldb/trunk/scripts/lldb.swig (original)
+++ lldb/trunk/scripts/lldb.swig Wed Jun 30 11:22:25 2010
@@ -43,6 +43,8 @@
}
}
$1[i] = 0;
+ } else if ($input == Py_None) {
+ $1 = NULL;
} else {
PyErr_SetString(PyExc_TypeError,"not a list");
return NULL;
Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=107287&r1=107286&r2=107287&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Wed Jun 30 11:22:25 2010
@@ -51,7 +51,6 @@
return debugger;
}
-
SBDebugger::SBDebugger () :
m_opaque_sp ()
{
@@ -549,3 +548,12 @@
}
+SBDebugger
+SBDebugger::FindDebuggerWithID (int id)
+{
+ SBDebugger sb_debugger;
+ lldb::DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id);
+ if (debugger_sp)
+ sb_debugger.reset (debugger_sp);
+ return sb_debugger;
+}
Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=107287&r1=107286&r2=107287&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Jun 30 11:22:25 2010
@@ -24,6 +24,8 @@
static uint32_t g_shared_debugger_refcount = 0;
+static lldb::user_id_t g_unique_id = 1;
+
void
Debugger::Initialize ()
{
@@ -115,6 +117,7 @@
Debugger::Debugger () :
+ UserID (g_unique_id++),
m_input_comm("debugger.input"),
m_input_file (),
m_output_file (),
@@ -491,3 +494,21 @@
}
}
+DebuggerSP
+Debugger::FindDebuggerWithID (lldb::user_id_t id)
+{
+ lldb::DebuggerSP debugger_sp;
+
+ Mutex::Locker locker (GetDebuggerListMutex ());
+ DebuggerList &debugger_list = GetDebuggerList();
+ DebuggerList::iterator pos, end = debugger_list.end();
+ for (pos = debugger_list.begin(); pos != end; ++pos)
+ {
+ if ((*pos).get()->GetID() == id)
+ {
+ debugger_sp = *pos;
+ break;
+ }
+ }
+ return debugger_sp;
+}
Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=107287&r1=107286&r2=107287&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Jun 30 11:22:25 2010
@@ -238,6 +238,10 @@
PyRun_SimpleString ("new_mode[3] = new_mode[3] | ECHO | ICANON");
PyRun_SimpleString ("new_mode[6][VEOF] = 255");
PyRun_SimpleString ("tcsetattr (new_stdin, TCSANOW, new_mode)");
+
+ run_string.Clear();
+ run_string.Printf ("debugger_unique_id = %d", interpreter.GetDebugger().GetID());
+ PyRun_SimpleString (run_string.GetData());
}
More information about the lldb-commits
mailing list