LLDB mainline
Utility.cpp
Go to the documentation of this file.
1//===-- Utility.cpp -------------------------------------------------------===//
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#include "Utility.h"
10
11#include "lldb/Core/Module.h"
12#include "lldb/Target/Target.h"
13
14namespace lldb_private {
15
16std::tuple<lldb::ModuleSP, HistoryPCType>
18 // Currently only Darwin provides ASan runtime support as part of the OS
19 // (libsanitizers).
20 if (!target.GetArchitecture().GetTriple().isOSDarwin())
21 return {nullptr, HistoryPCType::Calls};
22
23 lldb::ModuleSP module;
24 llvm::Regex pattern(R"(libclang_rt\.asan_.*_dynamic\.dylib)");
25 target.GetImages().ForEach([&](const lldb::ModuleSP &m) {
26 if (pattern.match(m->GetFileSpec().GetFilename().GetStringRef())) {
27 module = m;
29 }
30
32 });
33
34 // `Calls` - The ASan compiler-rt runtime already massages the return
35 // addresses into call addresses, so we don't want LLDB's unwinder to try to
36 // locate the previous instruction again as this might lead to us reporting
37 // a different line.
38 // `ReturnsNoZerothFrame` - Darwin, but not ASan compiler-rt implies
39 // libsanitizers which collects return addresses. It also discards a few
40 // non-user frames at the top of the stack.
41 auto pc_type =
42 (module ? HistoryPCType::Calls : HistoryPCType::ReturnsNoZerothFrame);
43 return {module, pc_type};
44}
45
46} // namespace lldb_private
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:468
void ForEach(std::function< IterationAction(const lldb::ModuleSP &module_sp)> const &callback) const
Applies 'callback' to each module in this ModuleList.
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1014
const ArchSpec & GetArchitecture() const
Definition Target.h:1056
A class that represents a running process on the host machine.
std::tuple< lldb::ModuleSP, HistoryPCType > GetPreferredAsanModule(const Target &target)
On Darwin, if LLDB loaded libclang_rt, it's coming from a locally built compiler-rt,...
Definition Utility.cpp:17
std::shared_ptr< lldb_private::Module > ModuleSP