diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:06:29 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:06:29 +0000 |
commit | 94994d372d014ce4c8758b9605d63fae651bd8aa (patch) | |
tree | 51c0b708bd59f205d6b35cb2a8c24d62f0c33d77 /packages/Python/lldbsuite/test/macosx | |
parent | 39be7ce23363d12ae3e49aeb1fdb2bfeb892e836 (diff) |
Notes
Diffstat (limited to 'packages/Python/lldbsuite/test/macosx')
11 files changed, 477 insertions, 83 deletions
diff --git a/packages/Python/lldbsuite/test/macosx/function-starts/Makefile b/packages/Python/lldbsuite/test/macosx/function-starts/Makefile new file mode 100644 index 000000000000..091876d51c35 --- /dev/null +++ b/packages/Python/lldbsuite/test/macosx/function-starts/Makefile @@ -0,0 +1,10 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp +EXE := StripMe +MAKE_DSYM := NO + +include $(LEVEL)/Makefile.rules + +main.o: main.cpp + $(CC) $(CFLAGS_NO_DEBUG) -c $< -o $@ diff --git a/packages/Python/lldbsuite/test/macosx/function-starts/TestFunctionStarts.py b/packages/Python/lldbsuite/test/macosx/function-starts/TestFunctionStarts.py new file mode 100644 index 000000000000..ae3b825f95cb --- /dev/null +++ b/packages/Python/lldbsuite/test/macosx/function-starts/TestFunctionStarts.py @@ -0,0 +1,76 @@ +""" +Test that we read the function starts section. +""" + +from __future__ import print_function + + +import os +import time +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +exe_name = "StripMe" # Must match Makefile + +class FunctionStartsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + @skipIfRemote + @skipUnlessDarwin + def test_function_starts_binary(self): + """Test that we make synthetic symbols when we have the binary.""" + self.build() + self.do_function_starts(False) + + @skipIfRemote + @skipUnlessDarwin + def test_function_starts_no_binary(self): + """Test that we make synthetic symbols when we don't have the binary""" + self.build() + self.do_function_starts(True) + + def do_function_starts(self, in_memory): + """Run the binary, stop at our unstripped function, + make sure the caller has synthetic symbols""" + + exe = self.getBuildArtifact(exe_name) + # Now strip the binary, but leave externals so we can break on dont_strip_me. + try: + fail_str = system([["strip", "-u", "-x", "-S", exe]]) + except CalledProcessError as cmd_error: + self.fail("Strip failed: %d"%(cmd_error.returncode)) + + popen = self.spawnSubprocess(exe) + self.addTearDownHook(self.cleanupSubprocesses) + if in_memory: + remove_file(exe) + + target = self.dbg.CreateTarget(None) + self.assertTrue(target.IsValid(), "Got a vaid empty target.") + error = lldb.SBError() + attach_info = lldb.SBAttachInfo() + attach_info.SetProcessID(popen.pid) + attach_info.SetIgnoreExisting(False) + process = target.Attach(attach_info, error) + self.assertTrue(error.Success(), "Didn't attach successfully to %d: %s"%(popen.pid, error.GetCString())) + + bkpt = target.BreakpointCreateByName("dont_strip_me", exe) + self.assertTrue(bkpt.GetNumLocations() > 0, "Didn't set the dont_strip_me bkpt.") + + threads = lldbutil.continue_to_breakpoint(process, bkpt) + self.assertEqual(len(threads), 1, "Didn't hit my breakpoint.") + + # Our caller frame should have been stripped. Make sure we made a synthetic symbol + # for it: + thread = threads[0] + self.assertTrue(thread.num_frames > 1, "Couldn't backtrace.") + name = thread.frame[1].GetFunctionName() + self.assertEqual("___lldb_unnamed_symbol1$$StripMe", name, "Frame name not synthetic") + + + diff --git a/packages/Python/lldbsuite/test/macosx/function-starts/main.cpp b/packages/Python/lldbsuite/test/macosx/function-starts/main.cpp new file mode 100644 index 000000000000..5a14506d6913 --- /dev/null +++ b/packages/Python/lldbsuite/test/macosx/function-starts/main.cpp @@ -0,0 +1,26 @@ +#include <stdio.h> +#include <fcntl.h> + +#include <chrono> +#include <thread> + +extern void dont_strip_me() +{ + printf("I wasn't stripped\n"); +} + +static void *a_function() +{ + while (1) + { + std::this_thread::sleep_for(std::chrono::microseconds(100)); + dont_strip_me(); + } + return 0; +} + +int main(int argc, char const *argv[]) +{ + a_function(); + return 0; +} diff --git a/packages/Python/lldbsuite/test/macosx/load-kext/TestLoadKext.py b/packages/Python/lldbsuite/test/macosx/load-kext/TestLoadKext.py new file mode 100644 index 000000000000..1bd5ec020dbe --- /dev/null +++ b/packages/Python/lldbsuite/test/macosx/load-kext/TestLoadKext.py @@ -0,0 +1,38 @@ +""" +Test loading of a kext binary. +""" + +from __future__ import print_function + +import shutil +import struct + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LoadKextTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + #super(LoadKextTestCase, self).setUp() + #self._initial_platform = lldb.DBG.GetSelectedPlatform() + + def test_load_kext(self): + """Test that lldb can load a kext binary.""" + + # Create kext from YAML. + self.yaml2obj("mykext.yaml", self.getBuildArtifact("mykext")) + + target = self.dbg.CreateTarget(self.getBuildArtifact("mykext")) + + self.assertTrue(target.IsValid()) + + self.assertEqual(target.GetNumModules(), 1) + mod = target.GetModuleAtIndex(0) + self.assertEqual(mod.GetFileSpec().GetFilename(), "mykext") diff --git a/packages/Python/lldbsuite/test/macosx/load-kext/mykext.yaml b/packages/Python/lldbsuite/test/macosx/load-kext/mykext.yaml new file mode 100644 index 000000000000..ccf016304c84 --- /dev/null +++ b/packages/Python/lldbsuite/test/macosx/load-kext/mykext.yaml @@ -0,0 +1,222 @@ +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x00000003 + filetype: 0x0000000B + ncmds: 7 + sizeofcmds: 520 + flags: 0x00000085 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 152 + segname: __TEXT + vmaddr: 0 + vmsize: 4096 + fileoff: 0 + filesize: 4096 + maxprot: 7 + initprot: 5 + nsects: 1 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0000000000000F60 + size: 158 + offset: 0x00000F60 + align: 4 + reloff: 0x00000000 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - cmd: LC_SEGMENT_64 + cmdsize: 152 + segname: __DATA + vmaddr: 4096 + vmsize: 4096 + fileoff: 4096 + filesize: 4096 + maxprot: 7 + initprot: 3 + nsects: 1 + flags: 0 + Sections: + - sectname: __data + segname: __DATA + addr: 0x0000000000001000 + size: 220 + offset: 0x00001000 + align: 3 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - cmd: LC_SEGMENT_64 + cmdsize: 72 + segname: __LINKEDIT + vmaddr: 8192 + vmsize: 4096 + fileoff: 8192 + filesize: 800 + maxprot: 7 + initprot: 1 + nsects: 0 + flags: 0 + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 8224 + nsyms: 19 + stroff: 8528 + strsize: 464 + - cmd: LC_DYSYMTAB + cmdsize: 80 + ilocalsym: 0 + nlocalsym: 16 + iextdefsym: 16 + nextdefsym: 3 + iundefsym: 19 + nundefsym: 0 + tocoff: 0 + ntoc: 0 + modtaboff: 0 + nmodtab: 0 + extrefsymoff: 0 + nextrefsyms: 0 + indirectsymoff: 0 + nindirectsyms: 0 + extreloff: 0 + nextrel: 0 + locreloff: 8192 + nlocrel: 4 + - cmd: LC_UUID + cmdsize: 24 + uuid: 17A97B33-09B7-3195-9408-DBD965D578A5 + - cmd: LC_SOURCE_VERSION + cmdsize: 16 + version: 0 +LinkEditData: + NameList: + - n_strx: 40 + n_type: 0x64 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 141 + n_type: 0x64 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 155 + n_type: 0x66 + n_sect: 3 + n_desc: 1 + n_value: 1543540349 + - n_strx: 276 + n_type: 0x20 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 287 + n_type: 0x20 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 298 + n_type: 0x20 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 309 + n_type: 0x20 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 1 + n_type: 0x64 + n_sect: 1 + n_desc: 0 + n_value: 0 + - n_strx: 325 + n_type: 0x1E + n_sect: 1 + n_desc: 0 + n_value: 3992 + - n_strx: 333 + n_type: 0x1E + n_sect: 1 + n_desc: 0 + n_value: 4018 + - n_strx: 361 + n_type: 0x1E + n_sect: 1 + n_desc: 0 + n_value: 4035 + - n_strx: 392 + n_type: 0x1E + n_sect: 1 + n_desc: 0 + n_value: 4052 + - n_strx: 417 + n_type: 0x1E + n_sect: 1 + n_desc: 0 + n_value: 4068 + - n_strx: 424 + n_type: 0x1E + n_sect: 2 + n_desc: 0 + n_value: 4296 + - n_strx: 435 + n_type: 0x1E + n_sect: 2 + n_desc: 0 + n_value: 4304 + - n_strx: 446 + n_type: 0x1E + n_sect: 2 + n_desc: 0 + n_value: 4312 + - n_strx: 2 + n_type: 0x0F + n_sect: 2 + n_desc: 0 + n_value: 4096 + - n_strx: 13 + n_type: 0x0F + n_sect: 1 + n_desc: 0 + n_value: 3936 + - n_strx: 27 + n_type: 0x0F + n_sect: 1 + n_desc: 0 + n_value: 3968 + StringTable: + - ' ' + - _kmod_info + - _mykext_start + - _mykext_stop + - /tmp/mykext/build/mykext/Build/Intermediates.noindex/mykext.build/Debug/mykext.build/DerivedSources/ + - mykext_info.c + - /tmp/mykext/build/mykext/Build/Intermediates.noindex/mykext.build/Debug/mykext.build/Objects-normal/x86_64/mykext_info.o + - _kmod_info + - __realmain + - __antimain + - __kext_apple_cc + - __start + - _OSKextGetCurrentIdentifier + - _OSKextGetCurrentVersionString + - _OSKextGetCurrentLoadTag + - __stop + - __realmain + - __antimain + - __kext_apple_cc + - '' + - '' +... diff --git a/packages/Python/lldbsuite/test/macosx/nslog/TestDarwinNSLogOutput.py b/packages/Python/lldbsuite/test/macosx/nslog/TestDarwinNSLogOutput.py index 59b325f57984..287c1c1b87b3 100644 --- a/packages/Python/lldbsuite/test/macosx/nslog/TestDarwinNSLogOutput.py +++ b/packages/Python/lldbsuite/test/macosx/nslog/TestDarwinNSLogOutput.py @@ -95,7 +95,8 @@ class DarwinNSLogOutputTestCase(TestBase): self.expect(re.compile(r"stop reason = breakpoint")) def runCmd(self, cmd): - self.child.sendline(cmd) + if self.child: + self.child.sendline(cmd) def expect_prompt(self, exactly=True): self.expect(self.child_prompt, exactly=exactly) diff --git a/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py b/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py index ba58372ce5b7..cdc9606c377a 100644 --- a/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py +++ b/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py @@ -18,10 +18,16 @@ class TestQueues(TestBase): @skipUnlessDarwin @add_test_categories(['pyapi']) - def test_with_python_api(self): + def test_with_python_api_queues(self): """Test queues inspection SB APIs.""" self.build() self.queues() + + @skipUnlessDarwin + @add_test_categories(['pyapi']) + def test_with_python_api_queues_with_backtrace(self): + """Test queues inspection SB APIs.""" + self.build() self.queues_with_libBacktraceRecording() def setUp(self): @@ -113,7 +119,7 @@ class TestQueues(TestBase): break1 = target.BreakpointCreateByName("stopper", 'a.out') self.assertTrue(break1, VALID_BREAKPOINT) process = target.LaunchSimple( - None, None, self.get_process_working_directory()) + [], None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1) if len(threads) != 1: @@ -267,10 +273,14 @@ class TestQueues(TestBase): self.assertTrue(break1, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. + libbtr_path = "/Applications/Xcode.app/Contents/Developer/usr/lib/libBacktraceRecording.dylib" + if self.getArchitecture() in ['arm', 'arm64', 'arm64e', 'arm64_32', 'armv7', 'armv7k']: + libbtr_path = "/Developer/usr/lib/libBacktraceRecording.dylib" + process = target.LaunchSimple( - None, + [], [ - 'DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/usr/lib/libBacktraceRecording.dylib', + 'DYLD_INSERT_LIBRARIES=%s' % (libbtr_path), 'DYLD_LIBRARY_PATH=/usr/lib/system/introspection'], self.get_process_working_directory()) diff --git a/packages/Python/lldbsuite/test/macosx/queues/main.c b/packages/Python/lldbsuite/test/macosx/queues/main.c index 715a3f3af52c..3978b92bff1a 100644 --- a/packages/Python/lldbsuite/test/macosx/queues/main.c +++ b/packages/Python/lldbsuite/test/macosx/queues/main.c @@ -1,13 +1,18 @@ -#include <stdio.h> +#include <stdatomic.h> +#include <string.h> #include <unistd.h> #include <dispatch/dispatch.h> #include <pthread.h> -int finished_enqueueing_work = 0; +atomic_int finished_enqueueing_work = 0; +atomic_int thread_count = 0; void doing_the_work_1(void *in) { + // This is only counted once because the first job in the queue + // starves all the others. + atomic_fetch_add(&thread_count, 1); while (1) sleep (1); } @@ -26,13 +31,15 @@ submit_work_1b(void *in) dispatch_queue_t *work_performer_1 = (dispatch_queue_t*) in; dispatch_async_f (*work_performer_1, NULL, doing_the_work_1); dispatch_async_f (*work_performer_1, NULL, doing_the_work_1); + atomic_fetch_add(&thread_count, 1); while (1) - sleep (1); + sleep (1); } void doing_the_work_2(void *in) { + atomic_fetch_add(&thread_count, 1); while (1) sleep (1); } @@ -42,20 +49,22 @@ submit_work_2(void *in) { dispatch_queue_t *work_performer_2 = (dispatch_queue_t*) in; int i = 0; - while (i++ < 5000) + while (i++ < 5000) { dispatch_async_f (*work_performer_2, NULL, doing_the_work_2); dispatch_async_f (*work_performer_2, NULL, doing_the_work_2); } - finished_enqueueing_work = 1; + atomic_fetch_add(&finished_enqueueing_work, 1); } void doing_the_work_3(void *in) { + // This counts four times, since the queue is marked as CONCURRENT. + atomic_fetch_add(&thread_count, 1); while (1) - sleep(1); + sleep (1); } void @@ -77,7 +86,7 @@ stopper () } -int main () +int main (int argc, const char **argv) { dispatch_queue_t work_submittor_1 = dispatch_queue_create ("com.apple.work_submittor_1", DISPATCH_QUEUE_SERIAL); dispatch_queue_t work_submittor_2 = dispatch_queue_create ("com.apple.work_submittor_and_quit_2", DISPATCH_QUEUE_SERIAL); @@ -97,41 +106,46 @@ int main () // Spin up threads with each of the different libdispatch QoS values. - dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ pthread_setname_np ("user initiated QoS"); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); - }); + }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ pthread_setname_np ("user interactive QoS"); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); - }); + }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ pthread_setname_np ("default QoS"); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); - }); + }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{ pthread_setname_np ("utility QoS"); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); - }); + }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ pthread_setname_np ("background QoS"); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); - }); + }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{ pthread_setname_np ("unspecified QoS"); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); - }); + }); - - while (finished_enqueueing_work == 0) + // Unfortunately there is no pthread_barrier on darwin. + while ((atomic_load(&thread_count) < 13) || (finished_enqueueing_work == 0)) sleep (1); - stopper (); + stopper (); } diff --git a/packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c index 613384ff73b3..586500876288 100644 --- a/packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c +++ b/packages/Python/lldbsuite/test/macosx/safe-to-func-call/main.c @@ -1,3 +1,4 @@ +#include <sys/time.h> // work around module map issue with iOS sdk, <rdar://problem/35159346> #include <sys/select.h> #include <stdio.h> #include <pthread.h> diff --git a/packages/Python/lldbsuite/test/macosx/universal/Makefile b/packages/Python/lldbsuite/test/macosx/universal/Makefile index d74ed26f50ab..a83de2a6c7e6 100644 --- a/packages/Python/lldbsuite/test/macosx/universal/Makefile +++ b/packages/Python/lldbsuite/test/macosx/universal/Makefile @@ -1,21 +1,25 @@ -CC ?= clang +LEVEL := ../../make + +EXE := testit + +include $(LEVEL)/Makefile.rules all: testit -testit: testit.i386 testit.x86_64 +testit: testit.x86_64h testit.x86_64 lipo -create -o testit $^ -testit.i386: testit.i386.o - $(CC) -arch i386 -o testit.i386 $< +testit.x86_64h: testit.x86_64h.o + $(CC) -arch x86_64h -o testit.x86_64h $< testit.x86_64: testit.x86_64.o $(CC) -arch x86_64 -o testit.x86_64 $< -testit.i386.o: main.c - $(CC) -g -O0 -arch i386 -c -o testit.i386.o $< +testit.x86_64h.o: main.c + $(CC) -g -O0 -arch x86_64h -c -o testit.x86_64h.o $< testit.x86_64.o: main.c $(CC) -g -O0 -arch x86_64 -c -o testit.x86_64.o $< -clean: +clean:: rm -rf $(wildcard testit* *~) diff --git a/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py b/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py index ca4f3ce9b137..93fb358f4c84 100644 --- a/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py +++ b/packages/Python/lldbsuite/test/macosx/universal/TestUniversal.py @@ -11,9 +11,13 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil +def haswellOrLater(): + features = subprocess.check_output(["sysctl", "machdep.cpu"]) + return "AVX2" in features.split() class UniversalTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True mydir = TestBase.compute_mydir(__file__) def setUp(self): @@ -24,8 +28,8 @@ class UniversalTestCase(TestBase): @add_test_categories(['pyapi']) @skipUnlessDarwin - @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in [ - 'i386', 'x86_64'], "requires i386 or x86_64") + @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in + ['x86_64'], "requires x86_64") @skipIfDarwinEmbedded # this test file assumes we're targetting an x86 system def test_sbdebugger_create_target_with_file_and_target_triple(self): """Test the SBDebugger.CreateTargetWithFileAndTargetTriple() API.""" @@ -37,8 +41,9 @@ class UniversalTestCase(TestBase): # Create a target by the debugger. target = self.dbg.CreateTargetWithFileAndTargetTriple( - exe, "i386-apple-macosx") + exe, "x86_64-apple-macosx") self.assertTrue(target, VALID_TARGET) + self.expect("image list -A -b", substrs=["x86_64 testit"]) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( @@ -46,13 +51,16 @@ class UniversalTestCase(TestBase): self.assertTrue(process, PROCESS_IS_VALID) @skipUnlessDarwin - @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in [ - 'i386', 'x86_64'], "requires i386 or x86_64") + @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in + ['x86_64'], "requires x86_64") @skipIfDarwinEmbedded # this test file assumes we're targetting an x86 system def test_process_launch_for_universal(self): """Test process launch of a universal binary.""" from lldbsuite.test.lldbutil import print_registers + if not haswellOrLater(): + return + # Invoke the default build rule. self.build() @@ -62,69 +70,54 @@ class UniversalTestCase(TestBase): # By default, x86_64 is assumed if no architecture is specified. self.expect("file " + exe, CURRENT_EXECUTABLE_SET, startstr="Current executable set to ", - substrs=["testit' (x86_64)."]) + substrs=["testit' (x86_64h)."]) # Break inside the main. lldbutil.run_break_set_by_file_and_line( self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - # We should be able to launch the x86_64 executable. + # We should be able to launch the x86_64h executable. self.runCmd("run", RUN_SUCCEEDED) - # Check whether we have a 64-bit process launched. + # Check whether we have a x86_64h process launched. target = self.dbg.GetSelectedTarget() process = target.GetProcess() - self.assertTrue(target and process and - self.invoke(process, 'GetAddressByteSize') == 8, - "64-bit process launched") - - frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0) - registers = print_registers(frame, string_buffer=True) - self.expect(registers, exe=False, - substrs=['Name: rax']) - + self.expect("image list -A -b", substrs=["x86_64h testit"]) self.runCmd("continue") - # Now specify i386 as the architecture for "testit". - self.expect("file -a i386 " + exe, CURRENT_EXECUTABLE_SET, + # Now specify x86_64 as the architecture for "testit". + self.expect("file -a x86_64 " + exe, CURRENT_EXECUTABLE_SET, startstr="Current executable set to ", - substrs=["testit' (i386)."]) + substrs=["testit' (x86_64)."]) # Break inside the main. lldbutil.run_break_set_by_file_and_line( self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - # We should be able to launch the i386 executable as well. + # We should be able to launch the x86_64 executable as well. self.runCmd("run", RUN_SUCCEEDED) - # Check whether we have a 32-bit process launched. - target = self.dbg.GetSelectedTarget() - process = target.GetProcess() - self.assertTrue(target and process, - "32-bit process launched") - - pointerSize = self.invoke(process, 'GetAddressByteSize') - self.assertTrue( - pointerSize == 4, - "AddressByteSize of 32-bit process should be 4, got %d instead." % - pointerSize) - - frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0) - registers = print_registers(frame, string_buffer=True) - self.expect(registers, exe=False, - substrs=['Name: eax']) - + # Check whether we have a x86_64 process launched. + + # FIXME: This wrong. We are expecting x86_64, but spawning a + # new process currently doesn't allow specifying a *sub*-architecture. + # <rdar://problem/46101466> + self.expect("image list -A -b", substrs=["x86_64h testit"]) self.runCmd("continue") @skipUnlessDarwin - @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in [ - 'i386', 'x86_64'], "requires i386 or x86_64") + @unittest2.skipUnless(hasattr(os, "uname") and os.uname()[4] in + ['x86_64'], "requires x86_64") @skipIfDarwinEmbedded # this test file assumes we're targetting an x86 system 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. + """Test that when we attach to a binary from the wrong fork of + a universal binary, we fix up the ABI correctly.""" + if not haswellOrLater(): + return + + # Now keep the architecture at x86_64, but switch the binary + # we launch to x86_64h, and make sure on attach we switch to + # the correct architecture. # Invoke the default build rule. self.build() @@ -134,10 +127,9 @@ class UniversalTestCase(TestBase): # Create a target by the debugger. target = self.dbg.CreateTargetWithFileAndTargetTriple( - exe, "i386-apple-macosx") + exe, "x86_64-apple-macosx") self.assertTrue(target, VALID_TARGET) - pointer_size = target.GetAddressByteSize() - self.assertTrue(pointer_size == 4, "Initially we were 32 bit.") + self.expect("image list -A -b", substrs=["x86_64 testit"]) bkpt = target.BreakpointCreateBySourceRegex( "sleep", lldb.SBFileSpec("main.c")) @@ -155,14 +147,14 @@ class UniversalTestCase(TestBase): 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.") + self.expect("image list -A -b", substrs=["x86_64h testit"]) - # 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. + # It may seem odd to check 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) |