@@ -55,13 +55,16 @@ static void ReportMutexMisuse(ThreadState *thr, uptr pc, ReportType typ,
5555 return ;
5656 if (!ShouldReport (thr, typ))
5757 return ;
58- ThreadRegistryLock l (&ctx->thread_registry );
5958 ScopedReport rep (typ);
60- rep.AddMutex (addr, creation_stack_id);
61- VarSizeStackTrace trace;
62- ObtainCurrentStack (thr, pc, &trace);
63- rep.AddStack (trace, true );
64- rep.AddLocation (addr, 1 );
59+ {
60+ ThreadRegistryLock l (&ctx->thread_registry );
61+ rep.AddMutex (addr, creation_stack_id);
62+ VarSizeStackTrace trace;
63+ ObtainCurrentStack (thr, pc, &trace);
64+ rep.AddStack (trace, true );
65+ rep.AddLocation (addr, 1 );
66+ }
67+ rep.SymbolizeReport ();
6568 OutputReport (thr, rep);
6669}
6770
@@ -528,50 +531,56 @@ void AfterSleep(ThreadState *thr, uptr pc) {
528531void ReportDeadlock (ThreadState *thr, uptr pc, DDReport *r) {
529532 if (r == 0 || !ShouldReport (thr, ReportTypeDeadlock))
530533 return ;
531- ThreadRegistryLock l (&ctx->thread_registry );
532534 ScopedReport rep (ReportTypeDeadlock);
533- for (int i = 0 ; i < r->n ; i++) {
534- rep.AddMutex (r->loop [i].mtx_ctx0 , r->loop [i].stk [0 ]);
535- rep.AddUniqueTid ((int )r->loop [i].thr_ctx );
536- rep.AddThread ((int )r->loop [i].thr_ctx );
537- }
538- uptr dummy_pc = 0x42 ;
539- for (int i = 0 ; i < r->n ; i++) {
540- for (int j = 0 ; j < (flags ()->second_deadlock_stack ? 2 : 1 ); j++) {
541- u32 stk = r->loop [i].stk [j];
542- if (stk && stk != kInvalidStackID ) {
543- rep.AddStack (StackDepotGet (stk), true );
544- } else {
545- // Sometimes we fail to extract the stack trace (FIXME: investigate),
546- // but we should still produce some stack trace in the report.
547- rep.AddStack (StackTrace (&dummy_pc, 1 ), true );
535+ {
536+ ThreadRegistryLock l (&ctx->thread_registry );
537+ for (int i = 0 ; i < r->n ; i++) {
538+ rep.AddMutex (r->loop [i].mtx_ctx0 , r->loop [i].stk [0 ]);
539+ rep.AddUniqueTid ((int )r->loop [i].thr_ctx );
540+ rep.AddThread ((int )r->loop [i].thr_ctx );
541+ }
542+ uptr dummy_pc = 0x42 ;
543+ for (int i = 0 ; i < r->n ; i++) {
544+ for (int j = 0 ; j < (flags ()->second_deadlock_stack ? 2 : 1 ); j++) {
545+ u32 stk = r->loop [i].stk [j];
546+ if (stk && stk != kInvalidStackID ) {
547+ rep.AddStack (StackDepotGet (stk), true );
548+ } else {
549+ // Sometimes we fail to extract the stack trace (FIXME: investigate),
550+ // but we should still produce some stack trace in the report.
551+ rep.AddStack (StackTrace (&dummy_pc, 1 ), true );
552+ }
548553 }
549554 }
550555 }
556+ rep.SymbolizeReport ();
551557 OutputReport (thr, rep);
552558}
553559
554560void ReportDestroyLocked (ThreadState *thr, uptr pc, uptr addr,
555561 FastState last_lock, StackID creation_stack_id) {
556- // We need to lock the slot during RestoreStack because it protects
557- // the slot journal.
558- Lock slot_lock (&ctx->slots [static_cast <uptr>(last_lock.sid ())].mtx );
559- ThreadRegistryLock l0 (&ctx->thread_registry );
560- Lock slots_lock (&ctx->slot_mtx );
561562 ScopedReport rep (ReportTypeMutexDestroyLocked);
562- rep.AddMutex (addr, creation_stack_id);
563- VarSizeStackTrace trace;
564- ObtainCurrentStack (thr, pc, &trace);
565- rep.AddStack (trace, true );
566-
567- Tid tid;
568- DynamicMutexSet mset;
569- uptr tag;
570- if (!RestoreStack (EventType::kLock , last_lock.sid (), last_lock.epoch (), addr,
571- 0 , kAccessWrite , &tid, &trace, mset, &tag))
572- return ;
573- rep.AddStack (trace, true );
574- rep.AddLocation (addr, 1 );
563+ {
564+ // We need to lock the slot during RestoreStack because it protects
565+ // the slot journal.
566+ Lock slot_lock (&ctx->slots [static_cast <uptr>(last_lock.sid ())].mtx );
567+ ThreadRegistryLock l0 (&ctx->thread_registry );
568+ Lock slots_lock (&ctx->slot_mtx );
569+ rep.AddMutex (addr, creation_stack_id);
570+ VarSizeStackTrace trace;
571+ ObtainCurrentStack (thr, pc, &trace);
572+ rep.AddStack (trace, true );
573+
574+ Tid tid;
575+ DynamicMutexSet mset;
576+ uptr tag;
577+ if (!RestoreStack (EventType::kLock , last_lock.sid (), last_lock.epoch (), addr,
578+ 0 , kAccessWrite , &tid, &trace, mset, &tag))
579+ return ;
580+ rep.AddStack (trace, true );
581+ rep.AddLocation (addr, 1 );
582+ }
583+ rep.SymbolizeReport ();
575584 OutputReport (thr, rep);
576585}
577586
0 commit comments