44#include " lldb/Symbol/Function.h"
55#include " lldb/Symbol/SymbolContext.h"
66#include " lldb/Target/Process.h"
7+ #include " lldb/Target/StackFrameRecognizer.h"
78#include " lldb/Target/Target.h"
89
910#include " lldb/Utility/LLDBLog.h"
1011#include " lldb/Utility/Log.h"
1112
13+ #include " clang/CodeGen/ModuleBuilder.h"
14+
1215using namespace llvm ;
1316using namespace lldb ;
1417using namespace lldb_private ;
@@ -55,26 +58,47 @@ VerboseTrapFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
5558 if (!inline_info)
5659 return {};
5760
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 ())
6063 return {};
6164
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 ());
7086
7187 return {};
7288 }
7389
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+ }
7599
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 ));
78102}
79103
80104lldb::StackFrameSP VerboseTrapRecognizedStackFrame::GetMostRelevantFrame () {
@@ -85,8 +109,8 @@ namespace lldb_private {
85109
86110void RegisterVerboseTrapFrameRecognizer (Process &process) {
87111 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 ( ));
90114
91115 StackFrameRecognizerSP srf_recognizer_sp =
92116 std::make_shared<VerboseTrapFrameRecognizer>();
0 commit comments