forked from OSchip/llvm-project
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). llvm-svn: 107287
This commit is contained in:
parent
7764ae2c98
commit
ebc1bb277c
|
@ -129,6 +129,9 @@ public:
|
|||
void
|
||||
PushInputReader (lldb::SBInputReader &reader);
|
||||
|
||||
static SBDebugger
|
||||
FindDebuggerWithID (int id);
|
||||
|
||||
private:
|
||||
|
||||
// Use the static function: SBDebugger::Create();
|
||||
|
|
|
@ -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 @@ namespace lldb_private {
|
|||
///
|
||||
/// Provides a global root objects for the debugger core.
|
||||
//----------------------------------------------------------------------
|
||||
class Debugger
|
||||
class Debugger :
|
||||
public UserID
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -139,6 +141,9 @@ public:
|
|||
void
|
||||
UpdateExecutionContext (ExecutionContext *override_context);
|
||||
|
||||
static lldb::DebuggerSP
|
||||
FindDebuggerWithID (lldb::user_id_t id);
|
||||
|
||||
protected:
|
||||
|
||||
static void
|
||||
|
@ -165,7 +170,7 @@ protected:
|
|||
|
||||
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
|
||||
|
|
|
@ -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."
|
|
@ -127,3 +127,10 @@ fi
|
|||
|
||||
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
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
}
|
||||
}
|
||||
$1[i] = 0;
|
||||
} else if ($input == Py_None) {
|
||||
$1 = NULL;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError,"not a list");
|
||||
return NULL;
|
||||
|
|
|
@ -51,7 +51,6 @@ SBDebugger::Create()
|
|||
return debugger;
|
||||
}
|
||||
|
||||
|
||||
SBDebugger::SBDebugger () :
|
||||
m_opaque_sp ()
|
||||
{
|
||||
|
@ -549,3 +548,12 @@ SBDebugger::ref () const
|
|||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ using namespace lldb_private;
|
|||
|
||||
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::FindTargetWithProcessID (lldb::pid_t pid)
|
|||
|
||||
|
||||
Debugger::Debugger () :
|
||||
UserID (g_unique_id++),
|
||||
m_input_comm("debugger.input"),
|
||||
m_input_file (),
|
||||
m_output_file (),
|
||||
|
@ -491,3 +494,21 @@ Debugger::UpdateExecutionContext (ExecutionContext *override_context)
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -238,6 +238,10 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
|
|||
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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue