LLDB mainline
VerboseTrapFrameRecognizer.cpp
Go to the documentation of this file.
2
3#include "lldb/Core/Module.h"
9
11#include "lldb/Utility/Log.h"
12
13#include "clang/CodeGen/ModuleBuilder.h"
14
15using namespace llvm;
16using namespace lldb;
17using namespace lldb_private;
18
20 StackFrameSP most_relevant_frame_sp, std::string stop_desc)
21 : m_most_relevant_frame(most_relevant_frame_sp) {
22 m_stop_desc = std::move(stop_desc);
23}
24
27 if (frame_sp->GetFrameIndex())
28 return {};
29
30 ThreadSP thread_sp = frame_sp->GetThread();
31 ProcessSP process_sp = thread_sp->GetProcess();
32
33 StackFrameSP most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(1);
34
35 if (!most_relevant_frame_sp) {
38 log,
39 "Failed to find most relevant frame: Hit unwinding bound (1 frame)!");
40 return {};
41 }
42
43 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
44
45 if (!sc.block)
46 return {};
47
48 // The runtime error is set as the function name in the inlined function info
49 // of frame #0 by the compiler
50 const InlineFunctionInfo *inline_info = nullptr;
51 Block *inline_block = sc.block->GetContainingInlinedBlock();
52
53 if (!inline_block)
54 return {};
55
56 inline_info = sc.block->GetInlinedFunctionInfo();
57
58 if (!inline_info)
59 return {};
60
61 auto func_name = inline_info->GetName().GetStringRef();
62 if (func_name.empty())
63 return {};
64
65 static auto trap_regex =
66 llvm::Regex(llvm::formatv("^{0}\\$(.*)\\$(.*)$", ClangTrapPrefix).str());
67 SmallVector<llvm::StringRef, 3> matches;
68 std::string regex_err_msg;
69 if (!trap_regex.match(func_name, &matches, &regex_err_msg)) {
71 "Failed to parse match trap regex for '%s': %s", func_name.data(),
72 regex_err_msg.c_str());
73
74 return {};
75 }
76
77 // For `__clang_trap_msg$category$message$` we expect 3 matches:
78 // 1. entire string
79 // 2. category
80 // 3. message
81 if (matches.size() != 3) {
83 "Unexpected function name format. Expected '<trap prefix>$<trap "
84 "category>$<trap message>'$ but got: '%s'.",
85 func_name.data());
86
87 return {};
88 }
89
90 auto category = matches[1];
91 auto message = matches[2];
92
93 std::string stop_reason =
94 category.empty() ? "<empty category>" : category.str();
95 if (!message.empty()) {
96 stop_reason += ": ";
97 stop_reason += message.str();
98 }
99
100 return std::make_shared<VerboseTrapRecognizedStackFrame>(
101 most_relevant_frame_sp, std::move(stop_reason));
102}
103
106}
107
108namespace lldb_private {
109
111 RegularExpressionSP module_regex_sp = nullptr;
112 auto symbol_regex_sp = std::make_shared<RegularExpression>(
113 llvm::formatv("^{0}", ClangTrapPrefix).str());
114
115 StackFrameRecognizerSP srf_recognizer_sp =
116 std::make_shared<VerboseTrapFrameRecognizer>();
117
119 srf_recognizer_sp, module_regex_sp, symbol_regex_sp, false);
120}
121
122} // namespace lldb_private
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:359
#define LLDB_LOGF(log,...)
Definition: Log.h:366
A class that describes a single lexical block.
Definition: Block.h:41
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: Block.cpp:208
const InlineFunctionInfo * GetInlinedFunctionInfo() const
Get const accessor for any inlined function information.
Definition: Block.h:276
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
A class that describes information for an inlined function.
Definition: Function.h:125
ConstString GetName() const
Definition: Function.cpp:96
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1285
void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, ConstString module, llvm::ArrayRef< ConstString > symbols, bool first_instruction_only=true)
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Block * block
The Block for a given query.
StackFrameRecognizerManager & GetFrameRecognizerManager()
Definition: Target.h:1473
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame) override
VerboseTrapRecognizedStackFrame(lldb::StackFrameSP most_relevant_frame_sp, std::string stop_desc)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:331
void RegisterVerboseTrapFrameRecognizer(Process &process)
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:420
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
Definition: lldb-forward.h:401
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:446
std::shared_ptr< lldb_private::RegularExpression > RegularExpressionSP
Definition: lldb-forward.h:395
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
std::shared_ptr< lldb_private::StackFrameRecognizer > StackFrameRecognizerSP
Definition: lldb-forward.h:424
Definition: Debugger.h:54