[Lldb-commits] [lldb] r265905 - Provide more information in ThreadSanitizer's JSON data. Move remaining TSan logic from SBThread to InstrumentationRuntime plugin.

2016-04-10 Thread Kuba Brecka via lldb-commits
Author: kuba.brecka
Date: Sun Apr 10 13:57:38 2016
New Revision: 265905

URL: http://llvm.org/viewvc/llvm-project?rev=265905&view=rev
Log:
Provide more information in ThreadSanitizer's JSON data.  Move remaining TSan 
logic from SBThread to InstrumentationRuntime plugin.


Modified:
lldb/trunk/include/lldb/Target/InstrumentationRuntime.h

lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
lldb/trunk/source/API/SBThread.cpp

lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp

lldb/trunk/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h
lldb/trunk/source/Target/InstrumentationRuntime.cpp

Modified: lldb/trunk/include/lldb/Target/InstrumentationRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/InstrumentationRuntime.h?rev=265905&r1=265904&r2=265905&view=diff
==
--- lldb/trunk/include/lldb/Target/InstrumentationRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/InstrumentationRuntime.h Sun Apr 10 13:57:38 
2016
@@ -20,6 +20,7 @@
 #include "lldb/lldb-private.h"
 #include "lldb/lldb-types.h"
 #include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/StructuredData.h"
 
 namespace lldb_private {
 
@@ -39,6 +40,9 @@ public:
 
 virtual bool
 IsActive();
+
+virtual lldb::ThreadCollectionSP
+GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info);
 
 };
 

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py?rev=265905&r1=265904&r2=265905&view=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/basic/TestTsanBasic.py
 Sun Apr 10 13:57:38 2016
@@ -73,7 +73,7 @@ class TsanBasicTestCase(TestBase):
 json_line = '\n'.join(output_lines[2:])
 data = json.loads(json_line)
 self.assertEqual(data["instrumentation_class"], "ThreadSanitizer")
-self.assertEqual(data["description"], "data-race")
+self.assertEqual(data["issue_type"], "data-race")
 self.assertEqual(len(data["mops"]), 2)
 
 backtraces = 
thread.GetStopReasonExtendedBacktraces(lldb.eInstrumentationRuntimeTypeAddressSanitizer)
@@ -109,7 +109,7 @@ class TsanBasicTestCase(TestBase):
 self.runCmd("continue")
 
 # the stop reason of the thread should be a SIGABRT.
-self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+self.expect("thread list", "We should be stopped due a SIGABRT",
 substrs = ['stopped', 'stop reason = signal SIGABRT'])
 
 # test that we're in pthread_kill now (TSan abort the process)

Modified: lldb/trunk/source/API/SBThread.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=265905&r1=265904&r2=265905&view=diff
==
--- lldb/trunk/source/API/SBThread.cpp (original)
+++ lldb/trunk/source/API/SBThread.cpp Sun Apr 10 13:57:38 2016
@@ -34,7 +34,6 @@
 #include "lldb/Target/ThreadPlanStepOut.h"
 #include "lldb/Target/ThreadPlanStepRange.h"
 #include "lldb/Target/ThreadPlanStepInRange.h"
-#include "Plugins/Process/Utility/HistoryThread.h"
 
 #include "lldb/API/SBAddress.h"
 #include "lldb/API/SBDebugger.h"
@@ -329,33 +328,6 @@ SBThread::GetStopReasonExtendedInfoAsJSO
 return true;
 }
 
