diff options
author | Jim Ingham <jingham@apple.com> | 2016-02-18 23:58:45 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2016-02-18 23:58:45 +0000 |
commit | 7b71c0ba6cb3cab0bdbcc17cf944e779d2ff66e8 (patch) | |
tree | bb170ead497f0ef044d21420272959a53396d0eb /lldb/packages/Python/lldbsuite/test | |
parent | faca2d83b13e00b76af481b91451bd9ad7da03fc (diff) | |
download | bcm5719-llvm-7b71c0ba6cb3cab0bdbcc17cf944e779d2ff66e8.tar.gz bcm5719-llvm-7b71c0ba6cb3cab0bdbcc17cf944e779d2ff66e8.zip |
Make sure code that is in the middle of figuring out the correct architecture
on attach uses the architecture it has figured out, rather than the Target's
architecture, which may not have been updated to the correct value yet.
<rdar://problem/24632895>
llvm-svn: 261279
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py | 50 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/macosx/universal/main.c | 14 |
2 files changed, 63 insertions, 1 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py b/lldb/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py index 64f0cca9095..70a83ea9079 100644 --- a/lldb/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py +++ b/lldb/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py @@ -19,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 @@ -106,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/lldb/packages/Python/lldbsuite/test/macosx/universal/main.c b/lldb/packages/Python/lldbsuite/test/macosx/universal/main.c index 9351c77f714..3edab51b1f6 100644 --- a/lldb/packages/Python/lldbsuite/test/macosx/universal/main.c +++ b/lldb/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; } |