aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/InstrumentationRuntime/Utility/Utility.cpp
blob: a5cee5d32432521834fcb65f0a33f795f71015b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//===-- Utility.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "Utility.h"

#include "lldb/Core/Module.h"
#include "lldb/Target/Target.h"

namespace lldb_private {

lldb::ModuleSP GetPreferredAsanModule(const Target &target) {
  // Currently only supported on Darwin.
  if (!target.GetArchitecture().GetTriple().isOSDarwin())
    return nullptr;

  lldb::ModuleSP module;
  llvm::Regex pattern(R"(libclang_rt\.asan_.*_dynamic\.dylib)");
  target.GetImages().ForEach([&](const lldb::ModuleSP &m) {
    if (pattern.match(m->GetFileSpec().GetFilename().GetStringRef())) {
      module = m;
      return IterationAction::Stop;
    }

    return IterationAction::Continue;
  });

  return module;
}

} // namespace lldb_private