brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 09c6988 Raw
47 lines · cpp
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-exception6//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>17GetPreferredAsanModule(const Target &target) {18  // Currently only Darwin provides ASan runtime support as part of the OS19  // (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;28      return IterationAction::Stop;29    }30 31    return IterationAction::Continue;32  });33 34  // `Calls` - The ASan compiler-rt runtime already massages the return35  //   addresses into call addresses, so we don't want LLDB's unwinder to try to36  //   locate the previous instruction again as this might lead to us reporting37  //   a different line.38  // `ReturnsNoZerothFrame` - Darwin, but not ASan compiler-rt implies39  //   libsanitizers which collects return addresses.  It also discards a few40  //   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_private47