From owner-svn-src-vendor@freebsd.org Fri Jun 16 21:04:26 2017 Return-Path: Delivered-To: svn-src-vendor@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 88FFED893AE; Fri, 16 Jun 2017 21:04:26 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2F1476F9AC; Fri, 16 Jun 2017 21:04:26 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v5GL4PZQ063941; Fri, 16 Jun 2017 21:04:25 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5GL4MZT063914; Fri, 16 Jun 2017 21:04:22 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201706162104.v5GL4MZT063914@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Fri, 16 Jun 2017 21:04:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r320023 - in vendor/lldb/dist: include/lldb/Core include/lldb/Target include/lldb/Utility packages/Python/lldbsuite/test/expression_command/call-restarts packages/Python/lldbsuite/test/... X-SVN-Group: vendor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-vendor@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the vendor work area tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jun 2017 21:04:26 -0000 Author: dim Date: Fri Jun 16 21:04:22 2017 New Revision: 320023 URL: https://svnweb.freebsd.org/changeset/base/320023 Log: Vendor import of lldb trunk r305575: https://llvm.org/svn/llvm-project/lldb/trunk@305575 Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/Makefile (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/bundle.c (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/main.c (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/Info.plist vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/Makefile (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/MyFramework.h (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/TestDeepBundle.py (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/main.c (contents, props changed) vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/myframework.c (contents, props changed) Modified: vendor/lldb/dist/include/lldb/Core/Debugger.h vendor/lldb/dist/include/lldb/Target/StackFrame.h vendor/lldb/dist/include/lldb/Target/StackFrameList.h vendor/lldb/dist/include/lldb/Target/Thread.h vendor/lldb/dist/include/lldb/Utility/Status.h vendor/lldb/dist/packages/Python/lldbsuite/test/expression_command/call-restarts/TestCallThatRestarts.py vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/thread/num_threads/TestNumThreads.py vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/thread/num_threads/main.cpp vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py vendor/lldb/dist/packages/Python/lldbsuite/test/lang/c/register_variables/test.c vendor/lldb/dist/packages/Python/lldbsuite/test/lang/objc/objc-new-syntax/TestObjCNewSyntax.py vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py vendor/lldb/dist/scripts/lldb.swig vendor/lldb/dist/source/Commands/CommandObjectThread.cpp vendor/lldb/dist/source/Core/Debugger.cpp vendor/lldb/dist/source/Host/common/Symbols.cpp vendor/lldb/dist/source/Target/StackFrame.cpp vendor/lldb/dist/source/Target/StackFrameList.cpp vendor/lldb/dist/source/Target/Thread.cpp vendor/lldb/dist/source/Utility/Status.cpp vendor/lldb/dist/unittests/Utility/StatusTest.cpp Modified: vendor/lldb/dist/include/lldb/Core/Debugger.h ============================================================================== --- vendor/lldb/dist/include/lldb/Core/Debugger.h Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/include/lldb/Core/Debugger.h Fri Jun 16 21:04:22 2017 (r320023) @@ -249,6 +249,8 @@ class Debugger : public std::enable_shared_from_this= 4, + num_threads >= 13, 'Number of expected threads and actual threads do not match.') + + def test_unique_stacks(self): + """Test backtrace unique with multiple threads executing the same stack.""" + self.build() + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Set a break point on the thread3 notify all (should get hit on threads 4-13). + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.thread3_before_lock_line, num_expected_locations=1) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # Stopped once. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=["stop reason = breakpoint 1."]) + + process = self.process() + + # Get the number of threads + num_threads = process.GetNumThreads() + + # Using std::thread may involve extra threads, so we assert that there are + # at least 10 thread3's rather than exactly 10. + self.assertTrue( + num_threads >= 10, + 'Number of expected threads and actual threads do not match.') + + # Attempt to walk each of the thread's executing the thread3 function to + # the same breakpoint. + def is_thread3(thread): + for frame in thread: + if "thread3" in frame.GetFunctionName(): return True + return False + + expect_threads = "" + for i in range(num_threads): + thread = process.GetThreadAtIndex(i) + self.assertTrue(thread.IsValid()) + if not is_thread3(thread): + continue + + # If we aren't stopped out the thread breakpoint try to resume. + if thread.GetStopReason() != lldb.eStopReasonBreakpoint: + self.runCmd("thread continue %d"%(i+1)) + self.assertEqual(thread.GetStopReason(), lldb.eStopReasonBreakpoint) + + expect_threads += " #%d"%(i+1) + + # Construct our expected back trace string + expect_string = "10 thread(s)%s" % (expect_threads) + + # Now that we are stopped, we should have 10 threads waiting in the + # thread3 function. All of these threads should show as one stack. + self.expect("thread backtrace unique", + "Backtrace with unique stack shown correctly", + substrs=[expect_string, + "main.cpp:%d"%self.thread3_before_lock_line]) Modified: vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/thread/num_threads/main.cpp ============================================================================== --- vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/thread/num_threads/main.cpp Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/thread/num_threads/main.cpp Fri Jun 16 21:04:22 2017 (r320023) @@ -1,15 +1,19 @@ +#include "pseudo_barrier.h" #include #include #include +#include std::mutex mutex; std::condition_variable cond; +pseudo_barrier_t thread3_barrier; void * thread3(void *input) { - std::unique_lock lock(mutex); - cond.notify_all(); // Set break point at this line. + pseudo_barrier_wait(thread3_barrier); + std::unique_lock lock(mutex); // Set thread3 break point on lock at this line. + cond.notify_all(); // Set thread3 break point on notify_all at this line. return NULL; } @@ -17,7 +21,7 @@ void * thread2(void *input) { std::unique_lock lock(mutex); - cond.notify_all(); + cond.notify_all(); // release main thread cond.wait(lock); return NULL; } @@ -36,15 +40,23 @@ int main() std::unique_lock lock(mutex); std::thread thread_1(thread1, nullptr); - cond.wait(lock); + cond.wait(lock); // wait for thread2 - std::thread thread_3(thread3, nullptr); - cond.wait(lock); + pseudo_barrier_init(thread3_barrier, 10); + std::vector thread_3s; + for (int i = 0; i < 10; i++) { + thread_3s.push_back(std::thread(thread3, nullptr)); + } + + cond.wait(lock); // wait for thread_3s + lock.unlock(); thread_1.join(); - thread_3.join(); + for (auto &t : thread_3s){ + t.join(); + } return 0; } Modified: vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py ============================================================================== --- vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py Fri Jun 16 21:04:22 2017 (r320023) @@ -19,6 +19,7 @@ class NoreturnUnwind(TestBase): @skipIfWindows # clang-cl does not support gcc style attributes. # clang does not preserve LR in noreturn functions, making unwinding impossible @skipIf(compiler="clang", archs=['arm'], oslist=['linux']) + @expectedFailureAll(bugnumber="llvm.org/pr33452", triple='^mips') def test(self): """Test that we can backtrace correctly with 'noreturn' functions on the stack""" self.build() Modified: vendor/lldb/dist/packages/Python/lldbsuite/test/lang/c/register_variables/test.c ============================================================================== --- vendor/lldb/dist/packages/Python/lldbsuite/test/lang/c/register_variables/test.c Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/lang/c/register_variables/test.c Fri Jun 16 21:04:22 2017 (r320023) @@ -1,6 +1,6 @@ #include -#if defined(__arm__) || defined(__aarch64__) +#if defined(__arm__) || defined(__aarch64__) || defined (__mips__) // Clang does not accept regparm attribute on these platforms. // Fortunately, the default calling convention passes arguments in registers // anyway. Modified: vendor/lldb/dist/packages/Python/lldbsuite/test/lang/objc/objc-new-syntax/TestObjCNewSyntax.py ============================================================================== --- vendor/lldb/dist/packages/Python/lldbsuite/test/lang/objc/objc-new-syntax/TestObjCNewSyntax.py Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/lang/objc/objc-new-syntax/TestObjCNewSyntax.py Fri Jun 16 21:04:22 2017 (r320023) @@ -121,6 +121,8 @@ class ObjCNewSyntaxTestCase(TestBase): '7.0.0']) @skipIf(macos_version=["<", "10.12"]) @expectedFailureAll(archs=["i[3-6]86"]) + @expectedFailureAll( + bugnumber="rdar://32777981") def test_update_dictionary(self): self.runToBreakpoint() @@ -163,6 +165,8 @@ class ObjCNewSyntaxTestCase(TestBase): '7.0.0']) @skipIf(macos_version=["<", "10.12"]) @expectedFailureAll(archs=["i[3-6]86"]) + @expectedFailureAll( + bugnumber="rdar://32777981") def test_dictionary_literal(self): self.runToBreakpoint() Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/Makefile Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,21 @@ +CC ?= clang + +ifeq "$(ARCH)" "" + ARCH = x86_64 +endif + +CFLAGS ?= -g -O0 -arch $(ARCH) + +all: clean + $(CC) $(CFLAGS) -dynamiclib -o com.apple.sbd bundle.c + mkdir com.apple.sbd.xpc + mv com.apple.sbd com.apple.sbd.xpc/ + mkdir -p com.apple.sbd.xpc.dSYM/Contents/Resources/DWARF + mv com.apple.sbd.dSYM/Contents/Resources/DWARF/com.apple.sbd com.apple.sbd.xpc.dSYM/Contents/Resources/DWARF/ + rm -rf com.apple.sbd.dSYM + mkdir hide.app + tar cf - com.apple.sbd.xpc com.apple.sbd.xpc.dSYM | ( cd hide.app;tar xBpf -) + $(CC) $(CFLAGS) -o find-bundle-with-dots-in-fn main.c + +clean: + rm -rf a.out a.out.dSYM hide.app com.apple.sbd com.apple.sbd.dSYM com.apple.sbd.xpc com.apple.sbd.xpc.dSYM find-bundle-with-dots-in-fn find-bundle-with-dots-in-fn.dSYM Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/TestBundleWithDotInFilename.py Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,71 @@ +"""Test that a dSYM can be found when a binary is in a bundle hnd has dots in the filename.""" + +from __future__ import print_function + +#import unittest2 +import os.path +from time import sleep + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +exe_name = 'find-bundle-with-dots-in-fn' # must match Makefile + +class BundleWithDotInFilenameTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfRemote + @skipUnlessDarwin + # This test is explicitly a dSYM test, it doesn't need to run for any other config, but + # the following doesn't work, fixme. + # @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is looking explicitly for a dSYM") + + def setUp(self): + TestBase.setUp(self) + self.source = 'main.c' + + def tearDown(self): + # Destroy process before TestBase.tearDown() + self.dbg.GetSelectedTarget().GetProcess().Destroy() + + # Call super's tearDown(). + TestBase.tearDown(self) + + def test_attach_and_check_dsyms(self): + """Test attach to binary, see if the bundle dSYM is found""" + exe = os.path.join(os.getcwd(), exe_name) + self.build() + popen = self.spawnSubprocess(exe) + self.addTearDownHook(self.cleanupSubprocesses) + + # Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in + sleep(5) + + # Since the library that was dlopen()'ed is now removed, lldb will need to find the + # binary & dSYM via target.exec-search-paths + settings_str = "settings set target.exec-search-paths " + self.get_process_working_directory() + "/hide.app" + self.runCmd(settings_str) + + self.runCmd("process attach -p " + str(popen.pid)) + + target = self.dbg.GetSelectedTarget() + self.assertTrue(target.IsValid(), 'Should have a valid Target after attaching to process') + + setup_complete = target.FindFirstGlobalVariable("setup_is_complete") + self.assertTrue(setup_complete.GetValueAsUnsigned() == 1, 'Check that inferior process has completed setup') + + # Find the bundle module, see if we found the dSYM too (they're both in "hide.app") + i = 0 + while i < target.GetNumModules(): + mod = target.GetModuleAtIndex(i) + if mod.GetFileSpec().GetFilename() == 'com.apple.sbd': + dsym_name = mod.GetSymbolFileSpec().GetFilename() + self.assertTrue (dsym_name == 'com.apple.sbd', "Check that we found the dSYM for the bundle that was loaded") + i=i+1 + +if __name__ == '__main__': + unittest.main() Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/bundle.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/bundle.c Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,4 @@ +int foo () +{ + return 5; +} Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/main.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/bundle-with-dot-in-filename/main.c Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,28 @@ +#include +#include +#include + +int setup_is_complete = 0; + +int main() +{ + + void *handle = dlopen ("com.apple.sbd.xpc/com.apple.sbd", RTLD_NOW); + if (handle) + { + if (dlsym(handle, "foo")) + { + system ("/bin/rm -rf com.apple.sbd.xpc com.apple.sbd.xpc.dSYM"); + setup_is_complete = 1; + + // At this point we want lldb to attach to the process. If lldb attaches + // before we've removed the dlopen'ed bundle, lldb will find the bundle + // at its actual filepath and not have to do any tricky work, invalidating + // the test. + + for (int loop_limiter = 0; loop_limiter < 100; loop_limiter++) + sleep (1); + } + } + return 0; +} Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/Info.plist ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/Info.plist Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,44 @@ + + + + + BuildMachineOSBuild + 16B2657 + CFBundleDevelopmentRegion + en + CFBundleExecutable + MyFramework + CFBundleIdentifier + com.apple.test.framework + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + MyFramework + CFBundlePackageType + FMWK + CFBundleShortVersionString + 113 + CFBundleSignature + ???? + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 113 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 9L120i + DTPlatformVersion + GM + DTSDKBuild + 17A261x + DTSDKName + macosx10.13 + DTXcode + 0900 + DTXcodeBuild + 9L120i + + Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/Makefile Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,28 @@ +CC ?= clang + +ifeq "$(ARCH)" "" + ARCH = x86_64 +endif + +CFLAGS ?= -g -O0 -arch $(ARCH) + +all: clean + $(CC) $(CFLAGS) -install_name $(PWD)/MyFramework.framework/Versions/A/MyFramework -dynamiclib -o MyFramework myframework.c + mkdir -p MyFramework.framework/Versions/A/Headers + mkdir -p MyFramework.framework/Versions/A/Resources + cp MyFramework MyFramework.framework/Versions/A + cp MyFramework.h MyFramework.framework/Versions/A/Headers + cp Info.plist MyFramework.framework/Versions/A/Resources + ( cd MyFramework.framework/Versions ; ln -s A Current ) + ( cd MyFramework.framework/ ; ln -s Versions/Current/Headers . ) + ( cd MyFramework.framework/ ; ln -s Versions/Current/MyFramework . ) + ( cd MyFramework.framework/ ; ln -s Versions/Current/Resources . ) + mv MyFramework.dSYM MyFramework.framework.dSYM + mkdir hide.app + rm -f MyFramework + tar cf - MyFramework.framework MyFramework.framework.dSYM | ( cd hide.app;tar xBpf -) + $(CC) $(CFLAGS) -o deep-bundle main.c -F. -framework MyFramework + + +clean: + rm -rf a.out a.out.dSYM deep-bundle deep-bundle.dSYM MyFramework.framework MyFramework.framework.dSYM MyFramework MyFramework.dSYM hide.app Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/MyFramework.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/MyFramework.h Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1 @@ +int foo (); Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/TestDeepBundle.py ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/TestDeepBundle.py Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,75 @@ +"""Test that a dSYM can be found when a binary is in a deep bundle with multiple pathname components.""" + +from __future__ import print_function + +#import unittest2 +import os.path +from time import sleep + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +exe_name = 'deep-bundle' # must match Makefile + +class DeepBundleTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfRemote + @skipUnlessDarwin + # This test is explicitly a dSYM test, it doesn't need to run for any other config, but + # the following doesn't work, fixme. + # @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is looking explicitly for a dSYM") + + def setUp(self): + TestBase.setUp(self) + self.source = 'main.c' + + def tearDown(self): + # Destroy process before TestBase.tearDown() + self.dbg.GetSelectedTarget().GetProcess().Destroy() + + # Call super's tearDown(). + TestBase.tearDown(self) + + def test_attach_and_check_dsyms(self): + """Test attach to binary, see if the framework dSYM is found""" + exe = os.path.join(os.getcwd(), exe_name) + self.build() + popen = self.spawnSubprocess(exe) + self.addTearDownHook(self.cleanupSubprocesses) + + # Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in + sleep(5) + + # Since the library that was dlopen()'ed is now removed, lldb will need to find the + # binary & dSYM via target.exec-search-paths + settings_str = "settings set target.exec-search-paths " + self.get_process_working_directory() + "/hide.app" + self.runCmd(settings_str) + + self.runCmd("process attach -p " + str(popen.pid)) + + target = self.dbg.GetSelectedTarget() + self.assertTrue(target.IsValid(), 'Should have a valid Target after attaching to process') + + setup_complete = target.FindFirstGlobalVariable("setup_is_complete") + self.assertTrue(setup_complete.GetValueAsUnsigned() == 1, 'Check that inferior process has completed setup') + + # Find the bundle module, see if we found the dSYM too (they're both in "hide.app") + i = 0 + found_module = False + while i < target.GetNumModules(): + mod = target.GetModuleAtIndex(i) + if mod.GetFileSpec().GetFilename() == 'MyFramework': + found_module = True + dsym_name = mod.GetSymbolFileSpec().GetFilename() + self.assertTrue (dsym_name == 'MyFramework', "Check that we found the dSYM for the bundle that was loaded") + i=i+1 + + self.assertTrue(found_module, "Check that we found the framework loaded in lldb's image list") + +if __name__ == '__main__': + unittest.main() Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/main.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/main.c Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,22 @@ +#include +#include +#include + +int setup_is_complete = 0; + +int main() +{ + system ("/bin/rm -rf MyFramework MyFramework.framework MyFramework.framework.dSYM"); + + setup_is_complete = 1; + + // At this point we want lldb to attach to the process. If lldb attaches + // before we've removed the framework we're running against, it will be + // easy for lldb to find the binary & dSYM without using target.exec-search-paths, + // which is the point of this test. + + for (int loop_limiter = 0; loop_limiter < 100; loop_limiter++) + sleep (1); + + return foo(); +} Added: vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/myframework.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/macosx/find-dsym/deep-bundle/myframework.c Fri Jun 16 21:04:22 2017 (r320023) @@ -0,0 +1,4 @@ +int foo () +{ + return 5; +} Modified: vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py ============================================================================== --- vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py Fri Jun 16 21:04:22 2017 (r320023) @@ -31,6 +31,7 @@ class TestGdbRemoteSingleStep(gdbremote_testcase.GdbRe "arm", "aarch64"], bugnumber="llvm.org/pr24739") + @skipIf(triple='^mips') def test_single_step_only_steps_one_instruction_with_s_llgs(self): self.init_llgs_test() self.build() Modified: vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py ============================================================================== --- vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py Fri Jun 16 21:04:22 2017 (r320023) @@ -108,6 +108,7 @@ class TestGdbRemote_vCont(gdbremote_testcase.GdbRemote "arm", "aarch64"], bugnumber="llvm.org/pr24739") + @skipIf(triple='^mips') def test_single_step_only_steps_one_instruction_with_Hc_vCont_s_llgs(self): self.init_llgs_test() self.build() @@ -136,6 +137,7 @@ class TestGdbRemote_vCont(gdbremote_testcase.GdbRemote "arm", "aarch64"], bugnumber="llvm.org/pr24739") + @skipIf(triple='^mips') def test_single_step_only_steps_one_instruction_with_vCont_s_thread_llgs( self): self.init_llgs_test() Modified: vendor/lldb/dist/scripts/lldb.swig ============================================================================== --- vendor/lldb/dist/scripts/lldb.swig Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/scripts/lldb.swig Fri Jun 16 21:04:22 2017 (r320023) @@ -40,7 +40,13 @@ us to override the module import logic to suit our nee Older swig versions will simply ignore this setting. */ %define MODULEIMPORT -"from . import $module" +"try: + # Try a relative import first + from . import $module +except ImportError: + # Maybe absolute import will work (if we're being loaded from lldb, it + # should). + import $module" %enddef // These versions will not generate working python modules, so error out early. #if SWIG_VERSION >= 0x030009 && SWIG_VERSION < 0x030011 Modified: vendor/lldb/dist/source/Commands/CommandObjectThread.cpp ============================================================================== --- vendor/lldb/dist/source/Commands/CommandObjectThread.cpp Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/source/Commands/CommandObjectThread.cpp Fri Jun 16 21:04:22 2017 (r320023) @@ -42,10 +42,44 @@ using namespace lldb; using namespace lldb_private; //------------------------------------------------------------------------- -// CommandObjectThreadBacktrace +// CommandObjectIterateOverThreads //------------------------------------------------------------------------- class CommandObjectIterateOverThreads : public CommandObjectParsed { + + class UniqueStack { + + public: + UniqueStack(std::stack stack_frames, uint32_t thread_index_id) + : m_stack_frames(stack_frames) { + m_thread_index_ids.push_back(thread_index_id); + } + + void AddThread(uint32_t thread_index_id) const { + m_thread_index_ids.push_back(thread_index_id); + } + + const std::vector &GetUniqueThreadIndexIDs() const { + return m_thread_index_ids; + } + + lldb::tid_t GetRepresentativeThread() const { + return m_thread_index_ids.front(); + } + + friend bool inline operator<(const UniqueStack &lhs, + const UniqueStack &rhs) { + return lhs.m_stack_frames < rhs.m_stack_frames; + } + + protected: + // Mark the thread index as mutable, as we don't care about it from a const + // perspective, we only care about m_stack_frames so we keep our std::set + // sorted. + mutable std::vector m_thread_index_ids; + std::stack m_stack_frames; + }; + public: CommandObjectIterateOverThreads(CommandInterpreter &interpreter, const char *name, const char *help, @@ -57,11 +91,15 @@ class CommandObjectIterateOverThreads : public Command bool DoExecute(Args &command, CommandReturnObject &result) override { result.SetStatus(m_success_return); + bool all_threads = false; if (command.GetArgumentCount() == 0) { Thread *thread = m_exe_ctx.GetThreadPtr(); if (!HandleOneThread(thread->GetID(), result)) return false; return result.Succeeded(); + } else if (command.GetArgumentCount() == 1) { + all_threads = ::strcmp(command.GetArgumentAtIndex(0), "all") == 0; + m_unique_stacks = ::strcmp(command.GetArgumentAtIndex(0), "unique") == 0; } // Use tids instead of ThreadSPs to prevent deadlocking problems which @@ -69,8 +107,7 @@ class CommandObjectIterateOverThreads : public Command // code while iterating over the (locked) ThreadSP list. std::vector tids; - if (command.GetArgumentCount() == 1 && - ::strcmp(command.GetArgumentAtIndex(0), "all") == 0) { + if (all_threads || m_unique_stacks) { Process *process = m_exe_ctx.GetProcessPtr(); for (ThreadSP thread_sp : process->Threads()) @@ -108,15 +145,47 @@ class CommandObjectIterateOverThreads : public Command } } - uint32_t idx = 0; - for (const lldb::tid_t &tid : tids) { - if (idx != 0 && m_add_return) - result.AppendMessage(""); + if (m_unique_stacks) { + // Iterate over threads, finding unique stack buckets. + std::set unique_stacks; + for (const lldb::tid_t &tid : tids) { + if (!BucketThread(tid, unique_stacks, result)) { + return false; + } + } - if (!HandleOneThread(tid, result)) - return false; + // Write the thread id's and unique call stacks to the output stream + Stream &strm = result.GetOutputStream(); + Process *process = m_exe_ctx.GetProcessPtr(); + for (const UniqueStack &stack : unique_stacks) { + // List the common thread ID's + const std::vector &thread_index_ids = + stack.GetUniqueThreadIndexIDs(); + strm.Printf("%lu thread(s) ", thread_index_ids.size()); + for (const uint32_t &thread_index_id : thread_index_ids) { + strm.Printf("#%u ", thread_index_id); + } + strm.EOL(); - ++idx; + // List the shared call stack for this set of threads + uint32_t representative_thread_id = stack.GetRepresentativeThread(); + ThreadSP thread = process->GetThreadList().FindThreadByIndexID( + representative_thread_id); + if (!HandleOneThread(thread->GetID(), result)) { + return false; + } + } + } else { + uint32_t idx = 0; + for (const lldb::tid_t &tid : tids) { + if (idx != 0 && m_add_return) + result.AppendMessage(""); + + if (!HandleOneThread(tid, result)) + return false; + + ++idx; + } } return result.Succeeded(); } @@ -134,7 +203,43 @@ class CommandObjectIterateOverThreads : public Command virtual bool HandleOneThread(lldb::tid_t, CommandReturnObject &result) = 0; + bool BucketThread(lldb::tid_t tid, std::set &unique_stacks, + CommandReturnObject &result) { + // Grab the corresponding thread for the given thread id. + Process *process = m_exe_ctx.GetProcessPtr(); + Thread *thread = process->GetThreadList().FindThreadByID(tid).get(); + if (thread == nullptr) { + result.AppendErrorWithFormat("Failed to process thread# %lu.\n", tid); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // Collect the each frame's address for this call-stack + std::stack stack_frames; + const uint32_t frame_count = thread->GetStackFrameCount(); + for (uint32_t frame_index = 0; frame_index < frame_count; frame_index++) { + const lldb::StackFrameSP frame_sp = + thread->GetStackFrameAtIndex(frame_index); + const lldb::addr_t pc = frame_sp->GetStackID().GetPC(); + stack_frames.push(pc); + } + + uint32_t thread_index_id = thread->GetIndexID(); + UniqueStack new_unique_stack(stack_frames, thread_index_id); + + // Try to match the threads stack to and existing entry. + std::set::iterator matching_stack = + unique_stacks.find(new_unique_stack); + if (matching_stack != unique_stacks.end()) { + matching_stack->AddThread(thread_index_id); + } else { + unique_stacks.insert(new_unique_stack); + } + return true; + } + ReturnStatus m_success_return = eReturnStatusSuccessFinishResult; + bool m_unique_stacks = false; bool m_add_return = true; }; @@ -218,9 +323,10 @@ class CommandObjectThreadBacktrace : public CommandObj : CommandObjectIterateOverThreads( interpreter, "thread backtrace", "Show thread call stacks. Defaults to the current thread, thread " - "indexes can be specified as arguments. Use the thread-index " - "\"all\" " - "to see all threads.", + "indexes can be specified as arguments.\n" + "Use the thread-index \"all\" to see all threads.\n" + "Use the thread-index \"unique\" to see threads grouped by unique " + "call stacks.", nullptr, eCommandRequiresProcess | eCommandRequiresThread | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | @@ -270,11 +376,14 @@ class CommandObjectThreadBacktrace : public CommandObj Stream &strm = result.GetOutputStream(); + // Only dump stack info if we processing unique stacks. + const bool only_stacks = m_unique_stacks; + // Don't show source context when doing backtraces. const uint32_t num_frames_with_source = 0; const bool stop_format = true; if (!thread->GetStatus(strm, m_options.m_start, m_options.m_count, - num_frames_with_source, stop_format)) { + num_frames_with_source, stop_format, only_stacks)) { result.AppendErrorWithFormat( "error displaying backtrace for thread: \"0x%4.4x\"\n", thread->GetIndexID()); Modified: vendor/lldb/dist/source/Core/Debugger.cpp ============================================================================== --- vendor/lldb/dist/source/Core/Debugger.cpp Fri Jun 16 21:04:18 2017 (r320022) +++ vendor/lldb/dist/source/Core/Debugger.cpp Fri Jun 16 21:04:22 2017 (r320023) @@ -112,6 +112,12 @@ OptionEnumValueElement g_language_enumerators[] = { "{ " \ "${module.file.basename}{`${function.name-with-args}" \ "{${frame.no-debug}${function.pc-offset}}}}" + +#define MODULE_WITH_FUNC_NO_ARGS \ + "{ " \ + "${module.file.basename}{`${function.name-without-args}" \ + "{${frame.no-debug}${function.pc-offset}}}}" + #define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}" #define IS_OPTIMIZED "{${function.is-optimized} [opt]}" @@ -141,6 +147,10 @@ OptionEnumValueElement g_language_enumerators[] = { "frame #${frame.index}: ${frame.pc}" MODULE_WITH_FUNC FILE_AND_LINE \ IS_OPTIMIZED "\\n" +#define DEFAULT_FRAME_FORMAT_NO_ARGS \ + "frame #${frame.index}: ${frame.pc}" MODULE_WITH_FUNC_NO_ARGS FILE_AND_LINE \ + IS_OPTIMIZED "\\n" + // Three parts to this disassembly format specification: // 1. If this is a new function/symbol (no previous symbol/function), print // dylib`funcname:\n @@ -186,13 +196,15 @@ static PropertyDefinition g_properties[] = { {"auto-confirm", OptionValue::eTypeBoolean, true, false, nullptr, nullptr, "If true all confirmation prompts will receive their default reply."}, {"disassembly-format", OptionValue::eTypeFormatEntity, true, 0, - DEFAULT_DISASSEMBLY_FORMAT, nullptr, "The default disassembly format " - "string to use when disassembling " - "instruction sequences."}, + DEFAULT_DISASSEMBLY_FORMAT, nullptr, + "The default disassembly format " + "string to use when disassembling " + "instruction sequences."}, {"frame-format", OptionValue::eTypeFormatEntity, true, 0, - DEFAULT_FRAME_FORMAT, nullptr, "The default frame format string to use " - "when displaying stack frame information " - "for threads."}, + DEFAULT_FRAME_FORMAT, nullptr, + "The default frame format string to use " + "when displaying stack frame information " + "for threads."}, {"notify-void", OptionValue::eTypeBoolean, true, false, nullptr, nullptr, "Notify the user explicitly if an expression returns void (default: " "false)."}, @@ -203,18 +215,21 @@ static PropertyDefinition g_properties[] = { nullptr, g_language_enumerators, "The script language to be used for evaluating user-written scripts."}, {"stop-disassembly-count", OptionValue::eTypeSInt64, true, 4, nullptr, - nullptr, "The number of disassembly lines to show when displaying a " - "stopped context."}, + nullptr, + "The number of disassembly lines to show when displaying a " + "stopped context."}, {"stop-disassembly-display", OptionValue::eTypeEnum, true, Debugger::eStopDisassemblyTypeNoDebugInfo, nullptr, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context."}, {"stop-line-count-after", OptionValue::eTypeSInt64, true, 3, nullptr, - nullptr, "The number of sources lines to display that come after the " - "current source line when displaying a stopped context."}, + nullptr, + "The number of sources lines to display that come after the " + "current source line when displaying a stopped context."}, {"stop-line-count-before", OptionValue::eTypeSInt64, true, 3, nullptr, - nullptr, "The number of sources lines to display that come before the " - "current source line when displaying a stopped context."}, + nullptr, + "The number of sources lines to display that come before the " + "current source line when displaying a stopped context."}, {"stop-show-column", OptionValue::eTypeEnum, false, eStopShowColumnAnsiOrCaret, nullptr, s_stop_show_column_values, "If true, LLDB will use the column information from the debug info to " @@ -232,19 +247,22 @@ static PropertyDefinition g_properties[] = { {"term-width", OptionValue::eTypeSInt64, true, 80, nullptr, nullptr, "The maximum number of columns to use for displaying text."}, {"thread-format", OptionValue::eTypeFormatEntity, true, 0, - DEFAULT_THREAD_FORMAT, nullptr, "The default thread format string to use " - "when displaying thread information."}, + DEFAULT_THREAD_FORMAT, nullptr, + "The default thread format string to use " + "when displaying thread information."}, {"thread-stop-format", OptionValue::eTypeFormatEntity, true, 0, - DEFAULT_THREAD_STOP_FORMAT, nullptr, "The default thread format " - "string to usewhen displaying thread " - "information as part of the stop display."}, + DEFAULT_THREAD_STOP_FORMAT, nullptr, + "The default thread format " + "string to use when displaying thread " + "information as part of the stop display."}, {"use-external-editor", OptionValue::eTypeBoolean, true, false, nullptr, nullptr, "Whether to use an external editor or not."}, {"use-color", OptionValue::eTypeBoolean, true, true, nullptr, nullptr, "Whether to use Ansi color codes or not."}, {"auto-one-line-summaries", OptionValue::eTypeBoolean, true, true, nullptr, - nullptr, "If true, LLDB will automatically display small structs in " - "one-liner format (default: true)."}, + nullptr, + "If true, LLDB will automatically display small structs in " + "one-liner format (default: true)."}, {"auto-indent", OptionValue::eTypeBoolean, true, true, nullptr, nullptr, "If true, LLDB will auto indent/outdent code. Currently only supported in " "the REPL (default: true)."}, @@ -255,8 +273,13 @@ static PropertyDefinition g_properties[] = { "The tab size to use when indenting code in multi-line input mode " "(default: 4)."}, {"escape-non-printables", OptionValue::eTypeBoolean, true, true, nullptr, - nullptr, "If true, LLDB will automatically escape non-printable and " - "escape characters when formatting strings."}, + nullptr, + "If true, LLDB will automatically escape non-printable and " + "escape characters when formatting strings."}, + {"frame-format-unique", OptionValue::eTypeFormatEntity, true, 0, + DEFAULT_FRAME_FORMAT_NO_ARGS, nullptr, + "The default frame format string to use when displaying stack frame" + "information for threads from thread backtrace unique."}, {nullptr, OptionValue::eTypeInvalid, true, 0, nullptr, nullptr, nullptr}}; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***