-static void
-AddThreadsForPath(std::string path, ThreadCollectionSP threads, ProcessSP 
process_sp, StructuredData::ObjectSP info)
-{
-
info->GetObjectForDotSeparatedPath(path)->GetAsArray()->ForEach([process_sp, 
threads] (StructuredData::Object *o) -> bool {
-std::vector pcs;
-o->GetObjectForDotSeparatedPath("trace")->GetAsArray()->ForEach([&pcs] 
(StructuredData::Object *pc) -> bool {
-pcs.push_back(pc->GetAsInteger()->GetValue());
-return true;
-});
-
-if (pcs.size() == 0)
-return true;
-
-StructuredData::ObjectSP thread_id_obj = 
o->GetObjectForDotSeparatedPath("thread_id");
-tid_t tid = thread_id_obj ? thread_id_obj->GetIntegerValue() : 0;
-uint32_t stop_id = 0;
-bool stop_id_is_valid = false;
-HistoryThread *history_thread = new HistoryThread(*process_sp, tid, 
pcs, stop_id, stop_id_is_valid);
-ThreadSP new_thread_sp(history_thread);
-// Save this in the Process' ExtendedThreadList so a strong pointer 
retains the object
-process_sp->GetExtendedThreadList().AddThread(new_thread_sp);
-threads->AddThread(new_thread_sp);
-
-return true;
-});

[Lldb-commits] [lldb] r265906 - Add a ThreadSanitizer testcase that tests multiple reported issues.

2016-04-10 Thread Kuba Brecka via lldb-commits
Author: kuba.brecka
Date: Sun Apr 10 14:29:40 2016
New Revision: 265906

URL: http://llvm.org/viewvc/llvm-project?rev=265906&view=rev
Log:
Add a ThreadSanitizer testcase that tests multiple reported issues.


Added:
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/

lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/Makefile

lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/TestTsanMultiple.py

lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/main.m

Added: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/Makefile?rev=265906&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/Makefile
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/Makefile
 Sun Apr 10 14:29:40 2016
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -fsanitize=thread -g
+
+include $(LEVEL)/Makefile.rules

Added: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/TestTsanMultiple.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/TestTsanMultiple.py?rev=265906&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/TestTsanMultiple.py
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/TestTsanMultiple.py
 Sun Apr 10 14:29:40 2016
@@ -0,0 +1,68 @@
+"""
+Test ThreadSanitizer when multiple different issues are found.
+"""
+
+import os, time
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+import json
+
+class TsanMultipleTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@expectedFailureAll(oslist=["linux"], bugnumber="non-core functionality, 
need to reenable and fix later (DES 2014.11.07)")
+@skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
+@skipIfRemote
+@skipUnlessCompilerRt
+def test (self):
+self.build ()
+self.tsan_tests ()
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+
+def tsan_tests (self):
+exe = os.path.join (os.getcwd(), "a.out")
+self.expect("file " + exe, patterns = [ "Current executable set to 
.*a.out" ])
+
+self.runCmd("env TSAN_OPTIONS=abort_on_error=0")
+
+self.runCmd("run")
+
+stop_reason = 
self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason()
+if stop_reason == lldb.eStopReasonExec:
+# On OS X 10.10 and older, we need to re-exec to enable 
interceptors.
+self.runCmd("continue")
+
+report_count = 0
+while 
self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason() == 
lldb.eStopReasonInstrumentation:
+report_count += 1
+
+stop_description = 
self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopDescription(100)
+
+self.assertTrue(
+ (stop_description == "Data race detected") or
+ (stop_description == "Use of deallocated memory detected") or
+ (stop_description == "Thread leak detected") or
+ (stop_description == "Use of an invalid mutex (e.g. 
uninitialized or destroyed) detected") or
+ (stop_description == "Unlock of an unlocked mutex (or by a 
wrong thread) detected")
+)
+
+self.expect("thread info -s", "The extended stop info should 
contain the TSan provided fields",
+substrs = ["instrumentation_class", "description", "mops"])
+
+output_lines = self.res.GetOutput().split('\n')
+json_line = '\n'.join(output_lines[2:])
+data = json.loads(json_line)
+self.assertEqual(data["instrumentation_class"], "ThreadSanitizer")
+
+backtraces = 
self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReasonExtendedBacktraces(lldb.eInstrumentationRuntimeTypeThreadSanitizer)
+self.assertTrue(backtraces.GetSize() >= 1)
+
+self.runCmd("continue")
+
+self.assertEqual(self.dbg.GetSelectedTarget().process.GetState(), 
lldb.eStateExited, PROCESS_EXITED)

Added: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/main.m
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/tsan/multiple/main.m?rev=265906&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/