Bug Summary

File:tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
Warning:line 105, column 3
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name DynamicLoaderPOSIXDYLD.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D HAVE_ROUND -D LLDB_CONFIGURATION_RELEASE -D LLDB_USE_BUILTIN_DEMANGLER -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/. -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
1//===-- DynamicLoaderPOSIXDYLD.cpp ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// Main header include
11#include "DynamicLoaderPOSIXDYLD.h"
12
13// Project includes
14#include "AuxVector.h"
15
16// Other libraries and framework includes
17#include "lldb/Breakpoint/BreakpointLocation.h"
18#include "lldb/Core/Module.h"
19#include "lldb/Core/ModuleSpec.h"
20#include "lldb/Core/PluginManager.h"
21#include "lldb/Core/Section.h"
22#include "lldb/Symbol/Function.h"
23#include "lldb/Symbol/ObjectFile.h"
24#include "lldb/Target/MemoryRegionInfo.h"
25#include "lldb/Target/Platform.h"
26#include "lldb/Target/Process.h"
27#include "lldb/Target/Target.h"
28#include "lldb/Target/Thread.h"
29#include "lldb/Target/ThreadPlanRunToAddress.h"
30#include "lldb/Utility/Log.h"
31
32// C++ Includes
33// C Includes
34
35using namespace lldb;
36using namespace lldb_private;
37
38void DynamicLoaderPOSIXDYLD::Initialize() {
39 PluginManager::RegisterPlugin(GetPluginNameStatic(),
40 GetPluginDescriptionStatic(), CreateInstance);
41}
42
43void DynamicLoaderPOSIXDYLD::Terminate() {}
44
45lldb_private::ConstString DynamicLoaderPOSIXDYLD::GetPluginName() {
46 return GetPluginNameStatic();
47}
48
49lldb_private::ConstString DynamicLoaderPOSIXDYLD::GetPluginNameStatic() {
50 static ConstString g_name("linux-dyld");
51 return g_name;
52}
53
54const char *DynamicLoaderPOSIXDYLD::GetPluginDescriptionStatic() {
55 return "Dynamic loader plug-in that watches for shared library "
56 "loads/unloads in POSIX processes.";
57}
58
59uint32_t DynamicLoaderPOSIXDYLD::GetPluginVersion() { return 1; }
60
61DynamicLoader *DynamicLoaderPOSIXDYLD::CreateInstance(Process *process,
62 bool force) {
63 bool create = force;
64 if (!create) {
65 const llvm::Triple &triple_ref =
66 process->GetTarget().GetArchitecture().GetTriple();
67 if (triple_ref.getOS() == llvm::Triple::FreeBSD ||
68 triple_ref.getOS() == llvm::Triple::Linux ||
69 triple_ref.getOS() == llvm::Triple::NetBSD)
70 create = true;
71 }
72
73 if (create)
74 return new DynamicLoaderPOSIXDYLD(process);
75 return NULL__null;
76}
77
78DynamicLoaderPOSIXDYLD::DynamicLoaderPOSIXDYLD(Process *process)
79 : DynamicLoader(process), m_rendezvous(process),
80 m_load_offset(LLDB_INVALID_ADDRESS(18446744073709551615UL)), m_entry_point(LLDB_INVALID_ADDRESS(18446744073709551615UL)),
81 m_auxv(), m_dyld_bid(LLDB_INVALID_BREAK_ID0),
82 m_vdso_base(LLDB_INVALID_ADDRESS(18446744073709551615UL)),
83 m_interpreter_base(LLDB_INVALID_ADDRESS(18446744073709551615UL)) {}
84
85DynamicLoaderPOSIXDYLD::~DynamicLoaderPOSIXDYLD() {
86 if (m_dyld_bid != LLDB_INVALID_BREAK_ID0) {
87 m_process->GetTarget().RemoveBreakpointByID(m_dyld_bid);
88 m_dyld_bid = LLDB_INVALID_BREAK_ID0;
89 }
90}
91
92void DynamicLoaderPOSIXDYLD::DidAttach() {
93 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
94 if (log)
1
Assuming 'log' is non-null
2
Taking true branch
95 log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64"l" "u", __FUNCTION__,
96 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID0);
3
Assuming pointer value is null
4
'?' condition is false
97
98 m_auxv.reset(new AuxVector(m_process));
99 if (log)
5
Taking true branch
100 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u" " reloaded auxv data",
101 __FUNCTION__,
102 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID0);
6
'?' condition is false
103
104 // ask the process if it can load any of its own modules
105 m_process->LoadModules();
7
Called C++ object pointer is null
106
107 ModuleSP executable_sp = GetTargetExecutable();
108 ResolveExecutableModule(executable_sp);
109
110 // find the main process load offset
111 addr_t load_offset = ComputeLoadOffset();
112 if (log)
113 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u"
114 " executable '%s', load_offset 0x%" PRIx64"l" "x",
115 __FUNCTION__,
116 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID0,
117 executable_sp ? executable_sp->GetFileSpec().GetPath().c_str()
118 : "<null executable>",
119 load_offset);
120
121 EvalSpecialModulesStatus();
122
123 // if we dont have a load address we cant re-base
124 bool rebase_exec = (load_offset == LLDB_INVALID_ADDRESS(18446744073709551615UL)) ? false : true;
125
126 // if we have a valid executable
127 if (executable_sp.get()) {
128 lldb_private::ObjectFile *obj = executable_sp->GetObjectFile();
129 if (obj) {
130 // don't rebase if the module already has a load address
131 Target &target = m_process->GetTarget();
132 Address addr = obj->GetImageInfoAddress(&target);
133 if (addr.GetLoadAddress(&target) != LLDB_INVALID_ADDRESS(18446744073709551615UL))
134 rebase_exec = false;
135 }
136 } else {
137 // no executable, nothing to re-base
138 rebase_exec = false;
139 }
140
141 // if the target executable should be re-based
142 if (rebase_exec) {
143 ModuleList module_list;
144
145 module_list.Append(executable_sp);
146 if (log)
147 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u"
148 " added executable '%s' to module load list",
149 __FUNCTION__,
150 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID0,
151 executable_sp->GetFileSpec().GetPath().c_str());
152
153 UpdateLoadedSections(executable_sp, LLDB_INVALID_ADDRESS(18446744073709551615UL), load_offset,
154 true);
155
156 LoadAllCurrentModules();
157 if (!SetRendezvousBreakpoint()) {
158 // If we cannot establish rendezvous breakpoint right now
159 // we'll try again at entry point.
160 ProbeEntry();
161 }
162
163 m_process->GetTarget().ModulesDidLoad(module_list);
164 if (log) {
165 log->Printf("DynamicLoaderPOSIXDYLD::%s told the target about the "
166 "modules that loaded:",
167 __FUNCTION__);
168 for (auto module_sp : module_list.Modules()) {
169 log->Printf("-- [module] %s (pid %" PRIu64"l" "u" ")",
170 module_sp ? module_sp->GetFileSpec().GetPath().c_str()
171 : "<null>",
172 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID0);
173 }
174 }
175 }
176}
177
178void DynamicLoaderPOSIXDYLD::DidLaunch() {
179 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
180 if (log)
181 log->Printf("DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__);
182
183 ModuleSP executable;
184 addr_t load_offset;
185
186 m_auxv.reset(new AuxVector(m_process));
187
188 executable = GetTargetExecutable();
189 load_offset = ComputeLoadOffset();
190 EvalSpecialModulesStatus();
191
192 if (executable.get() && load_offset != LLDB_INVALID_ADDRESS(18446744073709551615UL)) {
193 ModuleList module_list;
194 module_list.Append(executable);
195 UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS(18446744073709551615UL), load_offset, true);
196
197 if (log)
198 log->Printf("DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()",
199 __FUNCTION__);
200
201 if (!SetRendezvousBreakpoint()) {
202 // If we cannot establish rendezvous breakpoint right now
203 // we'll try again at entry point.
204 ProbeEntry();
205 }
206
207 LoadVDSO();
208 m_process->GetTarget().ModulesDidLoad(module_list);
209 }
210}
211
212Status DynamicLoaderPOSIXDYLD::CanLoadImage() { return Status(); }
213
214void DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module,
215 addr_t link_map_addr,
216 addr_t base_addr,
217 bool base_addr_is_offset) {
218 m_loaded_modules[module] = link_map_addr;
219 UpdateLoadedSectionsCommon(module, base_addr, base_addr_is_offset);
220}
221
222void DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module) {
223 m_loaded_modules.erase(module);
224
225 UnloadSectionsCommon(module);
226}
227
228void DynamicLoaderPOSIXDYLD::ProbeEntry() {
229 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
230
231 const addr_t entry = GetEntryPoint();
232 if (entry == LLDB_INVALID_ADDRESS(18446744073709551615UL)) {
233 if (log)
234 log->Printf(
235 "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u"
236 " GetEntryPoint() returned no address, not setting entry breakpoint",
237 __FUNCTION__,
238 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID0);
239 return;
240 }
241
242 if (log)
243 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u"
244 " GetEntryPoint() returned address 0x%" PRIx64"l" "x"
245 ", setting entry breakpoint",
246 __FUNCTION__,
247 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID0,
248 entry);
249
250 if (m_process) {
251 Breakpoint *const entry_break =
252 m_process->GetTarget().CreateBreakpoint(entry, true, false).get();
253 entry_break->SetCallback(EntryBreakpointHit, this, true);
254 entry_break->SetBreakpointKind("shared-library-event");
255
256 // Shoudn't hit this more than once.
257 entry_break->SetOneShot(true);
258 }
259}
260
261// The runtime linker has run and initialized the rendezvous structure once the
262// process has hit its entry point. When we hit the corresponding breakpoint we
263// interrogate the rendezvous structure to get the load addresses of all
264// dependent modules for the process. Similarly, we can discover the runtime
265// linker function and setup a breakpoint to notify us of any dynamically loaded
266// modules (via dlopen).
267bool DynamicLoaderPOSIXDYLD::EntryBreakpointHit(
268 void *baton, StoppointCallbackContext *context, user_id_t break_id,
269 user_id_t break_loc_id) {
270 assert(baton && "null baton")(static_cast <bool> (baton && "null baton") ? void
(0) : __assert_fail ("baton && \"null baton\"", "/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, 270, __extension__ __PRETTY_FUNCTION__))
;
271 if (!baton)
272 return false;
273
274 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
275 DynamicLoaderPOSIXDYLD *const dyld_instance =
276 static_cast<DynamicLoaderPOSIXDYLD *>(baton);
277 if (log)
278 log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64"l" "u",
279 __FUNCTION__,
280 dyld_instance->m_process ? dyld_instance->m_process->GetID()
281 : LLDB_INVALID_PROCESS_ID0);
282
283 // Disable the breakpoint --- if a stop happens right after this, which we've
284 // seen on occasion, we don't
285 // want the breakpoint stepping thread-plan logic to show a breakpoint
286 // instruction at the disassembled
287 // entry point to the program. Disabling it prevents it. (One-shot is not
288 // enough - one-shot removal logic
289 // only happens after the breakpoint goes public, which wasn't happening in
290 // our scenario).
291 if (dyld_instance->m_process) {
292 BreakpointSP breakpoint_sp =
293 dyld_instance->m_process->GetTarget().GetBreakpointByID(break_id);
294 if (breakpoint_sp) {
295 if (log)
296 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u"
297 " disabling breakpoint id %" PRIu64"l" "u",
298 __FUNCTION__, dyld_instance->m_process->GetID(), break_id);
299 breakpoint_sp->SetEnabled(false);
300 } else {
301 if (log)
302 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u"
303 " failed to find breakpoint for breakpoint id %" PRIu64"l" "u",
304 __FUNCTION__, dyld_instance->m_process->GetID(), break_id);
305 }
306 } else {
307 if (log)
308 log->Printf("DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64"l" "u"
309 " no Process instance! Cannot disable breakpoint",
310 __FUNCTION__, break_id);
311 }
312
313 dyld_instance->LoadAllCurrentModules();
314 dyld_instance->SetRendezvousBreakpoint();
315 return false; // Continue running.
316}
317
318bool DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint() {
319 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
320 if (m_dyld_bid != LLDB_INVALID_BREAK_ID0) {
321 LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint breakpoint id {0} for pid {1}"
"is already set.", m_dyld_bid, m_process ? m_process->GetID
() : 0); } while (0)
322 "Rendezvous breakpoint breakpoint id {0} for pid {1}"do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint breakpoint id {0} for pid {1}"
"is already set.", m_dyld_bid, m_process ? m_process->GetID
() : 0); } while (0)
323 "is already set.",do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint breakpoint id {0} for pid {1}"
"is already set.", m_dyld_bid, m_process ? m_process->GetID
() : 0); } while (0)
324 m_dyld_bid,do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint breakpoint id {0} for pid {1}"
"is already set.", m_dyld_bid, m_process ? m_process->GetID
() : 0); } while (0)
325 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID)do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint breakpoint id {0} for pid {1}"
"is already set.", m_dyld_bid, m_process ? m_process->GetID
() : 0); } while (0)
;
326 return true;
327 }
328
329 addr_t break_addr;
330 Target &target = m_process->GetTarget();
331 BreakpointSP dyld_break;
332 if (m_rendezvous.IsValid()) {
333 break_addr = m_rendezvous.GetBreakAddress();
334 LLDB_LOG(log, "Setting rendezvous break address for pid {0} at {1:x}",do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Setting rendezvous break address for pid {0} at {1:x}"
, m_process ? m_process->GetID() : 0, break_addr); } while
(0)
335 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID,do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Setting rendezvous break address for pid {0} at {1:x}"
, m_process ? m_process->GetID() : 0, break_addr); } while
(0)
336 break_addr)do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Setting rendezvous break address for pid {0} at {1:x}"
, m_process ? m_process->GetID() : 0, break_addr); } while
(0)
;
337 dyld_break = target.CreateBreakpoint(break_addr, true, false);
338 } else {
339 LLDB_LOG(log, "Rendezvous structure is not set up yet. "do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous structure is not set up yet. " "Trying to locate rendezvous breakpoint in the interpreter "
"by symbol name."); } while (0)
340 "Trying to locate rendezvous breakpoint in the interpreter "do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous structure is not set up yet. " "Trying to locate rendezvous breakpoint in the interpreter "
"by symbol name."); } while (0)
341 "by symbol name.")do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous structure is not set up yet. " "Trying to locate rendezvous breakpoint in the interpreter "
"by symbol name."); } while (0)
;
342 ModuleSP interpreter = LoadInterpreterModule();
343 if (!interpreter) {
344 LLDB_LOG(log, "Can't find interpreter, rendezvous breakpoint isn't set.")do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Can't find interpreter, rendezvous breakpoint isn't set."
); } while (0)
;
345 return false;
346 }
347
348 // Function names from different dynamic loaders that are known
349 // to be used as rendezvous between the loader and debuggers.
350 static std::vector<std::string> DebugStateCandidates{
351 "_dl_debug_state", "rtld_db_dlactivity", "__dl_rtld_db_dlactivity",
352 "r_debug_state", "_r_debug_state", "_rtld_debug_state",
353 };
354
355 FileSpecList containingModules;
356 containingModules.Append(interpreter->GetFileSpec());
357 dyld_break = target.CreateBreakpoint(
358 &containingModules, nullptr /* containingSourceFiles */,
359 DebugStateCandidates, eFunctionNameTypeFull, eLanguageTypeC,
360 0, /* offset */
361 eLazyBoolNo, /* skip_prologue */
362 true, /* internal */
363 false /* request_hardware */);
364 }
365
366 if (dyld_break->GetNumResolvedLocations() != 1) {
367 LLDB_LOG(do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint has abnormal number of" " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1."
, dyld_break->GetNumResolvedLocations(), m_process ? m_process
->GetID() : 0); } while (0)
368 log,do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint has abnormal number of" " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1."
, dyld_break->GetNumResolvedLocations(), m_process ? m_process
->GetID() : 0); } while (0)
369 "Rendezvous breakpoint has abnormal number of"do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint has abnormal number of" " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1."
, dyld_break->GetNumResolvedLocations(), m_process ? m_process
->GetID() : 0); } while (0)
370 " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1.",do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint has abnormal number of" " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1."
, dyld_break->GetNumResolvedLocations(), m_process ? m_process
->GetID() : 0); } while (0)
371 dyld_break->GetNumResolvedLocations(),do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint has abnormal number of" " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1."
, dyld_break->GetNumResolvedLocations(), m_process ? m_process
->GetID() : 0); } while (0)
372 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID)do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Rendezvous breakpoint has abnormal number of" " resolved locations ({0}) in pid {1}. It's supposed to be exactly 1."
, dyld_break->GetNumResolvedLocations(), m_process ? m_process
->GetID() : 0); } while (0)
;
373
374 target.RemoveBreakpointByID(dyld_break->GetID());
375 return false;
376 }
377
378 BreakpointLocationSP location = dyld_break->GetLocationAtIndex(0);
379 LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Successfully set rendezvous breakpoint at address {0:x} "
"for pid {1}", location->GetLoadAddress(), m_process ? m_process
->GetID() : 0); } while (0)
380 "Successfully set rendezvous breakpoint at address {0:x} "do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Successfully set rendezvous breakpoint at address {0:x} "
"for pid {1}", location->GetLoadAddress(), m_process ? m_process
->GetID() : 0); } while (0)
381 "for pid {1}",do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Successfully set rendezvous breakpoint at address {0:x} "
"for pid {1}", location->GetLoadAddress(), m_process ? m_process
->GetID() : 0); } while (0)
382 location->GetLoadAddress(),do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Successfully set rendezvous breakpoint at address {0:x} "
"for pid {1}", location->GetLoadAddress(), m_process ? m_process
->GetID() : 0); } while (0)
383 m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID)do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Successfully set rendezvous breakpoint at address {0:x} "
"for pid {1}", location->GetLoadAddress(), m_process ? m_process
->GetID() : 0); } while (0)
;
384
385 dyld_break->SetCallback(RendezvousBreakpointHit, this, true);
386 dyld_break->SetBreakpointKind("shared-library-event");
387 m_dyld_bid = dyld_break->GetID();
388 return true;
389}
390
391bool DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(
392 void *baton, StoppointCallbackContext *context, user_id_t break_id,
393 user_id_t break_loc_id) {
394 assert(baton && "null baton")(static_cast <bool> (baton && "null baton") ? void
(0) : __assert_fail ("baton && \"null baton\"", "/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, 394, __extension__ __PRETTY_FUNCTION__))
;
395 if (!baton)
396 return false;
397
398 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
399 DynamicLoaderPOSIXDYLD *const dyld_instance =
400 static_cast<DynamicLoaderPOSIXDYLD *>(baton);
401 if (log)
402 log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64"l" "u",
403 __FUNCTION__,
404 dyld_instance->m_process ? dyld_instance->m_process->GetID()
405 : LLDB_INVALID_PROCESS_ID0);
406
407 dyld_instance->RefreshModules();
408
409 // Return true to stop the target, false to just let the target run.
410 const bool stop_when_images_change = dyld_instance->GetStopWhenImagesChange();
411 if (log)
412 log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64"l" "u"
413 " stop_when_images_change=%s",
414 __FUNCTION__,
415 dyld_instance->m_process ? dyld_instance->m_process->GetID()
416 : LLDB_INVALID_PROCESS_ID0,
417 stop_when_images_change ? "true" : "false");
418 return stop_when_images_change;
419}
420
421void DynamicLoaderPOSIXDYLD::RefreshModules() {
422 if (!m_rendezvous.Resolve())
423 return;
424
425 DYLDRendezvous::iterator I;
426 DYLDRendezvous::iterator E;
427
428 ModuleList &loaded_modules = m_process->GetTarget().GetImages();
429
430 if (m_rendezvous.ModulesDidLoad()) {
431 ModuleList new_modules;
432
433 E = m_rendezvous.loaded_end();
434 for (I = m_rendezvous.loaded_begin(); I != E; ++I) {
435 ModuleSP module_sp =
436 LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
437 if (module_sp.get()) {
438 loaded_modules.AppendIfNeeded(module_sp);
439 new_modules.Append(module_sp);
440 }
441 }
442 m_process->GetTarget().ModulesDidLoad(new_modules);
443 }
444
445 if (m_rendezvous.ModulesDidUnload()) {
446 ModuleList old_modules;
447
448 E = m_rendezvous.unloaded_end();
449 for (I = m_rendezvous.unloaded_begin(); I != E; ++I) {
450 ModuleSpec module_spec{I->file_spec};
451 ModuleSP module_sp = loaded_modules.FindFirstModule(module_spec);
452
453 if (module_sp.get()) {
454 old_modules.Append(module_sp);
455 UnloadSections(module_sp);
456 }
457 }
458 loaded_modules.Remove(old_modules);
459 m_process->GetTarget().ModulesDidUnload(old_modules, false);
460 }
461}
462
463ThreadPlanSP
464DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread,
465 bool stop) {
466 ThreadPlanSP thread_plan_sp;
467
468 StackFrame *frame = thread.GetStackFrameAtIndex(0).get();
469 const SymbolContext &context = frame->GetSymbolContext(eSymbolContextSymbol);
470 Symbol *sym = context.symbol;
471
472 if (sym == NULL__null || !sym->IsTrampoline())
473 return thread_plan_sp;
474
475 ConstString sym_name = sym->GetName();
476 if (!sym_name)
477 return thread_plan_sp;
478
479 SymbolContextList target_symbols;
480 Target &target = thread.GetProcess()->GetTarget();
481 const ModuleList &images = target.GetImages();
482
483 images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
484 size_t num_targets = target_symbols.GetSize();
485 if (!num_targets)
486 return thread_plan_sp;
487
488 typedef std::vector<lldb::addr_t> AddressVector;
489 AddressVector addrs;
490 for (size_t i = 0; i < num_targets; ++i) {
491 SymbolContext context;
492 AddressRange range;
493 if (target_symbols.GetContextAtIndex(i, context)) {
494 context.GetAddressRange(eSymbolContextEverything, 0, false, range);
495 lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
496 if (addr != LLDB_INVALID_ADDRESS(18446744073709551615UL))
497 addrs.push_back(addr);
498 }
499 }
500
501 if (addrs.size() > 0) {
502 AddressVector::iterator start = addrs.begin();
503 AddressVector::iterator end = addrs.end();
504
505 std::sort(start, end);
506 addrs.erase(std::unique(start, end), end);
507 thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop));
508 }
509
510 return thread_plan_sp;
511}
512
513void DynamicLoaderPOSIXDYLD::LoadVDSO() {
514 if (m_vdso_base == LLDB_INVALID_ADDRESS(18446744073709551615UL))
515 return;
516
517 FileSpec file("[vdso]", false);
518
519 MemoryRegionInfo info;
520 Status status = m_process->GetMemoryRegionInfo(m_vdso_base, info);
521 if (status.Fail()) {
522 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
523 LLDB_LOG(log, "Failed to get vdso region info: {0}", status)do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Failed to get vdso region info: {0}", status); }
while (0)
;
524 return;
525 }
526
527 if (ModuleSP module_sp = m_process->ReadModuleFromMemory(
528 file, m_vdso_base, info.GetRange().GetByteSize())) {
529 UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS(18446744073709551615UL), m_vdso_base, false);
530 m_process->GetTarget().GetImages().AppendIfNeeded(module_sp);
531 }
532}
533
534ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
535 if (m_interpreter_base == LLDB_INVALID_ADDRESS(18446744073709551615UL))
536 return nullptr;
537
538 MemoryRegionInfo info;
539 Target &target = m_process->GetTarget();
540 Status status = m_process->GetMemoryRegionInfo(m_interpreter_base, info);
541 if (status.Fail() || info.GetMapped() != MemoryRegionInfo::eYes ||
542 info.GetName().IsEmpty()) {
543 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
544 LLDB_LOG(log, "Failed to get interpreter region info: {0}", status)do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "Failed to get interpreter region info: {0}", status
); } while (0)
;
545 return nullptr;
546 }
547
548 FileSpec file(info.GetName().GetCString(), false);
549 ModuleSpec module_spec(file, target.GetArchitecture());
550
551 if (ModuleSP module_sp = target.GetSharedModule(module_spec)) {
552 UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS(18446744073709551615UL), m_interpreter_base,
553 false);
554 return module_sp;
555 }
556 return nullptr;
557}
558
559void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {
560 DYLDRendezvous::iterator I;
561 DYLDRendezvous::iterator E;
562 ModuleList module_list;
563 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
564
565 LoadVDSO();
566
567 if (!m_rendezvous.Resolve()) {
568 if (log)
569 log->Printf("DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD "
570 "rendezvous address",
571 __FUNCTION__);
572 return;
573 }
574
575 // The rendezvous class doesn't enumerate the main module, so track
576 // that ourselves here.
577 ModuleSP executable = GetTargetExecutable();
578 m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
579
580 std::vector<FileSpec> module_names;
581 for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
582 module_names.push_back(I->file_spec);
583 m_process->PrefetchModuleSpecs(
584 module_names, m_process->GetTarget().GetArchitecture().GetTriple());
585
586 for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) {
587 ModuleSP module_sp =
588 LoadModuleAtAddress(I->file_spec, I->link_addr, I->base_addr, true);
589 if (module_sp.get()) {
590 LLDB_LOG(log, "LoadAllCurrentModules loading module: {0}",do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "LoadAllCurrentModules loading module: {0}", I->
file_spec.GetFilename()); } while (0)
591 I->file_spec.GetFilename())do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/build/llvm-toolchain-snapshot-7~svn329677/tools/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp"
, __func__, "LoadAllCurrentModules loading module: {0}", I->
file_spec.GetFilename()); } while (0)
;
592 module_list.Append(module_sp);
593 } else {
594 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
595 if (log)
596 log->Printf(
597 "DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64"l" "x",
598 __FUNCTION__, I->file_spec.GetCString(), I->base_addr);
599 }
600 }
601
602 m_process->GetTarget().ModulesDidLoad(module_list);
603}
604
605addr_t DynamicLoaderPOSIXDYLD::ComputeLoadOffset() {
606 addr_t virt_entry;
607
608 if (m_load_offset != LLDB_INVALID_ADDRESS(18446744073709551615UL))
609 return m_load_offset;
610
611 if ((virt_entry = GetEntryPoint()) == LLDB_INVALID_ADDRESS(18446744073709551615UL))
612 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
613
614 ModuleSP module = m_process->GetTarget().GetExecutableModule();
615 if (!module)
616 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
617
618 ObjectFile *exe = module->GetObjectFile();
619 if (!exe)
620 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
621
622 Address file_entry = exe->GetEntryPointAddress();
623
624 if (!file_entry.IsValid())
625 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
626
627 m_load_offset = virt_entry - file_entry.GetFileAddress();
628 return m_load_offset;
629}
630
631void DynamicLoaderPOSIXDYLD::EvalSpecialModulesStatus() {
632 auto I = m_auxv->FindEntry(AuxVector::AUXV_AT_SYSINFO_EHDR);
633 if (I != m_auxv->end() && I->value != 0)
634 m_vdso_base = I->value;
635
636 I = m_auxv->FindEntry(AuxVector::AUXV_AT_BASE);
637 if (I != m_auxv->end() && I->value != 0)
638 m_interpreter_base = I->value;
639}
640
641addr_t DynamicLoaderPOSIXDYLD::GetEntryPoint() {
642 if (m_entry_point != LLDB_INVALID_ADDRESS(18446744073709551615UL))
643 return m_entry_point;
644
645 if (m_auxv.get() == NULL__null)
646 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
647
648 AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AUXV_AT_ENTRY);
649
650 if (I == m_auxv->end())
651 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
652
653 m_entry_point = static_cast<addr_t>(I->value);
654
655 const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
656
657 // On ppc64, the entry point is actually a descriptor. Dereference it.
658 if (arch.GetMachine() == llvm::Triple::ppc64)
659 m_entry_point = ReadUnsignedIntWithSizeInBytes(m_entry_point, 8);
660
661 return m_entry_point;
662}
663
664lldb::addr_t
665DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp,
666 const lldb::ThreadSP thread,
667 lldb::addr_t tls_file_addr) {
668 auto it = m_loaded_modules.find(module_sp);
669 if (it == m_loaded_modules.end())
670 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
671
672 addr_t link_map = it->second;
673 if (link_map == LLDB_INVALID_ADDRESS(18446744073709551615UL))
674 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
675
676 const DYLDRendezvous::ThreadInfo &metadata = m_rendezvous.GetThreadInfo();
677 if (!metadata.valid)
678 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
679
680 // Get the thread pointer.
681 addr_t tp = thread->GetThreadPointer();
682 if (tp == LLDB_INVALID_ADDRESS(18446744073709551615UL))
683 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
684
685 // Find the module's modid.
686 int modid_size = 4; // FIXME(spucci): This isn't right for big-endian 64-bit
687 int64_t modid = ReadUnsignedIntWithSizeInBytes(
688 link_map + metadata.modid_offset, modid_size);
689 if (modid == -1)
690 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
691
692 // Lookup the DTV structure for this thread.
693 addr_t dtv_ptr = tp + metadata.dtv_offset;
694 addr_t dtv = ReadPointer(dtv_ptr);
695 if (dtv == LLDB_INVALID_ADDRESS(18446744073709551615UL))
696 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
697
698 // Find the TLS block for this module.
699 addr_t dtv_slot = dtv + metadata.dtv_slot_size * modid;
700 addr_t tls_block = ReadPointer(dtv_slot + metadata.tls_offset);
701
702 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
703 if (log)
704 log->Printf("DynamicLoaderPOSIXDYLD::Performed TLS lookup: "
705 "module=%s, link_map=0x%" PRIx64"l" "x" ", tp=0x%" PRIx64"l" "x"
706 ", modid=%" PRId64"l" "d" ", tls_block=0x%" PRIx64"l" "x" "\n",
707 module_sp->GetObjectName().AsCString(""), link_map, tp,
708 (int64_t)modid, tls_block);
709
710 if (tls_block == LLDB_INVALID_ADDRESS(18446744073709551615UL))
711 return LLDB_INVALID_ADDRESS(18446744073709551615UL);
712 else
713 return tls_block + tls_file_addr;
714}
715
716void DynamicLoaderPOSIXDYLD::ResolveExecutableModule(
717 lldb::ModuleSP &module_sp) {
718 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER(1u << 3)));
719
720 if (m_process == nullptr)
721 return;
722
723 auto &target = m_process->GetTarget();
724 const auto platform_sp = target.GetPlatform();
725
726 ProcessInstanceInfo process_info;
727 if (!m_process->GetProcessInfo(process_info)) {
728 if (log)
729 log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to get process info for "
730 "pid %" PRIu64"l" "u",
731 __FUNCTION__, m_process->GetID());
732 return;
733 }
734
735 if (log)
736 log->Printf("DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64"l" "u"
737 ": %s",
738 __FUNCTION__, m_process->GetID(),
739 process_info.GetExecutableFile().GetPath().c_str());
740
741 ModuleSpec module_spec(process_info.GetExecutableFile(),
742 process_info.GetArchitecture());
743 if (module_sp && module_sp->MatchesModuleSpec(module_spec))
744 return;
745
746 const auto executable_search_paths(Target::GetDefaultExecutableSearchPaths());
747 auto error = platform_sp->ResolveExecutable(
748 module_spec, module_sp,
749 !executable_search_paths.IsEmpty() ? &executable_search_paths : nullptr);
750 if (error.Fail()) {
751 StreamString stream;
752 module_spec.Dump(stream);
753
754 if (log)
755 log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to resolve executable "
756 "with module spec \"%s\": %s",
757 __FUNCTION__, stream.GetData(), error.AsCString());
758 return;
759 }
760
761 target.SetExecutableModule(module_sp, false);
762}
763
764bool DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo(
765 lldb_private::SymbolContext &sym_ctx) {
766 ModuleSP module_sp;
767 if (sym_ctx.symbol)
768 module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
769 if (!module_sp && sym_ctx.function)
770 module_sp =
771 sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
772 if (!module_sp)
773 return false;
774
775 return module_sp->GetFileSpec().GetPath() == "[vdso]";
776}