[LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns ...
[llvm-project.git] / lldb / source / Plugins / InstrumentationRuntime / ASanLibsanitizers / InstrumentationRuntimeASanLibsanitizers.cpp
blobcd91f4a6ff1bc2344092d109cf69d6f322953206
1 //===-- InstrumentationRuntimeASanLibsanitizers.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 //===----------------------------------------------------------------------===//
9 #include "InstrumentationRuntimeASanLibsanitizers.h"
11 #include "lldb/Breakpoint/StoppointCallbackContext.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/PluginInterface.h"
14 #include "lldb/Core/PluginManager.h"
15 #include "lldb/Symbol/Symbol.h"
16 #include "lldb/Target/Process.h"
17 #include "lldb/Utility/RegularExpression.h"
19 #include "Plugins/InstrumentationRuntime/Utility/ReportRetriever.h"
21 using namespace lldb;
22 using namespace lldb_private;
24 LLDB_PLUGIN_DEFINE(InstrumentationRuntimeASanLibsanitizers)
26 lldb::InstrumentationRuntimeSP
27 InstrumentationRuntimeASanLibsanitizers::CreateInstance(
28 const lldb::ProcessSP &process_sp) {
29 return InstrumentationRuntimeSP(
30 new InstrumentationRuntimeASanLibsanitizers(process_sp));
33 void InstrumentationRuntimeASanLibsanitizers::Initialize() {
34 PluginManager::RegisterPlugin(
35 GetPluginNameStatic(),
36 "AddressSanitizer instrumentation runtime plugin for Libsanitizers.",
37 CreateInstance, GetTypeStatic);
40 void InstrumentationRuntimeASanLibsanitizers::Terminate() {
41 PluginManager::UnregisterPlugin(CreateInstance);
44 lldb::InstrumentationRuntimeType
45 InstrumentationRuntimeASanLibsanitizers::GetTypeStatic() {
46 return eInstrumentationRuntimeTypeLibsanitizersAsan;
49 InstrumentationRuntimeASanLibsanitizers::
50 ~InstrumentationRuntimeASanLibsanitizers() {
51 Deactivate();
54 const RegularExpression &
55 InstrumentationRuntimeASanLibsanitizers::GetPatternForRuntimeLibrary() {
56 static RegularExpression regex(
57 llvm::StringRef("libsystem_sanitizers\\.dylib"));
58 return regex;
61 bool InstrumentationRuntimeASanLibsanitizers::CheckIfRuntimeIsValid(
62 const lldb::ModuleSP module_sp) {
63 const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
64 ConstString("__asan_abi_init"), lldb::eSymbolTypeAny);
66 return symbol != nullptr;
69 bool InstrumentationRuntimeASanLibsanitizers::NotifyBreakpointHit(
70 void *baton, StoppointCallbackContext *context, user_id_t break_id,
71 user_id_t break_loc_id) {
72 assert(baton && "null baton");
73 if (!baton)
74 return false;
76 InstrumentationRuntimeASanLibsanitizers *const instance =
77 static_cast<InstrumentationRuntimeASanLibsanitizers *>(baton);
79 ProcessSP process_sp = instance->GetProcessSP();
81 return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id,
82 break_loc_id);
85 void InstrumentationRuntimeASanLibsanitizers::Activate() {
86 if (IsActive())
87 return;
89 ProcessSP process_sp = GetProcessSP();
90 if (!process_sp)
91 return;
93 lldb::ModuleSP module_sp = GetRuntimeModuleSP();
95 Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint(
96 module_sp, process_sp, ConstString("sanitizers_address_on_report"));
98 if (!breakpoint) {
99 breakpoint = ReportRetriever::SetupBreakpoint(
100 module_sp, process_sp,
101 ConstString("_Z22raise_sanitizers_error23sanitizer_error_context"));
104 if (!breakpoint)
105 return;
107 const bool sync = false;
109 breakpoint->SetCallback(
110 InstrumentationRuntimeASanLibsanitizers::NotifyBreakpointHit, this, sync);
111 breakpoint->SetBreakpointKind("address-sanitizer-report");
112 SetBreakpointID(breakpoint->GetID());
114 SetActive(true);
117 void InstrumentationRuntimeASanLibsanitizers::Deactivate() {
118 SetActive(false);
120 if (GetBreakpointID() == LLDB_INVALID_BREAK_ID)
121 return;
123 if (ProcessSP process_sp = GetProcessSP()) {
124 process_sp->GetTarget().RemoveBreakpointByID(GetBreakpointID());
125 SetBreakpointID(LLDB_INVALID_BREAK_ID);