diff options
Diffstat (limited to 'scripts/Python')
-rw-r--r-- | scripts/Python/Makefile | 15 | ||||
-rw-r--r-- | scripts/Python/finishSwigPythonLLDB.py | 63 | ||||
-rw-r--r-- | scripts/Python/modules/Makefile | 20 | ||||
-rw-r--r-- | scripts/Python/modules/readline/Makefile | 100 | ||||
-rw-r--r-- | scripts/Python/modules/readline/readline.cpp | 34 | ||||
-rw-r--r-- | scripts/Python/prepare_binding_Python.py | 4 | ||||
-rw-r--r-- | scripts/Python/python-extensions.swig | 80 | ||||
-rw-r--r-- | scripts/Python/python-typemaps.swig | 225 | ||||
-rw-r--r-- | scripts/Python/python-wrapper.swig | 2 | ||||
-rw-r--r-- | scripts/Python/use_lldb_suite.py | 9 |
10 files changed, 271 insertions, 281 deletions
diff --git a/scripts/Python/Makefile b/scripts/Python/Makefile deleted file mode 100644 index ad6c0af442b4d..0000000000000 --- a/scripts/Python/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -##===- scripts/Python/Makefile------------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LLDB_LEVEL := ../.. -include $(LLDB_LEVEL)/../../Makefile.config - -DIRS := modules - -include $(LLDB_LEVEL)/Makefile diff --git a/scripts/Python/finishSwigPythonLLDB.py b/scripts/Python/finishSwigPythonLLDB.py index 435cb88c20f04..4d733a1643612 100644 --- a/scripts/Python/finishSwigPythonLLDB.py +++ b/scripts/Python/finishSwigPythonLLDB.py @@ -229,6 +229,23 @@ def make_symlink_windows(vstrSrcPath, vstrTargetPath): dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_windows()") bOk = True strErrMsg = "" + # If the src file doesn't exist, this is an error and we should throw. + src_stat = os.stat(vstrSrcPath) + + try: + target_stat = os.stat(vstrTargetPath) + # If the target file exists but refers to a different file, delete it so that we can + # re-create the link. This can happen if you run this script once (creating a link) + # and then delete the source file (so that a brand new file gets created the next time + # you compile and link), and then re-run this script, so that both the target hardlink + # and the source file exist, but the target refers to an old copy of the source. + if (target_stat.st_ino == src_stat.st_ino) and (target_stat.st_dev == src_stat.st_dev): + return (bOk, strErrMsg) + + os.remove(vstrTargetPath) + except: + # If the target file don't exist, ignore this exception, we will link it shortly. + pass try: csl = ctypes.windll.kernel32.CreateHardLinkW @@ -280,10 +297,6 @@ def make_symlink_native(vDictArgs, strSrc, strTarget): bOk = False strErrMsg = strErrMsgOsTypeUnknown elif eOSType == utilsOsType.EnumOsType.Windows: - if os.path.isfile(strTarget): - if bDbg: - print((strMsgSymlinkExists % target_filename)) - return (bOk, strErrMsg) if bDbg: print((strMsgSymlinkMk % (target_filename, strSrc, strTarget))) bOk, strErrMsg = make_symlink_windows(strSrc, @@ -345,11 +358,12 @@ def make_symlink(vDictArgs, vstrFrameworkPythonDir, vstrSrcFile, vstrTargetFile) # Args: vDictArgs - (R) Program input parameters. # vstrFrameworkPythonDir - (R) Python framework directory. # vstrLiblldbName - (R) File name for _lldb library. +# vstrLiblldbDir - (R) liblldb directory. # Returns: Bool - True = function success, False = failure. # Str - Error description on task failure. # Throws: None. #-- -def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName): +def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName, vstrLldbLibDir): dbg = utilsDebug.CDebugFnVerbose("Python script make_symlink_liblldb()") bOk = True strErrMsg = "" @@ -369,7 +383,7 @@ def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName) bMakeFileCalled = "-m" in vDictArgs if not bMakeFileCalled: - strSrc = os.path.join("lib", "LLDB") + strSrc = os.path.join(vstrLldbLibDir, "LLDB") else: strLibFileExtn = "" if eOSType == utilsOsType.EnumOsType.Windows: @@ -379,7 +393,7 @@ def make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, vstrLiblldbFileName) strLibFileExtn = ".dylib" else: strLibFileExtn = ".so" - strSrc = os.path.join("lib", "liblldb" + strLibFileExtn) + strSrc = os.path.join(vstrLldbLibDir, "liblldb" + strLibFileExtn) bOk, strErrMsg = make_symlink(vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget) @@ -449,11 +463,12 @@ def make_symlink_lldb_argdumper(vDictArgs, vstrFrameworkPythonDir, vstrArgdumper # the Python framework directory. # Args: vDictArgs - (R) Program input parameters. # vstrFrameworkPythonDir - (R) Python framework directory. +# vstrLldbLibDir - (R) liblldb directory. # Returns: Bool - True = function success, False = failure. # strErrMsg - Error description on task failure. # Throws: None. #-- -def create_symlinks(vDictArgs, vstrFrameworkPythonDir): +def create_symlinks(vDictArgs, vstrFrameworkPythonDir, vstrLldbLibDir): dbg = utilsDebug.CDebugFnVerbose("Python script create_symlinks()") bOk = True strErrMsg = "" @@ -464,7 +479,8 @@ def create_symlinks(vDictArgs, vstrFrameworkPythonDir): if bOk: bOk, strErrMsg = make_symlink_liblldb(vDictArgs, vstrFrameworkPythonDir, - strLibLldbFileName) + strLibLldbFileName, + vstrLldbLibDir) # Make symlink for darwin-debug on Darwin strDarwinDebugFileName = "darwin-debug" @@ -659,6 +675,28 @@ def get_framework_python_dir(vDictArgs): return (bOk, strWkDir, strErrMsg) +#++--------------------------------------------------------------------------- +# Details: Retrieve the liblldb directory path, if it exists and is valid. +# Args: vDictArgs - (R) Program input parameters. +# Returns: Bool - True = function success, False = failure. +# Str - liblldb directory path. +# strErrMsg - Error description on task failure. +# Throws: None. +#-- +def get_liblldb_dir(vDictArgs): + dbg = utilsDebug.CDebugFnVerbose("Python script get_liblldb_dir()") + bOk = True + strErrMsg = "" + + strLldbLibDir = "" + bHaveLldbLibDir = "--lldbLibDir" in vDictArgs + if bHaveLldbLibDir: + strLldbLibDir = vDictArgs["--lldbLibDir"] + if (bHaveLldbLibDir == False) or (strLldbLibDir.__len__() == 0): + strLldbLibDir = "lib" + + return (bOk, strLldbLibDir, strErrMsg) + #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- @@ -684,6 +722,8 @@ def get_framework_python_dir(vDictArgs): be installed. Where non-Darwin systems want to put the .py and .so files so that Python can find them automatically. Python install directory. + --lldbLibDir The name of the directory containing liblldb.so. + (optional) "lib" by default. Results: 0 Success -100+ Error from this script to the caller script. -100 Error program failure with optional message. @@ -714,10 +754,13 @@ def main(vDictArgs): print((strMsgConfigBuildDir % strCfgBldDir)) if bOk: + bOk, strLldbLibDir, strMsg = get_liblldb_dir(vDictArgs) + + if bOk: bOk, strMsg = find_or_create_python_dir(vDictArgs, strFrameworkPythonDir) if bOk: - bOk, strMsg = create_symlinks(vDictArgs, strFrameworkPythonDir) + bOk, strMsg = create_symlinks(vDictArgs, strFrameworkPythonDir, strLldbLibDir) if bOk: bOk, strMsg = copy_six(vDictArgs, strFrameworkPythonDir) diff --git a/scripts/Python/modules/Makefile b/scripts/Python/modules/Makefile deleted file mode 100644 index b6989889858db..0000000000000 --- a/scripts/Python/modules/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -##===- scripts/Python/modules/Makefile ---------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LLDB_LEVEL := ../../.. -include $(LLDB_LEVEL)/../../Makefile.config - -DIRS:= - -# only build the readline suppression module on Linux, Kfreebsd & Hurd -ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD)) -DIRS += readline -endif - -include $(LLDB_LEVEL)/Makefile diff --git a/scripts/Python/modules/readline/Makefile b/scripts/Python/modules/readline/Makefile deleted file mode 100644 index dc0d757bc1752..0000000000000 --- a/scripts/Python/modules/readline/Makefile +++ /dev/null @@ -1,100 +0,0 @@ -##===- scripts/Python/modules/readline/Makefile ------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -# Skip this entire Makefile if python is disabled. -ifeq (,$(findstring -DLLDB_DISABLE_PYTHON,$(CXXFLAGS))) - -LEVEL := ../../../../../.. -LLDB_LEVEL := ../../../.. - -LIBRARYNAME = readline - -NO_BUILD_ARCHIVE = 1 -LINK_LIBS_IN_SHARED = 1 -SHARED_LIBRARY = 1 -LOADABLE_MODULE = 1 - -PYTHON_CONFIG?= python-config -PYTHON_INC_DIR = $(shell $(PYTHON_CONFIG) --includes) - -# Include all archives in the shared lib -USEDLIBS := - -include $(LLDB_LEVEL)/../../Makefile.config - -LINK_COMPONENTS := - -include $(LEVEL)/Makefile.common - -# include python headers -CPP.Flags += $(PYTHON_INC_DIR) - -ifeq ($(HOST_OS),Darwin) - LLVMLibsOptions += -Wl,-all_load - # set dylib internal version number to llvmCore submission number - ifdef LLDB_SUBMIT_VERSION - LLVMLibsOptions += -Wl,-current_version \ - -Wl,$(LLDB_SUBMIT_VERSION).$(LLDB_SUBMIT_SUBVERSION) \ - -Wl,-compatibility_version -Wl,1 - endif - # extra options to override libtool defaults - LVMLibsOptions += -F/System/Library/Frameworks -F/System/Library/PrivateFrameworks - LLVMLibsOptions += -framework Foundation -framework CoreFoundation - LLVMLibsOptions += -framework CoreServices -framework Carbon -framework Security - LLVMLibsOptions += -framework DebugSymbols $(PYTHON_BUILD_FLAGS) -lobjc - # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line - DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/') - ifneq ($(DARWIN_VERS),8) - LLVMLibsOptions += -Wl,-install_name \ - -Wl,"@executable_path/../lib/$(LIBRARYNAME)$(SHLIBEXT)" - endif -endif - -ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD)) - # Include everything from the .a's into the shared library. - ProjLibsOptions := -Wl,--whole-archive $(ProjLibsOptions) \ - -Wl,--no-whole-archive - # Link in libedit - # LLVMLibsOptions += -ledit - LLVMLibsOptions += -Wl,--soname,$(LIBRARYNAME)$(SHLIBEXT) -endif - -ifeq ($(HOST_OS),FreeBSD) - # Include everything from the .a's into the shared library. - ProjLibsOptions := -Wl,--whole-archive $(ProjLibsOptions) \ - -Wl,--no-whole-archive - # Allow unresolved symbols. - LLVMLibsOptions += -Wl,--allow-shlib-undefined - # Link in libedit - # LLVMLibsOptions += -L/usr/local/lib -ledit -endif - -# FIXME: dynamically construct the version from `python -V` -PYTHON_VERSION:=2.7 -LLDB_PYTHON_MODULE_REL_DIR:=python$(PYTHON_VERSION)/site-packages -LLDB_PYTHON_MODULE_DIR:=$(LibDir)/$(LLDB_PYTHON_MODULE_REL_DIR) - -# Target to move readline module from shared lib build location to -# local python module directory. -all-local:: $(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT) - -$(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT): $(SharedLibDir)/$(LIBRARYNAME)$(SHLIBEXT) - $(Echo) Staging $(BuildMode) $(LIBRARYNAME)$(SHLIBEXT) to $(LLDB_PYTHON_MODULE_DIR) - $(Verb) $(MKDIR) "$(LLDB_PYTHON_MODULE_DIR)" - $(Verb) $(ProgInstall) $(SharedLibDir)/$(LIBRARYNAME)$(SHLIBEXT) $(LLDB_PYTHON_MODULE_DIR) - -# Target to move the shared library from the build python lib dir to -# the install python lib dir. -install-local:: $(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT) - $(Echo) Installing $(BuildMode) $(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT) to $(DESTDIR)$(prefix)/lib/$(LLDB_PYTHON_MODULE_REL_DIR) - $(Verb) $(MKDIR) "$(DESTDIR)$(prefix)/lib/$(LLDB_PYTHON_MODULE_REL_DIR)" - $(Verb) $(ProgInstall) "$(LLDB_PYTHON_MODULE_DIR)/$(LIBRARYNAME)$(SHLIBEXT)" "$(DESTDIR)$(prefix)/lib/$(LLDB_PYTHON_MODULE_REL_DIR)" - $(Verb) $(RM) "$(DESTDIR)$(prefix)/lib/$(LIBRARYNAME)$(SHLIBEXT)" - -endif # if !defined(LLDB_DISABLE_PYTHON) diff --git a/scripts/Python/modules/readline/readline.cpp b/scripts/Python/modules/readline/readline.cpp index d66ccf4b6b7dc..d4b4962cc313f 100644 --- a/scripts/Python/modules/readline/readline.cpp +++ b/scripts/Python/modules/readline/readline.cpp @@ -20,11 +20,6 @@ // work around LLVM pr18841 to avoid seg faults in the stock Python // readline.so linked against GNU readline. -static struct PyMethodDef moduleMethods[] = -{ - {nullptr, nullptr, 0, nullptr} -}; - #ifndef LLDB_DISABLE_LIBEDIT PyDoc_STRVAR( moduleDocumentation, @@ -35,9 +30,33 @@ PyDoc_STRVAR( "Stub module meant to avoid linking GNU readline."); #endif +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef readline_module = +{ + PyModuleDef_HEAD_INIT, // m_base + "readline", // m_name + moduleDocumentation, // m_doc + -1, // m_size + nullptr, // m_methods + nullptr, // m_reload + nullptr, // m_traverse + nullptr, // m_clear + nullptr, // m_free +}; +#else +static struct PyMethodDef moduleMethods[] = +{ + {nullptr, nullptr, 0, nullptr} +}; +#endif + #ifndef LLDB_DISABLE_LIBEDIT static char* +#if PY_MAJOR_VERSION >= 3 +simple_readline(FILE *stdin, FILE *stdout, const char *prompt) +#else simple_readline(FILE *stdin, FILE *stdout, char *prompt) +#endif { rl_instream = stdin; rl_outstream = stdout; @@ -67,10 +86,15 @@ initreadline(void) #ifndef LLDB_DISABLE_LIBEDIT PyOS_ReadlineFunctionPointer = simple_readline; #endif + +#if PY_MAJOR_VERSION >= 3 + return PyModule_Create(&readline_module); +#else Py_InitModule4( "readline", moduleMethods, moduleDocumentation, static_cast<PyObject *>(NULL), PYTHON_API_VERSION); +#endif } diff --git a/scripts/Python/prepare_binding_Python.py b/scripts/Python/prepare_binding_Python.py index 1996841baf18e..28fc3e5bc7fc9 100644 --- a/scripts/Python/prepare_binding_Python.py +++ b/scripts/Python/prepare_binding_Python.py @@ -16,7 +16,7 @@ import re import shutil import subprocess import sys - +import platform class SwigSettings(object): """Provides a single object to represent swig files and settings.""" @@ -205,6 +205,8 @@ def do_swig_rebuild(options, dependency_file, config_build_dir, settings): "-I\"%s\"" % os.path.normcase("./."), "-D__STDC_LIMIT_MACROS", "-D__STDC_CONSTANT_MACROS"] + if options.target_platform == "Darwin": + command.append("-D__APPLE__") if options.generate_dependency_file: command.append("-MMD -MF \"%s\"" % temp_dep_file_path) command.extend([ diff --git a/scripts/Python/python-extensions.swig b/scripts/Python/python-extensions.swig index fae7f401bf134..693b06b9aab39 100644 --- a/scripts/Python/python-extensions.swig +++ b/scripts/Python/python-extensions.swig @@ -325,6 +325,22 @@ return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) %} } + +%extend lldb::SBMemoryRegionInfo { + PyObject *lldb::SBMemoryRegionInfo::__str__ (){ + lldb::SBStream description; + $self->GetDescription (description); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return lldb_private::PythonString(llvm::StringRef(desc, desc_len)).release(); + else + return lldb_private::PythonString("").release(); + } +} + %extend lldb::SBModule { PyObject *lldb::SBModule::__str__ (){ lldb::SBStream description; @@ -810,6 +826,7 @@ def command(*args, **kwargs): import lldb + import inspect """A decorator function that registers an LLDB command line command that is bound to the function it is attached to.""" class obj(object): @@ -821,11 +838,15 @@ def command(*args, **kwargs): command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name) lldb.debugger.HandleCommand(command) self.function = function - def __call__(self, *args, **kwargs): - self.function(*args, **kwargs) + def __call__(self, debugger, command, exe_ctx, result, dict): + if len(inspect.getargspec(self.function).args) == 5: + self.function(debugger, command, exe_ctx, result, dict) + else: + self.function(debugger, command, result, dict) def callable(function): """Creates a callable object that gets used.""" - return obj(function, *args, **kwargs) + f = obj(function, *args, **kwargs) + return f.__call__ return callable class declaration(object): @@ -1024,11 +1045,13 @@ class value(object): return complex (int(self)) def __int__(self): + is_num,is_sign = is_numeric_type(self.sbvalue.GetType().GetCanonicalType().GetBasicType()) + if is_num and not is_sign: return self.sbvalue.GetValueAsUnsigned() return self.sbvalue.GetValueAsSigned() - + def __long__(self): - return self.sbvalue.GetValueAsSigned() - + return self.__int__() + def __float__(self): return float (self.sbvalue.GetValueAsSigned()) @@ -1084,4 +1107,47 @@ class SBSyntheticValueProvider(object): return False -%}
\ No newline at end of file +%} + +%pythoncode %{ + +# given an lldb.SBBasicType it returns a tuple +# (is_numeric, is_signed) +# the value of is_signed is undefined if is_numeric == false +def is_numeric_type(basic_type): + if basic_type == eBasicTypeInvalid: return (False,False) + if basic_type == eBasicTypeVoid: return (False,False) + if basic_type == eBasicTypeChar: return (True,False) + if basic_type == eBasicTypeSignedChar: return (True,True) + if basic_type == eBasicTypeUnsignedChar: return (True,False) + if basic_type == eBasicTypeWChar: return (True,False) + if basic_type == eBasicTypeSignedWChar: return (True,True) + if basic_type == eBasicTypeUnsignedWChar: return (True,False) + if basic_type == eBasicTypeChar16: return (True,False) + if basic_type == eBasicTypeChar32: return (True,False) + if basic_type == eBasicTypeShort: return (True,True) + if basic_type == eBasicTypeUnsignedShort: return (True,False) + if basic_type == eBasicTypeInt: return (True,True) + if basic_type == eBasicTypeUnsignedInt: return (True,False) + if basic_type == eBasicTypeLong: return (True,True) + if basic_type == eBasicTypeUnsignedLong: return (True,False) + if basic_type == eBasicTypeLongLong: return (True,True) + if basic_type == eBasicTypeUnsignedLongLong: return (True,False) + if basic_type == eBasicTypeInt128: return (True,True) + if basic_type == eBasicTypeUnsignedInt128: return (True,False) + if basic_type == eBasicTypeBool: return (False,False) + if basic_type == eBasicTypeHalf: return (True,True) + if basic_type == eBasicTypeFloat: return (True,True) + if basic_type == eBasicTypeDouble: return (True,True) + if basic_type == eBasicTypeLongDouble: return (True,True) + if basic_type == eBasicTypeFloatComplex: return (True,True) + if basic_type == eBasicTypeDoubleComplex: return (True,True) + if basic_type == eBasicTypeLongDoubleComplex: return (True,True) + if basic_type == eBasicTypeObjCID: return (False,False) + if basic_type == eBasicTypeObjCClass: return (False,False) + if basic_type == eBasicTypeObjCSel: return (False,False) + if basic_type == eBasicTypeNullPtr: return (False,False) + #if basic_type == eBasicTypeOther: + return (False,False) + +%} diff --git a/scripts/Python/python-typemaps.swig b/scripts/Python/python-typemaps.swig index 9c4e5cecb3639..df16a6d27b3b9 100644 --- a/scripts/Python/python-typemaps.swig +++ b/scripts/Python/python-typemaps.swig @@ -1,20 +1,22 @@ /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */ %typemap(in) char ** { + using namespace lldb_private; /* Check if is a list */ - if (PyList_Check($input)) { - int size = PyList_Size($input); + if (PythonList::Check($input)) { + PythonList list(PyRefType::Borrowed, $input); + int size = list.GetSize(); int i = 0; - $1 = (char **) malloc((size+1) * sizeof(char*)); + $1 = (char**)malloc((size+1)*sizeof(char*)); for (i = 0; i < size; i++) { - PyObject *o = PyList_GetItem($input,i); - if (PyString_Check(o)) - $1[i] = PyString_AsString(o); - else { + PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>(); + if (!py_str.IsAllocated()) { PyErr_SetString(PyExc_TypeError,"list must contain strings"); free($1); - return NULL; + return nullptr; } + + $1[i] = const_cast<char*>(py_str.GetString().data()); } $1[i] = 0; } else if ($input == Py_None) { @@ -25,29 +27,17 @@ } } -%typemap(in) lldb::tid_t { - using namespace lldb_private; - if (PythonInteger::Check($input)) - { - PythonInteger py_int(PyRefType::Borrowed, $input); - $1 = static_cast<lldb::tid_t>(py_int.GetInteger()); - } - else - { - PyErr_SetString(PyExc_ValueError, "Expecting an integer"); - return nullptr; - } -} - %typemap(typecheck) char ** { /* Check if is a list */ $1 = 1; - if (PyList_Check($input)) { - int size = PyList_Size($input); + using namespace lldb_private; + if (PythonList::Check($input)) { + PythonList list(PyRefType::Borrowed, $input); + int size = list.GetSize(); int i = 0; for (i = 0; i < size; i++) { - PyObject *o = PyList_GetItem($input,i); - if (!PyString_Check(o)) { $1 = 0; } + PythonString s = list.GetItemAtIndex(i).AsType<PythonString>(); + if (!s.IsAllocated()) { $1 = 0; } } } else @@ -72,63 +62,18 @@ $result = list.release(); } -%typemap(in) char const ** { - /* Check if is a list */ - using namespace lldb_private; - if (PythonList::Check($input)) { - PythonList py_list(PyRefType::Borrowed, $input); - int size = py_list.GetSize(); - $1 = (char**)malloc((size+1)*sizeof(char*)); - for (int i = 0; i < size; i++) { - PythonObject o = py_list.GetItemAtIndex(i); - if (!PythonString::Check(o.get())) { - PyErr_SetString(PyExc_TypeError,"list must contain strings"); - free($1); - return nullptr; - } - auto py_str = o.AsType<PythonString>(); - $1[i] = const_cast<char*>(py_str.GetString().data()); - } - - $1[size] = 0; - } else if ($input == Py_None) { - $1 = nullptr; - } else { - PyErr_SetString(PyExc_TypeError,"not a list"); - return nullptr; - } -} - -%typemap(typecheck) char const ** { - /* Check if is a list */ - $1 = 1; - if (PyList_Check($input)) { - int size = PyList_Size($input); - int i = 0; - for (i = 0; i < size; i++) { - PyObject *o = PyList_GetItem($input,i); - if (!PyString_Check(o)) { $1 = 0; } - } +%typemap(in) lldb::tid_t { + using namespace lldb_private; + if (PythonInteger::Check($input)) + { + PythonInteger py_int(PyRefType::Borrowed, $input); + $1 = static_cast<lldb::tid_t>(py_int.GetInteger()); } else { - $1 = ( ($input == Py_None) ? 1 : 0); - } -} - -%typemap(freearg) char const ** { - free((char *) $1); -} - -%typemap(out) char const ** { - int len; - int i; - len = 0; - while ($1[len]) len++; - $result = PyList_New(len); - for (i = 0; i < len; i++) { - PyList_SetItem($result, i, PyString_FromString($1[i])); + PyErr_SetString(PyExc_ValueError, "Expecting an integer"); + return nullptr; } } @@ -148,6 +93,9 @@ } $1 = (char *) malloc($2); } +// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated +// as char data instead of byte data. +%typemap(in) (void *char_buf, size_t size) = (char *dst, size_t dst_len); // Return the char buffer. Discarding any previous return result // See also SBThread::GetStopDescription. @@ -163,18 +111,29 @@ } free($1); } +// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated +// as char data instead of byte data. +%typemap(argout) (void *char_buf, size_t size) = (char *dst, size_t dst_len); // typemap for an outgoing buffer // See also SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len). %typemap(in) (const char *cstr, uint32_t cstr_len) { - if (PyString_Check($input)) { - $1 = (char *) PyString_AsString($input); - $2 = PyString_Size($input); + using namespace lldb_private; + if (PythonString::Check($input)) { + PythonString str(PyRefType::Borrowed, $input); + $1 = (char*)str.GetString().data(); + $2 = str.GetSize(); + } + else if(PythonByteArray::Check($input)) { + PythonByteArray bytearray(PyRefType::Borrowed, $input); + $1 = (char*)bytearray.GetBytes().data(); + $2 = bytearray.GetSize(); } - else if(PyByteArray_Check($input)) { - $1 = (char *) PyByteArray_AsString($input); - $2 = PyByteArray_Size($input); + else if (PythonBytes::Check($input)) { + PythonBytes bytes(PyRefType::Borrowed, $input); + $1 = (char*)bytes.GetBytes().data(); + $2 = bytes.GetSize(); } else { PyErr_SetString(PyExc_ValueError, "Expecting a string"); @@ -183,13 +142,21 @@ } // Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len). %typemap(in) (const char *src, size_t src_len) { - if (PyString_Check($input)) { - $1 = (char *) PyString_AsString($input); - $2 = PyString_Size($input); + using namespace lldb_private; + if (PythonString::Check($input)) { + PythonString str(PyRefType::Borrowed, $input); + $1 = (char*)str.GetString().data(); + $2 = str.GetSize(); } - else if(PyByteArray_Check($input)) { - $1 = (char *) PyByteArray_AsString($input); - $2 = PyByteArray_Size($input); + else if(PythonByteArray::Check($input)) { + PythonByteArray bytearray(PyRefType::Borrowed, $input); + $1 = (char*)bytearray.GetBytes().data(); + $2 = bytearray.GetSize(); + } + else if (PythonBytes::Check($input)) { + PythonBytes bytes(PyRefType::Borrowed, $input); + $1 = (char*)bytes.GetBytes().data(); + $2 = bytes.GetSize(); } else { PyErr_SetString(PyExc_ValueError, "Expecting a string"); @@ -198,32 +165,48 @@ } // And SBProcess::WriteMemory. %typemap(in) (const void *buf, size_t size) { - if (PyString_Check($input)) { - $1 = (void *) PyString_AsString($input); - $2 = PyString_Size($input); + using namespace lldb_private; + if (PythonString::Check($input)) { + PythonString str(PyRefType::Borrowed, $input); + $1 = (void*)str.GetString().data(); + $2 = str.GetSize(); } - else if(PyByteArray_Check($input)) { - $1 = (void *) PyByteArray_AsString($input); - $2 = PyByteArray_Size($input); + else if(PythonByteArray::Check($input)) { + PythonByteArray bytearray(PyRefType::Borrowed, $input); + $1 = (void*)bytearray.GetBytes().data(); + $2 = bytearray.GetSize(); + } + else if (PythonBytes::Check($input)) { + PythonBytes bytes(PyRefType::Borrowed, $input); + $1 = (void*)bytes.GetBytes().data(); + $2 = bytes.GetSize(); } else { - PyErr_SetString(PyExc_ValueError, "Expecting a string"); + PyErr_SetString(PyExc_ValueError, "Expecting a buffer"); return NULL; } } // For SBDebugger::DispatchInput %typemap(in) (const void *data, size_t data_len) { - if (PyString_Check($input)) { - $1 = static_cast<void *>(PyString_AsString($input)); - $2 = PyString_Size($input); + using namespace lldb_private; + if (PythonString::Check($input)) { + PythonString str(PyRefType::Borrowed, $input); + $1 = (void*)str.GetString().data(); + $2 = str.GetSize(); } - else if(PyByteArray_Check($input)) { - $1 = static_cast<void *>(PyByteArray_AsString($input)); - $2 = PyByteArray_Size($input); + else if(PythonByteArray::Check($input)) { + PythonByteArray bytearray(PyRefType::Borrowed, $input); + $1 = (void*)bytearray.GetBytes().data(); + $2 = bytearray.GetSize(); + } + else if (PythonBytes::Check($input)) { + PythonBytes bytes(PyRefType::Borrowed, $input); + $1 = (void*)bytes.GetBytes().data(); + $2 = bytes.GetSize(); } else { - PyErr_SetString(PyExc_ValueError, "Expecting a string or byte array"); + PyErr_SetString(PyExc_ValueError, "Expecting a buffer"); return NULL; } } @@ -254,9 +237,8 @@ $result = Py_None; Py_INCREF($result); } else { - llvm::StringRef ref(static_cast<const char*>($1), result); - lldb_private::PythonString string(ref); - $result = string.release(); + lldb_private::PythonBytes bytes(static_cast<const uint8_t*>($1), result); + $result = bytes.release(); } free($1); } @@ -545,22 +527,27 @@ return nullptr; $1 = file.GetStream(); - } + if ($1) + file.Clear(); + } } %typemap(out) FILE * { char mode[4] = {0}; -#ifdef __MACOSX__ +%#ifdef __APPLE__ int i = 0; - short flags = $1->_flags; - - if (flags & __SRD) - mode[i++] = 'r'; - else if (flags & __SWR) - mode[i++] = 'w'; - else // if (flags & __SRW) - mode[i++] = 'a'; -#endif + if ($1) + { + short flags = $1->_flags; + + if (flags & __SRD) + mode[i++] = 'r'; + else if (flags & __SWR) + mode[i++] = 'w'; + else // if (flags & __SRW) + mode[i++] = 'a'; + } +%#endif using namespace lldb_private; File file($1, false); PythonFile py_file(file, mode); diff --git a/scripts/Python/python-wrapper.swig b/scripts/Python/python-wrapper.swig index 5d7bfaa89439b..a92102e328388 100644 --- a/scripts/Python/python-wrapper.swig +++ b/scripts/Python/python-wrapper.swig @@ -610,7 +610,7 @@ LLDBSwigPythonCallCommand PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb)); PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb)); - if (argc.count == 5 || argc.has_varargs) + if (argc.count == 5 || argc.is_bound_method || argc.has_varargs) pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg, dict); else pfunc(debugger_arg, PythonString(args), cmd_retobj_arg, dict); diff --git a/scripts/Python/use_lldb_suite.py b/scripts/Python/use_lldb_suite.py index 63a098cea220f..f3e358af143bf 100644 --- a/scripts/Python/use_lldb_suite.py +++ b/scripts/Python/use_lldb_suite.py @@ -17,6 +17,9 @@ def find_lldb_root(): lldb_root = find_lldb_root() if lldb_root is not None: import imp - module = imp.find_module("use_lldb_suite_root", [lldb_root]) - if module is not None: - imp.load_module("use_lldb_suite_root", *module) + fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root]) + try: + imp.load_module("use_lldb_suite_root", fp, pathname, desc) + finally: + if fp: + fp.close() |