1*5ffd83dbSDimitry Andric //===-- InstrumentationRuntimeASan.cpp ------------------------------------===//
2*5ffd83dbSDimitry Andric //
3*5ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*5ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5ffd83dbSDimitry Andric //
7*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
8*5ffd83dbSDimitry Andric 
9*5ffd83dbSDimitry Andric #include "InstrumentationRuntimeASan.h"
10*5ffd83dbSDimitry Andric 
11*5ffd83dbSDimitry Andric #include "lldb/Breakpoint/StoppointCallbackContext.h"
12*5ffd83dbSDimitry Andric #include "lldb/Core/Debugger.h"
13*5ffd83dbSDimitry Andric #include "lldb/Core/Module.h"
14*5ffd83dbSDimitry Andric #include "lldb/Core/PluginInterface.h"
15*5ffd83dbSDimitry Andric #include "lldb/Core/PluginManager.h"
16*5ffd83dbSDimitry Andric #include "lldb/Core/StreamFile.h"
17*5ffd83dbSDimitry Andric #include "lldb/Core/ValueObject.h"
18*5ffd83dbSDimitry Andric #include "lldb/Expression/UserExpression.h"
19*5ffd83dbSDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
20*5ffd83dbSDimitry Andric #include "lldb/Symbol/Symbol.h"
21*5ffd83dbSDimitry Andric #include "lldb/Target/InstrumentationRuntimeStopInfo.h"
22*5ffd83dbSDimitry Andric #include "lldb/Target/StopInfo.h"
23*5ffd83dbSDimitry Andric #include "lldb/Target/Target.h"
24*5ffd83dbSDimitry Andric #include "lldb/Target/Thread.h"
25*5ffd83dbSDimitry Andric #include "lldb/Utility/RegularExpression.h"
26*5ffd83dbSDimitry Andric #include "lldb/Utility/Stream.h"
27*5ffd83dbSDimitry Andric 
28*5ffd83dbSDimitry Andric #include "llvm/ADT/StringSwitch.h"
29*5ffd83dbSDimitry Andric 
30*5ffd83dbSDimitry Andric using namespace lldb;
31*5ffd83dbSDimitry Andric using namespace lldb_private;
32*5ffd83dbSDimitry Andric 
33*5ffd83dbSDimitry Andric LLDB_PLUGIN_DEFINE(InstrumentationRuntimeASan)
34*5ffd83dbSDimitry Andric 
35*5ffd83dbSDimitry Andric lldb::InstrumentationRuntimeSP
36*5ffd83dbSDimitry Andric InstrumentationRuntimeASan::CreateInstance(const lldb::ProcessSP &process_sp) {
37*5ffd83dbSDimitry Andric   return InstrumentationRuntimeSP(new InstrumentationRuntimeASan(process_sp));
38*5ffd83dbSDimitry Andric }
39*5ffd83dbSDimitry Andric 
40*5ffd83dbSDimitry Andric void InstrumentationRuntimeASan::Initialize() {
41*5ffd83dbSDimitry Andric   PluginManager::RegisterPlugin(
42*5ffd83dbSDimitry Andric       GetPluginNameStatic(), "AddressSanitizer instrumentation runtime plugin.",
43*5ffd83dbSDimitry Andric       CreateInstance, GetTypeStatic);
44*5ffd83dbSDimitry Andric }
45*5ffd83dbSDimitry Andric 
46*5ffd83dbSDimitry Andric void InstrumentationRuntimeASan::Terminate() {
47*5ffd83dbSDimitry Andric   PluginManager::UnregisterPlugin(CreateInstance);
48*5ffd83dbSDimitry Andric }
49*5ffd83dbSDimitry Andric 
50*5ffd83dbSDimitry Andric lldb_private::ConstString InstrumentationRuntimeASan::GetPluginNameStatic() {
51*5ffd83dbSDimitry Andric   return ConstString("AddressSanitizer");
52*5ffd83dbSDimitry Andric }
53*5ffd83dbSDimitry Andric 
54*5ffd83dbSDimitry Andric lldb::InstrumentationRuntimeType InstrumentationRuntimeASan::GetTypeStatic() {
55*5ffd83dbSDimitry Andric   return eInstrumentationRuntimeTypeAddressSanitizer;
56*5ffd83dbSDimitry Andric }
57*5ffd83dbSDimitry Andric 
58*5ffd83dbSDimitry Andric InstrumentationRuntimeASan::~InstrumentationRuntimeASan() { Deactivate(); }
59*5ffd83dbSDimitry Andric 
60*5ffd83dbSDimitry Andric const RegularExpression &
61*5ffd83dbSDimitry Andric InstrumentationRuntimeASan::GetPatternForRuntimeLibrary() {
62*5ffd83dbSDimitry Andric   // FIXME: This shouldn't include the "dylib" suffix.
63*5ffd83dbSDimitry Andric   static RegularExpression regex(
64*5ffd83dbSDimitry Andric       llvm::StringRef("libclang_rt.asan_(.*)_dynamic\\.dylib"));
65*5ffd83dbSDimitry Andric   return regex;
66*5ffd83dbSDimitry Andric }
67*5ffd83dbSDimitry Andric 
68*5ffd83dbSDimitry Andric bool InstrumentationRuntimeASan::CheckIfRuntimeIsValid(
69*5ffd83dbSDimitry Andric     const lldb::ModuleSP module_sp) {
70*5ffd83dbSDimitry Andric   const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
71*5ffd83dbSDimitry Andric       ConstString("__asan_get_alloc_stack"), lldb::eSymbolTypeAny);
72*5ffd83dbSDimitry Andric 
73*5ffd83dbSDimitry Andric   return symbol != nullptr;
74*5ffd83dbSDimitry Andric }
75*5ffd83dbSDimitry Andric 
76*5ffd83dbSDimitry Andric const char *address_sanitizer_retrieve_report_data_prefix = R"(
77*5ffd83dbSDimitry Andric extern "C"
78*5ffd83dbSDimitry Andric {
79*5ffd83dbSDimitry Andric int __asan_report_present();
80*5ffd83dbSDimitry Andric void *__asan_get_report_pc();
81*5ffd83dbSDimitry Andric void *__asan_get_report_bp();
82*5ffd83dbSDimitry Andric void *__asan_get_report_sp();
83*5ffd83dbSDimitry Andric void *__asan_get_report_address();
84*5ffd83dbSDimitry Andric const char *__asan_get_report_description();
85*5ffd83dbSDimitry Andric int __asan_get_report_access_type();
86*5ffd83dbSDimitry Andric size_t __asan_get_report_access_size();
87*5ffd83dbSDimitry Andric }
88*5ffd83dbSDimitry Andric )";
89*5ffd83dbSDimitry Andric 
90*5ffd83dbSDimitry Andric const char *address_sanitizer_retrieve_report_data_command = R"(
91*5ffd83dbSDimitry Andric struct {
92*5ffd83dbSDimitry Andric     int present;
93*5ffd83dbSDimitry Andric     int access_type;
94*5ffd83dbSDimitry Andric     void *pc;
95*5ffd83dbSDimitry Andric     void *bp;
96*5ffd83dbSDimitry Andric     void *sp;
97*5ffd83dbSDimitry Andric     void *address;
98*5ffd83dbSDimitry Andric     size_t access_size;
99*5ffd83dbSDimitry Andric     const char *description;
100*5ffd83dbSDimitry Andric } t;
101*5ffd83dbSDimitry Andric 
102*5ffd83dbSDimitry Andric t.present = __asan_report_present();
103*5ffd83dbSDimitry Andric t.access_type = __asan_get_report_access_type();
104*5ffd83dbSDimitry Andric t.pc = __asan_get_report_pc();
105*5ffd83dbSDimitry Andric t.bp = __asan_get_report_bp();
106*5ffd83dbSDimitry Andric t.sp = __asan_get_report_sp();
107*5ffd83dbSDimitry Andric t.address = __asan_get_report_address();
108*5ffd83dbSDimitry Andric t.access_size = __asan_get_report_access_size();
109*5ffd83dbSDimitry Andric t.description = __asan_get_report_description();
110*5ffd83dbSDimitry Andric t
111*5ffd83dbSDimitry Andric )";
112*5ffd83dbSDimitry Andric 
113*5ffd83dbSDimitry Andric StructuredData::ObjectSP InstrumentationRuntimeASan::RetrieveReportData() {
114*5ffd83dbSDimitry Andric   ProcessSP process_sp = GetProcessSP();
115*5ffd83dbSDimitry Andric   if (!process_sp)
116*5ffd83dbSDimitry Andric     return StructuredData::ObjectSP();
117*5ffd83dbSDimitry Andric 
118*5ffd83dbSDimitry Andric   ThreadSP thread_sp =
119*5ffd83dbSDimitry Andric       process_sp->GetThreadList().GetExpressionExecutionThread();
120*5ffd83dbSDimitry Andric   StackFrameSP frame_sp = thread_sp->GetSelectedFrame();
121*5ffd83dbSDimitry Andric 
122*5ffd83dbSDimitry Andric   if (!frame_sp)
123*5ffd83dbSDimitry Andric     return StructuredData::ObjectSP();
124*5ffd83dbSDimitry Andric 
125*5ffd83dbSDimitry Andric   EvaluateExpressionOptions options;
126*5ffd83dbSDimitry Andric   options.SetUnwindOnError(true);
127*5ffd83dbSDimitry Andric   options.SetTryAllThreads(true);
128*5ffd83dbSDimitry Andric   options.SetStopOthers(true);
129*5ffd83dbSDimitry Andric   options.SetIgnoreBreakpoints(true);
130*5ffd83dbSDimitry Andric   options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
131*5ffd83dbSDimitry Andric   options.SetPrefix(address_sanitizer_retrieve_report_data_prefix);
132*5ffd83dbSDimitry Andric   options.SetAutoApplyFixIts(false);
133*5ffd83dbSDimitry Andric   options.SetLanguage(eLanguageTypeObjC_plus_plus);
134*5ffd83dbSDimitry Andric 
135*5ffd83dbSDimitry Andric   ValueObjectSP return_value_sp;
136*5ffd83dbSDimitry Andric   ExecutionContext exe_ctx;
137*5ffd83dbSDimitry Andric   Status eval_error;
138*5ffd83dbSDimitry Andric   frame_sp->CalculateExecutionContext(exe_ctx);
139*5ffd83dbSDimitry Andric   ExpressionResults result = UserExpression::Evaluate(
140*5ffd83dbSDimitry Andric       exe_ctx, options, address_sanitizer_retrieve_report_data_command, "",
141*5ffd83dbSDimitry Andric       return_value_sp, eval_error);
142*5ffd83dbSDimitry Andric   if (result != eExpressionCompleted) {
143*5ffd83dbSDimitry Andric     process_sp->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf(
144*5ffd83dbSDimitry Andric         "Warning: Cannot evaluate AddressSanitizer expression:\n%s\n",
145*5ffd83dbSDimitry Andric         eval_error.AsCString());
146*5ffd83dbSDimitry Andric     return StructuredData::ObjectSP();
147*5ffd83dbSDimitry Andric   }
148*5ffd83dbSDimitry Andric 
149*5ffd83dbSDimitry Andric   int present = return_value_sp->GetValueForExpressionPath(".present")
150*5ffd83dbSDimitry Andric                     ->GetValueAsUnsigned(0);
151*5ffd83dbSDimitry Andric   if (present != 1)
152*5ffd83dbSDimitry Andric     return StructuredData::ObjectSP();
153*5ffd83dbSDimitry Andric 
154*5ffd83dbSDimitry Andric   addr_t pc =
155*5ffd83dbSDimitry Andric       return_value_sp->GetValueForExpressionPath(".pc")->GetValueAsUnsigned(0);
156*5ffd83dbSDimitry Andric   /* commented out because rdar://problem/18533301
157*5ffd83dbSDimitry Andric   addr_t bp =
158*5ffd83dbSDimitry Andric   return_value_sp->GetValueForExpressionPath(".bp")->GetValueAsUnsigned(0);
159*5ffd83dbSDimitry Andric   addr_t sp =
160*5ffd83dbSDimitry Andric   return_value_sp->GetValueForExpressionPath(".sp")->GetValueAsUnsigned(0);
161*5ffd83dbSDimitry Andric   */
162*5ffd83dbSDimitry Andric   addr_t address = return_value_sp->GetValueForExpressionPath(".address")
163*5ffd83dbSDimitry Andric                        ->GetValueAsUnsigned(0);
164*5ffd83dbSDimitry Andric   addr_t access_type =
165*5ffd83dbSDimitry Andric       return_value_sp->GetValueForExpressionPath(".access_type")
166*5ffd83dbSDimitry Andric           ->GetValueAsUnsigned(0);
167*5ffd83dbSDimitry Andric   addr_t access_size =
168*5ffd83dbSDimitry Andric       return_value_sp->GetValueForExpressionPath(".access_size")
169*5ffd83dbSDimitry Andric           ->GetValueAsUnsigned(0);
170*5ffd83dbSDimitry Andric   addr_t description_ptr =
171*5ffd83dbSDimitry Andric       return_value_sp->GetValueForExpressionPath(".description")
172*5ffd83dbSDimitry Andric           ->GetValueAsUnsigned(0);
173*5ffd83dbSDimitry Andric   std::string description;
174*5ffd83dbSDimitry Andric   Status error;
175*5ffd83dbSDimitry Andric   process_sp->ReadCStringFromMemory(description_ptr, description, error);
176*5ffd83dbSDimitry Andric 
177*5ffd83dbSDimitry Andric   StructuredData::Dictionary *dict = new StructuredData::Dictionary();
178*5ffd83dbSDimitry Andric   dict->AddStringItem("instrumentation_class", "AddressSanitizer");
179*5ffd83dbSDimitry Andric   dict->AddStringItem("stop_type", "fatal_error");
180*5ffd83dbSDimitry Andric   dict->AddIntegerItem("pc", pc);
181*5ffd83dbSDimitry Andric   /* commented out because rdar://problem/18533301
182*5ffd83dbSDimitry Andric   dict->AddIntegerItem("bp", bp);
183*5ffd83dbSDimitry Andric   dict->AddIntegerItem("sp", sp);
184*5ffd83dbSDimitry Andric   */
185*5ffd83dbSDimitry Andric   dict->AddIntegerItem("address", address);
186*5ffd83dbSDimitry Andric   dict->AddIntegerItem("access_type", access_type);
187*5ffd83dbSDimitry Andric   dict->AddIntegerItem("access_size", access_size);
188*5ffd83dbSDimitry Andric   dict->AddStringItem("description", description);
189*5ffd83dbSDimitry Andric 
190*5ffd83dbSDimitry Andric   return StructuredData::ObjectSP(dict);
191*5ffd83dbSDimitry Andric }
192*5ffd83dbSDimitry Andric 
193*5ffd83dbSDimitry Andric std::string
194*5ffd83dbSDimitry Andric InstrumentationRuntimeASan::FormatDescription(StructuredData::ObjectSP report) {
195*5ffd83dbSDimitry Andric   std::string description = std::string(report->GetAsDictionary()
196*5ffd83dbSDimitry Andric                                             ->GetValueForKey("description")
197*5ffd83dbSDimitry Andric                                             ->GetAsString()
198*5ffd83dbSDimitry Andric                                             ->GetValue());
199*5ffd83dbSDimitry Andric   return llvm::StringSwitch<std::string>(description)
200*5ffd83dbSDimitry Andric       .Case("heap-use-after-free", "Use of deallocated memory")
201*5ffd83dbSDimitry Andric       .Case("heap-buffer-overflow", "Heap buffer overflow")
202*5ffd83dbSDimitry Andric       .Case("stack-buffer-underflow", "Stack buffer underflow")
203*5ffd83dbSDimitry Andric       .Case("initialization-order-fiasco", "Initialization order problem")
204*5ffd83dbSDimitry Andric       .Case("stack-buffer-overflow", "Stack buffer overflow")
205*5ffd83dbSDimitry Andric       .Case("stack-use-after-return", "Use of stack memory after return")
206*5ffd83dbSDimitry Andric       .Case("use-after-poison", "Use of poisoned memory")
207*5ffd83dbSDimitry Andric       .Case("container-overflow", "Container overflow")
208*5ffd83dbSDimitry Andric       .Case("stack-use-after-scope", "Use of out-of-scope stack memory")
209*5ffd83dbSDimitry Andric       .Case("global-buffer-overflow", "Global buffer overflow")
210*5ffd83dbSDimitry Andric       .Case("unknown-crash", "Invalid memory access")
211*5ffd83dbSDimitry Andric       .Case("stack-overflow", "Stack space exhausted")
212*5ffd83dbSDimitry Andric       .Case("null-deref", "Dereference of null pointer")
213*5ffd83dbSDimitry Andric       .Case("wild-jump", "Jump to non-executable address")
214*5ffd83dbSDimitry Andric       .Case("wild-addr-write", "Write through wild pointer")
215*5ffd83dbSDimitry Andric       .Case("wild-addr-read", "Read from wild pointer")
216*5ffd83dbSDimitry Andric       .Case("wild-addr", "Access through wild pointer")
217*5ffd83dbSDimitry Andric       .Case("signal", "Deadly signal")
218*5ffd83dbSDimitry Andric       .Case("double-free", "Deallocation of freed memory")
219*5ffd83dbSDimitry Andric       .Case("new-delete-type-mismatch",
220*5ffd83dbSDimitry Andric             "Deallocation size different from allocation size")
221*5ffd83dbSDimitry Andric       .Case("bad-free", "Deallocation of non-allocated memory")
222*5ffd83dbSDimitry Andric       .Case("alloc-dealloc-mismatch",
223*5ffd83dbSDimitry Andric             "Mismatch between allocation and deallocation APIs")
224*5ffd83dbSDimitry Andric       .Case("bad-malloc_usable_size", "Invalid argument to malloc_usable_size")
225*5ffd83dbSDimitry Andric       .Case("bad-__sanitizer_get_allocated_size",
226*5ffd83dbSDimitry Andric             "Invalid argument to __sanitizer_get_allocated_size")
227*5ffd83dbSDimitry Andric       .Case("param-overlap",
228*5ffd83dbSDimitry Andric             "Call to function disallowing overlapping memory ranges")
229*5ffd83dbSDimitry Andric       .Case("negative-size-param", "Negative size used when accessing memory")
230*5ffd83dbSDimitry Andric       .Case("bad-__sanitizer_annotate_contiguous_container",
231*5ffd83dbSDimitry Andric             "Invalid argument to __sanitizer_annotate_contiguous_container")
232*5ffd83dbSDimitry Andric       .Case("odr-violation", "Symbol defined in multiple translation units")
233*5ffd83dbSDimitry Andric       .Case(
234*5ffd83dbSDimitry Andric           "invalid-pointer-pair",
235*5ffd83dbSDimitry Andric           "Comparison or arithmetic on pointers from different memory regions")
236*5ffd83dbSDimitry Andric       // for unknown report codes just show the code
237*5ffd83dbSDimitry Andric       .Default("AddressSanitizer detected: " + description);
238*5ffd83dbSDimitry Andric }
239*5ffd83dbSDimitry Andric 
240*5ffd83dbSDimitry Andric bool InstrumentationRuntimeASan::NotifyBreakpointHit(
241*5ffd83dbSDimitry Andric     void *baton, StoppointCallbackContext *context, user_id_t break_id,
242*5ffd83dbSDimitry Andric     user_id_t break_loc_id) {
243*5ffd83dbSDimitry Andric   assert(baton && "null baton");
244*5ffd83dbSDimitry Andric   if (!baton)
245*5ffd83dbSDimitry Andric     return false;
246*5ffd83dbSDimitry Andric 
247*5ffd83dbSDimitry Andric   InstrumentationRuntimeASan *const instance =
248*5ffd83dbSDimitry Andric       static_cast<InstrumentationRuntimeASan *>(baton);
249*5ffd83dbSDimitry Andric 
250*5ffd83dbSDimitry Andric   ProcessSP process_sp = instance->GetProcessSP();
251*5ffd83dbSDimitry Andric 
252*5ffd83dbSDimitry Andric   if (process_sp->GetModIDRef().IsLastResumeForUserExpression())
253*5ffd83dbSDimitry Andric     return false;
254*5ffd83dbSDimitry Andric 
255*5ffd83dbSDimitry Andric   StructuredData::ObjectSP report = instance->RetrieveReportData();
256*5ffd83dbSDimitry Andric   std::string description;
257*5ffd83dbSDimitry Andric   if (report) {
258*5ffd83dbSDimitry Andric     description = instance->FormatDescription(report);
259*5ffd83dbSDimitry Andric   }
260*5ffd83dbSDimitry Andric   // Make sure this is the right process
261*5ffd83dbSDimitry Andric   if (process_sp && process_sp == context->exe_ctx_ref.GetProcessSP()) {
262*5ffd83dbSDimitry Andric     ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP();
263*5ffd83dbSDimitry Andric     if (thread_sp)
264*5ffd83dbSDimitry Andric       thread_sp->SetStopInfo(InstrumentationRuntimeStopInfo::
265*5ffd83dbSDimitry Andric                                  CreateStopReasonWithInstrumentationData(
266*5ffd83dbSDimitry Andric                                      *thread_sp, description, report));
267*5ffd83dbSDimitry Andric 
268*5ffd83dbSDimitry Andric     StreamFileSP stream_sp(
269*5ffd83dbSDimitry Andric         process_sp->GetTarget().GetDebugger().GetOutputStreamSP());
270*5ffd83dbSDimitry Andric     if (stream_sp) {
271*5ffd83dbSDimitry Andric       stream_sp->Printf("AddressSanitizer report breakpoint hit. Use 'thread "
272*5ffd83dbSDimitry Andric                         "info -s' to get extended information about the "
273*5ffd83dbSDimitry Andric                         "report.\n");
274*5ffd83dbSDimitry Andric     }
275*5ffd83dbSDimitry Andric     return true; // Return true to stop the target
276*5ffd83dbSDimitry Andric   } else
277*5ffd83dbSDimitry Andric     return false; // Let target run
278*5ffd83dbSDimitry Andric }
279*5ffd83dbSDimitry Andric 
280*5ffd83dbSDimitry Andric void InstrumentationRuntimeASan::Activate() {
281*5ffd83dbSDimitry Andric   if (IsActive())
282*5ffd83dbSDimitry Andric     return;
283*5ffd83dbSDimitry Andric 
284*5ffd83dbSDimitry Andric   ProcessSP process_sp = GetProcessSP();
285*5ffd83dbSDimitry Andric   if (!process_sp)
286*5ffd83dbSDimitry Andric     return;
287*5ffd83dbSDimitry Andric 
288*5ffd83dbSDimitry Andric   ConstString symbol_name("__asan::AsanDie()");
289*5ffd83dbSDimitry Andric   const Symbol *symbol = GetRuntimeModuleSP()->FindFirstSymbolWithNameAndType(
290*5ffd83dbSDimitry Andric       symbol_name, eSymbolTypeCode);
291*5ffd83dbSDimitry Andric 
292*5ffd83dbSDimitry Andric   if (symbol == nullptr)
293*5ffd83dbSDimitry Andric     return;
294*5ffd83dbSDimitry Andric 
295*5ffd83dbSDimitry Andric   if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid())
296*5ffd83dbSDimitry Andric     return;
297*5ffd83dbSDimitry Andric 
298*5ffd83dbSDimitry Andric   Target &target = process_sp->GetTarget();
299*5ffd83dbSDimitry Andric   addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
300*5ffd83dbSDimitry Andric 
301*5ffd83dbSDimitry Andric   if (symbol_address == LLDB_INVALID_ADDRESS)
302*5ffd83dbSDimitry Andric     return;
303*5ffd83dbSDimitry Andric 
304*5ffd83dbSDimitry Andric   bool internal = true;
305*5ffd83dbSDimitry Andric   bool hardware = false;
306*5ffd83dbSDimitry Andric   Breakpoint *breakpoint =
307*5ffd83dbSDimitry Andric       process_sp->GetTarget()
308*5ffd83dbSDimitry Andric           .CreateBreakpoint(symbol_address, internal, hardware)
309*5ffd83dbSDimitry Andric           .get();
310*5ffd83dbSDimitry Andric   breakpoint->SetCallback(InstrumentationRuntimeASan::NotifyBreakpointHit, this,
311*5ffd83dbSDimitry Andric                           true);
312*5ffd83dbSDimitry Andric   breakpoint->SetBreakpointKind("address-sanitizer-report");
313*5ffd83dbSDimitry Andric   SetBreakpointID(breakpoint->GetID());
314*5ffd83dbSDimitry Andric 
315*5ffd83dbSDimitry Andric   SetActive(true);
316*5ffd83dbSDimitry Andric }
317*5ffd83dbSDimitry Andric 
318*5ffd83dbSDimitry Andric void InstrumentationRuntimeASan::Deactivate() {
319*5ffd83dbSDimitry Andric   if (GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
320*5ffd83dbSDimitry Andric     ProcessSP process_sp = GetProcessSP();
321*5ffd83dbSDimitry Andric     if (process_sp) {
322*5ffd83dbSDimitry Andric       process_sp->GetTarget().RemoveBreakpointByID(GetBreakpointID());
323*5ffd83dbSDimitry Andric       SetBreakpointID(LLDB_INVALID_BREAK_ID);
324*5ffd83dbSDimitry Andric     }
325*5ffd83dbSDimitry Andric   }
326*5ffd83dbSDimitry Andric   SetActive(false);
327*5ffd83dbSDimitry Andric }
328