• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #include "lldb/Target/DynamicLoader.h"
24 #include "lldb/Target/Process.h"
25 #include "lldb/Utility/FileSpec.h"
26 #include "lldb/Utility/StructuredData.h"
27 #include "lldb/Utility/UUID.h"
28 
29 #include "DynamicLoaderDarwin.h"
30 
31 class DynamicLoaderMacOS : public lldb_private::DynamicLoaderDarwin {
32 public:
33   DynamicLoaderMacOS(lldb_private::Process *process);
34 
35   ~DynamicLoaderMacOS() override;
36 
37   // Static Functions
38   static void Initialize();
39 
40   static void Terminate();
41 
42   static lldb_private::ConstString GetPluginNameStatic();
43 
44   static const char *GetPluginDescriptionStatic();
45 
46   static lldb_private::DynamicLoader *
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 
55   lldb_private::Status CanLoadImage() override;
56 
57   bool GetSharedCacheInformation(
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   lldb_private::ConstString GetPluginName() override;
64 
65   uint32_t GetPluginVersion() override;
66 
67 protected:
68   void PutToLog(lldb_private::Log *log) const;
69 
70   void DoInitialImageFetch() override;
71 
72   bool NeedToDoInitialImageFetch() override;
73 
74   bool DidSetNotificationBreakpoint() override;
75 
76   void AddBinaries(const std::vector<lldb::addr_t> &load_addresses);
77 
78   void DoClear() override;
79 
80   static bool
81   NotifyBreakpointHit(void *baton,
82                       lldb_private::StoppointCallbackContext *context,
83                       lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
84 
85   bool SetNotificationBreakpoint() override;
86 
87   void ClearNotificationBreakpoint() override;
88 
89   void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos,
90                                              uint32_t infos_count,
91                                              bool update_executable);
92 
93   lldb::addr_t
94   GetDyldLockVariableAddressFromModule(lldb_private::Module *module);
95 
96   uint32_t m_image_infos_stop_id; // The Stop ID the last time we
97                                   // loaded/unloaded images
98   lldb::user_id_t m_break_id;
99   mutable std::recursive_mutex m_mutex;
100   lldb::addr_t m_maybe_image_infos_address; // If dyld is still maintaining the
101                                             // all_image_infos address, store it
102                                             // here so we can use it to detect
103                                             // exec's when talking to
104                                             // debugservers that don't support
105                                             // the "reason:exec" annotation.
106 };
107 
108 #endif // LLDB_SOURCE_PLUGINS_DYNAMICLOADER_MACOSX_DYLD_DYNAMICLOADERMACOS_H
109