LLDB  mainline
DynamicLoaderMacOS.h
Go to the documentation of this file.
1 //===-- DynamicLoaderMacOS.h -------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS /
10 // watchOS / BridgeOS)
11 // platforms late 2016 and newer, where lldb will call dyld SPI functions to get
12 // information about shared libraries, information about the shared cache, and
13 // the _dyld_debugger_notification function we put a breakpoint on give us an
14 // array of load addresses for solibs loaded and unloaded. The SPI will tell us
15 // about both dyld and the executable, in addition to all of the usual solibs.
16 
17 #ifndef LLDB_SOURCE_PLUGINS_DYNAMICLOADER_MACOSX_DYLD_DYNAMICLOADERMACOS_H
18 #define LLDB_SOURCE_PLUGINS_DYNAMICLOADER_MACOSX_DYLD_DYNAMICLOADERMACOS_H
19 
20 #include <mutex>
21 #include <vector>
22 
24 #include "lldb/Target/Process.h"
25 #include "lldb/Utility/FileSpec.h"
27 #include "lldb/Utility/UUID.h"
28 
29 #include "DynamicLoaderDarwin.h"
30 
32 public:
34 
35  ~DynamicLoaderMacOS() override;
36 
37  // Static Functions
38  static void Initialize();
39 
40  static void Terminate();
41 
42  static llvm::StringRef GetPluginNameStatic() { return "macos-dyld"; }
43 
44  static llvm::StringRef GetPluginDescriptionStatic();
45 
47  CreateInstance(lldb_private::Process *process, bool force);
48 
49  /// Called after attaching a process.
50  ///
51  /// Allow DynamicLoader plug-ins to execute some code after
52  /// attaching to a process.
53  bool ProcessDidExec() override;
54 
56 
58  lldb::addr_t &base_address, lldb_private::UUID &uuid,
59  lldb_private::LazyBool &using_shared_cache,
60  lldb_private::LazyBool &private_shared_cache) override;
61 
62  // PluginInterface protocol
63  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
64 
65 protected:
66  void PutToLog(lldb_private::Log *log) const;
67 
68  void DoInitialImageFetch() override;
69 
70  bool NeedToDoInitialImageFetch() override;
71 
72  bool DidSetNotificationBreakpoint() override;
73 
74  bool SetDYLDHandoverBreakpoint(lldb::addr_t notification_address);
75 
77 
78  void AddBinaries(const std::vector<lldb::addr_t> &load_addresses);
79 
80  void DoClear() override;
81 
82  bool IsFullyInitialized() override;
83 
84  static bool
85  NotifyBreakpointHit(void *baton,
87  lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
88 
89  bool SetNotificationBreakpoint() override;
90 
91  void ClearNotificationBreakpoint() override;
92 
94  uint32_t infos_count,
95  bool update_executable);
96 
99 
100  uint32_t m_image_infos_stop_id; // The Stop ID the last time we
101  // loaded/unloaded images
104  mutable std::recursive_mutex m_mutex;
105  lldb::addr_t m_maybe_image_infos_address; // If dyld is still maintaining the
106  // all_image_infos address, store it
107  // here so we can use it to detect
108  // exec's when talking to
109  // debugservers that don't support
110  // the "reason:exec" annotation.
112 };
113 
114 #endif // LLDB_SOURCE_PLUGINS_DYNAMICLOADER_MACOSX_DYLD_DYNAMICLOADERMACOS_H
lldb_private::UUID
Definition: UUID.h:23
DynamicLoaderMacOS::GetDyldLockVariableAddressFromModule
lldb::addr_t GetDyldLockVariableAddressFromModule(lldb_private::Module *module)
Definition: DynamicLoaderMacOS.cpp:468
lldb_private::StoppointCallbackContext
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
Definition: StoppointCallbackContext.h:26
DynamicLoaderMacOS::CanLoadImage
lldb_private::Status CanLoadImage() override
Ask if it is ok to try and load or unload an shared library (image).
Definition: DynamicLoaderMacOS.cpp:494
DynamicLoaderMacOS::DoInitialImageFetch
void DoInitialImageFetch() override
Definition: DynamicLoaderMacOS.cpp:194
DynamicLoaderMacOS::IsFullyInitialized
bool IsFullyInitialized() override
Return whether the dynamic loader is fully initialized and it's safe to call its APIs.
Definition: DynamicLoaderMacOS.cpp:152
StructuredData.h
UUID.h
DynamicLoaderMacOS::m_image_infos_stop_id
uint32_t m_image_infos_stop_id
Definition: DynamicLoaderMacOS.h:100
lldb_private::DynamicLoaderDarwin::ImageInfo::collection
std::vector< ImageInfo > collection
Definition: DynamicLoaderDarwin.h:170
DynamicLoaderMacOS::Initialize
static void Initialize()
Definition: DynamicLoaderMacOS.cpp:594
DynamicLoaderMacOS::CreateInstance
static lldb_private::DynamicLoader * CreateInstance(lldb_private::Process *process, bool force)
Definition: DynamicLoaderMacOS.cpp:36
lldb_private::Process
Definition: Process.h:338
DynamicLoaderDarwin.h
DynamicLoaderMacOS::DidSetNotificationBreakpoint
bool DidSetNotificationBreakpoint() override
Definition: DynamicLoaderMacOS.cpp:179
DynamicLoaderMacOS::~DynamicLoaderMacOS
~DynamicLoaderMacOS() override
Definition: DynamicLoaderMacOS.cpp:86
lldb_private::Module
Definition: Module.h:87
DynamicLoaderMacOS::SetNotificationBreakpoint
bool SetNotificationBreakpoint() override
Definition: DynamicLoaderMacOS.cpp:420
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
DynamicLoaderMacOS
Definition: DynamicLoaderMacOS.h:31
lldb_private::LazyBool
LazyBool
Definition: lldb-private-enumerations.h:115
DynamicLoaderMacOS::NeedToDoInitialImageFetch
bool NeedToDoInitialImageFetch() override
Definition: DynamicLoaderMacOS.cpp:226
DynamicLoaderMacOS::PutToLog
void PutToLog(lldb_private::Log *log) const
Definition: DynamicLoaderMacOS.cpp:415
Process.h
DynamicLoaderMacOS::m_libsystem_fully_initalized
bool m_libsystem_fully_initalized
Definition: DynamicLoaderMacOS.h:111
DynamicLoaderMacOS::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DynamicLoaderMacOS.h:42
DynamicLoaderMacOS::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: DynamicLoaderMacOS.cpp:603
DynamicLoaderMacOS::NotifyBreakpointHit
static bool NotifyBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
Definition: DynamicLoaderMacOS.cpp:232
DynamicLoaderMacOS::AddBinaries
void AddBinaries(const std::vector< lldb::addr_t > &load_addresses)
Definition: DynamicLoaderMacOS.cpp:387
DynamicLoaderMacOS::ClearDYLDHandoverBreakpoint
void ClearDYLDHandoverBreakpoint()
Definition: DynamicLoaderMacOS.cpp:461
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
DynamicLoaderMacOS::DynamicLoaderMacOS
DynamicLoaderMacOS(lldb_private::Process *process)
Definition: DynamicLoaderMacOS.cpp:78
DynamicLoaderMacOS::m_dyld_handover_break_id
lldb::user_id_t m_dyld_handover_break_id
Definition: DynamicLoaderMacOS.h:103
lldb_private::DynamicLoaderDarwin
Definition: DynamicLoaderDarwin.h:27
DynamicLoaderMacOS::Terminate
static void Terminate()
Definition: DynamicLoaderMacOS.cpp:599
DynamicLoaderMacOS::m_maybe_image_infos_address
lldb::addr_t m_maybe_image_infos_address
Definition: DynamicLoaderMacOS.h:105
DynamicLoaderMacOS::ClearNotificationBreakpoint
void ClearNotificationBreakpoint() override
Definition: DynamicLoaderMacOS.cpp:183
lldb_private::Status
Definition: Status.h:44
uint32_t
DynamicLoaderMacOS::GetPluginName
llvm::StringRef GetPluginName() override
Definition: DynamicLoaderMacOS.h:63
DynamicLoaderMacOS::GetSharedCacheInformation
bool GetSharedCacheInformation(lldb::addr_t &base_address, lldb_private::UUID &uuid, lldb_private::LazyBool &using_shared_cache, lldb_private::LazyBool &private_shared_cache) override
Get information about the shared cache for a process, if possible.
Definition: DynamicLoaderMacOS.cpp:550
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
DynamicLoaderMacOS::SetDYLDHandoverBreakpoint
bool SetDYLDHandoverBreakpoint(lldb::addr_t notification_address)
Definition: DynamicLoaderMacOS.cpp:447
DynamicLoaderMacOS::DoClear
void DoClear() override
Definition: DynamicLoaderMacOS.cpp:139
FileSpec.h
lldb_private::Log
Definition: Log.h:115
DynamicLoaderMacOS::UpdateImageInfosHeaderAndLoadCommands
void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos, uint32_t infos_count, bool update_executable)
DynamicLoaderMacOS::ProcessDidExec
bool ProcessDidExec() override
Called after attaching a process.
Definition: DynamicLoaderMacOS.cpp:93
DynamicLoaderMacOS::m_break_id
lldb::user_id_t m_break_id
Definition: DynamicLoaderMacOS.h:102
DynamicLoader.h
DynamicLoaderMacOS::m_mutex
std::recursive_mutex m_mutex
Definition: DynamicLoaderMacOS.h:104