@@ -491,19 +491,32 @@ ValueObjectSP AppleObjCRuntime::GetExceptionObjectForThread(
491
491
return ValueObjectSP ();
492
492
}
493
493
494
+ // / Utility method for error handling in GetBacktraceThreadFromException.
495
+ // / \param msg The message to add to the log.
496
+ // / \return An invalid ThreadSP to be returned from
497
+ // / GetBacktraceThreadFromException.
498
+ LLVM_NODISCARD
499
+ static ThreadSP FailExceptionParsing (llvm::StringRef msg) {
500
+ Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_LANGUAGE));
501
+ LLDB_LOG (log, " Failed getting backtrace from exception: {0}" , msg);
502
+ return ThreadSP ();
503
+ }
504
+
494
505
ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException (
495
506
lldb::ValueObjectSP exception_sp) {
496
507
ValueObjectSP reserved_dict =
497
508
exception_sp->GetChildMemberWithName (ConstString (" reserved" ), true );
498
- if (!reserved_dict) return ThreadSP ();
509
+ if (!reserved_dict)
510
+ return FailExceptionParsing (" Failed to get 'reserved' member." );
499
511
500
512
reserved_dict = reserved_dict->GetSyntheticValue ();
501
- if (!reserved_dict) return ThreadSP ();
513
+ if (!reserved_dict)
514
+ return FailExceptionParsing (" Failed to get synthetic value." );
502
515
503
516
TypeSystemClang *clang_ast_context =
504
517
TypeSystemClang::GetScratch (*exception_sp->GetTargetSP ());
505
518
if (!clang_ast_context)
506
- return ThreadSP ( );
519
+ return FailExceptionParsing ( " Failed to get scratch AST. " );
507
520
CompilerType objc_id =
508
521
clang_ast_context->GetBasicType (lldb::eBasicTypeObjCID);
509
522
ValueObjectSP return_addresses;
@@ -544,15 +557,22 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
544
557
}
545
558
}
546
559
547
- if (!return_addresses) return ThreadSP ();
560
+ if (!return_addresses)
561
+ return FailExceptionParsing (" Failed to get return addresses." );
548
562
auto frames_value =
549
563
return_addresses->GetChildMemberWithName (ConstString (" _frames" ), true );
564
+ if (!frames_value)
565
+ return FailExceptionParsing (" Failed to get frames_value." );
550
566
addr_t frames_addr = frames_value->GetValueAsUnsigned (0 );
551
567
auto count_value =
552
568
return_addresses->GetChildMemberWithName (ConstString (" _cnt" ), true );
569
+ if (!count_value)
570
+ return FailExceptionParsing (" Failed to get count_value." );
553
571
size_t count = count_value->GetValueAsUnsigned (0 );
554
572
auto ignore_value =
555
573
return_addresses->GetChildMemberWithName (ConstString (" _ignore" ), true );
574
+ if (!ignore_value)
575
+ return FailExceptionParsing (" Failed to get ignore_value." );
556
576
size_t ignore = ignore_value->GetValueAsUnsigned (0 );
557
577
558
578
size_t ptr_size = m_process->GetAddressByteSize ();
@@ -564,7 +584,8 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
564
584
pcs.push_back (pc);
565
585
}
566
586
567
- if (pcs.empty ()) return ThreadSP ();
587
+ if (pcs.empty ())
588
+ return FailExceptionParsing (" Failed to get PC list." );
568
589
569
590
ThreadSP new_thread_sp (new HistoryThread (*m_process, 0 , pcs));
570
591
m_process->GetExtendedThreadList ().AddThread (new_thread_sp);
0 commit comments