We had support that assumed that thread local data for a variable could be determined solely from the module in which the variable exists. While this work for linux, it doesn't work for Apple OSs. The DWARF for thread local variables consists of location opcodes that do something like: DW_OP_const8u (x) DW_OP_form_tls_address or DW_OP_const8u (x) DW_OP_GNU_push_tls_address The "x" is allowed to be anything that is needed to determine the location of the variable. For Linux "x" is the offset within the TLS data for a given executable (ModuleSP in LLDB). For Apple OS variants, it is the file address of the data structure that contains a pthread key that can be used with pthread_getspecific() and the offset needed. This fix passes the "x" along to the thread: virtual lldb::addr_t lldb_private::Thread::GetThreadLocalData(const lldb::ModuleSP module, lldb::addr_t tls_file_addr); Then this is passed along to the DynamicLoader::GetThreadLocalData(): virtual lldb::addr_t lldb_private::DynamicLoader::GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr); This allows each DynamicLoader plug-in do the right thing for the current OS. The DynamicLoaderMacOSXDYLD was modified to be able to grab the pthread key from the data structure that is in memory and call "void *pthread_getspecific(pthread_key_t key)" to get the value of the thread local storage and it caches it per thread since it never changes. I had to update the test case to access the thread local data before trying to print it as on Apple OS variants, thread locals are not available unless they have been accessed at least one by the current thread. I also added a new lldb::ValueType named "eValueTypeVariableThreadLocal" so that we can ask SBValue objects for their ValueType and be able to tell when we have a thread local variable. <rdar://problem/23308080> llvm-svn: 274366
180 lines
5.5 KiB
C++
180 lines
5.5 KiB
C++
//===-- DynamicLoaderPOSIXDYLD.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_DynamicLoaderPOSIXDYLD_h_
|
|
#define liblldb_DynamicLoaderPOSIXDYLD_h_
|
|
|
|
// C Includes
|
|
// C++ Includes
|
|
// Other libraries and framework includes
|
|
// Project includes
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
|
#include "lldb/Target/DynamicLoader.h"
|
|
|
|
#include "DYLDRendezvous.h"
|
|
|
|
class AuxVector;
|
|
|
|
class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader
|
|
{
|
|
public:
|
|
DynamicLoaderPOSIXDYLD(lldb_private::Process *process);
|
|
|
|
~DynamicLoaderPOSIXDYLD() override;
|
|
|
|
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);
|
|
|
|
//------------------------------------------------------------------
|
|
// DynamicLoader protocol
|
|
//------------------------------------------------------------------
|
|
|
|
void
|
|
DidAttach() override;
|
|
|
|
void
|
|
DidLaunch() override;
|
|
|
|
lldb::ThreadPlanSP
|
|
GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
|
|
bool stop_others) override;
|
|
|
|
lldb_private::Error
|
|
CanLoadImage() override;
|
|
|
|
lldb::addr_t
|
|
GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override;
|
|
|
|
//------------------------------------------------------------------
|
|
// PluginInterface protocol
|
|
//------------------------------------------------------------------
|
|
lldb_private::ConstString
|
|
GetPluginName() override;
|
|
|
|
uint32_t
|
|
GetPluginVersion() override;
|
|
|
|
protected:
|
|
/// Runtime linker rendezvous structure.
|
|
DYLDRendezvous m_rendezvous;
|
|
|
|
/// Virtual load address of the inferior process.
|
|
lldb::addr_t m_load_offset;
|
|
|
|
/// Virtual entry address of the inferior process.
|
|
lldb::addr_t m_entry_point;
|
|
|
|
/// Auxiliary vector of the inferior process.
|
|
std::unique_ptr<AuxVector> m_auxv;
|
|
|
|
/// Rendezvous breakpoint.
|
|
lldb::break_id_t m_dyld_bid;
|
|
|
|
/// Contains AT_SYSINFO_EHDR, which means a vDSO has been
|
|
/// mapped to the address space
|
|
lldb::addr_t m_vdso_base;
|
|
|
|
/// Loaded module list. (link map for each module)
|
|
std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> m_loaded_modules;
|
|
|
|
/// Enables a breakpoint on a function called by the runtime
|
|
/// linker each time a module is loaded or unloaded.
|
|
virtual void
|
|
SetRendezvousBreakpoint();
|
|
|
|
/// Callback routine which updates the current list of loaded modules based
|
|
/// on the information supplied by the runtime linker.
|
|
static bool
|
|
RendezvousBreakpointHit(void *baton,
|
|
lldb_private::StoppointCallbackContext *context,
|
|
lldb::user_id_t break_id,
|
|
lldb::user_id_t break_loc_id);
|
|
|
|
/// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
|
|
/// of loaded modules.
|
|
void
|
|
RefreshModules();
|
|
|
|
/// Updates the load address of every allocatable section in @p module.
|
|
///
|
|
/// @param module The module to traverse.
|
|
///
|
|
/// @param link_map_addr The virtual address of the link map for the @p module.
|
|
///
|
|
/// @param base_addr The virtual base address @p module is loaded at.
|
|
void
|
|
UpdateLoadedSections(lldb::ModuleSP module,
|
|
lldb::addr_t link_map_addr,
|
|
lldb::addr_t base_addr,
|
|
bool base_addr_is_offset) override;
|
|
|
|
/// Removes the loaded sections from the target in @p module.
|
|
///
|
|
/// @param module The module to traverse.
|
|
void
|
|
UnloadSections(const lldb::ModuleSP module) override;
|
|
|
|
/// Resolves the entry point for the current inferior process and sets a
|
|
/// breakpoint at that address.
|
|
void
|
|
ProbeEntry();
|
|
|
|
/// Callback routine invoked when we hit the breakpoint on process entry.
|
|
///
|
|
/// This routine is responsible for resolving the load addresses of all
|
|
/// dependent modules required by the inferior and setting up the rendezvous
|
|
/// breakpoint.
|
|
static bool
|
|
EntryBreakpointHit(void *baton,
|
|
lldb_private::StoppointCallbackContext *context,
|
|
lldb::user_id_t break_id,
|
|
lldb::user_id_t break_loc_id);
|
|
|
|
/// Helper for the entry breakpoint callback. Resolves the load addresses
|
|
/// of all dependent modules.
|
|
virtual void
|
|
LoadAllCurrentModules();
|
|
|
|
/// Computes a value for m_load_offset returning the computed address on
|
|
/// success and LLDB_INVALID_ADDRESS on failure.
|
|
lldb::addr_t
|
|
ComputeLoadOffset();
|
|
|
|
/// Computes a value for m_entry_point returning the computed address on
|
|
/// success and LLDB_INVALID_ADDRESS on failure.
|
|
lldb::addr_t
|
|
GetEntryPoint();
|
|
|
|
/// Evaluate if Aux vectors contain vDSO information
|
|
/// in case they do, read and assign the address to m_vdso_base
|
|
void
|
|
EvalVdsoStatus();
|
|
|
|
/// Loads Module from inferior process.
|
|
void
|
|
ResolveExecutableModule(lldb::ModuleSP &module_sp);
|
|
|
|
private:
|
|
DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
|
|
};
|
|
|
|
#endif // liblldb_DynamicLoaderPOSIXDYLD_h_
|