LLDB mainline
InstrumentationRuntimeStopInfo.cpp
Go to the documentation of this file.
1//===-- InstrumentationRuntimeStopInfo.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
11#include "lldb/Core/Module.h"
13#include "lldb/Target/Process.h"
15#include "lldb/lldb-private.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20static bool IsStoppedInDarwinSanitizer(Thread &thread, Module &module) {
21 return module.GetFileSpec().GetFilename().GetStringRef().starts_with(
22 "libclang_rt.");
23}
24
26 Thread &thread, std::string description,
27 StructuredData::ObjectSP additional_data)
28 : StopInfo(thread, 0) {
29 m_extended_info = additional_data;
30 m_description = description;
31}
32
36
39 Thread &thread, std::string description,
40 StructuredData::ObjectSP additionalData) {
41 return StopInfoSP(
42 new InstrumentationRuntimeStopInfo(thread, description, additionalData));
43}
44
45std::optional<uint32_t>
47 bool inlined_stack) {
48 ThreadSP thread_sp = GetThread();
49 if (!thread_sp)
50 return std::nullopt;
51
52 // Defensive upper-bound of when we stop walking up the frames in
53 // case we somehow ended up looking at an infinite recursion.
54 constexpr size_t max_stack_depth = 128;
55
56 // Start at parent frame.
57 size_t stack_idx = 1;
58 StackFrameSP most_relevant_frame_sp =
59 thread_sp->GetStackFrameAtIndex(stack_idx);
60
61 while (most_relevant_frame_sp && stack_idx <= max_stack_depth) {
62 auto const &sc =
63 most_relevant_frame_sp->GetSymbolContext(lldb::eSymbolContextModule);
64
65 if (!sc.module_sp)
66 return std::nullopt;
67
68 // Found a frame outside of the sanitizer runtime libraries.
69 // That's the one we want to display.
70 if (!IsStoppedInDarwinSanitizer(*thread_sp, *sc.module_sp))
71 return stack_idx;
72
73 ++stack_idx;
74 most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(stack_idx);
75 }
76
77 return stack_idx;
78}
static bool IsStoppedInDarwinSanitizer(Thread &thread, Module &module)
static lldb::StopInfoSP CreateStopReasonWithInstrumentationData(Thread &thread, std::string description, StructuredData::ObjectSP additional_data)
InstrumentationRuntimeStopInfo(Thread &thread, std::string description, StructuredData::ObjectSP additional_data)
std::optional< uint32_t > GetSuggestedStackFrameIndex(bool inlined_stack) override
This gives the StopInfo a chance to suggest a stack frame to select.
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
std::string m_description
Definition StopInfo.h:227
StructuredData::ObjectSP m_extended_info
Definition StopInfo.h:232
lldb::ThreadSP GetThread() const
Definition StopInfo.h:35
friend class Thread
Definition StopInfo.h:245
StopInfo(Thread &thread, uint64_t value)
Definition StopInfo.cpp:34
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP