LLDB mainline
MSVCRTCFrameRecognizer.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
12#include "lldb/Target/Process.h"
14#include "lldb/Target/Target.h"
15#include "lldb/Target/Thread.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22namespace lldb_private {
23
26 std::make_shared<MSVCRTCFrameRecognizer>(), ConstString(""),
27 {ConstString("failwithmessage")}, Mangled::ePreferDemangled,
28 /*first_instruction_only=*/false);
29}
30
33 // failwithmessage calls __debugbreak() which lands at frame 0.
34 if (frame_sp->GetFrameIndex() != 0)
36
37 const char *fn_name = frame_sp->GetFunctionName();
38 if (!fn_name)
40 if (!llvm::StringRef(fn_name).contains("failwithmessage"))
42
43 VariableListSP vars = frame_sp->GetInScopeVariableList(false);
44 if (!vars)
46
47 for (size_t i = 0; i < vars->GetSize(); ++i) {
48 VariableSP var = vars->GetVariableAtIndex(i);
49 if (!var || var->GetName() != ConstString("msg"))
50 continue;
51
52 ValueObjectSP val =
53 frame_sp->GetValueObjectForFrameVariable(var, eNoDynamicValues);
54 if (!val)
55 break;
56
57 uint64_t ptr = val->GetValueAsUnsigned(0);
58 if (!ptr)
59 break;
60
61 std::string msg;
62 Status err;
63 frame_sp->GetThread()->GetProcess()->ReadCStringFromMemory(ptr, msg, err);
64 if (err.Success() && !msg.empty())
66 new MSVCRTCRecognizedFrame("Run-time check failure: " + msg));
67 break;
68 }
69
71}
72
73} // namespace lldb_private
A uniqued constant string class.
Definition ConstString.h:40
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame_sp) override
Recognized stack frame for an MSVC _RTC failure.
void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, ConstString module, llvm::ArrayRef< ConstString > symbols, Mangled::NamePreference symbol_mangling, bool first_instruction_only=true)
Add a new recognizer that triggers on a given symbol name.
An error handling class.
Definition Status.h:118
bool Success() const
Test for success condition.
Definition Status.cpp:303
StackFrameRecognizerManager & GetFrameRecognizerManager()
Definition Target.h:1993
A class that represents a running process on the host machine.
void RegisterMSVCRTCFrameRecognizer(Target &target)
Registers the MSVC run-time check failure frame recognizer with the target.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::Variable > VariableSP