LLDB mainline
InstrumentationRuntimeASanLibsanitizers.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
10
12#include "lldb/Core/Module.h"
15#include "lldb/Symbol/Symbol.h"
16#include "lldb/Target/Process.h"
18
20
21using namespace lldb;
22using namespace lldb_private;
23
25
28 const lldb::ProcessSP &process_sp) {
31}
32
36 "AddressSanitizer instrumentation runtime plugin for Libsanitizers.",
38}
39
42}
43
47}
48
51 Deactivate();
52}
53
56 static RegularExpression regex(
57 llvm::StringRef("libsystem_sanitizers\\.dylib"));
58 return regex;
59}
60
62 const lldb::ModuleSP module_sp) {
63 const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
64 ConstString("__asan_abi_init"), lldb::eSymbolTypeAny);
65
66 return symbol != nullptr;
67}
68
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;
75
77 static_cast<InstrumentationRuntimeASanLibsanitizers *>(baton);
78
79 ProcessSP process_sp = instance->GetProcessSP();
80
81 return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id,
82 break_loc_id);
83}
84
86 if (IsActive())
87 return;
88
89 ProcessSP process_sp = GetProcessSP();
90 if (!process_sp)
91 return;
92
94
96 module_sp, process_sp, ConstString("sanitizers_address_on_report"));
97
98 if (!breakpoint) {
100 module_sp, process_sp,
101 ConstString("_Z22raise_sanitizers_error23sanitizer_error_context"));
102 }
103
104 if (!breakpoint)
105 return;
106
107 const bool sync = false;
108
109 breakpoint->SetCallback(
111 breakpoint->SetBreakpointKind("address-sanitizer-report");
112 SetBreakpointID(breakpoint->GetID());
113
114 SetActive(true);
115}
116
118 SetActive(false);
119
121 return;
122
123 if (ProcessSP process_sp = GetProcessSP()) {
124 process_sp->GetTarget().RemoveBreakpointByID(GetBreakpointID());
126 }
127}
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
static lldb::InstrumentationRuntimeType GetTypeStatic()
static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp)
bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override
Check whether module_sp corresponds to a valid runtime library.
const lldb_private::RegularExpression & GetPatternForRuntimeLibrary() override
Return a regular expression which can be used to identify a valid version of the runtime library.
void Activate() override
Register a breakpoint in the runtime library and perform any other necessary initialization.
static bool NotifyBreakpointHit(void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:81
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
Definition: Breakpoint.h:452
void SetCallback(BreakpointHitCallback callback, void *baton, bool is_synchronous=false)
Set the callback action invoked when the breakpoint is hit.
Definition: Breakpoint.cpp:408
A uniqued constant string class.
Definition: ConstString.h:40
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool NotifyBreakpointHit(lldb::ProcessSP process_sp, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
static Breakpoint * SetupBreakpoint(lldb::ModuleSP, lldb::ProcessSP, ConstString)
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
lldb::break_id_t GetID() const
Definition: Stoppoint.cpp:22
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
InstrumentationRuntimeType
@ eInstrumentationRuntimeTypeLibsanitizersAsan
uint64_t user_id_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::InstrumentationRuntime > InstrumentationRuntimeSP
Definition: lldb-forward.h:358
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:371