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().starts_with("libclang_rt.");
22}
23
25 Thread &thread, std::string description,
26 StructuredData::ObjectSP additional_data)
27 : StopInfo(thread, 0) {
28 m_extended_info = additional_data;
29 m_description = description;
30}
31
35
38 Thread &thread, std::string description,
39 StructuredData::ObjectSP additionalData) {
40 return StopInfoSP(
41 new InstrumentationRuntimeStopInfo(thread, description, additionalData));
42}
43
44std::optional<uint32_t>
46 bool inlined_stack) {
47 ThreadSP thread_sp = GetThread();
48 if (!thread_sp)
49 return std::nullopt;
50
51 // Defensive upper-bound of when we stop walking up the frames in
52 // case we somehow ended up looking at an infinite recursion.
53 constexpr size_t max_stack_depth = 128;
54
55 // Start at parent frame.
56 size_t stack_idx = 1;
57 StackFrameSP most_relevant_frame_sp =
58 thread_sp->GetStackFrameAtIndex(stack_idx);
59
60 while (most_relevant_frame_sp && stack_idx <= max_stack_depth) {
61 auto const &sc =
62 most_relevant_frame_sp->GetSymbolContext(lldb::eSymbolContextModule);
63
64 if (!sc.module_sp)
65 return std::nullopt;
66
67 // Found a frame outside of the sanitizer runtime libraries.
68 // That's the one we want to display.
69 if (!IsStoppedInDarwinSanitizer(*thread_sp, *sc.module_sp))
70 return stack_idx;
71
72 ++stack_idx;
73 most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(stack_idx);
74 }
75
76 return stack_idx;
77}
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:91
std::string m_description
Definition StopInfo.h:233
StructuredData::ObjectSP m_extended_info
Definition StopInfo.h:238
lldb::ThreadSP GetThread() const
Definition StopInfo.h:35
friend class Thread
Definition StopInfo.h:251
StopInfo(Thread &thread, uint64_t value)
Definition StopInfo.cpp:37
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