[Lldb-commits] [lldb] r300416 - ThreadSanitizer plugin: Support Swift access races and fix how external races are displayed.

Kuba Mracek via lldb-commits lldb-commits at lists.llvm.org
Sat Apr 15 21:02:45 PDT 2017


Author: kuba.brecka
Date: Sat Apr 15 23:02:45 2017
New Revision: 300416

URL: http://llvm.org/viewvc/llvm-project?rev=300416&view=rev
Log:
ThreadSanitizer plugin: Support Swift access races and fix how external races are displayed.


Modified:
    lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
    lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h

Modified: lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp?rev=300416&r1=300415&r2=300416&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp Sat Apr 15 23:02:45 2017
@@ -524,6 +524,8 @@ ThreadSanitizerRuntime::FormatDescriptio
     return "Lock order inversion (potential deadlock)";
   } else if (description == "external-race") {
     return "Race on a library object";
+  } else if (description == "swift-access-race") {
+    return "Swift access race";
   }
 
   // for unknown report codes just show the code
@@ -581,27 +583,31 @@ static void GetSymbolDeclarationFromAddr
 }
 
 addr_t ThreadSanitizerRuntime::GetFirstNonInternalFramePc(
-    StructuredData::ObjectSP trace) {
+    StructuredData::ObjectSP trace, bool skip_one_frame) {
   ProcessSP process_sp = GetProcessSP();
   ModuleSP runtime_module_sp = GetRuntimeModuleSP();
 
-  addr_t result = 0;
-  trace->GetAsArray()->ForEach([process_sp, runtime_module_sp,
-                                &result](StructuredData::Object *o) -> bool {
-    addr_t addr = o->GetIntegerValue();
+  StructuredData::Array *trace_array = trace->GetAsArray();
+  for (int i = 0; i < trace_array->GetSize(); i++) {
+    if (skip_one_frame && i == 0)
+      continue;
+
+    addr_t addr;
+    if (!trace_array->GetItemAtIndexAsInteger(i, addr))
+      continue;
+
     lldb_private::Address so_addr;
     if (!process_sp->GetTarget().GetSectionLoadList().ResolveLoadAddress(
             addr, so_addr))
-      return true;
+      continue;
 
     if (so_addr.GetModule() == runtime_module_sp)
-      return true;
+      continue;
 
-    result = addr;
-    return false;
-  });
+    return addr;
+  }
 
-  return result;
+  return 0;
 }
 
 std::string
@@ -612,6 +618,10 @@ ThreadSanitizerRuntime::GenerateSummary(
                             ->GetValueForKey("description")
                             ->GetAsString()
                             ->GetValue();
+  bool skip_one_frame =
+      report->GetObjectForDotSeparatedPath("issue_type")->GetStringValue() ==
+      "external-race";
+
   addr_t pc = 0;
   if (report->GetAsDictionary()
           ->GetValueForKey("mops")
@@ -622,7 +632,8 @@ ThreadSanitizerRuntime::GenerateSummary(
                                         ->GetAsArray()
                                         ->GetItemAtIndex(0)
                                         ->GetAsDictionary()
-                                        ->GetValueForKey("trace"));
+                                        ->GetValueForKey("trace"),
+                                    skip_one_frame);
 
   if (report->GetAsDictionary()
           ->GetValueForKey("stacks")
@@ -633,7 +644,8 @@ ThreadSanitizerRuntime::GenerateSummary(
                                         ->GetAsArray()
                                         ->GetItemAtIndex(0)
                                         ->GetAsDictionary()
-                                        ->GetValueForKey("trace"));
+                                        ->GetValueForKey("trace"),
+                                    skip_one_frame);
 
   if (pc != 0) {
     summary = summary + " in " + GetSymbolNameFromAddress(process_sp, pc);
@@ -949,9 +961,18 @@ static std::string GenerateThreadName(co
       addr_string = "";
     }
 
-    result = Sprintf("%s%s of size %d%s by thread %d",
-                     is_atomic ? "atomic " : "", is_write ? "write" : "read",
-                     size, addr_string.c_str(), thread_id);
+    if (main_info->GetObjectForDotSeparatedPath("issue_type")
+            ->GetStringValue() == "external-race") {
+      result = Sprintf("%s access by thread %d",
+                       is_write ? "mutating" : "read-only", thread_id);
+    } else if (main_info->GetObjectForDotSeparatedPath("issue_type")
+                   ->GetStringValue() == "swift-access-race") {
+      result = Sprintf("modifying access by thread %d", thread_id);
+    } else {
+      result = Sprintf("%s%s of size %d%s by thread %d",
+                       is_atomic ? "atomic " : "", is_write ? "write" : "read",
+                       size, addr_string.c_str(), thread_id);
+    }
   }
 
   if (path == "threads") {

Modified: lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h?rev=300416&r1=300415&r2=300416&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h (original)
+++ lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h Sat Apr 15 23:02:45 2017
@@ -77,7 +77,8 @@ private:
                                      std::string &global_name,
                                      std::string &filename, uint32_t &line);
 
-  lldb::addr_t GetFirstNonInternalFramePc(StructuredData::ObjectSP trace);
+  lldb::addr_t GetFirstNonInternalFramePc(StructuredData::ObjectSP trace,
+                                          bool skip_one_frame = false);
 };
 
 } // namespace lldb_private




More information about the lldb-commits mailing list