summaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/macosx/universal
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/macosx/universal')
-rw-r--r--packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py53
-rw-r--r--packages/Python/lldbsuite/test/macosx/universal/main.c14
2 files changed, 65 insertions, 2 deletions
diff --git a/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py b/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py
index 4b722b0c1d8e2..70a83ea90792a 100644
--- a/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py
+++ b/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py
@@ -7,8 +7,9 @@ from __future__ import print_function
import unittest2
import os, time
import lldb
+from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
-import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test import lldbutil
class UniversalTestCase(TestBase):
@@ -18,7 +19,7 @@ class UniversalTestCase(TestBase):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
- self.line = line_number('main.c', '// Set break point at this line.')
+ self.line = line_number('main.c', '// Set break point at this line.')
@add_test_categories(['pyapi'])
@skipUnlessDarwin
@@ -105,3 +106,51 @@ class UniversalTestCase(TestBase):
substrs = ['Name: eax'])
self.runCmd("continue")
+
+
+ @skipUnlessDarwin
+ @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in ['i386', 'x86_64'],
+ "requires i386 or x86_64")
+ def test_process_attach_with_wrong_arch(self):
+ """Test that when we attach to a binary from the wrong fork of a universal binary, we fix up the ABI correctly."""
+ # Now keep the architecture at 32 bit, but switch the binary we launch to
+ # 64 bit, and make sure on attach we switch to the correct architecture.
+
+ # Invoke the default build rule.
+ self.build()
+
+ # Note that "testit" is a universal binary.
+ exe = os.path.join(os.getcwd(), "testit")
+
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTargetWithFileAndTargetTriple(exe, "i386-apple-macosx")
+ self.assertTrue(target, VALID_TARGET)
+ pointer_size = target.GetAddressByteSize()
+ self.assertTrue(pointer_size == 4, "Initially we were 32 bit.")
+
+ bkpt = target.BreakpointCreateBySourceRegex("sleep", lldb.SBFileSpec("main.c"))
+ self.assertTrue (bkpt.IsValid(), "Valid breakpoint")
+ self.assertTrue(bkpt.GetNumLocations() >= 1, "Our main breakpoint has locations.")
+
+ popen = self.spawnSubprocess(exe, ["keep_waiting"])
+ self.addTearDownHook(self.cleanupSubprocesses)
+
+ error = lldb.SBError()
+ empty_listener = lldb.SBListener()
+ process = target.AttachToProcessWithID(empty_listener, popen.pid, error)
+ self.assertTrue(error.Success(), "Attached to process.")
+
+ pointer_size = target.GetAddressByteSize()
+ self.assertTrue(pointer_size == 8, "We switched to 64 bit.")
+
+ # It may seem odd that I am checking the number of frames, but the bug that
+ # motivated this test was that we eventually fixed the architecture, but we
+ # left the ABI set to the original value. In that case, if you asked the
+ # process for its architecture, it would look right, but since the ABI was
+ # wrong, backtracing failed.
+
+ threads = lldbutil.continue_to_breakpoint(process, bkpt)
+ self.assertTrue(len(threads) == 1)
+ thread = threads[0]
+ self.assertTrue(thread.GetNumFrames() > 1, "We were able to backtrace.")
diff --git a/packages/Python/lldbsuite/test/macosx/universal/main.c b/packages/Python/lldbsuite/test/macosx/universal/main.c
index 9351c77f7146a..3edab51b1f6ad 100644
--- a/packages/Python/lldbsuite/test/macosx/universal/main.c
+++ b/packages/Python/lldbsuite/test/macosx/universal/main.c
@@ -1,7 +1,21 @@
#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+void
+call_me()
+{
+ sleep(1);
+}
+
int
main (int argc, char **argv)
{
printf ("Hello there!\n"); // Set break point at this line.
+ if (argc == 2 && strcmp(argv[1], "keep_waiting") == 0)
+ while (1)
+ {
+ call_me();
+ }
return 0;
}