Initial checkin of lldb code from internal Apple repo.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@105619 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/scripts/Python/build-swig-Python.sh b/scripts/Python/build-swig-Python.sh
new file mode 100755
index 0000000..9dc4b99
--- /dev/null
+++ b/scripts/Python/build-swig-Python.sh
@@ -0,0 +1,127 @@
+#!/bin/sh
+
+# build-swig-Python.sh
+
+
+debug_flag=$1
+
+if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
+then
+    Debug=1
+else
+    Debug=0
+fi
+
+
+HEADER_FILES="${SRCROOT}/include/lldb/lldb-types.h"\
+" ${SRCROOT}/include/lldb/API/SBAddress.h"\
+" ${SRCROOT}/include/lldb/API/SBBlock.h"\
+" ${SRCROOT}/include/lldb/API/SBBreakpoint.h"\
+" ${SRCROOT}/include/lldb/API/SBBreakpointLocation.h"\
+" ${SRCROOT}/include/lldb/API/SBBroadcaster.h"\
+" ${SRCROOT}/include/lldb/API/SBCommandContext.h"\
+" ${SRCROOT}/include/lldb/API/SBCommandInterpreter.h"\
+" ${SRCROOT}/include/lldb/API/SBCommandReturnObject.h"\
+" ${SRCROOT}/include/lldb/API/SBCompileUnit.h"\
+" ${SRCROOT}/include/lldb/API/SBDebugger.h"\
+" ${SRCROOT}/include/lldb/API/SBError.h"\
+" ${SRCROOT}/include/lldb/API/SBEvent.h"\
+" ${SRCROOT}/include/lldb/API/SBFrame.h"\
+" ${SRCROOT}/include/lldb/API/SBFunction.h"\
+" ${SRCROOT}/include/lldb/API/SBLineEntry.h"\
+" ${SRCROOT}/include/lldb/API/SBListener.h"\
+" ${SRCROOT}/include/lldb/API/SBModule.h"\
+" ${SRCROOT}/include/lldb/API/SBProcess.h"\
+" ${SRCROOT}/include/lldb/API/SBSourceManager.h"\
+" ${SRCROOT}/include/lldb/API/SBStringList.h"\
+" ${SRCROOT}/include/lldb/API/SBSymbol.h"\
+" ${SRCROOT}/include/lldb/API/SBSymbolContext.h"\
+" ${SRCROOT}/include/lldb/API/SBTarget.h"\
+" ${SRCROOT}/include/lldb/API/SBThread.h"\
+" ${SRCROOT}/include/lldb/API/SBType.h"\
+" ${SRCROOT}/include/lldb/API/SBValue.h"
+
+
+if [ $Debug == 1 ]
+then
+    echo "Header files are:"
+    echo ${HEADER_FILES}
+fi
+
+NeedToUpdate=0
+
+swig_output_file=${SCRIPT_INPUT_FILE_1}
+
+if [ ! -f $swig_output_file ]
+then
+    NeedToUpdate=1
+    if [ $Debug == 1 ]
+    then
+        echo "Failed to find LLDBWrapPython.cpp"
+    fi
+fi
+
+if [ $NeedToUpdate == 0 ]
+then
+    for hdrfile in ${HEADER_FILES}
+    do
+        if [ $hdrfile -nt $swig_output_file ]
+        then
+            NeedToUpdate=1
+            if [ $Debug == 1 ]
+            then
+                echo "${hdrfile} is newer than ${swig_output_file}"
+                echo "swig file will need to be re-built."
+            fi
+        fi
+    done
+fi
+
+framework_python_dir="${CONFIGURATION_BUILD_DIR}/LLDB.framework/Versions/A/Resources/Python"
+
+if [ ! -L "${framework_python_dir}/_lldb.so" ]
+then
+    NeedToUpdate=1
+fi
+
+if [ ! -f "${framework_python_dir}/lldb.py" ]
+then
+    NeedToUpdate=1
+fi
+
+
+if [ $NeedToUpdate == 0 ]
+then
+    echo "Everything is up-to-date."
+    exit 0
+else
+    echo "SWIG needs to be re-run."
+fi
+
+
+# Build the SWIG C++ wrapper file for Python.
+
+swig -c++ -shadow -python -I"${SRCROOT}/include" -I./. -outdir "${CONFIGURATION_BUILD_DIR}" -o "${SCRIPT_INPUT_FILE_1}" "${SCRIPT_INPUT_FILE_0}"
+
+# Edit the C++ wrapper file that SWIG generated for Python.  There are two
+# global string replacements needed, which the following script file takes
+# care of.  It reads in 'LLDBWrapPython.cpp' and generates 
+# 'LLDBWrapPython.cpp.edited'.
+
+# The need for this has been eliminated by fixing the namespace qualifiers on return types.
+# Leaving this here for now, just in case...
+#
+#if [ -f "${SRCROOT}/scripts/Python/edit-swig-python-wrapper-file.py" ]
+#then
+#    python "${SRCROOT}/scripts/Python/edit-swig-python-wrapper-file.py"
+#fi
+
+#
+# Now that we've got a C++ file we're happy with (hopefully), rename the
+# edited file and move it to the appropriate places.
+#
+
+if [ -f "${SCRIPT_INPUT_FILE_1}.edited" ]
+then
+    mv "${SCRIPT_INPUT_FILE_1}.edited" "${SCRIPT_INPUT_FILE_1}"
+fi
diff --git a/scripts/Python/edit-swig-python-wrapper-file.py b/scripts/Python/edit-swig-python-wrapper-file.py
new file mode 100644
index 0000000..a8c4323
--- /dev/null
+++ b/scripts/Python/edit-swig-python-wrapper-file.py
@@ -0,0 +1,58 @@
+#
+# edit-swig-python-wrapper-file.py
+#
+# This script performs some post-processing editing on the C++ file that
+# SWIG generates for python, after running on 'lldb.swig'.   In
+# particular, the types SWIGTYPE_p_SBThread and SWIGTYPE_p_SBTarget are
+# being used, when the types that *should* be used are 
+# SWIGTYPE_p_lldb__SBThread and SWIGTYPE_p_lldb__SBTarget.
+# This script goes through the C++ file SWIG generated, reading it in line
+# by line and doing a search-and-replace for these strings.
+#
+
+
+import os
+
+full_input_name = os.environ["SCRIPT_INPUT_FILE_1"];
+full_output_name = full_input_name + ".edited"
+
+try:
+    f_in = open (full_input_name, 'r')
+except IOError:
+    print "Error:  Unable to open file for reading: " + full_input_name
+else:
+    try:
+        f_out = open (full_output_name, 'w')
+    except IOError:
+        print "Error:  Unable to open file for writing: " + full_output_name
+    else:
+        target_typedef_found = False
+        thread_typedef_found = False
+
+        try:
+            line = f_in.readline()
+        except IOError:
+            print "Error occurred while reading file."
+        else:
+            while line:
+                #
+                #
+                if (line.find ("SWIGTYPE_p_SBTarget")):
+                    if (line.find ("define") < 0):
+                        line = line.replace ("SWIGTYPE_p_SBTarget", 
+                                             "SWIGTYPE_p_lldb__SBTarget")
+                if (line.find ("SWIGTYPE_p_SBThread")):
+                    if (line.find ("define") < 0):
+                        line = line.replace ("SWIGTYPE_p_SBThread", 
+                                             "SWIGTYPE_p_lldb__SBThread")
+                f_out.write (line)
+                try:
+                    line = f_in.readline()
+                except IOError:
+                    print "Error occurred while reading file."
+                    
+            try:
+                f_in.close()
+                f_out.close()
+            except:
+                print "Error occurred while closing files"
diff --git a/scripts/Python/finish-swig-Python-LLDB.sh b/scripts/Python/finish-swig-Python-LLDB.sh
new file mode 100755
index 0000000..293a8b1
--- /dev/null
+++ b/scripts/Python/finish-swig-Python-LLDB.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+
+# finish-swig-Python.sh
+#
+# For the Python script interpreter (external to liblldb) to be able to import
+# and use the lldb module, there must be a "_lldb.so" in the framework 
+# resources directory. Here we make a symlink called "_lldb.so" that just
+# points to the executable in the LLDB.framework and copy over the needed
+# .py files.
+
+if [ ! -d "${TARGET_BUILD_DIR}/LLDB.framework" ]
+then
+    echo "Error:  Unable to find LLDB.framework" >&2
+    exit 1
+fi
+
+# Make the Python directory down in the framework if it doesn't already exist
+framework_python_dir="${TARGET_BUILD_DIR}/LLDB.framework/Versions/A/Resources/Python"
+if [ ! -d "${framework_python_dir}" ]
+then
+	mkdir -p "${framework_python_dir}"
+fi
+
+# Make the symlink that the script bridge for Python will need in the Python
+# framework directory
+if [ ! -L "${framework_python_dir}/_lldb.so" ]
+then
+	cd "${framework_python_dir}"
+        ln -s "../../LLDB" _lldb.so
+fi
+
+# Copy the python module (lldb.py) that was generated by SWIG 
+# over to the framework Python directory
+if [ -f "${CONFIGURATION_BUILD_DIR}/lldb.py" ]
+then
+	cp "${CONFIGURATION_BUILD_DIR}/lldb.py" "${framework_python_dir}"
+fi
+
+# Copy the embedded interpreter script over to the framework Python directory
+if [ -f "${SRCROOT}/source/Interpreter/embedded_interpreter.py" ]
+then
+    cp "${SRCROOT}/source/Interpreter/embedded_interpreter.py" "${framework_python_dir}"
+fi
+
+exit 0