Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,16 @@
add_lldb_library(lldbPluginDynamicLoaderMacOSXDYLD PLUGIN
DynamicLoaderMacOSXDYLD.cpp
DynamicLoaderMacOS.cpp
DynamicLoaderDarwin.cpp
LINK_LIBS
lldbBreakpoint
lldbCore
lldbExpression
lldbHost
lldbSymbol
lldbTarget
lldbUtility
LINK_COMPONENTS
Support
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,245 @@
//===-- DynamicLoaderDarwin.h -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_DynamicLoaderDarwin_h_
#define liblldb_DynamicLoaderDarwin_h_
// C Includes
// C++ Includes
#include <map>
#include <mutex>
#include <vector>
// Other libraries and framework includes
// Project includes
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/SafeMachO.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/UUID.h"
#include "llvm/ADT/Triple.h"
namespace lldb_private {
class DynamicLoaderDarwin : public lldb_private::DynamicLoader {
public:
DynamicLoaderDarwin(lldb_private::Process *process);
virtual ~DynamicLoaderDarwin() override;
//------------------------------------------------------------------
/// Called after attaching a process.
///
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
void DidAttach() override;
void DidLaunch() override;
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
bool stop_others) override;
size_t FindEquivalentSymbols(
lldb_private::Symbol *original_symbol,
lldb_private::ModuleList &module_list,
lldb_private::SymbolContextList &equivalent_symbols) override;
lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
const lldb::ThreadSP thread,
lldb::addr_t tls_file_addr) override;
bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
virtual void DoInitialImageFetch() = 0;
virtual bool NeedToDoInitialImageFetch() = 0;
protected:
void PrivateInitialize(lldb_private::Process *process);
void PrivateProcessStateChanged(lldb_private::Process *process,
lldb::StateType state);
void Clear(bool clear_process);
// Clear method for classes derived from this one
virtual void DoClear() = 0;
void SetDYLDModule(lldb::ModuleSP &dyld_module_sp);
lldb::ModuleSP GetDYLDModule();
class Segment {
public:
Segment()
: name(), vmaddr(LLDB_INVALID_ADDRESS), vmsize(0), fileoff(0),
filesize(0), maxprot(0), initprot(0), nsects(0), flags(0) {}
lldb_private::ConstString name;
lldb::addr_t vmaddr;
lldb::addr_t vmsize;
lldb::addr_t fileoff;
lldb::addr_t filesize;
uint32_t maxprot;
uint32_t initprot;
uint32_t nsects;
uint32_t flags;
bool operator==(const Segment &rhs) const {
return name == rhs.name && vmaddr == rhs.vmaddr && vmsize == rhs.vmsize;
}
void PutToLog(lldb_private::Log *log, lldb::addr_t slide) const;
};
struct ImageInfo {
lldb::addr_t address; // Address of mach header for this dylib
lldb::addr_t slide; // The amount to slide all segments by if there is a
// global slide.
lldb::addr_t mod_date; // Modification date for this dylib
lldb_private::FileSpec file_spec; // Resolved path for this dylib
lldb_private::UUID
uuid; // UUID for this dylib if it has one, else all zeros
llvm::MachO::mach_header header; // The mach header for this image
std::vector<Segment> segments; // All segment vmaddr and vmsize pairs for
// this executable (from memory of inferior)
uint32_t load_stop_id; // The process stop ID that the sections for this
// image were loaded
llvm::Triple::OSType os_type; // LC_VERSION_MIN_... load command os type
std::string min_version_os_sdk; // LC_VERSION_MIN_... sdk value
ImageInfo()
: address(LLDB_INVALID_ADDRESS), slide(0), mod_date(0), file_spec(),
uuid(), header(), segments(), load_stop_id(0),
os_type(llvm::Triple::OSType::UnknownOS), min_version_os_sdk() {}
void Clear(bool load_cmd_data_only) {
if (!load_cmd_data_only) {
address = LLDB_INVALID_ADDRESS;
slide = 0;
mod_date = 0;
file_spec.Clear();
::memset(&header, 0, sizeof(header));
}
uuid.Clear();
segments.clear();
load_stop_id = 0;
os_type = llvm::Triple::OSType::UnknownOS;
min_version_os_sdk.clear();
}
bool operator==(const ImageInfo &rhs) const {
return address == rhs.address && slide == rhs.slide &&
mod_date == rhs.mod_date && file_spec == rhs.file_spec &&
uuid == rhs.uuid &&
memcmp(&header, &rhs.header, sizeof(header)) == 0 &&
segments == rhs.segments && os_type == rhs.os_type;
}
bool UUIDValid() const { return uuid.IsValid(); }
uint32_t GetAddressByteSize() {
if (header.cputype) {
if (header.cputype & llvm::MachO::CPU_ARCH_ABI64)
return 8;
else
return 4;
}
return 0;
}
lldb_private::ArchSpec GetArchitecture() const {
return lldb_private::ArchSpec(lldb_private::eArchTypeMachO,
header.cputype, header.cpusubtype);
}
const Segment *FindSegment(const lldb_private::ConstString &name) const;
void PutToLog(lldb_private::Log *log) const;
typedef std::vector<ImageInfo> collection;
typedef collection::iterator iterator;
typedef collection::const_iterator const_iterator;
};
bool UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo &info);
bool UnloadModuleSections(lldb_private::Module *module, ImageInfo &info);
lldb::ModuleSP FindTargetModuleForImageInfo(ImageInfo &image_info,
bool can_create,
bool *did_create_ptr);
void UnloadImages(const std::vector<lldb::addr_t> &solib_addresses);
void UnloadAllImages();
virtual bool SetNotificationBreakpoint() = 0;
virtual void ClearNotificationBreakpoint() = 0;
virtual bool DidSetNotificationBreakpoint() = 0;
typedef std::map<uint64_t, lldb::addr_t> PthreadKeyToTLSMap;
typedef std::map<lldb::user_id_t, PthreadKeyToTLSMap> ThreadIDToTLSMap;
std::recursive_mutex &GetMutex() const { return m_mutex; }
lldb::ModuleSP GetPThreadLibraryModule();
lldb_private::Address GetPthreadSetSpecificAddress();
bool JSONImageInformationIntoImageInfo(
lldb_private::StructuredData::ObjectSP image_details,
ImageInfo::collection &image_infos);
// If image_infos contains / may contain dyld or executable image, call this
// method
// to keep our internal record keeping of the special binaries up-to-date.
void
UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos);
// if image_info is a dyld binary, call this method
void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info);
// If image_infos contains / may contain executable image, call this method
// to keep our internal record keeping of the special dyld binary up-to-date.
void AddExecutableModuleIfInImageInfos(ImageInfo::collection &image_infos);
bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos);
// Whether we should use the new dyld SPI to get shared library information,
// or read
// it directly out of the dyld_all_image_infos. Whether we use the (newer)
// DynamicLoaderMacOS
// plugin or the (older) DynamicLoaderMacOSX plugin.
static bool UseDYLDSPI(lldb_private::Process *process);
lldb::ModuleWP m_dyld_module_wp; // the dyld whose file type (mac, ios, etc)
// matches the process
lldb::ModuleWP m_libpthread_module_wp;
lldb_private::Address m_pthread_getspecific_addr;
ThreadIDToTLSMap m_tid_to_tls_map;
ImageInfo::collection
m_dyld_image_infos; // Current shared libraries information
uint32_t m_dyld_image_infos_stop_id; // The process stop ID that
// "m_dyld_image_infos" is valid for
ImageInfo m_dyld;
mutable std::recursive_mutex m_mutex;
private:
DISALLOW_COPY_AND_ASSIGN(DynamicLoaderDarwin);
};
} // namespace lldb_private
#endif // liblldb_DynamicLoaderDarwin_h_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,117 @@
//===-- DynamicLoaderMacOS.h -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS /
// watchOS)
// platforms late 2016 and newer, where lldb will call dyld SPI functions to get
// information about shared libraries, information about the shared cache, and
// the _dyld_debugger_notification function we put a breakpoint on give us an
// array of load addresses for solibs loaded and unloaded. The SPI will tell us
// about both dyld and the executable, in addition to all of the usual solibs.
#ifndef liblldb_DynamicLoaderMacOS_h_
#define liblldb_DynamicLoaderMacOS_h_
// C Includes
// C++ Includes
#include <mutex>
#include <vector>
// Other libraries and framework includes
// Project includes
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/SafeMachO.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/UUID.h"
#include "DynamicLoaderDarwin.h"
class DynamicLoaderMacOS : public lldb_private::DynamicLoaderDarwin {
public:
DynamicLoaderMacOS(lldb_private::Process *process);
virtual ~DynamicLoaderMacOS() override;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetPluginDescriptionStatic();
static lldb_private::DynamicLoader *
CreateInstance(lldb_private::Process *process, bool force);
//------------------------------------------------------------------
/// Called after attaching a process.
///
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
bool ProcessDidExec() override;
lldb_private::Status CanLoadImage() override;
bool GetSharedCacheInformation(
lldb::addr_t &base_address, lldb_private::UUID &uuid,
lldb_private::LazyBool &using_shared_cache,
lldb_private::LazyBool &private_shared_cache) override;
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
protected:
void PutToLog(lldb_private::Log *log) const;
void DoInitialImageFetch() override;
bool NeedToDoInitialImageFetch() override;
bool DidSetNotificationBreakpoint() override;
void AddBinaries(const std::vector<lldb::addr_t> &load_addresses);
void DoClear() override;
static bool
NotifyBreakpointHit(void *baton,
lldb_private::StoppointCallbackContext *context,
lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
bool SetNotificationBreakpoint() override;
void ClearNotificationBreakpoint() override;
void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos,
uint32_t infos_count,
bool update_executable);
lldb::addr_t
GetDyldLockVariableAddressFromModule(lldb_private::Module *module);
uint32_t m_image_infos_stop_id; // The Stop ID the last time we
// loaded/unloaded images
lldb::user_id_t m_break_id;
mutable std::recursive_mutex m_mutex;
private:
DISALLOW_COPY_AND_ASSIGN(DynamicLoaderMacOS);
};
#endif // liblldb_DynamicLoaderMacOS_h_

