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
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index d8d0dbb..84856ef 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -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;
+}
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 0b7676c..32b1bf3 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -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;
+}
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index 5fb0130..d7a3363 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -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());
     }