diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt index 6170ab625c54d..573b8556989e4 100644 --- a/lldb/CMakeLists.txt +++ b/lldb/CMakeLists.txt @@ -56,7 +56,7 @@ if (LLDB_ENABLE_PYTHON) endif () if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA) - add_subdirectory(scripts) + add_subdirectory(bindings) endif () # We need the headers generated by instrinsics_gen before we can compile @@ -97,7 +97,7 @@ if(LLDB_INCLUDE_TESTS) endif() if (LLDB_ENABLE_PYTHON) - get_target_property(lldb_scripts_dir swig_wrapper BINARY_DIR) + get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR) if(LLDB_BUILD_FRAMEWORK) set(lldb_python_build_path "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb") @@ -109,7 +109,7 @@ if (LLDB_ENABLE_PYTHON) # to liblldb.so for the Python API(hardlink on Windows). add_custom_target(finish_swig ALL VERBATIM COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_build_path} - DEPENDS ${lldb_scripts_dir}/lldb.py + DEPENDS ${lldb_bindings_dir}/lldb.py COMMENT "Python script sym-linking LLDB Python API") if(NOT LLDB_USE_SYSTEM_SIX) @@ -121,7 +121,7 @@ if (LLDB_ENABLE_PYTHON) add_custom_command(TARGET finish_swig POST_BUILD VERBATIM COMMAND ${CMAKE_COMMAND} -E copy - "${lldb_scripts_dir}/lldb.py" + "${lldb_bindings_dir}/lldb.py" "${lldb_python_build_path}/__init__.py") function(create_python_package pkg_dir) @@ -131,7 +131,7 @@ if (LLDB_ENABLE_PYTHON) endif() if(NOT ARG_NOINIT) set(init_cmd COMMAND ${PYTHON_EXECUTABLE} - "${LLDB_SOURCE_DIR}/scripts/Python/createPythonInit.py" + "${LLDB_SOURCE_DIR}/bindings/python/createPythonInit.py" "${pkg_dir}" ${ARG_FILES}) endif() add_custom_command(TARGET finish_swig POST_BUILD VERBATIM diff --git a/lldb/scripts/CMakeLists.txt b/lldb/bindings/CMakeLists.txt similarity index 93% rename from lldb/scripts/CMakeLists.txt rename to lldb/bindings/CMakeLists.txt index 515c63293bc20..92ae402c478e9 100644 --- a/lldb/scripts/CMakeLists.txt +++ b/lldb/bindings/CMakeLists.txt @@ -1,4 +1,4 @@ -file(GLOB SWIG_INTERFACES interface/*.i) +file(GLOB SWIG_INTERFACES interfaces/*.i) file(GLOB_RECURSE SWIG_SOURCES *.swig) file(GLOB SWIG_HEADERS ${LLDB_SOURCE_DIR}/include/lldb/API/*.h @@ -46,7 +46,7 @@ if (LLDB_ENABLE_PYTHON) -python -threads -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - ${LLDB_SOURCE_DIR}/scripts/lldb.swig + ${LLDB_SOURCE_DIR}/bindings/python.swig VERBATIM COMMENT "Builds LLDB Python wrapper") @@ -67,7 +67,7 @@ if (LLDB_ENABLE_LUA) -lua -w503 -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp - ${LLDB_SOURCE_DIR}/scripts/lldb_lua.swig + ${LLDB_SOURCE_DIR}/bindings/lua.swig VERBATIM COMMENT "Builds LLDB Lua wrapper") diff --git a/lldb/scripts/headers.swig b/lldb/bindings/headers.swig similarity index 100% rename from lldb/scripts/headers.swig rename to lldb/bindings/headers.swig diff --git a/lldb/scripts/interface/SBAddress.i b/lldb/bindings/interface/SBAddress.i similarity index 99% rename from lldb/scripts/interface/SBAddress.i rename to lldb/bindings/interface/SBAddress.i index 6c5352bac6d7c..4658534d153ea 100644 --- a/lldb/scripts/interface/SBAddress.i +++ b/lldb/bindings/interface/SBAddress.i @@ -140,6 +140,8 @@ public: lldb::SBLineEntry GetLineEntry (); + STRING_EXTENSION(SBAddress) + #ifdef SWIGPYTHON %pythoncode %{ def __get_load_addr_property__ (self): diff --git a/lldb/scripts/interface/SBAttachInfo.i b/lldb/bindings/interface/SBAttachInfo.i similarity index 100% rename from lldb/scripts/interface/SBAttachInfo.i rename to lldb/bindings/interface/SBAttachInfo.i diff --git a/lldb/scripts/interface/SBBlock.i b/lldb/bindings/interface/SBBlock.i similarity index 99% rename from lldb/scripts/interface/SBBlock.i rename to lldb/bindings/interface/SBBlock.i index 73079a11760c6..8bd8e37953cfc 100644 --- a/lldb/scripts/interface/SBBlock.i +++ b/lldb/bindings/interface/SBBlock.i @@ -100,6 +100,8 @@ public: bool locals, bool statics); + STRING_EXTENSION(SBBlock) + #ifdef SWIGPYTHON %pythoncode %{ def get_range_at_index(self, idx): diff --git a/lldb/scripts/interface/SBBreakpoint.i b/lldb/bindings/interface/SBBreakpoint.i similarity index 99% rename from lldb/scripts/interface/SBBreakpoint.i rename to lldb/bindings/interface/SBBreakpoint.i index f84f2ada3d329..20354346be900 100644 --- a/lldb/scripts/interface/SBBreakpoint.i +++ b/lldb/bindings/interface/SBBreakpoint.i @@ -249,6 +249,8 @@ public: bool IsHardware (); + STRING_EXTENSION(SBBreakpoint) + #ifdef SWIGPYTHON %pythoncode %{ diff --git a/lldb/scripts/interface/SBBreakpointLocation.i b/lldb/bindings/interface/SBBreakpointLocation.i similarity index 97% rename from lldb/scripts/interface/SBBreakpointLocation.i rename to lldb/bindings/interface/SBBreakpointLocation.i index 44fd42b514f7f..dc39c83c2d67b 100644 --- a/lldb/scripts/interface/SBBreakpointLocation.i +++ b/lldb/bindings/interface/SBBreakpointLocation.i @@ -134,6 +134,8 @@ public: SBBreakpoint GetBreakpoint (); + + STRING_EXTENSION_LEVEL(SBBreakpointLocation, lldb::eDescriptionLevelFull) }; } // namespace lldb diff --git a/lldb/scripts/interface/SBBreakpointName.i b/lldb/bindings/interface/SBBreakpointName.i similarity index 98% rename from lldb/scripts/interface/SBBreakpointName.i rename to lldb/bindings/interface/SBBreakpointName.i index 2a06d0a2105f0..e280d42245915 100644 --- a/lldb/scripts/interface/SBBreakpointName.i +++ b/lldb/bindings/interface/SBBreakpointName.i @@ -108,6 +108,7 @@ public: bool GetDescription(lldb::SBStream &description); + STRING_EXTENSION(SBBreakpointName) }; } // namespace lldb diff --git a/lldb/scripts/interface/SBBroadcaster.i b/lldb/bindings/interface/SBBroadcaster.i similarity index 100% rename from lldb/scripts/interface/SBBroadcaster.i rename to lldb/bindings/interface/SBBroadcaster.i diff --git a/lldb/scripts/interface/SBCommandInterpreter.i b/lldb/bindings/interface/SBCommandInterpreter.i similarity index 100% rename from lldb/scripts/interface/SBCommandInterpreter.i rename to lldb/bindings/interface/SBCommandInterpreter.i diff --git a/lldb/scripts/interface/SBCommandReturnObject.i b/lldb/bindings/interface/SBCommandReturnObject.i similarity index 98% rename from lldb/scripts/interface/SBCommandReturnObject.i rename to lldb/bindings/interface/SBCommandReturnObject.i index 73d4001aaba59..affa16520f28d 100644 --- a/lldb/scripts/interface/SBCommandReturnObject.i +++ b/lldb/bindings/interface/SBCommandReturnObject.i @@ -96,6 +96,8 @@ public: void SetImmediateOutputFile(lldb::FileSP BORROWED); void SetImmediateErrorFile(lldb::FileSP BORROWED); + STRING_EXTENSION(SBCommandReturnObject) + %extend { // transfer_ownership does nothing, and is here for compatibility with // old scripts. Ownership is tracked by reference count in the ordinary way. diff --git a/lldb/scripts/interface/SBCommunication.i b/lldb/bindings/interface/SBCommunication.i similarity index 100% rename from lldb/scripts/interface/SBCommunication.i rename to lldb/bindings/interface/SBCommunication.i diff --git a/lldb/scripts/interface/SBCompileUnit.i b/lldb/bindings/interface/SBCompileUnit.i similarity index 99% rename from lldb/scripts/interface/SBCompileUnit.i rename to lldb/bindings/interface/SBCompileUnit.i index bc2d45ae8e56c..d6a4c07038c65 100644 --- a/lldb/scripts/interface/SBCompileUnit.i +++ b/lldb/bindings/interface/SBCompileUnit.i @@ -116,6 +116,8 @@ public: bool operator != (const lldb::SBCompileUnit &rhs) const; + STRING_EXTENSION(SBCompileUnit) + #ifdef SWIGPYTHON %pythoncode %{ def __iter__(self): diff --git a/lldb/scripts/interface/SBData.i b/lldb/bindings/interface/SBData.i similarity index 99% rename from lldb/scripts/interface/SBData.i rename to lldb/bindings/interface/SBData.i index fdaa6962f0eca..3e74240329e05 100644 --- a/lldb/scripts/interface/SBData.i +++ b/lldb/bindings/interface/SBData.i @@ -134,6 +134,8 @@ public: bool SetDataFromDoubleArray (double* array, size_t array_len); + STRING_EXTENSION(SBData) + #ifdef SWIGPYTHON %pythoncode %{ diff --git a/lldb/scripts/interface/SBDebugger.i b/lldb/bindings/interface/SBDebugger.i similarity index 99% rename from lldb/scripts/interface/SBDebugger.i rename to lldb/bindings/interface/SBDebugger.i index 52f65841893c6..f2e23a7ed7804 100644 --- a/lldb/scripts/interface/SBDebugger.i +++ b/lldb/bindings/interface/SBDebugger.i @@ -479,6 +479,8 @@ public: lldb::SBTypeSynthetic GetSyntheticForType (lldb::SBTypeNameSpecifier); + STRING_EXTENSION(SBDebugger) + %feature("docstring", "Launch a command interpreter session. Commands are read from standard input or from the input handle specified for the debugger object. Output/errors are diff --git a/lldb/scripts/interface/SBDeclaration.i b/lldb/bindings/interface/SBDeclaration.i similarity index 97% rename from lldb/scripts/interface/SBDeclaration.i rename to lldb/bindings/interface/SBDeclaration.i index cdaec85676461..621c1a0ab7c87 100644 --- a/lldb/scripts/interface/SBDeclaration.i +++ b/lldb/bindings/interface/SBDeclaration.i @@ -53,6 +53,8 @@ namespace lldb { bool operator != (const lldb::SBDeclaration &rhs) const; + STRING_EXTENSION(SBDeclaration) + #ifdef SWIGPYTHON %pythoncode %{ file = property(GetFileSpec, None, doc='''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this line entry.''') diff --git a/lldb/scripts/interface/SBError.i b/lldb/bindings/interface/SBError.i similarity index 99% rename from lldb/scripts/interface/SBError.i rename to lldb/bindings/interface/SBError.i index 96cd6c4886f5f..ea48e2263a77a 100644 --- a/lldb/scripts/interface/SBError.i +++ b/lldb/bindings/interface/SBError.i @@ -105,6 +105,8 @@ public: bool GetDescription (lldb::SBStream &description); + STRING_EXTENSION(SBError) + #ifdef SWIGPYTHON %pythoncode %{ value = property(GetError, None, doc='''A read only property that returns the same result as GetError().''') diff --git a/lldb/scripts/interface/SBEvent.i b/lldb/bindings/interface/SBEvent.i similarity index 100% rename from lldb/scripts/interface/SBEvent.i rename to lldb/bindings/interface/SBEvent.i diff --git a/lldb/scripts/interface/SBExecutionContext.i b/lldb/bindings/interface/SBExecutionContext.i similarity index 100% rename from lldb/scripts/interface/SBExecutionContext.i rename to lldb/bindings/interface/SBExecutionContext.i diff --git a/lldb/scripts/interface/SBExpressionOptions.i b/lldb/bindings/interface/SBExpressionOptions.i similarity index 100% rename from lldb/scripts/interface/SBExpressionOptions.i rename to lldb/bindings/interface/SBExpressionOptions.i diff --git a/lldb/scripts/interface/SBFile.i b/lldb/bindings/interface/SBFile.i similarity index 100% rename from lldb/scripts/interface/SBFile.i rename to lldb/bindings/interface/SBFile.i diff --git a/lldb/scripts/interface/SBFileSpec.i b/lldb/bindings/interface/SBFileSpec.i similarity index 98% rename from lldb/scripts/interface/SBFileSpec.i rename to lldb/bindings/interface/SBFileSpec.i index 07a7630ebbac8..d287a940c051a 100644 --- a/lldb/scripts/interface/SBFileSpec.i +++ b/lldb/bindings/interface/SBFileSpec.i @@ -80,6 +80,8 @@ public: void AppendPathComponent (const char *file_or_directory); + STRING_EXTENSION(SBFileSpec) + #ifdef SWIGPYTHON %pythoncode %{ def __get_fullpath__(self): diff --git a/lldb/scripts/interface/SBFileSpecList.i b/lldb/bindings/interface/SBFileSpecList.i similarity index 100% rename from lldb/scripts/interface/SBFileSpecList.i rename to lldb/bindings/interface/SBFileSpecList.i diff --git a/lldb/scripts/interface/SBFrame.i b/lldb/bindings/interface/SBFrame.i similarity index 99% rename from lldb/scripts/interface/SBFrame.i rename to lldb/bindings/interface/SBFrame.i index 811f7f22f9b4d..c65b88f863e7d 100644 --- a/lldb/scripts/interface/SBFrame.i +++ b/lldb/bindings/interface/SBFrame.i @@ -285,6 +285,8 @@ public: bool GetDescription (lldb::SBStream &description); + STRING_EXTENSION(SBFrame) + #ifdef SWIGPYTHON %pythoncode %{ def get_all_variables(self): diff --git a/lldb/scripts/interface/SBFunction.i b/lldb/bindings/interface/SBFunction.i similarity index 99% rename from lldb/scripts/interface/SBFunction.i rename to lldb/bindings/interface/SBFunction.i index 7b157bb388169..630c4db22c55d 100644 --- a/lldb/scripts/interface/SBFunction.i +++ b/lldb/bindings/interface/SBFunction.i @@ -111,6 +111,8 @@ public: bool operator != (const lldb::SBFunction &rhs) const; + STRING_EXTENSION(SBFunction) + #ifdef SWIGPYTHON %pythoncode %{ def get_instructions_from_current_target (self): diff --git a/lldb/scripts/interface/SBHostOS.i b/lldb/bindings/interface/SBHostOS.i similarity index 100% rename from lldb/scripts/interface/SBHostOS.i rename to lldb/bindings/interface/SBHostOS.i diff --git a/lldb/scripts/interface/SBInstruction.i b/lldb/bindings/interface/SBInstruction.i similarity index 98% rename from lldb/scripts/interface/SBInstruction.i rename to lldb/bindings/interface/SBInstruction.i index 09688214630b1..d50a080fd0454 100644 --- a/lldb/scripts/interface/SBInstruction.i +++ b/lldb/bindings/interface/SBInstruction.i @@ -74,6 +74,8 @@ public: bool TestEmulation (lldb::SBStream &output_stream, const char *test_file); + STRING_EXTENSION(SBInstruction) + #ifdef SWIGPYTHON %pythoncode %{ def __mnemonic_property__ (self): diff --git a/lldb/scripts/interface/SBInstructionList.i b/lldb/bindings/interface/SBInstructionList.i similarity index 98% rename from lldb/scripts/interface/SBInstructionList.i rename to lldb/bindings/interface/SBInstructionList.i index d50deba4f5e1f..1357323027573 100644 --- a/lldb/scripts/interface/SBInstructionList.i +++ b/lldb/bindings/interface/SBInstructionList.i @@ -66,6 +66,8 @@ public: bool DumpEmulationForAllInstructions (const char *triple); + STRING_EXTENSION(SBInstructionList) + #ifdef SWIGPYTHON %pythoncode %{ def __iter__(self): diff --git a/lldb/scripts/interface/SBLanguageRuntime.i b/lldb/bindings/interface/SBLanguageRuntime.i similarity index 100% rename from lldb/scripts/interface/SBLanguageRuntime.i rename to lldb/bindings/interface/SBLanguageRuntime.i diff --git a/lldb/scripts/interface/SBLaunchInfo.i b/lldb/bindings/interface/SBLaunchInfo.i similarity index 100% rename from lldb/scripts/interface/SBLaunchInfo.i rename to lldb/bindings/interface/SBLaunchInfo.i diff --git a/lldb/scripts/interface/SBLineEntry.i b/lldb/bindings/interface/SBLineEntry.i similarity index 98% rename from lldb/scripts/interface/SBLineEntry.i rename to lldb/bindings/interface/SBLineEntry.i index 90f60df23247d..be365377ba8b0 100644 --- a/lldb/scripts/interface/SBLineEntry.i +++ b/lldb/bindings/interface/SBLineEntry.i @@ -84,6 +84,8 @@ public: bool operator != (const lldb::SBLineEntry &rhs) const; + STRING_EXTENSION(SBLineEntry) + #ifdef SWIGPYTHON %pythoncode %{ file = property(GetFileSpec, None, doc='''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this line entry.''') diff --git a/lldb/scripts/interface/SBListener.i b/lldb/bindings/interface/SBListener.i similarity index 100% rename from lldb/scripts/interface/SBListener.i rename to lldb/bindings/interface/SBListener.i diff --git a/lldb/scripts/interface/SBMemoryRegionInfo.i b/lldb/bindings/interface/SBMemoryRegionInfo.i similarity index 96% rename from lldb/scripts/interface/SBMemoryRegionInfo.i rename to lldb/bindings/interface/SBMemoryRegionInfo.i index 7a59d0051ceac..6a2ad6a3e3649 100644 --- a/lldb/scripts/interface/SBMemoryRegionInfo.i +++ b/lldb/bindings/interface/SBMemoryRegionInfo.i @@ -55,6 +55,7 @@ public: bool GetDescription (lldb::SBStream &description); + STRING_EXTENSION(SBMemoryRegionInfo) }; } // namespace lldb diff --git a/lldb/scripts/interface/SBMemoryRegionInfoList.i b/lldb/bindings/interface/SBMemoryRegionInfoList.i similarity index 100% rename from lldb/scripts/interface/SBMemoryRegionInfoList.i rename to lldb/bindings/interface/SBMemoryRegionInfoList.i diff --git a/lldb/scripts/interface/SBModule.i b/lldb/bindings/interface/SBModule.i similarity index 99% rename from lldb/scripts/interface/SBModule.i rename to lldb/bindings/interface/SBModule.i index 03c8aeb2bed9e..a9d9480cd7cf1 100644 --- a/lldb/scripts/interface/SBModule.i +++ b/lldb/bindings/interface/SBModule.i @@ -344,6 +344,8 @@ public: lldb::SBAddress GetObjectFileEntryPointAddress() const; + STRING_EXTENSION(SBModule) + #ifdef SWIGPYTHON %pythoncode %{ def __len__(self): diff --git a/lldb/scripts/interface/SBModuleSpec.i b/lldb/bindings/interface/SBModuleSpec.i similarity index 97% rename from lldb/scripts/interface/SBModuleSpec.i rename to lldb/bindings/interface/SBModuleSpec.i index ec4e9bb7fbf72..64d0aa641a774 100644 --- a/lldb/scripts/interface/SBModuleSpec.i +++ b/lldb/bindings/interface/SBModuleSpec.i @@ -91,6 +91,7 @@ public: bool GetDescription (lldb::SBStream &description); + STRING_EXTENSION(SBModuleSpec) }; @@ -127,6 +128,7 @@ public: bool GetDescription (lldb::SBStream &description); + STRING_EXTENSION(SBModuleSpecList) }; } // namespace lldb diff --git a/lldb/scripts/interface/SBPlatform.i b/lldb/bindings/interface/SBPlatform.i similarity index 100% rename from lldb/scripts/interface/SBPlatform.i rename to lldb/bindings/interface/SBPlatform.i diff --git a/lldb/scripts/interface/SBProcess.i b/lldb/bindings/interface/SBProcess.i similarity index 99% rename from lldb/scripts/interface/SBProcess.i rename to lldb/bindings/interface/SBProcess.i index c5ebc24686155..ac6a265faec9f 100644 --- a/lldb/scripts/interface/SBProcess.i +++ b/lldb/bindings/interface/SBProcess.i @@ -417,6 +417,8 @@ public: lldb::SBProcessInfo GetProcessInfo(); + STRING_EXTENSION(SBProcess) + #ifdef SWIGPYTHON %pythoncode %{ def __get_is_alive__(self): diff --git a/lldb/scripts/interface/SBProcessInfo.i b/lldb/bindings/interface/SBProcessInfo.i similarity index 100% rename from lldb/scripts/interface/SBProcessInfo.i rename to lldb/bindings/interface/SBProcessInfo.i diff --git a/lldb/scripts/interface/SBQueue.i b/lldb/bindings/interface/SBQueue.i similarity index 100% rename from lldb/scripts/interface/SBQueue.i rename to lldb/bindings/interface/SBQueue.i diff --git a/lldb/scripts/interface/SBQueueItem.i b/lldb/bindings/interface/SBQueueItem.i similarity index 100% rename from lldb/scripts/interface/SBQueueItem.i rename to lldb/bindings/interface/SBQueueItem.i diff --git a/lldb/scripts/interface/SBSection.i b/lldb/bindings/interface/SBSection.i similarity index 99% rename from lldb/scripts/interface/SBSection.i rename to lldb/bindings/interface/SBSection.i index c1a84acc4f144..3d1c900917fd8 100644 --- a/lldb/scripts/interface/SBSection.i +++ b/lldb/bindings/interface/SBSection.i @@ -114,6 +114,8 @@ public: bool operator != (const lldb::SBSection &rhs); + STRING_EXTENSION(SBSection) + #ifdef SWIGPYTHON %pythoncode %{ def __iter__(self): diff --git a/lldb/scripts/interface/SBSourceManager.i b/lldb/bindings/interface/SBSourceManager.i similarity index 100% rename from lldb/scripts/interface/SBSourceManager.i rename to lldb/bindings/interface/SBSourceManager.i diff --git a/lldb/scripts/interface/SBStream.i b/lldb/bindings/interface/SBStream.i similarity index 100% rename from lldb/scripts/interface/SBStream.i rename to lldb/bindings/interface/SBStream.i diff --git a/lldb/scripts/interface/SBStringList.i b/lldb/bindings/interface/SBStringList.i similarity index 100% rename from lldb/scripts/interface/SBStringList.i rename to lldb/bindings/interface/SBStringList.i diff --git a/lldb/scripts/interface/SBStructuredData.i b/lldb/bindings/interface/SBStructuredData.i similarity index 100% rename from lldb/scripts/interface/SBStructuredData.i rename to lldb/bindings/interface/SBStructuredData.i diff --git a/lldb/scripts/interface/SBSymbol.i b/lldb/bindings/interface/SBSymbol.i similarity index 99% rename from lldb/scripts/interface/SBSymbol.i rename to lldb/bindings/interface/SBSymbol.i index e5880e66d300f..4e17ab5af0fd6 100644 --- a/lldb/scripts/interface/SBSymbol.i +++ b/lldb/bindings/interface/SBSymbol.i @@ -72,6 +72,8 @@ public: bool operator != (const lldb::SBSymbol &rhs) const; + STRING_EXTENSION(SBSymbol) + #ifdef SWIGPYTHON %pythoncode %{ def get_instructions_from_current_target (self): diff --git a/lldb/scripts/interface/SBSymbolContext.i b/lldb/bindings/interface/SBSymbolContext.i similarity index 99% rename from lldb/scripts/interface/SBSymbolContext.i rename to lldb/bindings/interface/SBSymbolContext.i index a6aa4d78bfe39..b6b336516c949 100644 --- a/lldb/scripts/interface/SBSymbolContext.i +++ b/lldb/bindings/interface/SBSymbolContext.i @@ -81,6 +81,7 @@ public: bool GetDescription (lldb::SBStream &description); + STRING_EXTENSION(SBSymbolContext) #ifdef SWIGPYTHON %pythoncode %{ diff --git a/lldb/scripts/interface/SBSymbolContextList.i b/lldb/bindings/interface/SBSymbolContextList.i similarity index 99% rename from lldb/scripts/interface/SBSymbolContextList.i rename to lldb/bindings/interface/SBSymbolContextList.i index 54adc659fa212..f5adcfcebfb56 100644 --- a/lldb/scripts/interface/SBSymbolContextList.i +++ b/lldb/bindings/interface/SBSymbolContextList.i @@ -60,6 +60,8 @@ public: void Clear(); + STRING_EXTENSION(SBSymbolContextList) + #ifdef SWIGPYTHON %pythoncode %{ def __iter__(self): diff --git a/lldb/scripts/interface/SBTarget.i b/lldb/bindings/interface/SBTarget.i similarity index 99% rename from lldb/scripts/interface/SBTarget.i rename to lldb/bindings/interface/SBTarget.i index b31622889e52f..371bf5c35ebd0 100644 --- a/lldb/scripts/interface/SBTarget.i +++ b/lldb/bindings/interface/SBTarget.i @@ -8,7 +8,6 @@ namespace lldb { - %feature("docstring", "Represents the target program running under the debugger. @@ -968,6 +967,8 @@ public: lldb::SBValue EvaluateExpression (const char *expr, const lldb::SBExpressionOptions &options); + STRING_EXTENSION_LEVEL(SBTarget, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ class modules_access(object): diff --git a/lldb/scripts/interface/SBThread.i b/lldb/bindings/interface/SBThread.i similarity index 99% rename from lldb/scripts/interface/SBThread.i rename to lldb/bindings/interface/SBThread.i index c1c045487fc1d..95b15b182ec26 100644 --- a/lldb/scripts/interface/SBThread.i +++ b/lldb/bindings/interface/SBThread.i @@ -402,6 +402,8 @@ public: bool SafeToCallFunctions (); + STRING_EXTENSION(SBThread) + #ifdef SWIGPYTHON %pythoncode %{ def __iter__(self): diff --git a/lldb/scripts/interface/SBThreadCollection.i b/lldb/bindings/interface/SBThreadCollection.i similarity index 100% rename from lldb/scripts/interface/SBThreadCollection.i rename to lldb/bindings/interface/SBThreadCollection.i diff --git a/lldb/scripts/interface/SBThreadPlan.i b/lldb/bindings/interface/SBThreadPlan.i similarity index 100% rename from lldb/scripts/interface/SBThreadPlan.i rename to lldb/bindings/interface/SBThreadPlan.i diff --git a/lldb/scripts/interface/SBTrace.i b/lldb/bindings/interface/SBTrace.i similarity index 100% rename from lldb/scripts/interface/SBTrace.i rename to lldb/bindings/interface/SBTrace.i diff --git a/lldb/scripts/interface/SBTraceOptions.i b/lldb/bindings/interface/SBTraceOptions.i similarity index 100% rename from lldb/scripts/interface/SBTraceOptions.i rename to lldb/bindings/interface/SBTraceOptions.i diff --git a/lldb/scripts/interface/SBType.i b/lldb/bindings/interface/SBType.i similarity index 98% rename from lldb/scripts/interface/SBType.i rename to lldb/bindings/interface/SBType.i index d9da9e39b9560..3cd82452084b4 100644 --- a/lldb/scripts/interface/SBType.i +++ b/lldb/bindings/interface/SBType.i @@ -43,6 +43,8 @@ public: uint32_t GetBitfieldSizeInBits(); + STRING_EXTENSION_LEVEL(SBTypeMember, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ name = property(GetName, None, doc='''A read only property that returns the name for this member as a string.''') @@ -100,6 +102,7 @@ public: GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); + STRING_EXTENSION_LEVEL(SBTypeMemberFunction, lldb::eDescriptionLevelBrief) protected: lldb::TypeMemberFunctionImplSP m_opaque_sp; }; @@ -314,6 +317,8 @@ public: bool operator!=(lldb::SBType &rhs); + STRING_EXTENSION_LEVEL(SBType, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ def template_arg_array(self): diff --git a/lldb/scripts/interface/SBTypeCategory.i b/lldb/bindings/interface/SBTypeCategory.i similarity index 99% rename from lldb/scripts/interface/SBTypeCategory.i rename to lldb/bindings/interface/SBTypeCategory.i index 43fe9faf70f52..b762bf8a95a36 100644 --- a/lldb/scripts/interface/SBTypeCategory.i +++ b/lldb/bindings/interface/SBTypeCategory.i @@ -124,6 +124,8 @@ namespace lldb { bool DeleteTypeSynthetic (lldb::SBTypeNameSpecifier); + STRING_EXTENSION_LEVEL(SBTypeCategory, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ diff --git a/lldb/scripts/interface/SBTypeEnumMember.i b/lldb/bindings/interface/SBTypeEnumMember.i similarity index 97% rename from lldb/scripts/interface/SBTypeEnumMember.i rename to lldb/bindings/interface/SBTypeEnumMember.i index b2d8617117823..006bdeaa8cee1 100644 --- a/lldb/scripts/interface/SBTypeEnumMember.i +++ b/lldb/bindings/interface/SBTypeEnumMember.i @@ -43,6 +43,7 @@ public: GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); + STRING_EXTENSION_LEVEL(SBTypeEnumMember, lldb::eDescriptionLevelBrief) #ifdef SWIGPYTHON %pythoncode %{ name = property(GetName, None, doc='''A read only property that returns the name for this enum member as a string.''') diff --git a/lldb/scripts/interface/SBTypeFilter.i b/lldb/bindings/interface/SBTypeFilter.i similarity index 95% rename from lldb/scripts/interface/SBTypeFilter.i rename to lldb/bindings/interface/SBTypeFilter.i index 3759e0a23d418..c1d282c6d4fbe 100644 --- a/lldb/scripts/interface/SBTypeFilter.i +++ b/lldb/bindings/interface/SBTypeFilter.i @@ -61,6 +61,8 @@ namespace lldb { bool operator != (lldb::SBTypeFilter &rhs); + STRING_EXTENSION_LEVEL(SBTypeFilter, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ options = property(GetOptions, SetOptions) diff --git a/lldb/scripts/interface/SBTypeFormat.i b/lldb/bindings/interface/SBTypeFormat.i similarity index 95% rename from lldb/scripts/interface/SBTypeFormat.i rename to lldb/bindings/interface/SBTypeFormat.i index 5efd135b73261..765a2a7bb99dc 100644 --- a/lldb/scripts/interface/SBTypeFormat.i +++ b/lldb/bindings/interface/SBTypeFormat.i @@ -61,6 +61,8 @@ namespace lldb { bool operator != (lldb::SBTypeFormat &rhs); + STRING_EXTENSION_LEVEL(SBTypeFormat, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ format = property(GetFormat, SetFormat) diff --git a/lldb/scripts/interface/SBTypeNameSpecifier.i b/lldb/bindings/interface/SBTypeNameSpecifier.i similarity index 94% rename from lldb/scripts/interface/SBTypeNameSpecifier.i rename to lldb/bindings/interface/SBTypeNameSpecifier.i index bb16e86b0bc50..772f7c174093f 100644 --- a/lldb/scripts/interface/SBTypeNameSpecifier.i +++ b/lldb/bindings/interface/SBTypeNameSpecifier.i @@ -53,6 +53,8 @@ namespace lldb { bool operator != (lldb::SBTypeNameSpecifier &rhs); + STRING_EXTENSION_LEVEL(SBTypeNameSpecifier, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ name = property(GetName) diff --git a/lldb/scripts/interface/SBTypeSummary.i b/lldb/bindings/interface/SBTypeSummary.i similarity index 97% rename from lldb/scripts/interface/SBTypeSummary.i rename to lldb/bindings/interface/SBTypeSummary.i index 225a404cf73c4..adcc79b5a6ee8 100644 --- a/lldb/scripts/interface/SBTypeSummary.i +++ b/lldb/bindings/interface/SBTypeSummary.i @@ -101,6 +101,8 @@ namespace lldb { bool operator != (lldb::SBTypeSummary &rhs); + STRING_EXTENSION_LEVEL(SBTypeSummary, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ options = property(GetOptions, SetOptions) diff --git a/lldb/scripts/interface/SBTypeSynthetic.i b/lldb/bindings/interface/SBTypeSynthetic.i similarity index 95% rename from lldb/scripts/interface/SBTypeSynthetic.i rename to lldb/bindings/interface/SBTypeSynthetic.i index d9d75e4c9efae..f57139ebf9f17 100644 --- a/lldb/scripts/interface/SBTypeSynthetic.i +++ b/lldb/bindings/interface/SBTypeSynthetic.i @@ -63,6 +63,8 @@ namespace lldb { bool operator != (lldb::SBTypeSynthetic &rhs); + STRING_EXTENSION_LEVEL(SBTypeSynthetic, lldb::eDescriptionLevelBrief) + #ifdef SWIGPYTHON %pythoncode %{ options = property(GetOptions, SetOptions) diff --git a/lldb/scripts/interface/SBUnixSignals.i b/lldb/bindings/interface/SBUnixSignals.i similarity index 100% rename from lldb/scripts/interface/SBUnixSignals.i rename to lldb/bindings/interface/SBUnixSignals.i diff --git a/lldb/scripts/interface/SBValue.i b/lldb/bindings/interface/SBValue.i similarity index 99% rename from lldb/scripts/interface/SBValue.i rename to lldb/bindings/interface/SBValue.i index 8647854e89c15..fb899805c3951 100644 --- a/lldb/scripts/interface/SBValue.i +++ b/lldb/bindings/interface/SBValue.i @@ -440,6 +440,8 @@ public: const SBExpressionOptions &options, const char *name) const; + STRING_EXTENSION(SBValue) + #ifdef SWIGPYTHON %pythoncode %{ def __get_dynamic__ (self): diff --git a/lldb/scripts/interface/SBValueList.i b/lldb/bindings/interface/SBValueList.i similarity index 85% rename from lldb/scripts/interface/SBValueList.i rename to lldb/bindings/interface/SBValueList.i index 56ef19054e4c5..17ba2056f0c23 100644 --- a/lldb/scripts/interface/SBValueList.i +++ b/lldb/bindings/interface/SBValueList.i @@ -101,6 +101,29 @@ public: lldb::SBValue GetFirstValueByName (const char* name) const; + %extend { + %nothreadallow; + std::string lldb::SBValueList::__str__ (){ + lldb::SBStream description; + const size_t n = $self->GetSize(); + if (n) + { + for (size_t i=0; i<n; ++i) + $self->GetValueAtIndex(i).GetDescription(description); + } + else + { + description.Printf("<empty> lldb.SBValueList()"); + } + 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; + return std::string(desc, desc_len); + } + %clearnothreadallow; + } + #ifdef SWIGPYTHON %pythoncode %{ def __iter__(self): diff --git a/lldb/scripts/interface/SBVariablesOptions.i b/lldb/bindings/interface/SBVariablesOptions.i similarity index 100% rename from lldb/scripts/interface/SBVariablesOptions.i rename to lldb/bindings/interface/SBVariablesOptions.i diff --git a/lldb/scripts/interface/SBWatchpoint.i b/lldb/bindings/interface/SBWatchpoint.i similarity index 96% rename from lldb/scripts/interface/SBWatchpoint.i rename to lldb/bindings/interface/SBWatchpoint.i index e11c4f213ca2e..cb0bc5f9859ac 100644 --- a/lldb/scripts/interface/SBWatchpoint.i +++ b/lldb/bindings/interface/SBWatchpoint.i @@ -90,6 +90,7 @@ public: static lldb::SBWatchpoint GetWatchpointFromEvent (const lldb::SBEvent& event); + STRING_EXTENSION_LEVEL(SBWatchpoint, lldb::eDescriptionLevelVerbose) }; } // namespace lldb diff --git a/lldb/scripts/interfaces.swig b/lldb/bindings/interfaces.swig similarity index 99% rename from lldb/scripts/interfaces.swig rename to lldb/bindings/interfaces.swig index cc6bb91febdac..780fe34392ff5 100644 --- a/lldb/scripts/interfaces.swig +++ b/lldb/bindings/interfaces.swig @@ -32,8 +32,8 @@ %include "./interface/SBEvent.i" %include "./interface/SBExecutionContext.i" %include "./interface/SBExpressionOptions.i" -%include "./interface/SBFileSpec.i" %include "./interface/SBFile.i" +%include "./interface/SBFileSpec.i" %include "./interface/SBFileSpecList.i" %include "./interface/SBFrame.i" %include "./interface/SBFunction.i" @@ -75,9 +75,8 @@ %include "./interface/SBTypeNameSpecifier.i" %include "./interface/SBTypeSummary.i" %include "./interface/SBTypeSynthetic.i" +%include "./interface/SBUnixSignals.i" %include "./interface/SBValue.i" %include "./interface/SBValueList.i" %include "./interface/SBVariablesOptions.i" %include "./interface/SBWatchpoint.i" -%include "./interface/SBUnixSignals.i" - diff --git a/lldb/scripts/lldb_lua.swig b/lldb/bindings/lua.swig similarity index 87% rename from lldb/scripts/lldb_lua.swig rename to lldb/bindings/lua.swig index 85edefff76f27..3b279a6b69e7f 100644 --- a/lldb/scripts/lldb_lua.swig +++ b/lldb/bindings/lua.swig @@ -8,6 +8,8 @@ %module lldb +%include <std_string.i> +%include "./macros.swig" %include "./headers.swig" %{ diff --git a/lldb/bindings/macros.swig b/lldb/bindings/macros.swig new file mode 100644 index 0000000000000..0387f27f3cb9b --- /dev/null +++ b/lldb/bindings/macros.swig @@ -0,0 +1,33 @@ +%define STRING_EXTENSION_LEVEL(Class, Level) +%extend { + %nothreadallow; + std::string lldb:: ## Class ## ::__str__(){ + lldb::SBStream stream; + $self->GetDescription (stream, Level); + const char *desc = stream.GetData(); + size_t desc_len = stream.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) { + --desc_len; + } + return std::string(desc, desc_len); + } + %clearnothreadallow; +} +%enddef + +%define STRING_EXTENSION(Class) +%extend { + %nothreadallow; + std::string lldb:: ## Class ## ::__str__(){ + lldb::SBStream stream; + $self->GetDescription (stream); + const char *desc = stream.GetData(); + size_t desc_len = stream.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) { + --desc_len; + } + return std::string(desc, desc_len); + } + %clearnothreadallow; +} +%enddef diff --git a/lldb/scripts/lldb.swig b/lldb/bindings/python.swig similarity index 87% rename from lldb/scripts/lldb.swig rename to lldb/bindings/python.swig index f030116b6cb8e..b086d436e57ba 100644 --- a/lldb/scripts/lldb.swig +++ b/lldb/bindings/python.swig @@ -59,6 +59,23 @@ except ImportError: // Parameter types will be used in the autodoc string. %feature("autodoc", "1"); +%define ARRAYHELPER(type,name) +%inline %{ +type *new_ ## name (int nitems) { + return (type *) malloc(sizeof(type)*nitems); +} +void delete_ ## name(type *t) { + free(t); +} +type name ## _get(type *t, int index) { + return t[index]; +} +void name ## _set(type *t, int index, type val) { + t[index] = val; +} +%} +%enddef + %pythoncode%{ import uuid import re @@ -93,20 +110,22 @@ def lldb_iter(obj, getsize, getelem): yield elem(i) %} -%include "./Python/python-typemaps.swig" +%include <std_string.i> +%include "./python/python-typemaps.swig" +%include "./macros.swig" %include "./headers.swig" %{ #include "../source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h" -#include "../scripts/Python/python-swigsafecast.swig" +#include "../bindings/python/python-swigsafecast.swig" using namespace lldb_private; using namespace lldb_private::python; using namespace lldb; %} %include "./interfaces.swig" -%include "./Python/python-extensions.swig" -%include "./Python/python-wrapper.swig" +%include "./python/python-extensions.swig" +%include "./python/python-wrapper.swig" %pythoncode%{ debugger_unique_id = 0 diff --git a/lldb/scripts/Python/createPythonInit.py b/lldb/bindings/python/createPythonInit.py similarity index 100% rename from lldb/scripts/Python/createPythonInit.py rename to lldb/bindings/python/createPythonInit.py diff --git a/lldb/bindings/python/python-extensions.swig b/lldb/bindings/python/python-extensions.swig new file mode 100644 index 0000000000000..0b23fdd400068 --- /dev/null +++ b/lldb/bindings/python/python-extensions.swig @@ -0,0 +1,592 @@ +%extend lldb::SBBreakpoint { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBBroadcaster { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBCommandReturnObject { + /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage + they are meant to make an SBCommandReturnObject into a file-like object so that instructions of the sort + print >>sb_command_return_object, "something" + will work correctly */ + + void lldb::SBCommandReturnObject::write (const char* str) + { + if (str) + $self->Printf("%s",str); + } + void lldb::SBCommandReturnObject::flush () + {} +} + +%extend lldb::SBCompileUnit { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBDeclaration { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBFunction { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBLineEntry { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBModule { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBSection { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} +%extend lldb::SBStream { + /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage + they are meant to make an SBStream into a file-like object so that instructions of the sort + print >>sb_stream, "something" + will work correctly */ + + void lldb::SBStream::write (const char* str) + { + if (str) + $self->Printf("%s",str); + } + void lldb::SBStream::flush () + {} +} +%extend lldb::SBSymbol { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBTarget { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBTypeFilter { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBTypeNameSpecifier { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBTypeSummary { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBTypeSynthetic { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%extend lldb::SBThread { + %pythoncode %{ + def __eq__(self, rhs): + if not isinstance(rhs, type(self)): + return False + + return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) + + def __ne__(self, rhs): + if not isinstance(rhs, type(self)): + return True + + return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) + %} +} + +%pythoncode %{ + +def command(command_name=None, doc=None): + import lldb + """A decorator function that registers an LLDB command line + command that is bound to the function it is attached to.""" + def callable(function): + """Registers an lldb command for the decorated function.""" + command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name or function.__name__) + lldb.debugger.HandleCommand(command) + if doc: + function.__doc__ = doc + return function + + return callable + +class declaration(object): + '''A class that represents a source declaration location with file, line and column.''' + def __init__(self, file, line, col): + self.file = file + self.line = line + self.col = col + +class value_iter(object): + def __iter__(self): + return self + + def __next__(self): + if self.index >= self.length: + raise StopIteration() + child_sbvalue = self.sbvalue.GetChildAtIndex(self.index) + self.index += 1 + return value(child_sbvalue) + + def next(self): + return self.__next__() + + def __init__(self,value): + self.index = 0 + self.sbvalue = value + if type(self.sbvalue) is value: + self.sbvalue = self.sbvalue.sbvalue + self.length = self.sbvalue.GetNumChildren() + +class value(object): + '''A class designed to wrap lldb.SBValue() objects so the resulting object + can be used as a variable would be in code. So if you have a Point structure + variable in your code in the current frame named "pt", you can initialize an instance + of this class with it: + + pt = lldb.value(lldb.frame.FindVariable("pt")) + print pt + print pt.x + print pt.y + + pt = lldb.value(lldb.frame.FindVariable("rectangle_array")) + print rectangle_array[12] + print rectangle_array[5].origin.x''' + def __init__(self, sbvalue): + self.sbvalue = sbvalue + + def __nonzero__(self): + return self.sbvalue.__nonzero__() + + def __bool__(self): + return self.sbvalue.__bool__() + + def __str__(self): + return self.sbvalue.__str__() + + def __getitem__(self, key): + # Allow array access if this value has children... + if type(key) is value: + key = int(key) + if type(key) is int: + child_sbvalue = (self.sbvalue.GetValueForExpressionPath("[%i]" % key)) + if child_sbvalue and child_sbvalue.IsValid(): + return value(child_sbvalue) + raise IndexError("Index '%d' is out of range" % key) + raise TypeError("No array item of type %s" % str(type(key))) + + def __iter__(self): + return value_iter(self.sbvalue) + + def __getattr__(self, name): + child_sbvalue = self.sbvalue.GetChildMemberWithName (name) + if child_sbvalue and child_sbvalue.IsValid(): + return value(child_sbvalue) + raise AttributeError("Attribute '%s' is not defined" % name) + + def __add__(self, other): + return int(self) + int(other) + + def __sub__(self, other): + return int(self) - int(other) + + def __mul__(self, other): + return int(self) * int(other) + + def __floordiv__(self, other): + return int(self) // int(other) + + def __mod__(self, other): + return int(self) % int(other) + + def __divmod__(self, other): + return int(self) % int(other) + + def __pow__(self, other): + return int(self) ** int(other) + + def __lshift__(self, other): + return int(self) << int(other) + + def __rshift__(self, other): + return int(self) >> int(other) + + def __and__(self, other): + return int(self) & int(other) + + def __xor__(self, other): + return int(self) ^ int(other) + + def __or__(self, other): + return int(self) | int(other) + + def __div__(self, other): + return int(self) / int(other) + + def __truediv__(self, other): + return int(self) / int(other) + + def __iadd__(self, other): + result = self.__add__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __isub__(self, other): + result = self.__sub__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __imul__(self, other): + result = self.__mul__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __idiv__(self, other): + result = self.__div__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __itruediv__(self, other): + result = self.__truediv__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ifloordiv__(self, other): + result = self.__floordiv__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __imod__(self, other): + result = self.__and__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ipow__(self, other): + result = self.__pow__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ipow__(self, other, modulo): + result = self.__pow__(self, other, modulo) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ilshift__(self, other): + result = self.__lshift__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __irshift__(self, other): + result = self.__rshift__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __iand__(self, other): + result = self.__and__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ixor__(self, other): + result = self.__xor__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ior__(self, other): + result = self.__ior__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __neg__(self): + return -int(self) + + def __pos__(self): + return +int(self) + + def __abs__(self): + return abs(int(self)) + + def __invert__(self): + return ~int(self) + + def __complex__(self): + 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.__int__() + + def __float__(self): + return float (self.sbvalue.GetValueAsSigned()) + + def __oct__(self): + return '0%o' % self.sbvalue.GetValueAsUnsigned() + + def __hex__(self): + return '0x%x' % self.sbvalue.GetValueAsUnsigned() + + def __len__(self): + return self.sbvalue.GetNumChildren() + + def __eq__(self, other): + if type(other) is int: + return int(self) == other + elif type(other) is str: + return str(self) == other + elif type(other) is value: + self_err = SBError() + other_err = SBError() + self_val = self.sbvalue.GetValueAsUnsigned(self_err) + if self_err.fail: + raise ValueError("unable to extract value of self") + other_val = other.sbvalue.GetValueAsUnsigned(other_err) + if other_err.fail: + raise ValueError("unable to extract value of other") + return self_val == other_val + raise TypeError("Unknown type %s, No equality operation defined." % str(type(other))) + + def __ne__(self, other): + return not self.__eq__(other) +%} + +%pythoncode %{ + +class SBSyntheticValueProvider(object): + def __init__(self,valobj): + pass + + def num_children(self): + return 0 + + def get_child_index(self,name): + return None + + def get_child_at_index(self,idx): + return None + + def update(self): + pass + + def has_children(self): + return False + + +%} + +%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/lldb/scripts/Python/python-swigsafecast.swig b/lldb/bindings/python/python-swigsafecast.swig similarity index 100% rename from lldb/scripts/Python/python-swigsafecast.swig rename to lldb/bindings/python/python-swigsafecast.swig diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig similarity index 100% rename from lldb/scripts/Python/python-typemaps.swig rename to lldb/bindings/python/python-typemaps.swig diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig similarity index 100% rename from lldb/scripts/Python/python-wrapper.swig rename to lldb/bindings/python/python-wrapper.swig diff --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt index 0082d004bd0d6..8fa46860e5cec 100644 --- a/lldb/docs/CMakeLists.txt +++ b/lldb/docs/CMakeLists.txt @@ -30,9 +30,9 @@ if (LLDB_ENABLE_PYTHON) # Because we don't build liblldb, epydoc will complain that the import of # _lldb.so failed, but that doesn't prevent it from generating the docs. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lldb) - get_target_property(lldb_scripts_dir swig_wrapper BINARY_DIR) + get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR) add_custom_target(lldb-python-doc-package - COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_scripts_dir}/lldb.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py" + COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_bindings_dir}/lldb.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py" COMMENT "Copying lldb.py to pretend package.") add_dependencies(lldb-python-doc-package swig_wrapper) diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig deleted file mode 100644 index c10c32b448774..0000000000000 --- a/lldb/scripts/Python/python-extensions.swig +++ /dev/null @@ -1,1122 +0,0 @@ - -%extend lldb::SBAddress { - %nothreadallow; - PyObject *lldb::SBAddress::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBBlock { - %nothreadallow; - PyObject *lldb::SBBlock::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBBreakpoint { - %nothreadallow; - PyObject *lldb::SBBreakpoint::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} - -} -%extend lldb::SBBreakpointLocation { - %nothreadallow; - PyObject *lldb::SBBreakpointLocation::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelFull); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} - -%extend lldb::SBBreakpointName { - %nothreadallow; - PyObject *lldb::SBBreakpointName::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} - -%extend lldb::SBBroadcaster { - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} - -%extend lldb::SBCommandReturnObject { - %nothreadallow; - PyObject *lldb::SBCommandReturnObject::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage - they are meant to make an SBCommandReturnObject into a file-like object so that instructions of the sort - print >>sb_command_return_object, "something" - will work correctly */ - - void lldb::SBCommandReturnObject::write (const char* str) - { - if (str) - $self->Printf("%s",str); - } - void lldb::SBCommandReturnObject::flush () - {} -} -%extend lldb::SBCompileUnit { - %nothreadallow; - PyObject *lldb::SBCompileUnit::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBData { - %nothreadallow; - PyObject *lldb::SBData::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBDebugger { - %nothreadallow; - PyObject *lldb::SBDebugger::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBDeclaration { - %nothreadallow; - PyObject *lldb::SBDeclaration::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} - -} -%extend lldb::SBError { - %nothreadallow; - PyObject *lldb::SBError::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBFileSpec { - %nothreadallow; - PyObject *lldb::SBFileSpec::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBFrame { - %nothreadallow; - PyObject *lldb::SBFrame::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBFunction { - %nothreadallow; - PyObject *lldb::SBFunction::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} - -} -%extend lldb::SBInstruction { - %nothreadallow; - PyObject *lldb::SBInstruction::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBInstructionList { - %nothreadallow; - PyObject *lldb::SBInstructionList::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBLineEntry { - %nothreadallow; - PyObject *lldb::SBLineEntry::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} - -%extend lldb::SBMemoryRegionInfo { - %nothreadallow; - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} - -%extend lldb::SBModule { - %nothreadallow; - PyObject *lldb::SBModule::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} - -%extend lldb::SBModuleSpec { - %nothreadallow; - PyObject *lldb::SBModuleSpec::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} - -%extend lldb::SBModuleSpecList { - %nothreadallow; - PyObject *lldb::SBModuleSpecList::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} - -%extend lldb::SBProcess { - %nothreadallow; - PyObject *lldb::SBProcess::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBSection { - %nothreadallow; - PyObject *lldb::SBSection::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBStream { - /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage - they are meant to make an SBStream into a file-like object so that instructions of the sort - print >>sb_stream, "something" - will work correctly */ - - void lldb::SBStream::write (const char* str) - { - if (str) - $self->Printf("%s",str); - } - void lldb::SBStream::flush () - {} -} -%extend lldb::SBSymbol { - %nothreadallow; - PyObject *lldb::SBSymbol::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBSymbolContext { - %nothreadallow; - PyObject *lldb::SBSymbolContext::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBSymbolContextList { - %nothreadallow; - PyObject *lldb::SBSymbolContextList::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} - -%extend lldb::SBTarget { - %nothreadallow; - PyObject *lldb::SBTarget::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} - -%extend lldb::SBType { - %nothreadallow; - PyObject *lldb::SBType::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBTypeCategory { - %nothreadallow; - PyObject *lldb::SBTypeCategory::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBTypeFilter { - %nothreadallow; - PyObject *lldb::SBTypeFilter::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBTypeFormat { - %nothreadallow; - PyObject *lldb::SBTypeFormat::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBTypeMember { - %nothreadallow; - PyObject *lldb::SBTypeMember::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBTypeMemberFunction { - %nothreadallow; - PyObject *lldb::SBTypeMemberFunction::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBTypeEnumMember { - %nothreadallow; - PyObject *lldb::SBTypeEnumMember::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBTypeNameSpecifier { - %nothreadallow; - PyObject *lldb::SBTypeNameSpecifier::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBTypeSummary { - %nothreadallow; - PyObject *lldb::SBTypeSummary::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBTypeSynthetic { - %nothreadallow; - PyObject *lldb::SBTypeSynthetic::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelBrief); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBThread { - %nothreadallow; - PyObject *lldb::SBThread::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; - %pythoncode %{ - def __eq__(self, rhs): - if not isinstance(rhs, type(self)): - return False - - return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) - - def __ne__(self, rhs): - if not isinstance(rhs, type(self)): - return True - - return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) - %} -} -%extend lldb::SBValue { - %nothreadallow; - PyObject *lldb::SBValue::__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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBValueList { - %nothreadallow; - PyObject *lldb::SBValueList::__str__ (){ - lldb::SBStream description; - const size_t n = $self->GetSize(); - if (n) - { - for (size_t i=0; i<n; ++i) - $self->GetValueAtIndex(i).GetDescription(description); - } - else - { - description.Printf("<empty> lldb.SBValueList()"); - } - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} -%extend lldb::SBWatchpoint { - %nothreadallow; - PyObject *lldb::SBWatchpoint::__str__ (){ - lldb::SBStream description; - $self->GetDescription (description, lldb::eDescriptionLevelVerbose); - 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; - return PythonString(llvm::StringRef(desc, desc_len)).release(); - } - %clearnothreadallow; -} - - -// %extend lldb::SBDebugger { -// // FIXME: We can't get the callback and baton -// PyObject *lldb::SBDebugger (){ -// // Only call Py_XDECREF if we have a Python object (or NULL) -// if (LLDBSwigPythonCallPythonLogOutputCallback == $self->GetLogOutPutCallback()) -// Py_XDECREF($self->GetCallbackBaton()); -// } -// } - -%pythoncode %{ - -def command(command_name=None, doc=None): - import lldb - """A decorator function that registers an LLDB command line - command that is bound to the function it is attached to.""" - def callable(function): - """Registers an lldb command for the decorated function.""" - command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name or function.__name__) - lldb.debugger.HandleCommand(command) - if doc: - function.__doc__ = doc - return function - - return callable - -class declaration(object): - '''A class that represents a source declaration location with file, line and column.''' - def __init__(self, file, line, col): - self.file = file - self.line = line - self.col = col - -class value_iter(object): - def __iter__(self): - return self - - def __next__(self): - if self.index >= self.length: - raise StopIteration() - child_sbvalue = self.sbvalue.GetChildAtIndex(self.index) - self.index += 1 - return value(child_sbvalue) - - def next(self): - return self.__next__() - - def __init__(self,value): - self.index = 0 - self.sbvalue = value - if type(self.sbvalue) is value: - self.sbvalue = self.sbvalue.sbvalue - self.length = self.sbvalue.GetNumChildren() - -class value(object): - '''A class designed to wrap lldb.SBValue() objects so the resulting object - can be used as a variable would be in code. So if you have a Point structure - variable in your code in the current frame named "pt", you can initialize an instance - of this class with it: - - pt = lldb.value(lldb.frame.FindVariable("pt")) - print pt - print pt.x - print pt.y - - pt = lldb.value(lldb.frame.FindVariable("rectangle_array")) - print rectangle_array[12] - print rectangle_array[5].origin.x''' - def __init__(self, sbvalue): - self.sbvalue = sbvalue - - def __nonzero__(self): - return self.sbvalue.__nonzero__() - - def __bool__(self): - return self.sbvalue.__bool__() - - def __str__(self): - return self.sbvalue.__str__() - - def __getitem__(self, key): - # Allow array access if this value has children... - if type(key) is value: - key = int(key) - if type(key) is int: - child_sbvalue = (self.sbvalue.GetValueForExpressionPath("[%i]" % key)) - if child_sbvalue and child_sbvalue.IsValid(): - return value(child_sbvalue) - raise IndexError("Index '%d' is out of range" % key) - raise TypeError("No array item of type %s" % str(type(key))) - - def __iter__(self): - return value_iter(self.sbvalue) - - def __getattr__(self, name): - child_sbvalue = self.sbvalue.GetChildMemberWithName (name) - if child_sbvalue and child_sbvalue.IsValid(): - return value(child_sbvalue) - raise AttributeError("Attribute '%s' is not defined" % name) - - def __add__(self, other): - return int(self) + int(other) - - def __sub__(self, other): - return int(self) - int(other) - - def __mul__(self, other): - return int(self) * int(other) - - def __floordiv__(self, other): - return int(self) // int(other) - - def __mod__(self, other): - return int(self) % int(other) - - def __divmod__(self, other): - return int(self) % int(other) - - def __pow__(self, other): - return int(self) ** int(other) - - def __lshift__(self, other): - return int(self) << int(other) - - def __rshift__(self, other): - return int(self) >> int(other) - - def __and__(self, other): - return int(self) & int(other) - - def __xor__(self, other): - return int(self) ^ int(other) - - def __or__(self, other): - return int(self) | int(other) - - def __div__(self, other): - return int(self) / int(other) - - def __truediv__(self, other): - return int(self) / int(other) - - def __iadd__(self, other): - result = self.__add__(other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __isub__(self, other): - result = self.__sub__(other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __imul__(self, other): - result = self.__mul__(other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __idiv__(self, other): - result = self.__div__(other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __itruediv__(self, other): - result = self.__truediv__(other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __ifloordiv__(self, other): - result = self.__floordiv__(self, other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __imod__(self, other): - result = self.__and__(self, other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __ipow__(self, other): - result = self.__pow__(self, other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __ipow__(self, other, modulo): - result = self.__pow__(self, other, modulo) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __ilshift__(self, other): - result = self.__lshift__(other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __irshift__(self, other): - result = self.__rshift__(other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __iand__(self, other): - result = self.__and__(self, other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __ixor__(self, other): - result = self.__xor__(self, other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __ior__(self, other): - result = self.__ior__(self, other) - self.sbvalue.SetValueFromCString (str(result)) - return result - - def __neg__(self): - return -int(self) - - def __pos__(self): - return +int(self) - - def __abs__(self): - return abs(int(self)) - - def __invert__(self): - return ~int(self) - - def __complex__(self): - 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.__int__() - - def __float__(self): - return float (self.sbvalue.GetValueAsSigned()) - - def __oct__(self): - return '0%o' % self.sbvalue.GetValueAsUnsigned() - - def __hex__(self): - return '0x%x' % self.sbvalue.GetValueAsUnsigned() - - def __len__(self): - return self.sbvalue.GetNumChildren() - - def __eq__(self, other): - if type(other) is int: - return int(self) == other - elif type(other) is str: - return str(self) == other - elif type(other) is value: - self_err = SBError() - other_err = SBError() - self_val = self.sbvalue.GetValueAsUnsigned(self_err) - if self_err.fail: - raise ValueError("unable to extract value of self") - other_val = other.sbvalue.GetValueAsUnsigned(other_err) - if other_err.fail: - raise ValueError("unable to extract value of other") - return self_val == other_val - raise TypeError("Unknown type %s, No equality operation defined." % str(type(other))) - - def __ne__(self, other): - return not self.__eq__(other) -%} - -%pythoncode %{ - -class SBSyntheticValueProvider(object): - def __init__(self,valobj): - pass - - def num_children(self): - return 0 - - def get_child_index(self,name): - return None - - def get_child_at_index(self,idx): - return None - - def update(self): - pass - - def has_children(self): - return False - - -%} - -%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/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index eea409bed185a..e0ecf29b502b7 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -5,13 +5,13 @@ endif() get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS) if(LLDB_ENABLE_PYTHON) - get_target_property(lldb_scripts_dir swig_wrapper BINARY_DIR) - set(lldb_python_wrapper ${lldb_scripts_dir}/LLDBWrapPython.cpp) + get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR) + set(lldb_python_wrapper ${lldb_bindings_dir}/LLDBWrapPython.cpp) endif() if(LLDB_ENABLE_LUA) - get_target_property(lldb_scripts_dir swig_wrapper_lua BINARY_DIR) - set(lldb_lua_wrapper ${lldb_scripts_dir}/LLDBWrapLua.cpp) + get_target_property(lldb_bindings_dir swig_wrapper_lua BINARY_DIR) + set(lldb_lua_wrapper ${lldb_bindings_dir}/LLDBWrapLua.cpp) endif() if(LLDB_BUILD_FRAMEWORK)