View File

@@ -0,0 +1,186 @@
//===-- DynamicLoaderMacOSXDYLD.h -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS /
// watchOS)
// platforms earlier than 2016, where lldb would read the "dyld_all_image_infos"
// dyld internal structure to understand where things were loaded and the
// solib loaded/unloaded notification function we put a breakpoint on gives us
// an array of (load address, mod time, file path) tuples.
//
// As of late 2016, the new DynamicLoaderMacOS plugin should be used, which uses
// dyld SPI functions to get the same information without reading internal dyld
// data structures.
#ifndef liblldb_DynamicLoaderMacOSXDYLD_h_
#define liblldb_DynamicLoaderMacOSXDYLD_h_
// C Includes
// C++ Includes
#include <mutex>
#include <vector>
// Other libraries and framework includes
// Project includes
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/SafeMachO.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/UUID.h"
#include "DynamicLoaderDarwin.h"
class DynamicLoaderMacOSXDYLD : public lldb_private::DynamicLoaderDarwin {
public:
DynamicLoaderMacOSXDYLD(lldb_private::Process *process);
virtual ~DynamicLoaderMacOSXDYLD() override;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetPluginDescriptionStatic();
static lldb_private::DynamicLoader *
CreateInstance(lldb_private::Process *process, bool force);
//------------------------------------------------------------------
/// Called after attaching a process.
///
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
bool ProcessDidExec() override;
lldb_private::Status CanLoadImage() override;
bool GetSharedCacheInformation(
lldb::addr_t &base_address, lldb_private::UUID &uuid,
lldb_private::LazyBool &using_shared_cache,
lldb_private::LazyBool &private_shared_cache) override;
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
protected:
void PutToLog(lldb_private::Log *log) const;
void DoInitialImageFetch() override;
bool NeedToDoInitialImageFetch() override;
bool DidSetNotificationBreakpoint() override;
void DoClear() override;
bool ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb::addr_t addr);
static bool
NotifyBreakpointHit(void *baton,
lldb_private::StoppointCallbackContext *context,
lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
uint32_t AddrByteSize();
bool ReadMachHeader(lldb::addr_t addr, llvm::MachO::mach_header *header,
lldb_private::DataExtractor *load_command_data);
uint32_t ParseLoadCommands(const lldb_private::DataExtractor &data,
ImageInfo &dylib_info,
lldb_private::FileSpec *lc_id_dylinker);
struct DYLDAllImageInfos {
uint32_t version;
uint32_t dylib_info_count; // Version >= 1
lldb::addr_t dylib_info_addr; // Version >= 1
lldb::addr_t notification; // Version >= 1
bool processDetachedFromSharedRegion; // Version >= 1
bool libSystemInitialized; // Version >= 2
lldb::addr_t dyldImageLoadAddress; // Version >= 2
DYLDAllImageInfos()
: version(0), dylib_info_count(0),
dylib_info_addr(LLDB_INVALID_ADDRESS),
notification(LLDB_INVALID_ADDRESS),
processDetachedFromSharedRegion(false), libSystemInitialized(false),
dyldImageLoadAddress(LLDB_INVALID_ADDRESS) {}
void Clear() {
version = 0;
dylib_info_count = 0;
dylib_info_addr = LLDB_INVALID_ADDRESS;
notification = LLDB_INVALID_ADDRESS;
processDetachedFromSharedRegion = false;
libSystemInitialized = false;
dyldImageLoadAddress = LLDB_INVALID_ADDRESS;
}
bool IsValid() const { return version >= 1 || version <= 6; }
};
static lldb::ByteOrder GetByteOrderFromMagic(uint32_t magic);
bool SetNotificationBreakpoint() override;
void ClearNotificationBreakpoint() override;
// There is a little tricky bit where you might initially attach while dyld is
// updating
// the all_image_infos, and you can't read the infos, so you have to continue
// and pick it
// up when you hit the update breakpoint. At that point, you need to run this
// initialize
// function, but when you do it that way you DON'T need to do the extra work
// you would at
// the breakpoint.
// So this function will only do actual work if the image infos haven't been
// read yet.
// If it does do any work, then it will return true, and false otherwise.
// That way you can
// call it in the breakpoint action, and if it returns true you're done.
bool InitializeFromAllImageInfos();
bool ReadAllImageInfosStructure();
bool AddModulesUsingImageInfosAddress(lldb::addr_t image_infos_addr,
uint32_t image_infos_count);
bool RemoveModulesUsingImageInfosAddress(lldb::addr_t image_infos_addr,
uint32_t image_infos_count);
void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos,
uint32_t infos_count,
bool update_executable);
bool ReadImageInfos(lldb::addr_t image_infos_addr, uint32_t image_infos_count,
ImageInfo::collection &image_infos);
lldb::addr_t m_dyld_all_image_infos_addr;
DYLDAllImageInfos m_dyld_all_image_infos;
uint32_t m_dyld_all_image_infos_stop_id;
lldb::user_id_t m_break_id;
mutable std::recursive_mutex m_mutex;
bool m_process_image_addr_is_all_images_infos;
private:
DISALLOW_COPY_AND_ASSIGN(DynamicLoaderMacOSXDYLD);
};
#endif // liblldb_DynamicLoaderMacOSXDYLD_h_