LLDB mainline
InstrumentationRuntimeASan.cpp
Go to the documentation of this file.
1//===-- InstrumentationRuntimeASan.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
29}
30
33 GetPluginNameStatic(), "AddressSanitizer instrumentation runtime plugin.",
35}
36
39}
40
43}
44
46
49 // FIXME: This shouldn't include the "dylib" suffix.
50 static RegularExpression regex(
51 llvm::StringRef("libclang_rt.asan_(.*)_dynamic\\.dylib"));
52 return regex;
53}
54
56 const lldb::ModuleSP module_sp) {
57 const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
58 ConstString("__asan_get_alloc_stack"), lldb::eSymbolTypeAny);
59
60 return symbol != nullptr;
61}
62
64 void *baton, StoppointCallbackContext *context, user_id_t break_id,
65 user_id_t break_loc_id) {
66 assert(baton && "null baton");
67 if (!baton)
68 return false;
69
70 InstrumentationRuntimeASan *const instance =
71 static_cast<InstrumentationRuntimeASan *>(baton);
72
73 ProcessSP process_sp = instance->GetProcessSP();
74
75 return ReportRetriever::NotifyBreakpointHit(process_sp, context, break_id,
76 break_loc_id);
77}
78
80 if (IsActive())
81 return;
82
83 ProcessSP process_sp = GetProcessSP();
84 if (!process_sp)
85 return;
86
88 GetRuntimeModuleSP(), process_sp, ConstString("_ZN6__asanL7AsanDieEv"));
89
90 if (!breakpoint)
91 return;
92
93 const bool sync = false;
94
96 sync);
97 breakpoint->SetBreakpointKind("address-sanitizer-report");
98 SetBreakpointID(breakpoint->GetID());
99
100 SetActive(true);
101}
102
104 SetActive(false);
105
107 return;
108
109 if (ProcessSP process_sp = GetProcessSP()) {
110 process_sp->GetTarget().RemoveBreakpointByID(GetBreakpointID());
112 }
113}
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
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 lldb::InstrumentationRuntimeType GetTypeStatic()
static bool NotifyBreakpointHit(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
void Activate() override
Register a breakpoint in the runtime library and perform any other necessary initialization.
static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp)
const RegularExpression & GetPatternForRuntimeLibrary() override
Return a regular expression which can be used to identify a valid version of the runtime library.
bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override
Check whether module_sp corresponds to a valid runtime library.
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
@ eInstrumentationRuntimeTypeAddressSanitizer
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