diff --git a/lldb/bindings/interface/SBAddressDocstrings.i b/lldb/bindings/interface/SBAddressDocstrings.i new file mode 100644 --- /dev/null +++ b/lldb/bindings/interface/SBAddressDocstrings.i @@ -0,0 +1,56 @@ +%feature("docstring", +"A section + offset based address class. + +The SBAddress class allows addresses to be relative to a section +that can move during runtime due to images (executables, shared +libraries, bundles, frameworks) being loaded at different +addresses than the addresses found in the object file that +represents them on disk. There are currently two types of addresses +for a section: + +* file addresses +* load addresses + +File addresses represents the virtual addresses that are in the 'on +disk' object files. These virtual addresses are converted to be +relative to unique sections scoped to the object file so that +when/if the addresses slide when the images are loaded/unloaded +in memory, we can easily track these changes without having to +update every object (compile unit ranges, line tables, function +address ranges, lexical block and inlined subroutine address +ranges, global and static variables) each time an image is loaded or +unloaded. + +Load addresses represents the virtual addresses where each section +ends up getting loaded at runtime. Before executing a program, it +is common for all of the load addresses to be unresolved. When a +DynamicLoader plug-in receives notification that shared libraries +have been loaded/unloaded, the load addresses of the main executable +and any images (shared libraries) will be resolved/unresolved. When +this happens, breakpoints that are in one of these sections can be +set/cleared. + +See docstring of SBFunction for example usage of SBAddress." +) lldb::SBAddress; + +%feature("docstring", " +Create an address by resolving a load address using the supplied target.") +lldb::SBAddress::SBAddress; + +%feature("docstring", " +GetSymbolContext() and the following can lookup symbol information for a given address. +An address might refer to code or data from an existing module, or it +might refer to something on the stack or heap. The following functions +will only return valid values if the address has been resolved to a code +or data address using :py:class:`SBAddress.SetLoadAddress' or +:py:class:`SBTarget.ResolveLoadAddress`.") lldb::SBAddress::GetSymbolContext; + +%feature("docstring", " +GetModule() and the following grab individual objects for a given address and +are less efficient if you want more than one symbol related objects. +Use :py:class:`SBAddress.GetSymbolContext` or +:py:class:`SBTarget.ResolveSymbolContextForAddress` when you want multiple +debug symbol related objects for an address. +One or more bits from the SymbolContextItem enumerations can be logically +OR'ed together to more efficiently retrieve multiple symbol objects.") +lldb::SBAddress::GetModule; diff --git a/lldb/bindings/interface/SBAddress.i b/lldb/bindings/interface/SBAddressExtensions.i rename from lldb/bindings/interface/SBAddress.i rename to lldb/bindings/interface/SBAddressExtensions.i --- a/lldb/bindings/interface/SBAddress.i +++ b/lldb/bindings/interface/SBAddressExtensions.i @@ -1,69 +1,6 @@ -//===-- SWIG Interface for SBAddress ----------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -namespace lldb { - -%feature("docstring", -"A section + offset based address class. - -The SBAddress class allows addresses to be relative to a section -that can move during runtime due to images (executables, shared -libraries, bundles, frameworks) being loaded at different -addresses than the addresses found in the object file that -represents them on disk. There are currently two types of addresses -for a section: - -* file addresses -* load addresses - -File addresses represents the virtual addresses that are in the 'on -disk' object files. These virtual addresses are converted to be -relative to unique sections scoped to the object file so that -when/if the addresses slide when the images are loaded/unloaded -in memory, we can easily track these changes without having to -update every object (compile unit ranges, line tables, function -address ranges, lexical block and inlined subroutine address -ranges, global and static variables) each time an image is loaded or -unloaded. - -Load addresses represents the virtual addresses where each section -ends up getting loaded at runtime. Before executing a program, it -is common for all of the load addresses to be unresolved. When a -DynamicLoader plug-in receives notification that shared libraries -have been loaded/unloaded, the load addresses of the main executable -and any images (shared libraries) will be resolved/unresolved. When -this happens, breakpoints that are in one of these sections can be -set/cleared. - -See docstring of SBFunction for example usage of SBAddress." -) SBAddress; -class SBAddress -{ -public: - - SBAddress (); - - SBAddress (const lldb::SBAddress &rhs); - - SBAddress (lldb::SBSection section, - lldb::addr_t offset); - - %feature("docstring", " - Create an address by resolving a load address using the supplied target.") SBAddress; - SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target); - - ~SBAddress (); - - bool - IsValid () const; - - explicit operator bool() const; +STRING_EXTENSION_OUTSIDE(SBAddress) +%extend lldb::SBAddress { #ifdef SWIGPYTHON // operator== is a free function, which swig does not handle, so we inject // our own equality operator here @@ -71,78 +8,7 @@ def __eq__(self, other): return not self.__ne__(other) %} -#endif - - bool operator!=(const SBAddress &rhs) const; - - void - Clear (); - - addr_t - GetFileAddress () const; - addr_t - GetLoadAddress (const lldb::SBTarget &target) const; - - void - SetLoadAddress (lldb::addr_t load_addr, - lldb::SBTarget &target); - - bool - OffsetAddress (addr_t offset); - - bool - GetDescription (lldb::SBStream &description); - - lldb::SBSection - GetSection (); - - lldb::addr_t - SBAddress::GetOffset (); - - void - SetAddress (lldb::SBSection section, - lldb::addr_t offset); - - %feature("docstring", " - GetSymbolContext() and the following can lookup symbol information for a given address. - An address might refer to code or data from an existing module, or it - might refer to something on the stack or heap. The following functions - will only return valid values if the address has been resolved to a code - or data address using :py:class:`SBAddress.SetLoadAddress' or - :py:class:`SBTarget.ResolveLoadAddress`.") GetSymbolContext; - lldb::SBSymbolContext - GetSymbolContext (uint32_t resolve_scope); - - %feature("docstring", " - GetModule() and the following grab individual objects for a given address and - are less efficient if you want more than one symbol related objects. - Use :py:class:`SBAddress.GetSymbolContext` or - :py:class:`SBTarget.ResolveSymbolContextForAddress` when you want multiple - debug symbol related objects for an address. - One or more bits from the SymbolContextItem enumerations can be logically - OR'ed together to more efficiently retrieve multiple symbol objects.") GetModule; - lldb::SBModule - GetModule (); - - lldb::SBCompileUnit - GetCompileUnit (); - - lldb::SBFunction - GetFunction (); - - lldb::SBBlock - GetBlock (); - - lldb::SBSymbol - GetSymbol (); - - lldb::SBLineEntry - GetLineEntry (); - - STRING_EXTENSION(SBAddress) - -#ifdef SWIGPYTHON %pythoncode %{ __runtime_error_str = 'This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.' @@ -186,7 +52,4 @@ load_addr = property(__get_load_addr_property__, __set_load_addr_property__, doc='''A read/write property that gets/sets the SBAddress using load address. This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.''') %} #endif - -}; - -} // namespace lldb +} diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig --- a/lldb/bindings/interfaces.swig +++ b/lldb/bindings/interfaces.swig @@ -11,7 +11,7 @@ %include "lldb/API/SBDefines.h" /* Python interface files with docstrings. */ -%include "./interface/SBAddress.i" +%include "lldb/API/SBAddress.h" %include "./interface/SBAttachInfo.i" %include "./interface/SBBlock.i" %include "./interface/SBBreakpoint.i" diff --git a/lldb/bindings/macros.swig b/lldb/bindings/macros.swig --- a/lldb/bindings/macros.swig +++ b/lldb/bindings/macros.swig @@ -27,3 +27,22 @@ } } %enddef + +// NOTE: +// This is for when you are peforming the extension from outside of the class +// instead of inside of it. If this change works out, it will replace +// STRING_EXTENSION entirely. +%define STRING_EXTENSION_OUTSIDE(Class) +%extend lldb:: ## Class ## { + std::string __repr__(){ + 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); + } +} +%enddef diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -83,10 +83,13 @@ get_filename_component(basename ${header} NAME) set(staged_header ${lldb_header_staging}/${basename}) + # unifdef returns 0 when the file is unchanged and 1 if something was changed. + # That means if we successfully remove SWIG code, the build system believes + # that the command has failed and stops. This is undesirable. add_custom_command( DEPENDS ${header} OUTPUT ${staged_header} - COMMAND ${CMAKE_COMMAND} -E copy ${header} ${staged_header} - COMMENT "LLDB.framework: collect framework header") + COMMAND unifdef -USWIG -o ${staged_header} ${header} || (exit 0) + COMMENT "LLDB.framework: collect framework header and remove SWIG macros") list(APPEND lldb_staged_headers ${staged_header}) endforeach() diff --git a/lldb/include/lldb/API/SBAddress.h b/lldb/include/lldb/API/SBAddress.h --- a/lldb/include/lldb/API/SBAddress.h +++ b/lldb/include/lldb/API/SBAddress.h @@ -11,6 +11,9 @@ #include "lldb/API/SBDefines.h" #include "lldb/API/SBModule.h" +#ifdef SWIG +%include "interface/SBAddressDocstrings.i" +#endif namespace lldb { @@ -27,7 +30,9 @@ ~SBAddress(); +#ifndef SWIG const lldb::SBAddress &operator=(const lldb::SBAddress &rhs); +#endif explicit operator bool() const; @@ -107,7 +112,9 @@ const lldb_private::Address *operator->() const; +#ifndef SWIG friend bool LLDB_API operator==(const SBAddress &lhs, const SBAddress &rhs); +#endif lldb_private::Address *get(); @@ -123,8 +130,13 @@ std::unique_ptr m_opaque_up; }; +#ifndef SWIG bool LLDB_API operator==(const SBAddress &lhs, const SBAddress &rhs); +#endif } // namespace lldb +#ifdef SWIG +%include "interface/SBAddressExtensions.i" +#endif #endif // LLDB_API_SBADDRESS_H