From edc77353daa707712fc92a31edb5b27ad103ba30 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Thu, 11 Aug 2022 22:26:36 -0700 Subject: [lldb/crashlog] Improve exception reporting for interactive mode This patch improve exception reporting when loading a crash report in a scripted process. Now, we parse the `exception` dictionary from the crash report use it the create a higher fidelity `MachException` stop info. This patch also updates the test to reflect that change. rdar://97096486 Differential Revision: https://reviews.llvm.org/D131086 Signed-off-by: Med Ismail Bennani --- .../Plugins/Process/scripted/ScriptedThread.cpp | 44 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'lldb/source/Plugins/Process/scripted/ScriptedThread.cpp') diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp index e28f66015dd5..5c49caedcfcc 100644 --- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp +++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp @@ -9,6 +9,7 @@ #include "ScriptedThread.h" #include "Plugins/Process/Utility/RegisterContextThreadMemory.h" +#include "Plugins/Process/Utility/StopInfoMachException.h" #include "lldb/Target/OperatingSystem.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" @@ -259,11 +260,46 @@ bool ScriptedThread::CalculateStopInfo() { StopInfo::CreateStopReasonWithSignal(*this, signal, description.data()); } break; case lldb::eStopReasonException: { - llvm::StringRef description; - data_dict->GetValueForKeyAsString("desc", description); - +#if defined(__APPLE__) + StructuredData::Dictionary *mach_exception; + if (data_dict->GetValueForKeyAsDictionary("mach_exception", + mach_exception)) { + llvm::StringRef value; + mach_exception->GetValueForKeyAsString("type", value); + auto exc_type = + StopInfoMachException::MachException::ExceptionCode(value.data()); + + if (!exc_type) + return false; + + uint32_t exc_data_size = 0; + llvm::SmallVector raw_codes; + + StructuredData::Array *exc_rawcodes; + mach_exception->GetValueForKeyAsArray("rawCodes", exc_rawcodes); + if (exc_rawcodes) { + auto fetch_data = [&raw_codes](StructuredData::Object *obj) { + if (!obj) + return false; + raw_codes.push_back(obj->GetIntegerValue()); + return true; + }; + + exc_rawcodes->ForEach(fetch_data); + exc_data_size = raw_codes.size(); + } + + stop_info_sp = StopInfoMachException::CreateStopReasonWithMachException( + *this, *exc_type, exc_data_size, + exc_data_size >= 1 ? raw_codes[0] : 0, + exc_data_size >= 2 ? raw_codes[1] : 0, + exc_data_size >= 3 ? raw_codes[2] : 0); + + break; + } +#endif stop_info_sp = - StopInfo::CreateStopReasonWithException(*this, description.data()); + StopInfo::CreateStopReasonWithException(*this, "EXC_BAD_ACCESS"); } break; default: return ScriptedInterface::ErrorWithMessage( -- cgit v1.2.3