@@ -75,8 +75,7 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
7575 StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
7676 if (stop_info_sp) {
7777 const StopReason &stop_reason = stop_info_sp->GetStopReason ();
78- if (stop_reason == StopReason::eStopReasonException ||
79- stop_reason == StopReason::eStopReasonSignal)
78+ if (stop_reason != lldb::eStopReasonInvalid)
8079 m_expected_directories++;
8180 }
8281 }
@@ -685,50 +684,45 @@ Status MinidumpFileBuilder::AddExceptions() {
685684 Status error;
686685 for (const ThreadSP &thread_sp : thread_list) {
687686 StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
688- bool add_exception = false ;
689- if (stop_info_sp) {
690- switch (stop_info_sp->GetStopReason ()) {
691- case eStopReasonSignal:
692- case eStopReasonException:
693- add_exception = true ;
694- break ;
695- default :
696- break ;
697- }
698- }
699- if (add_exception) {
700- constexpr size_t minidump_exception_size =
701- sizeof (llvm::minidump::ExceptionStream);
702- error = AddDirectory (StreamType::Exception, minidump_exception_size);
703- if (error.Fail ())
704- return error;
687+ // If we don't have a stop info, or if it's invalid, skip.
688+ if (!stop_info_sp ||
689+ stop_info_sp->GetStopReason () == lldb::eStopReasonInvalid)
690+ continue ;
705691
706- StopInfoSP stop_info_sp = thread_sp->GetStopInfo ();
707- RegisterContextSP reg_ctx_sp (thread_sp->GetRegisterContext ());
708- Exception exp_record = {};
709- exp_record.ExceptionCode =
710- static_cast <llvm::support::ulittle32_t >(stop_info_sp->GetValue ());
711- exp_record.ExceptionFlags = static_cast <llvm::support::ulittle32_t >(0 );
712- exp_record.ExceptionRecord = static_cast <llvm::support::ulittle64_t >(0 );
713- exp_record.ExceptionAddress = reg_ctx_sp->GetPC ();
714- exp_record.NumberParameters = static_cast <llvm::support::ulittle32_t >(0 );
715- exp_record.UnusedAlignment = static_cast <llvm::support::ulittle32_t >(0 );
716- // exp_record.ExceptionInformation;
717-
718- ExceptionStream exp_stream;
719- exp_stream.ThreadId =
720- static_cast <llvm::support::ulittle32_t >(thread_sp->GetID ());
721- exp_stream.UnusedAlignment = static_cast <llvm::support::ulittle32_t >(0 );
722- exp_stream.ExceptionRecord = exp_record;
723- auto Iter = m_tid_to_reg_ctx.find (thread_sp->GetID ());
724- if (Iter != m_tid_to_reg_ctx.end ()) {
725- exp_stream.ThreadContext = Iter->second ;
726- } else {
727- exp_stream.ThreadContext .DataSize = 0 ;
728- exp_stream.ThreadContext .RVA = 0 ;
729- }
730- m_data.AppendData (&exp_stream, minidump_exception_size);
692+ constexpr size_t minidump_exception_size =
693+ sizeof (llvm::minidump::ExceptionStream);
694+ error = AddDirectory (StreamType::Exception, minidump_exception_size);
695+ if (error.Fail ())
696+ return error;
697+
698+ RegisterContextSP reg_ctx_sp (thread_sp->GetRegisterContext ());
699+ Exception exp_record = {};
700+ exp_record.ExceptionCode =
701+ static_cast <llvm::support::ulittle32_t >(stop_info_sp->GetValue ());
702+ exp_record.ExceptionFlags =
703+ static_cast <llvm::support::ulittle32_t >(Exception::LLDB_FLAG);
704+ exp_record.ExceptionRecord = static_cast <llvm::support::ulittle64_t >(0 );
705+ exp_record.ExceptionAddress = reg_ctx_sp->GetPC ();
706+ exp_record.NumberParameters = static_cast <llvm::support::ulittle32_t >(1 );
707+ std::string description = stop_info_sp->GetDescription ();
708+ // We have 120 bytes to work with and it's unlikely description will
709+ // overflow, but we gotta check.
710+ memcpy (&exp_record.ExceptionInformation , description.c_str (),
711+ std::max (description.size (), Exception::MaxParameterBytes));
712+ exp_record.UnusedAlignment = static_cast <llvm::support::ulittle32_t >(0 );
713+ ExceptionStream exp_stream;
714+ exp_stream.ThreadId =
715+ static_cast <llvm::support::ulittle32_t >(thread_sp->GetID ());
716+ exp_stream.UnusedAlignment = static_cast <llvm::support::ulittle32_t >(0 );
717+ exp_stream.ExceptionRecord = exp_record;
718+ auto Iter = m_tid_to_reg_ctx.find (thread_sp->GetID ());
719+ if (Iter != m_tid_to_reg_ctx.end ()) {
720+ exp_stream.ThreadContext = Iter->second ;
721+ } else {
722+ exp_stream.ThreadContext .DataSize = 0 ;
723+ exp_stream.ThreadContext .RVA = 0 ;
731724 }
725+ m_data.AppendData (&exp_stream, minidump_exception_size);
732726 }
733727
734728 return error;
0 commit comments