diff options
33 files changed, 1172 insertions, 158 deletions
diff --git a/lldb/include/lldb/API/SBAddress.h b/lldb/include/lldb/API/SBAddress.h index e8a32a654ed..2d34fa5f63c 100644 --- a/lldb/include/lldb/API/SBAddress.h +++ b/lldb/include/lldb/API/SBAddress.h @@ -54,9 +54,6 @@ public: bool GetDescription (lldb::SBStream &description); - SectionType - GetSectionType (); - // The following queries 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 @@ -76,6 +73,9 @@ public: // One or more bits from the SymbolContextItem enumerations can be logically // OR'ed together to more efficiently retrieve multiple symbol objects. + lldb::SBSection + GetSection (); + lldb::SBModule GetModule (); @@ -102,6 +102,7 @@ protected: friend class SBLineEntry; friend class SBInstruction; friend class SBModule; + friend class SBSection; friend class SBSymbol; friend class SBSymbolContext; friend class SBTarget; @@ -135,7 +136,7 @@ protected: private: - std::auto_ptr<lldb_private::Address> m_opaque_ap; + std::auto_ptr<lldb_private::AddressImpl> m_opaque_ap; }; diff --git a/lldb/include/lldb/API/SBData.h b/lldb/include/lldb/API/SBData.h index 63673153460..a2006482e92 100644 --- a/lldb/include/lldb/API/SBData.h +++ b/lldb/include/lldb/API/SBData.h @@ -126,7 +126,8 @@ protected: private: friend class SBValue; - + friend class SBSection; + lldb::DataExtractorSP m_opaque_sp; }; diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h index e71795b9ca8..6b4fff678e2 100644 --- a/lldb/include/lldb/API/SBDebugger.h +++ b/lldb/include/lldb/API/SBDebugger.h @@ -100,6 +100,13 @@ public: FILE *err); lldb::SBTarget + CreateTarget (const char *filename, + const char *target_triple, + const char *platform_name, + bool add_dependent_modules, + lldb::SBError& error); + + lldb::SBTarget CreateTargetWithFileAndTargetTriple (const char *filename, const char *target_triple); diff --git a/lldb/include/lldb/API/SBModule.h b/lldb/include/lldb/API/SBModule.h index ba4f4e94c76..de7cd3af53a 100644 --- a/lldb/include/lldb/API/SBModule.h +++ b/lldb/include/lldb/API/SBModule.h @@ -11,6 +11,8 @@ #define LLDB_SBModule_h_ #include "lldb/API/SBDefines.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBSection.h" #include "lldb/API/SBSymbolContext.h" #include "lldb/API/SBValueList.h" @@ -84,10 +86,11 @@ public: operator != (const lldb::SBModule &rhs) const; #endif + lldb::SBSection + FindSection (const char *sect_name); - bool - ResolveFileAddress (lldb::addr_t vm_addr, - lldb::SBAddress& addr); + lldb::SBAddress + ResolveFileAddress (lldb::addr_t vm_addr); lldb::SBSymbolContext ResolveSymbolContextForAddress (const lldb::SBAddress& addr, @@ -102,6 +105,11 @@ public: lldb::SBSymbol GetSymbolAtIndex (size_t idx); + size_t + GetNumSections (); + + lldb::SBSection + GetSectionAtIndex (size_t idx); //------------------------------------------------------------------ /// Find functions by name. /// @@ -162,6 +170,7 @@ public: private: friend class SBAddress; friend class SBFrame; + friend class SBSection; friend class SBSymbolContext; friend class SBTarget; @@ -187,6 +196,10 @@ private: const lldb_private::Module * get() const; + const lldb::ModuleSP & + get_sp() const; + + #endif lldb::ModuleSP m_opaque_sp; diff --git a/lldb/include/lldb/API/SBSection.h b/lldb/include/lldb/API/SBSection.h new file mode 100644 index 00000000000..a71086b74ce --- /dev/null +++ b/lldb/include/lldb/API/SBSection.h @@ -0,0 +1,97 @@ +//===-- SBSection.h ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_SBSection_h_ +#define LLDB_SBSection_h_ + +#include "lldb/API/SBDefines.h" +#include "lldb/API/SBData.h" + +namespace lldb { + +class SBSection +{ +public: + + SBSection (); + + SBSection (const lldb::SBSection &rhs); + + ~SBSection (); + +#ifndef SWIG + const lldb::SBSection & + operator = (const lldb::SBSection &rhs); +#endif + bool + IsValid () const; + + lldb::SBSection + FindSubSection (const char *sect_name); + + size_t + GetNumSubSections (); + + lldb::SBSection + GetSubSectionAtIndex (size_t idx); + + lldb::addr_t + GetFileAddress (); + + lldb::addr_t + GetByteSize (); + + uint64_t + GetFileOffset (); + + uint64_t + GetFileByteSize (); + + lldb::SBData + GetSectionData (uint64_t offset = 0, + uint64_t size = UINT64_MAX); + + SectionType + GetSectionType (); + +#ifndef SWIG + bool + operator == (const lldb::SBSection &rhs); + + bool + operator != (const lldb::SBSection &rhs); + +#endif + + bool + GetDescription (lldb::SBStream &description); + +private: + +#ifndef SWIG + friend class SBAddress; + friend class SBModule; + friend class SBTarget; + + SBSection (const lldb_private::Section *section); + + const lldb_private::Section * + GetSection(); + + void + SetSection (const lldb_private::Section *section); +#endif + + std::auto_ptr<lldb_private::SectionImpl> m_opaque_ap; +}; + + +} // namespace lldb + +#endif // LLDB_SBSection_h_ diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 2aadbd1afe6..b12185c83d5 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -237,12 +237,23 @@ public: lldb::SBFileSpec GetExecutable (); + bool + AddModule (lldb::SBModule &module); + + lldb::SBModule + AddModule (const char *path, + const char *triple, + const char *uuid); + uint32_t GetNumModules () const; lldb::SBModule GetModuleAtIndex (uint32_t idx); + bool + RemoveModule (lldb::SBModule module); + lldb::SBDebugger GetDebugger() const; @@ -250,6 +261,76 @@ public: FindModule (const lldb::SBFileSpec &file_spec); //------------------------------------------------------------------ + /// Set the base load address for a module section. + /// + /// @param[in] section + /// The section whose base load address will be set within this + /// target. + /// + /// @param[in] section_base_addr + /// The base address for the section. + /// + /// @return + /// An error to indicate success, fail, and any reason for + /// failure. + //------------------------------------------------------------------ + lldb::SBError + SetSectionLoadAddress (lldb::SBSection section, + lldb::addr_t section_base_addr); + + //------------------------------------------------------------------ + /// Clear the base load address for a module section. + /// + /// @param[in] section + /// The section whose base load address will be cleared within + /// this target. + /// + /// @return + /// An error to indicate success, fail, and any reason for + /// failure. + //------------------------------------------------------------------ + lldb::SBError + ClearSectionLoadAddress (lldb::SBSection section); + + //------------------------------------------------------------------ + /// Slide all file addresses for all module sections so that \a module + /// appears to loaded at these slide addresses. + /// + /// When you need all sections within a module to be loaded at a + /// rigid slide from the addresses found in the module object file, + /// this function will allow you to easily and quickly slide all + /// module sections. + /// + /// @param[in] module + /// The module to load. + /// + /// @param[in] sections_offset + /// An offset that will be applied to all section file addresses + /// (the virtual addresses found in the object file itself). + /// + /// @return + /// An error to indicate success, fail, and any reason for + /// failure. + //------------------------------------------------------------------ + lldb::SBError + SetModuleLoadAddress (lldb::SBModule module, + int64_t sections_offset); + + + //------------------------------------------------------------------ + /// The the section base load addresses for all sections in a module. + /// + /// @param[in] module + /// The module to unload. + /// + /// @return + /// An error to indicate success, fail, and any reason for + /// failure. + //------------------------------------------------------------------ + lldb::SBError + ClearModuleLoadAddress (lldb::SBModule module); + + //------------------------------------------------------------------ /// Find functions by name. /// /// @param[in] name diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 020d13f688c..6b71f3e59ff 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -73,10 +73,10 @@ public: /// A shared pointer to a module to add to this collection. //------------------------------------------------------------------ void - Append (lldb::ModuleSP &module_sp); + Append (const lldb::ModuleSP &module_sp); bool - AppendIfNeeded (lldb::ModuleSP &module_sp); + AppendIfNeeded (const lldb::ModuleSP &module_sp); //------------------------------------------------------------------ /// Clear the object's state. @@ -358,7 +358,7 @@ public: TypeList& types); bool - Remove (lldb::ModuleSP &module_sp); + Remove (const lldb::ModuleSP &module_sp); size_t Remove (ModuleList &module_list); diff --git a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h index a6dcfe1d381..8305ecc5f63 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h +++ b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h @@ -61,7 +61,7 @@ public: lldb::PlatformSP CreatePlatformWithOptions (CommandInterpreter &interpreter, bool make_selected, - Error& error); + Error& error) const; bool PlatformWasSpecified () const diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 9390c1f9dc2..53e7596dbe0 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -32,8 +32,6 @@ #include "lldb/Target/PathMappingList.h" #include "lldb/Target/SectionLoadList.h" -#include "lldb/API/SBTarget.h" - namespace lldb_private { //---------------------------------------------------------------------- @@ -854,9 +852,7 @@ public: }; -protected: - friend class lldb::SBTarget; - +protected: //------------------------------------------------------------------ // Member variables. //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Target/TargetList.h b/lldb/include/lldb/Target/TargetList.h index 975684e0ea8..5940e9a5370 100644 --- a/lldb/include/lldb/Target/TargetList.h +++ b/lldb/include/lldb/Target/TargetList.h @@ -58,31 +58,55 @@ public: /// locate an appropriate target to deliver asynchronous information /// to. /// + /// @param[in] debugger + /// The debugger to associate this target with + /// /// @param[in] file_spec /// The main executable file for a debug target. This value /// can be NULL and the file can be set later using: /// Target::SetExecutableModule (ModuleSP&) /// - /// @param[in] arch - /// The architecture to use when launching the \a file_spec for - /// debugging. This can be NULL if the architecture is not known - /// or when attaching to a process. + /// @param[in] triple_cstr + /// A target triple string to be used for the target. This can + /// be NULL if the triple is not known or when attaching to a + /// process. + /// + /// @param[in] get_dependent_modules + /// Track down the dependent modules for an executable and + /// load those into the module list. + /// + /// @param[in] platform_options + /// A pointer to the platform options to use when creating this + /// target. If this value is NULL, then the currently selected + /// platform will be used. /// - /// @param[in] uuid_ptr - /// An optional UUID to use when loading a target. When this is - /// specified, plug-ins might be able to track down a different - /// executable than the one on disk specified by "file_spec" in - /// an alternate SDK or build location (such as when doing - /// symbolication on non-native OS builds). + /// @param[out] target_sp + /// A shared pointer to a target that will be filled in if + /// this call is successful. /// /// @return - /// A shared pointer to a target object. + /// An error object that indicates success or failure + //------------------------------------------------------------------ + Error + CreateTarget (Debugger &debugger, + const FileSpec& file_spec, + const char *triple_cstr, + bool get_dependent_modules, + const OptionGroupPlatform *platform_options, + lldb::TargetSP &target_sp); + + //------------------------------------------------------------------ + /// Create a new Target. + /// + /// Same as the function above, but used when you already know the + /// platform you will be using //------------------------------------------------------------------ Error CreateTarget (Debugger &debugger, const FileSpec& file_spec, const ArchSpec& arch, - bool get_dependent_files, + bool get_dependent_modules, + const lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp); //------------------------------------------------------------------ diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index 9bf9d6b7481..6e6265c718e 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -19,6 +19,7 @@ namespace lldb_private { class ABI; class Address; +class AddressImpl; class AddressRange; class AddressResolver; class ArchSpec; @@ -100,6 +101,8 @@ class Mutex; class NameSearchContext; class ObjCLanguageRuntime; class ObjectContainer; +class OptionGroup; +class OptionGroupPlatform; class ObjectFile; class OperatingSystem; class Options; @@ -125,6 +128,7 @@ class ScriptInterpreter; class ScriptInterpreterPython; class SearchFilter; class Section; +class SectionImpl; class SectionList; class SourceManager; class StackFrame; diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index 6308f5a9644..16a92be0379 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -350,6 +350,8 @@ 26B1FCBD13381071002886E2 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C74CB6212288704006A8171 /* Carbon.framework */; }; 26B1FCC21338115F002886E2 /* Host.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7EE810F1B88F00F91463 /* Host.mm */; }; 26B42C4D1187ABA50079C8C8 /* LLDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B42C4C1187ABA50079C8C8 /* LLDB.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 26B8283D142D01E9002DBC64 /* SBSection.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B8283C142D01E9002DBC64 /* SBSection.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 26B82840142D020F002DBC64 /* SBSection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26B8283F142D020F002DBC64 /* SBSection.cpp */; }; 26BCFC521368AE38006DC050 /* OptionGroupFormat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BCFC511368AE38006DC050 /* OptionGroupFormat.cpp */; }; 26BD407F135D2AE000237D80 /* FileLineResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BD407E135D2ADF00237D80 /* FileLineResolver.cpp */; }; 26C72C94124322890068DC16 /* SBStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 26C72C93124322890068DC16 /* SBStream.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -753,6 +755,8 @@ 26B167A41123BF5500DC7B4F /* ThreadSafeValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadSafeValue.h; path = include/lldb/Core/ThreadSafeValue.h; sourceTree = "<group>"; }; 26B42C4C1187ABA50079C8C8 /* LLDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLDB.h; path = include/lldb/API/LLDB.h; sourceTree = "<group>"; }; 26B4E26E112F35F700AB3F64 /* TimeValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimeValue.h; path = include/lldb/Host/TimeValue.h; sourceTree = "<group>"; }; + 26B8283C142D01E9002DBC64 /* SBSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBSection.h; path = include/lldb/API/SBSection.h; sourceTree = "<group>"; }; + 26B8283F142D020F002DBC64 /* SBSection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBSection.cpp; path = source/API/SBSection.cpp; sourceTree = "<group>"; }; 26B8B42212EEC52A00A831B2 /* UniqueDWARFASTType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UniqueDWARFASTType.h; sourceTree = "<group>"; }; 26B8B42312EEC52A00A831B2 /* UniqueDWARFASTType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueDWARFASTType.cpp; sourceTree = "<group>"; }; 26BC7C2510F1B3BC00F91463 /* lldb-defines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-defines.h"; path = "include/lldb/lldb-defines.h"; sourceTree = "<group>"; }; @@ -1718,6 +1722,8 @@ 26DE204C11618E7A00A093E2 /* SBModule.cpp */, 9A9831041125FC5800A56CB0 /* SBProcess.h */, 9A9831031125FC5800A56CB0 /* SBProcess.cpp */, + 26B8283C142D01E9002DBC64 /* SBSection.h */, + 26B8283F142D020F002DBC64 /* SBSection.cpp */, 9A9831061125FC5800A56CB0 /* SBSourceManager.h */, 9A9831051125FC5800A56CB0 /* SBSourceManager.cpp */, 26C72C93124322890068DC16 /* SBStream.h */, @@ -2773,6 +2779,7 @@ 26D265BC136B4269002EEE45 /* lldb-public.h in Headers */, 4CAA56131422D96A001FFA01 /* BreakpointResolverFileRegex.h in Headers */, 4CF52AF51428291E0051E832 /* SBFileSpecList.h in Headers */, + 26B8283D142D01E9002DBC64 /* SBSection.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3058,6 +3065,7 @@ 9443B122140C18C40013457C /* SBData.cpp in Sources */, 4CAA56151422D986001FFA01 /* BreakpointResolverFileRegex.cpp in Sources */, 4CF52AF8142829390051E832 /* SBFileSpecList.cpp in Sources */, + 26B82840142D020F002DBC64 /* SBSection.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/lldb/scripts/Python/interface/SBAddress.i b/lldb/scripts/Python/interface/SBAddress.i index f0e2253438c..88cf0c453a6 100644 --- a/lldb/scripts/Python/interface/SBAddress.i +++ b/lldb/scripts/Python/interface/SBAddress.i @@ -79,8 +79,8 @@ public: bool GetDescription (lldb::SBStream &description); - SectionType - GetSectionType (); + lldb::SBSection + GetSection (); %feature("docstring", " //------------------------------------------------------------------ diff --git a/lldb/scripts/Python/interface/SBDebugger.i b/lldb/scripts/Python/interface/SBDebugger.i index 60f4864ee35..184109b5a5a 100644 --- a/lldb/scripts/Python/interface/SBDebugger.i +++ b/lldb/scripts/Python/interface/SBDebugger.i @@ -177,6 +177,13 @@ public: FILE *err); lldb::SBTarget + CreateTarget (const char *filename, + const char *target_triple, + const char *platform_name, + bool add_dependent_modules, + lldb::SBError& sb_error); + + lldb::SBTarget CreateTargetWithFileAndTargetTriple (const char *filename, const char *target_triple); diff --git a/lldb/scripts/Python/interface/SBModule.i b/lldb/scripts/Python/interface/SBModule.i index 6f78dff68df..466fcfad796 100644 --- a/lldb/scripts/Python/interface/SBModule.i +++ b/lldb/scripts/Python/interface/SBModule.i @@ -89,9 +89,11 @@ public: const char * GetUUIDString () const; - bool - ResolveFileAddress (lldb::addr_t vm_addr, - lldb::SBAddress& addr); + lldb::SBSection + FindSection (const char *sect_name); + + lldb::SBAddress + ResolveFileAddress (lldb::addr_t vm_addr); lldb::SBSymbolContext ResolveSymbolContextForAddress (const lldb::SBAddress& addr, @@ -106,6 +108,13 @@ public: lldb::SBSymbol GetSymbolAtIndex (size_t idx); + size_t + GetNumSections (); + + lldb::SBSection + GetSectionAtIndex (size_t idx); + + %feature("docstring", " //------------------------------------------------------------------ /// Find functions by name. diff --git a/lldb/scripts/Python/interface/SBTarget.i b/lldb/scripts/Python/interface/SBTarget.i index aafc80bea39..acd894cb57a 100644 --- a/lldb/scripts/Python/interface/SBTarget.i +++ b/lldb/scripts/Python/interface/SBTarget.i @@ -277,18 +277,43 @@ public: lldb::SBFileSpec GetExecutable (); + bool + AddModule (lldb::SBModule &module); + + lldb::SBModule + AddModule (const char *path, + const char *triple, + const char *uuid); + uint32_t GetNumModules () const; lldb::SBModule GetModuleAtIndex (uint32_t idx); + bool + RemoveModule (lldb::SBModule module); + lldb::SBDebugger GetDebugger() const; lldb::SBModule FindModule (const lldb::SBFileSpec &file_spec); + lldb::SBError + SetSectionLoadAddress (lldb::SBSection section, + lldb::addr_t section_base_addr); + + lldb::SBError + ClearSectionLoadAddress (lldb::SBSection section); + + lldb::SBError + SetModuleLoadAddress (lldb::SBModule module, + int64_t sections_offset); + + lldb::SBError + ClearModuleLoadAddress (lldb::SBModule module); + %feature("docstring", " //------------------------------------------------------------------ /// Find functions by name. diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig index 7c7d3b011f6..3b0fab43538 100644 --- a/lldb/scripts/lldb.swig +++ b/lldb/scripts/lldb.swig @@ -67,6 +67,7 @@ o SBLineEntry: Specifies an association with a contiguous range of instructions #include "lldb/API/SBListener.h" #include "lldb/API/SBModule.h" #include "lldb/API/SBProcess.h" +#include "lldb/API/SBSection.h" #include "lldb/API/SBSourceManager.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBStringList.h" @@ -118,6 +119,7 @@ o SBLineEntry: Specifies an association with a contiguous range of instructions %include "./Python/interface/SBListener.i" %include "./Python/interface/SBModule.i" %include "./Python/interface/SBProcess.i" +%include "./Python/interface/SBSection.i" %include "./Python/interface/SBSourceManager.i" %include "./Python/interface/SBStream.i" %include "./Python/interface/SBStringList.i" diff --git a/lldb/source/API/SBAddress.cpp b/lldb/source/API/SBAddress.cpp index e4161a2bebc..9066bb448fb 100644 --- a/lldb/source/API/SBAddress.cpp +++ b/lldb/source/API/SBAddress.cpp @@ -9,6 +9,7 @@ #include "lldb/API/SBAddress.h" #include "lldb/API/SBProcess.h" +#include "lldb/API/SBSection.h" #include "lldb/API/SBStream.h" #include "lldb/Core/Address.h" #include "lldb/Core/Log.h" @@ -16,6 +17,69 @@ #include "lldb/Host/Mutex.h" #include "lldb/Target/Target.h" +namespace lldb_private +{ + // We need a address implementation to hold onto a reference to the module + // since if the module goes away and we have anyone still holding onto a + // SBAddress object, we could crash. + class AddressImpl + { + public: + AddressImpl () : + m_module_sp(), + m_address() + { + } + + AddressImpl (const Address &addr) : + m_module_sp (addr.GetModule()), + m_address (addr) + { + } + + AddressImpl (const AddressImpl &rhs) : + m_module_sp (rhs.m_module_sp), + m_address (rhs.m_address) + { + } + + bool + IsValid () const + { + return m_address.IsValid(); + } + + void + operator = (const AddressImpl &rhs) + { + m_module_sp = rhs.m_module_sp; + m_address = rhs.m_address; + } + + Address & + GetAddress () + { + return m_address; + } + + Module * + GetModule() + { + return m_module_sp.get(); + } + + const lldb::ModuleSP & + GetModuleSP() const + { + return m_module_sp; + } + protected: + lldb::ModuleSP m_module_sp; + Address m_address; + }; +} + + using namespace lldb; using namespace lldb_private; @@ -25,18 +89,18 @@ SBAddress::SBAddress () : { } -SBAddress::SBAddress (const lldb_private::Address *lldb_object_ptr) : +SBAddress::SBAddress (const Address *lldb_object_ptr) : m_opaque_ap () { if (lldb_object_ptr) - m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr)); + m_opaque_ap.reset (new AddressImpl(*lldb_object_ptr)); } SBAddress::SBAddress (const SBAddress &rhs) : m_opaque_ap () { if (rhs.IsValid()) - m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get())); + m_opaque_ap.reset (new AddressImpl(*rhs.m_opaque_ap.get())); } // Create an address by resolving a load address using the supplied target @@ -55,8 +119,13 @@ SBAddress::~SBAddress () const SBAddress & SBAddress::operator = (const SBAddress &rhs) { - if (this != &rhs && rhs.IsValid()) - m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get())); + if (this != &rhs) + { + if (rhs.IsValid()) + m_opaque_ap.reset(new AddressImpl(*rhs.m_opaque_ap.get())); + else + m_opaque_ap.reset(); + } return *this; } @@ -73,25 +142,24 @@ SBAddress::Clear () } void -SBAddress::SetAddress (const lldb_private::Address *lldb_object_ptr) +SBAddress::SetAddress (const Address *lldb_object_ptr) { if (lldb_object_ptr) { if (m_opaque_ap.get()) *m_opaque_ap = *lldb_object_ptr; else - m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr)); - return; + m_opaque_ap.reset (new AddressImpl(*lldb_object_ptr)); } - if (m_opaque_ap.get()) - m_opaque_ap->Clear(); + else + m_opaque_ap.reset(); } lldb::addr_t SBAddress::GetFileAddress () const { if (m_opaque_ap.get()) - return m_opaque_ap->GetFileAddress(); + return m_opaque_ap->GetAddress().GetFileAddress(); else return LLDB_INVALID_ADDRESS; } @@ -99,13 +167,13 @@ SBAddress::GetFileAddress () const lldb::addr_t SBAddress::GetLoadAddress (const SBTarget &target) const { - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); lldb::addr_t addr = LLDB_INVALID_ADDRESS; if (m_opaque_ap.get()) { Mutex::Locker api_locker (target->GetAPIMutex()); - addr = m_opaque_ap->GetLoadAddress (target.get()); + addr = m_opaque_ap->GetAddress().GetLoadAddress (target.get()); } if (log) @@ -127,14 +195,14 @@ SBAddress::SetLoadAddress (lldb::addr_t load_addr, lldb::SBTarget &target) if (target.IsValid()) *this = target.ResolveLoadAddress(load_addr); else - m_opaque_ap->Clear(); + m_opaque_ap->GetAddress().Clear(); // Check if we weren't were able to resolve a section offset address. // If we weren't it is ok, the load address might be a location on the // stack or heap, so we should just have an address with no section and // a valid offset if (!m_opaque_ap->IsValid()) - m_opaque_ap->SetOffset(load_addr); + m_opaque_ap->GetAddress().SetOffset(load_addr); } bool @@ -142,50 +210,66 @@ SBAddress::OffsetAddress (addr_t offset) { if (m_opaque_ap.get()) { - addr_t addr_offset = m_opaque_ap->GetOffset(); + addr_t addr_offset = m_opaque_ap->GetAddress().GetOffset(); if (addr_offset != LLDB_INVALID_ADDRESS) { - m_opaque_ap->SetOffset(addr_offset + offset); + m_opaque_ap->GetAddress().SetOffset(addr_offset + offset); return true; } } return false; } -lldb_private::Address * +lldb::SBSection +SBAddress::GetSection () +{ + lldb::SBSection sb_section; + if (m_opaque_ap.get()) + sb_section.SetSection(m_opaque_ap->GetAddress().GetSection()); + return sb_section; +} + + +Address * SBAddress::operator->() { - return m_opaque_ap.get(); + if (m_opaque_ap.get()) + return &m_opaque_ap->GetAddress(); + return NULL; } -const lldb_private::Address * +const Address * SBAddress::operator->() const { - return m_opaque_ap.get(); + if (m_opaque_ap.get()) + return &m_opaque_ap->GetAddress(); + return NULL; } -lldb_private::Address & +Address & SBAddress::ref () { if (m_opaque_ap.get() == NULL) - m_opaque_ap.reset (new lldb_private::Address); - return *m_opaque_ap; + m_opaque_ap.reset (new AddressImpl()); + return m_opaque_ap->GetAddress(); } -const lldb_private::Address & +const Address & SBAddress::ref () const { // "const SBAddress &addr" should already have checked "addr.IsValid()" // prior to calling this function. In case you didn't we will assert // and die to let you know. assert (m_opaque_ap.get()); - return *m_opaque_ap; + return m_opaque_ap->GetAddress(); } -lldb_private::Address * +Address * SBAddress::get () { - return m_opaque_ap.get(); + if (m_opaque_ap.get()) + return &m_opaque_ap->GetAddress(); + return NULL; } bool @@ -195,26 +279,13 @@ SBAddress::GetDescription (SBStream &description) // case there isn't one already... description.ref(); if (m_opaque_ap.get()) - m_opaque_ap->Dump (description.get(), NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); + m_opaque_ap->GetAddress().Dump (description.get(), NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); else description.Printf ("No value"); return true; } -SectionType -SBAddress::GetSectionType () -{ - if (m_opaque_ap.get()) - { - const Section *section = m_opaque_ap->GetSection(); - if (section) - return section->GetType(); - } - return eSectionTypeInvalid; -} - - SBModule SBAddress::GetModule () { @@ -233,7 +304,7 @@ SBAddress::GetSymbolContext (uint32_t resolve_scope) { SBSymbolContext sb_sc; if (m_opaque_ap.get()) - m_opaque_ap->CalculateSymbolContext (&sb_sc.ref(), resolve_scope); + m_opaque_ap->GetAddress().CalculateSymbolContext (&sb_sc.ref(), resolve_scope); return sb_sc; } @@ -242,7 +313,7 @@ SBAddress::GetCompileUnit () { SBCompileUnit sb_comp_unit; if (m_opaque_ap.get()) - sb_comp_unit.reset(m_opaque_ap->CalculateSymbolContextCompileUnit()); + sb_comp_unit.reset(m_opaque_ap->GetAddress().CalculateSymbolContextCompileUnit()); return sb_comp_unit; } @@ -251,7 +322,7 @@ SBAddress::GetFunction () { SBFunction sb_function; if (m_opaque_ap.get()) - sb_function.reset(m_opaque_ap->CalculateSymbolContextFunction()); + sb_function.reset(m_opaque_ap->GetAddress().CalculateSymbolContextFunction()); return sb_function; } @@ -260,7 +331,7 @@ SBAddress::GetBlock () { SBBlock sb_block; if (m_opaque_ap.get()) - sb_block.reset(m_opaque_ap->CalculateSymbolContextBlock()); + sb_block.reset(m_opaque_ap->GetAddress().CalculateSymbolContextBlock()); return sb_block; } @@ -269,7 +340,7 @@ SBAddress::GetSymbol () { SBSymbol sb_symbol; if (m_opaque_ap.get()) - sb_symbol.reset(m_opaque_ap->CalculateSymbolContextSymbol()); + sb_symbol.reset(m_opaque_ap->GetAddress().CalculateSymbolContextSymbol()); return sb_symbol; } @@ -280,7 +351,7 @@ SBAddress::GetLineEntry () if (m_opaque_ap.get()) { LineEntry line_entry; - if (m_opaque_ap->CalculateSymbolContextLineEntry (line_entry)) + if (m_opaque_ap->GetAddress().CalculateSymbolContextLineEntry (line_entry)) sb_line_entry.SetLineEntry (line_entry); } return sb_line_entry; diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index acb69faad70..0f5472a9be3 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -29,6 +29,7 @@ #include "lldb/Core/State.h" #include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/OptionGroupPlatform.h" #include "lldb/Target/Process.h" #include "lldb/Target/TargetList.h" @@ -459,6 +460,52 @@ SBDebugger::StateIsStoppedState (StateType state) return result; } +lldb::SBTarget +SBDebugger::CreateTarget (const char *filename, + const char *target_triple, + const char *platform_name, + bool add_dependent_modules, + lldb::SBError& sb_error) +{ + SBTarget sb_target; + if (m_opaque_sp) + { + sb_error.Clear(); + FileSpec filename_spec (filename, true); + OptionGroupPlatform platform_options (false); + platform_options.SetPlatformName (platform_name); + + TargetSP target_sp; + sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, + filename_spec, + target_triple, + add_dependent_modules, + &platform_options, + target_sp); + + if (sb_error.Success()) + sb_target.reset (target_sp); + } + else + { + sb_error.SetErrorString("invalid target"); + } + + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (log) + { + log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)", + m_opaque_sp.get(), + filename, + target_triple, + platform_name, + add_dependent_modules, + sb_error.GetCString(), + sb_target.get()); + } + + return sb_target; +} SBTarget SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, @@ -467,11 +514,15 @@ SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, SBTarget target; if (m_opaque_sp) { - ArchSpec arch; FileSpec file_spec (filename, true); - arch.SetTriple (target_triple, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get()); TargetSP target_sp; - Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file_spec, arch, true, target_sp)); + const bool add_dependent_modules = true; + Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, + file_spec, + target_triple, + add_dependent_modules, + NULL, + target_sp)); target.reset (target_sp); } @@ -494,14 +545,16 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_ if (m_opaque_sp) { FileSpec file (filename, true); - ArchSpec arch; TargetSP target_sp; Error error; + const bool add_dependent_modules = true; - if (arch_cstr) - arch.SetTriple (arch_cstr, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get()); - - error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file, arch, true, target_sp); + error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, + file, + arch_cstr, + add_dependent_modules, + NULL, + target_sp); if (error.Success()) { @@ -529,8 +582,14 @@ SBDebugger::CreateTarget (const char *filename) ArchSpec arch = Target::GetDefaultArchitecture (); TargetSP target_sp; Error error; - - error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file, arch, true, target_sp); + const bool add_dependent_modules = true; + + error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, + file, + arch, + add_dependent_modules, + m_opaque_sp->GetPlatformList().GetSelectedPlatform(), + target_sp); if (error.Success()) { diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp index 1a76af66b31..790d8ddca89 100644 --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -217,6 +217,11 @@ SBModule::get() const return m_opaque_sp.get(); } +const lldb::ModuleSP & +SBModule::get_sp() const +{ + return m_opaque_sp; +} void SBModule::SetModule (const lldb::ModuleSP& module_sp) @@ -225,15 +230,17 @@ SBModule::SetModule (const lldb::ModuleSP& module_sp) } -bool -SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr) +SBAddress +SBModule::ResolveFileAddress (lldb::addr_t vm_addr) { - if (m_opaque_sp && addr.IsValid()) - return m_opaque_sp->ResolveFileAddress (vm_addr, addr.ref()); - - if (addr.IsValid()) - addr->Clear(); - return false; + lldb::SBAddress sb_addr; + if (m_opaque_sp) + { + Address addr; + if (m_opaque_sp->ResolveFileAddress (vm_addr, addr)) + sb_addr.ref() = addr; + } + return sb_addr; } SBSymbolContext @@ -292,6 +299,40 @@ SBModule::GetSymbolAtIndex (size_t idx) return sb_symbol; } +size_t +SBModule::GetNumSections () +{ + if (m_opaque_sp) + { + ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); + if (obj_file) + { + SectionList *section_list = obj_file->GetSectionList (); + if (section_list) + return section_list->GetSize(); + } + } + return 0; +} + +SBSection +SBModule::GetSectionAtIndex (size_t idx) +{ + SBSection sb_section; + if (m_opaque_sp) + { + ObjectFile *obj_file = m_opaque_sp->GetObjectFile(); + if (obj_file) + { + SectionList *section_list = obj_file->GetSectionList (); + + if (section_list) + sb_section.SetSection(section_list->GetSectionAtIndex (idx).get()); + } + } + return sb_section; +} + uint32_t SBModule::FindFunctions (const char *name, uint32_t name_type_mask, @@ -396,3 +437,30 @@ SBModule::FindTypes (const char* type) return retval; } + + +SBSection +SBModule::FindSection (const char *sect_name) +{ + SBSection sb_section; + + if (IsValid()) + { + ObjectFile *objfile = m_opaque_sp->GetObjectFile(); + if (objfile) + { + SectionList *section_list = objfile->GetSectionList(); + if (section_list) + { + ConstString const_sect_name(sect_name); + SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); + if (section_sp) + { + sb_section.SetSection(section_sp.get()); + } + } + } + } + return sb_section; +} + diff --git a/lldb/source/API/SBSection.cpp b/lldb/source/API/SBSection.cpp new file mode 100644 index 00000000000..6d665962465 --- /dev/null +++ b/lldb/source/API/SBSection.cpp @@ -0,0 +1,324 @@ +//===-- SBSection.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/API/SBSection.h" +#include "lldb/API/SBStream.h" +#include "lldb/Core/DataBuffer.h" +#include "lldb/Core/DataExtractor.h" +#include "lldb/Core/Log.h" +#include "lldb/Core/Section.h" +#include "lldb/Core/Module.h" + +namespace lldb_private +{ + // We need a section implementation to hold onto a reference to the module + // since if the module goes away and we have anyone still holding onto a + // SBSection object, we could crash. + class SectionImpl + { + public: + SectionImpl (const lldb_private::Section *section = NULL) : + m_module_sp (), + m_section (section) + { + if (section) + m_module_sp = section->GetModule(); + } + + SectionImpl (const SectionImpl &rhs) : + m_module_sp (rhs.m_module_sp), + m_section (rhs.m_section) + { + } + + bool + IsValid () const + { + return m_section != NULL; + } + + void + operator = (const SectionImpl &rhs) + { + m_module_sp = rhs.m_module_sp; + m_section = rhs.m_section; + } + + void + operator =(const lldb_private::Section *section) + { + m_section = section; + if (section) + m_module_sp.reset(section->GetModule()); + else + m_module_sp.reset(); + } + + const lldb_private::Section * + GetSection () const + { + return m_section; + } + + Module * + GetModule() + { + return m_module_sp.get(); + } + + const lldb::ModuleSP & + GetModuleSP() const + { + return m_module_sp; + } + protected: + lldb::ModuleSP m_module_sp; + const lldb_private::Section *m_section; + }; +} + +using namespace lldb; +using namespace lldb_private; + + +SBSection::SBSection () : + m_opaque_ap () +{ +} + +SBSection::SBSection (const SBSection &rhs) : + m_opaque_ap () +{ + if (rhs.IsValid()) + m_opaque_ap.reset (new SectionImpl (*rhs.m_opaque_ap)); +} + + + +SBSection::SBSection (const lldb_private::Section *section) : + m_opaque_ap () +{ + if (section) + m_opaque_ap.reset (new SectionImpl(section)); +} + +const SBSection & +SBSection::operator = (const SBSection &rhs) +{ + if (this != &rhs && rhs.IsValid()) + m_opaque_ap.reset (new SectionImpl(*rhs.m_opaque_ap)); + else + m_opaque_ap.reset (); + return *this; +} + +SBSection::~SBSection () +{ +} + +bool +SBSection::IsValid () const +{ + return m_opaque_ap.get() != NULL && m_opaque_ap->IsValid(); +} + +lldb::SBSection +SBSection::FindSubSection (const char *sect_name) +{ + lldb::SBSection sb_section; + if (IsValid()) + { + ConstString const_sect_name(sect_name); + sb_section.SetSection(m_opaque_ap->GetSection()->GetChildren ().FindSectionByName(const_sect_name).get()); + } + return sb_section; +} + +size_t +SBSection::GetNumSubSections () +{ + if (IsValid()) + return m_opaque_ap->GetSection()->GetChildren ().GetSize(); + return 0; +} + +lldb::SBSection +SBSection::GetSubSectionAtIndex (size_t idx) +{ + lldb::SBSection sb_section; + if (IsValid()) + sb_section.SetSection(m_opaque_ap->GetSection()->GetChildren ().GetSectionAtIndex(idx).get()); + return sb_section; +} + +const lldb_private::Section * +SBSection::GetSection() +{ + if (m_opaque_ap.get()) + return m_opaque_ap->GetSection(); + return NULL; +} + +void +SBSection::SetSection (const lldb_private::Section *section) +{ + m_opaque_ap.reset (new SectionImpl(section)); +} + + + + +lldb::addr_t +SBSection::GetFileAddress () +{ + lldb::addr_t file_addr = LLDB_INVALID_ADDRESS; + if (IsValid()) + return m_opaque_ap->GetSection()->GetFileAddress(); + return file_addr; +} + +lldb::addr_t +SBSection::GetByteSize () +{ + if (IsValid()) + { + const Section *section = m_opaque_ap->GetSection(); + if (section) + return section->GetByteSize(); + } + return 0; +} + +uint64_t +SBSection::GetFileOffset () +{ + if (IsValid()) + { + const Section *section = m_opaque_ap->GetSection(); + if (section) + { + Module *module = m_opaque_ap->GetModule(); + if (module) + { + ObjectFile *objfile = module->GetObjectFile(); + if (objfile) + return objfile->GetOffset() + section->GetFileOffset(); + } + return section->GetFileOffset(); + } + } + return 0; +} + +uint64_t +SBSection::GetFileByteSize () +{ + if (IsValid()) + { + const Section *section = m_opaque_ap->GetSection(); + if (section) + return section->GetFileSize(); + } + return 0; +} + +SBData +SBSection::GetSectionData (uint64_t offset, uint64_t size) +{ + SBData sb_data; + if (IsValid()) + { + const Section *section = m_opaque_ap->GetSection(); + if (section) + { + const uint64_t sect_file_size = section->GetFileSize(); + if (sect_file_size > 0) + { + Module *module = m_opaque_ap->GetModule(); + if (module) + { + ObjectFile *objfile = module->GetObjectFile(); + if (objfile) + { + const uint64_t sect_file_offset = objfile->GetOffset() + section->GetFileOffset(); + const uint64_t file_offset = sect_file_offset + offset; + uint64_t file_size = size; + if (file_size == UINT64_MAX) + { + file_size = section->GetByteSize(); + if (file_size > offset) + file_size -= offset; + else + file_size = 0; + } + DataBufferSP data_buffer_sp (objfile->GetFileSpec().ReadFileContents (file_offset, file_size)); + if (data_buffer_sp && data_buffer_sp->GetByteSize() > 0) + { + DataExtractorSP data_extractor_sp (new DataExtractor (data_buffer_sp, + objfile->GetByteOrder(), + objfile->GetAddressByteSize())); + + sb_data.SetOpaque (data_extractor_sp); + } + } + } + } + } + } + return sb_data; +} + +SectionType +SBSection::GetSectionType () +{ + if (m_opaque_ap.get()) + { + const Section *section = m_opaque_ap->GetSection(); + if (section) + return section->GetType(); + } + return eSectionTypeInvalid; +} + + +bool +SBSection::operator == (const SBSection &rhs) +{ + SectionImpl *lhs_ptr = m_opaque_ap.get(); + SectionImpl *rhs_ptr = rhs.m_opaque_ap.get(); + if (lhs_ptr && rhs_ptr) + return lhs_ptr->GetSection() == rhs_ptr->GetSection(); + return false; +} + +bool +SBSection::operator != (const SBSection &rhs) +{ + SectionImpl *lhs_ptr = m_opaque_ap.get(); + SectionImpl *rhs_ptr = rhs.m_opaque_ap.get(); + if (lhs_ptr && rhs_ptr) + return lhs_ptr->GetSection() != rhs_ptr->GetSection(); + return false; +} + +bool +SBSection::GetDescription (SBStream &description) +{ + if (m_opaque_ap.get()) + { + description.Printf ("SBSection"); + } + else + { + description.Printf ("No value"); + } + + return true; +} + diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index e17f258ab0a..74580c431e2 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -867,6 +867,52 @@ SBTarget::DeleteAllBreakpoints () } +lldb::SBModule +SBTarget::AddModule (const char *path, + const char *triple, + const char *uuid_cstr) +{ + lldb::SBModule sb_module; + if (m_opaque_sp) + { + FileSpec module_file_spec; + UUID module_uuid; + ArchSpec module_arch; + + if (path) + module_file_spec.SetFile(path, false); + + if (uuid_cstr) + module_uuid.SetfromCString(uuid_cstr); + + if (triple) + module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get()); + + sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec, + module_arch, + uuid_cstr ? &module_uuid : NULL)); + } + return sb_module; +} + +bool +SBTarget::AddModule (lldb::SBModule &module) +{ + if (m_opaque_sp) + { + m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp()); + return true; + } + return false; +} + +lldb::SBModule +AddModule (const char *path, + const char *triple, + const char *uuid); + + + uint32_t SBTarget::GetNumModules () const { @@ -930,6 +976,14 @@ SBTarget::GetModuleAtIndex (uint32_t idx) return sb_module; } +bool +SBTarget::RemoveModule (lldb::SBModule module) +{ + if (m_opaque_sp) + return m_opaque_sp->GetImages().Remove(module.get_sp()); + return false; +} + SBBroadcaster SBTarget::GetBroadcaster () const @@ -1079,3 +1133,149 @@ SBTarget::GetSourceManager() SBSourceManager source_manager (*this); return source_manager; } + + +SBError +SBTarget::SetSectionLoadAddress (lldb::SBSection section, + lldb::addr_t section_base_addr) +{ + SBError sb_error; + + if (IsValid()) + { + if (!section.IsValid()) + { + sb_error.SetErrorStringWithFormat ("invalid section"); + } + else + { + m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr); + } + } + else + { + sb_error.SetErrorStringWithFormat ("invalid target"); + } + return sb_error; +} + +SBError +SBTarget::ClearSectionLoadAddress (lldb::SBSection section) +{ + SBError sb_error; + + if (IsValid()) + { + if (!section.IsValid()) + { + sb_error.SetErrorStringWithFormat ("invalid section"); + } + else + { + m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection()); + } + } + else + { + sb_error.SetErrorStringWithFormat ("invalid target"); + } + return sb_error; +} + +SBError +SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) +{ + SBError sb_error; + + char path[PATH_MAX]; + if (IsValid()) + { + if (!module.IsValid()) + { + sb_error.SetErrorStringWithFormat ("invalid module"); + } + else + { + ObjectFile *objfile = module->GetObjectFile(); + if (objfile) + { + SectionList *section_list = objfile->GetSectionList(); + if (section_list) + { + const size_t num_sections = section_list->GetSize(); + for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) + { + SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); + if (section_sp) + m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset); + } + } + else + { + module->GetFileSpec().GetPath (path, sizeof(path)); + sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); + } + } + else + { + module->GetFileSpec().GetPath (path, sizeof(path)); + sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); + } + } + } + else + { + sb_error.SetErrorStringWithFormat ("invalid target"); + } + return sb_error; +} + +SBError +SBTarget::ClearModuleLoadAddress (lldb::SBModule module) +{ + SBError sb_error; + + char path[PATH_MAX]; + if (IsValid()) + { + if (!module.IsValid()) + { + sb_error.SetErrorStringWithFormat ("invalid module"); + } + else + { + ObjectFile *objfile = module->GetObjectFile(); + if (objfile) + { + SectionList *section_list = objfile->GetSectionList(); + if (section_list) + { + const size_t num_sections = section_list->GetSize(); + for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) + { + SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); + if (section_sp) + m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get()); + } + } + else + { + module->GetFileSpec().GetPath (path, sizeof(path)); + sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); + } + } + else + { + module->GetFileSpec().GetPath (path, sizeof(path)); + sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); + } + } + } + else + { + sb_error.SetErrorStringWithFormat ("invalid target"); + } + return sb_error; +} + + diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 980f9d21e94..72aba1c7c0d 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -585,13 +585,13 @@ public: // If there isn't a current target create one. TargetSP new_target_sp; FileSpec emptyFileSpec; - ArchSpec emptyArchSpec; Error error; error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(), emptyFileSpec, - emptyArchSpec, + NULL, false, + NULL, // No platform options new_target_sp); target = new_target_sp.get(); if (target == NULL || error.Fail()) @@ -1041,12 +1041,12 @@ public: { // If there isn't a current target create one. FileSpec emptyFileSpec; - ArchSpec emptyArchSpec; error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(), emptyFileSpec, - emptyArchSpec, + NULL, false, + NULL, // No platform options target_sp); if (!target_sp || error.Fail()) { diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index eb2ef07698e..4ff540defd7 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -186,48 +186,18 @@ public: const char *file_path = command.GetArgumentAtIndex(0); Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path); FileSpec file_spec (file_path, true); - - bool select = true; - PlatformSP platform_sp; - - Error error; - - if (m_platform_options.PlatformWasSpecified ()) - { - platform_sp = m_platform_options.CreatePlatformWithOptions(m_interpreter, select, error); - if (!platform_sp) - { - result.AppendError(error.AsCString()); - result.SetStatus (eReturnStatusFailed); - return false; - } - } - ArchSpec file_arch; - - const char *arch_cstr = m_arch_option.GetArchitectureName(); - if (arch_cstr) - { - if (!platform_sp) - platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform(); - if (!m_arch_option.GetArchitecture(platform_sp.get(), file_arch)) - { - result.AppendErrorWithFormat("invalid architecture '%s'\n", arch_cstr); - result.SetStatus (eReturnStatusFailed); - return false; - } - } - - if (! file_spec.Exists() && !file_spec.ResolveExecutableLocation()) - { - result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path); - result.SetStatus (eReturnStatusFailed); - return false; - } - + TargetSP target_sp; Debugger &debugger = m_interpreter.GetDebugger(); - error = debugger.GetTargetList().CreateTarget (debugger, file_spec, file_arch, true, target_sp); - + const char *arch_cstr = m_arch_option.GetArchitectureName(); + const bool get_dependent_files = true; + Error error (debugger.GetTargetList().CreateTarget (debugger, + file_spec, + arch_cstr, + get_dependent_files, + &m_platform_options, + target_sp)); + if (target_sp) { debugger.GetTargetList().SetSelectedTarget(target_sp.get()); diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index ebbbcd31820..4ee475b050d 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -61,7 +61,7 @@ ModuleList::~ModuleList() } void -ModuleList::Append (ModuleSP &module_sp) +ModuleList::Append (const ModuleSP &module_sp) { if (module_sp) { @@ -71,7 +71,7 @@ ModuleList::Append (ModuleSP &module_sp) } bool -ModuleList::AppendIfNeeded (ModuleSP &module_sp) +ModuleList::AppendIfNeeded (const ModuleSP &module_sp) { if (module_sp) { @@ -90,7 +90,7 @@ ModuleList::AppendIfNeeded (ModuleSP &module_sp) } bool -ModuleList::Remove (ModuleSP &module_sp) +ModuleList::Remove (const ModuleSP &module_sp) { if (module_sp) { diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp index 910a6e9b376..e65ee8cee6e 100644 --- a/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -21,7 +21,7 @@ using namespace lldb; using namespace lldb_private; PlatformSP -OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, bool make_selected, Error& error) +OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter, bool make_selected, Error& error) const { PlatformSP platform_sp; if (!m_platform_name.empty()) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index d33d16d2520..93be92353ef 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -423,12 +423,12 @@ PlatformDarwin::Attach (lldb::pid_t pid, { TargetSP new_target_sp; FileSpec emptyFileSpec; - ArchSpec emptyArchSpec; error = debugger.GetTargetList().CreateTarget (debugger, emptyFileSpec, - emptyArchSpec, + NULL, false, + NULL, new_target_sp); target = new_target_sp.get(); } diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 66534c3d323..01c0fb8860a 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -360,12 +360,12 @@ PlatformRemoteGDBServer::Attach (lldb::pid_t pid, { TargetSP new_target_sp; FileSpec emptyFileSpec; - ArchSpec emptyArchSpec; error = debugger.GetTargetList().CreateTarget (debugger, emptyFileSpec, - emptyArchSpec, + NULL, false, + NULL, new_target_sp); target = new_target_sp.get(); } diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 299f4aef88e..60831baae05 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -782,7 +782,7 @@ Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) } } - if (executable_objfile) + if (executable_objfile && get_dependent_files) { executable_objfile->GetDependentModules(dependent_files); for (uint32_t i=0; i<dependent_files.GetSize(); i++) diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index e8a8ba906a3..d30cfa171ea 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -17,6 +17,7 @@ #include "lldb/Core/State.h" #include "lldb/Core/Timer.h" #include "lldb/Host/Host.h" +#include "lldb/Interpreter/OptionGroupPlatform.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/TargetList.h" @@ -46,12 +47,59 @@ TargetList::~TargetList() } Error +TargetList::CreateTarget (Debugger &debugger, + const FileSpec& file, + const char *triple_cstr, + bool get_dependent_files, + const OptionGroupPlatform *platform_options, + TargetSP &target_sp) +{ + Error error; + PlatformSP platform_sp; + if (platform_options) + { + if (platform_options->PlatformWasSpecified ()) + { + const bool select_platform = true; + platform_sp = platform_options->CreatePlatformWithOptions (debugger.GetCommandInterpreter(), + select_platform, + error); + if (!platform_sp) + return error; + } + } + + if (!platform_sp) + platform_sp = debugger.GetPlatformList().GetSelectedPlatform (); + + ArchSpec arch; + + if (triple_cstr) + { + arch.SetTriple(triple_cstr, platform_sp.get()); + if (!arch.IsValid()) + { + error.SetErrorStringWithFormat("invalid triple '%s'\n", triple_cstr); + return error; + } + } + error = TargetList::CreateTarget (debugger, + file, + arch, + get_dependent_files, + platform_sp, + target_sp); + return error; +} + +Error TargetList::CreateTarget ( Debugger &debugger, const FileSpec& file, const ArchSpec& arch, bool get_dependent_files, + const PlatformSP &platform_sp, TargetSP &target_sp ) { @@ -62,7 +110,6 @@ TargetList::CreateTarget arch.GetArchitectureName()); Error error; - PlatformSP platform_sp (debugger.GetPlatformList().GetSelectedPlatform ()); if (file) { diff --git a/lldb/test/python_api/default-constructor/sb_address.py b/lldb/test/python_api/default-constructor/sb_address.py index 419e1f5c724..570e224a0de 100644 --- a/lldb/test/python_api/default-constructor/sb_address.py +++ b/lldb/test/python_api/default-constructor/sb_address.py @@ -11,7 +11,7 @@ def fuzz_obj(obj): obj.SetLoadAddress(0xffff, lldb.SBTarget()) obj.OffsetAddress(sys.maxint) obj.GetDescription(lldb.SBStream()) - obj.GetSectionType() + obj.GetSection() obj.GetSymbolContext(lldb.eSymbolContextEverything) obj.GetModule() obj.GetCompileUnit() diff --git a/lldb/test/python_api/default-constructor/sb_module.py b/lldb/test/python_api/default-constructor/sb_module.py index d475ba96d22..5867a11f62f 100644 --- a/lldb/test/python_api/default-constructor/sb_module.py +++ b/lldb/test/python_api/default-constructor/sb_module.py @@ -10,7 +10,7 @@ def fuzz_obj(obj): obj.GetPlatformFileSpec() obj.SetPlatformFileSpec(lldb.SBFileSpec()) obj.GetUUIDString() - obj.ResolveFileAddress(sys.maxint, lldb.SBAddress()) + obj.ResolveFileAddress(sys.maxint) obj.ResolveSymbolContextForAddress(lldb.SBAddress(), 0) obj.GetDescription(lldb.SBStream()) obj.GetNumSymbols() diff --git a/lldb/test/python_api/function_symbol/TestSymbolAPI.py b/lldb/test/python_api/function_symbol/TestSymbolAPI.py index f983ed645dc..85e97d3e8fc 100644 --- a/lldb/test/python_api/function_symbol/TestSymbolAPI.py +++ b/lldb/test/python_api/function_symbol/TestSymbolAPI.py @@ -66,7 +66,7 @@ class SymbolAPITestCase(TestBase): self.assertTrue(symbol_line1.GetType() == lldb.eSymbolTypeCode) addr_line1 = symbol_line1.GetStartAddress() # And a section type of code, too. - self.assertTrue(addr_line1.GetSectionType() == lldb.eSectionTypeCode) + self.assertTrue(addr_line1.GetSection().GetSectionType() == lldb.eSectionTypeCode) # Continue the inferior, the breakpoint 2 should be hit. process.Continue() @@ -79,7 +79,7 @@ class SymbolAPITestCase(TestBase): self.assertTrue(symbol_line2.GetType() == lldb.eSymbolTypeCode) addr_line2 = symbol_line2.GetStartAddress() # And a section type of code, too. - self.assertTrue(addr_line2.GetSectionType() == lldb.eSectionTypeCode) + self.assertTrue(addr_line2.GetSection().GetSectionType() == lldb.eSectionTypeCode) # Now verify that both addresses point to the same module. if self.TraceOn(): |