4
4
#include " lldb/Symbol/Function.h"
5
5
#include " lldb/Symbol/SymbolContext.h"
6
6
#include " lldb/Target/Process.h"
7
+ #include " lldb/Target/StackFrameRecognizer.h"
7
8
#include " lldb/Target/Target.h"
8
9
9
10
#include " lldb/Utility/LLDBLog.h"
10
11
#include " lldb/Utility/Log.h"
11
12
13
+ #include " clang/CodeGen/ModuleBuilder.h"
14
+
12
15
using namespace llvm ;
13
16
using namespace lldb ;
14
17
using namespace lldb_private ;
@@ -55,26 +58,47 @@ VerboseTrapFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
55
58
if (!inline_info)
56
59
return {};
57
60
58
- auto error_message = inline_info->GetName ().GetString ();
59
- if (error_message .empty ())
61
+ auto func_name = inline_info->GetName ().GetStringRef ();
62
+ if (func_name .empty ())
60
63
return {};
61
64
62
- // Replaces "__llvm_verbose_trap: " with "Runtime Error: "
63
- auto space_position = error_message.find (" " );
64
- if (space_position == std::string::npos) {
65
- Log *log = GetLog (LLDBLog::Unwind);
66
- LLDB_LOGF (log ,
67
- " Unexpected function name format. Expected '<trap prefix>: "
68
- " <trap message>' but got: '%s'." ,
69
- error_message.c_str ());
65
+ static auto trap_regex =
66
+ llvm::Regex (llvm::formatv (" ^{0}\\ $(.*)\\ $(.*)$" , ClangTrapPrefix).str ());
67
+ SmallVector<llvm::StringRef, 2 > matches;
68
+ std::string regex_err_msg;
69
+ if (!trap_regex.match (func_name, &matches, ®ex_err_msg)) {
70
+ LLDB_LOGF (GetLog (LLDBLog::Unwind),
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 ) {
82
+ LLDB_LOGF (GetLog (LLDBLog::Unwind),
83
+ " Unexpected function name format. Expected '<trap prefix>$<trap "
84
+ " category>$<trap message>'$ but got: '%s'. %zu" ,
85
+ func_name.data (), matches.size ());
70
86
71
87
return {};
72
88
}
73
89
74
- error_message.replace (0 , space_position, " Runtime Error:" );
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
+ }
75
99
76
- return lldb::RecognizedStackFrameSP ( new VerboseTrapRecognizedStackFrame (
77
- most_relevant_frame_sp, std::move (error_message) ));
100
+ return std::make_shared< VerboseTrapRecognizedStackFrame> (
101
+ most_relevant_frame_sp, std::move (stop_reason ));
78
102
}
79
103
80
104
lldb::StackFrameSP VerboseTrapRecognizedStackFrame::GetMostRelevantFrame () {
@@ -85,8 +109,8 @@ namespace lldb_private {
85
109
86
110
void RegisterVerboseTrapFrameRecognizer (Process &process) {
87
111
RegularExpressionSP module_regex_sp = nullptr ;
88
- RegularExpressionSP symbol_regex_sp (
89
- new RegularExpression (" ^__llvm_verbose_trap: " ));
112
+ auto symbol_regex_sp = std::make_shared<RegularExpression> (
113
+ llvm::formatv (" ^{0} " , ClangTrapPrefix). str ( ));
90
114
91
115
StackFrameRecognizerSP srf_recognizer_sp =
92
116
std::make_shared<VerboseTrapFrameRecognizer>();
0 commit comments