From a51ea3822a47e0f873261af8a684eba8308abeff Mon Sep 17 00:00:00 2001 From: Kuba Brecka Date: Sat, 6 Sep 2014 01:33:13 +0000 Subject: [PATCH] Implement ASan history threads in SB API Reviewed at http://reviews.llvm.org/D5219 and http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20140901/012809.html llvm-svn: 217300 --- lldb/include/lldb/API/SBProcess.h | 3 +++ lldb/include/lldb/Target/Process.h | 3 +++ lldb/scripts/Python/interface/SBProcess.i | 3 +++ lldb/source/API/SBProcess.cpp | 13 +++++++++++++ lldb/source/Target/Process.cpp | 17 +++++++++++++++++ lldb/test/functionalities/asan/TestAsan.py | 18 ++++++++++++++++++ 6 files changed, 57 insertions(+) diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 4b59462ca3f1..5ddb0290998e 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -316,6 +316,9 @@ public: //------------------------------------------------------------------ const char * GetExtendedBacktraceTypeAtIndex (uint32_t idx); + + lldb::SBThreadCollection + GetHistoryThreads (addr_t addr); protected: friend class SBAddress; diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 9d08541a21a5..96885b609b18 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2922,6 +2922,9 @@ public: Error return_error ("Sending an event is not supported for this process."); return return_error; } + + lldb::ThreadCollectionSP + GetHistoryThreads(lldb::addr_t addr); protected: diff --git a/lldb/scripts/Python/interface/SBProcess.i b/lldb/scripts/Python/interface/SBProcess.i index 5cd99c0296c9..dce930c350bb 100644 --- a/lldb/scripts/Python/interface/SBProcess.i +++ b/lldb/scripts/Python/interface/SBProcess.i @@ -389,6 +389,9 @@ public: const char * GetExtendedBacktraceTypeAtIndex (uint32_t idx); + lldb::SBThreadCollection + GetHistoryThreads (addr_t addr); + %pythoncode %{ def __get_is_alive__(self): '''Returns "True" if the process is currently alive, "False" otherwise''' diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 41efd86177d6..7b519b16bd19 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -38,6 +38,7 @@ #include "lldb/API/SBEvent.h" #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBThread.h" +#include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBStringList.h" #include "lldb/API/SBUnixSignals.h" @@ -1381,3 +1382,15 @@ SBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx) } return NULL; } + +SBThreadCollection +SBProcess::GetHistoryThreads (addr_t addr) +{ + ProcessSP process_sp(GetSP()); + SBThreadCollection threads; + if (process_sp) + { + threads = SBThreadCollection(process_sp->GetHistoryThreads(addr)); + } + return threads; +} diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 02f963584331..28f02359b744 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -32,6 +32,7 @@ #include "lldb/Target/ABI.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/JITLoader.h" +#include "lldb/Target/MemoryHistory.h" #include "lldb/Target/OperatingSystem.h" #include "lldb/Target/LanguageRuntime.h" #include "lldb/Target/CPPLanguageRuntime.h" @@ -6022,3 +6023,19 @@ Process::ModulesDidLoad (ModuleList &module_list) GetJITLoaders().ModulesDidLoad (module_list); } + +ThreadCollectionSP +Process::GetHistoryThreads(lldb::addr_t addr) +{ + ThreadCollectionSP threads; + + const MemoryHistorySP &memory_history = MemoryHistory::FindPlugin(shared_from_this()); + + if (! memory_history.get()) { + return threads; + } + + threads.reset(new ThreadCollection(memory_history->GetHistoryThreads(addr))); + + return threads; +} diff --git a/lldb/test/functionalities/asan/TestAsan.py b/lldb/test/functionalities/asan/TestAsan.py index ba4b4e72e52c..a687e268752a 100644 --- a/lldb/test/functionalities/asan/TestAsan.py +++ b/lldb/test/functionalities/asan/TestAsan.py @@ -70,6 +70,24 @@ class AsanTestCase(TestBase): 'Memory allocated at', 'a.out`f1', 'main.c:%d' % self.line_malloc, 'Memory deallocated at', 'a.out`f2', 'main.c:%d' % self.line_free]) + # do the same using SB API + process = self.dbg.GetSelectedTarget().process + val = process.GetSelectedThread().GetSelectedFrame().EvaluateExpression("pointer") + addr = val.GetValueAsUnsigned() + threads = process.GetHistoryThreads(addr); + self.assertEqual(threads.GetSize(), 2) + + history_thread = threads.GetThreadAtIndex(0) + self.assertTrue(history_thread.num_frames >= 2) + self.assertEqual(history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(), "main.c") + self.assertEqual(history_thread.frames[1].GetLineEntry().GetLine(), self.line_malloc) + + history_thread = threads.GetThreadAtIndex(1) + self.assertTrue(history_thread.num_frames >= 2) + self.assertEqual(history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(), "main.c") + self.assertEqual(history_thread.frames[1].GetLineEntry().GetLine(), self.line_free) + + # now let's break when an ASan report occurs and try the API then self.runCmd("breakpoint set -n __asan_report_error") self.runCmd("continue")