From ee44a92df6964df623f8bddca96b3007c80ce613 Mon Sep 17 00:00:00 2001 From: Dimitar Vlahovski Date: Tue, 6 Sep 2016 11:00:37 +0000 Subject: Revert "Intel(R) Memory Protection Extensions (Intel(R) MPX) support." This reverts commit rL280668 because the register tests fail on i386 Linux. I investigated a little bit what causes the failure - there are missing registers when running 'register read -a'. This is the output I got at the bottom: """ ... Memory Protection Extensions: bnd0 = {0x0000000000000000 0x0000000000000000} bnd1 = {0x0000000000000000 0x0000000000000000} bnd2 = {0x0000000000000000 0x0000000000000000} bnd3 = {0x0000000000000000 0x0000000000000000} unknown: 2 registers were unavailable. """ Also looking at the packets exchanged between the client and server: """ ... history[308] tid=0x7338 < 19> send packet: $qRegisterInfo4a#d7 history[309] tid=0x7338 < 130> read packet: $name:bnd0;bitsize:128;offset:1032;encoding:vector;format:vector-uint64;set:Memory Protection Extensions;ehframe:101;dwarf:101;#48 history[310] tid=0x7338 < 19> send packet: $qRegisterInfo4b#d8 history[311] tid=0x7338 < 130> read packet: $name:bnd1;bitsize:128;offset:1048;encoding:vector;format:vector-uint64;set:Memory Protection Extensions;ehframe:102;dwarf:102;#52 history[312] tid=0x7338 < 19> send packet: $qRegisterInfo4c#d9 history[313] tid=0x7338 < 130> read packet: $name:bnd2;bitsize:128;offset:1064;encoding:vector;format:vector-uint64;set:Memory Protection Extensions;ehframe:103;dwarf:103;#53 history[314] tid=0x7338 < 19> send packet: $qRegisterInfo4d#da history[315] tid=0x7338 < 130> read packet: $name:bnd3;bitsize:128;offset:1080;encoding:vector;format:vector-uint64;set:Memory Protection Extensions;ehframe:104;dwarf:104;#54 history[316] tid=0x7338 < 19> send packet: $qRegisterInfo4e#db history[317] tid=0x7338 < 76> read packet: $name:bndcfgu;bitsize:64;offset:1096;encoding:vector;format:vector-uint8;#99 history[318] tid=0x7338 < 19> send packet: $qRegisterInfo4f#dc history[319] tid=0x7338 < 78> read packet: $name:bndstatus;bitsize:64;offset:1104;encoding:vector;format:vector-uint8;#8e ... """ The bndcfgu and bndstatus registers don't have the 'Memory Protections Extension' set. I looked at the code and it seems that that is set correctly. So I'm not sure what's the problem or where does it come from. Also there is a second failure related to something like this in the tests: """ registerSet.GetName().lower() """ For some reason the registerSet.GetName() returns None. llvm-svn: 280703 --- .../test/functionalities/register/Makefile | 5 + .../test/functionalities/register/TestRegisters.py | 350 ++++++++++++++++++++ .../lldbsuite/test/functionalities/register/a.cpp | 44 +++ .../register/intel_xtended_registers/Makefile | 6 - .../intel_xtended_registers/TestMPXRegisters.py | 59 ---- .../register/intel_xtended_registers/main.cpp | 69 ---- .../test/functionalities/register/main.cpp | 36 ++ .../register/register_command/Makefile | 5 - .../register/register_command/TestRegisters.py | 368 --------------------- .../register/register_command/a.cpp | 44 --- .../register/register_command/main.cpp | 36 -- 11 files changed, 435 insertions(+), 587 deletions(-) create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/Makefile create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/TestRegisters.py create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/a.cpp delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/main.cpp delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/Makefile delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/TestRegisters.py delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/a.cpp delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/main.cpp (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/register') diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/register/Makefile new file mode 100644 index 00000000000..7144b25c58c --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/register/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp a.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/TestRegisters.py b/lldb/packages/Python/lldbsuite/test/functionalities/register/TestRegisters.py new file mode 100644 index 00000000000..21de3ab7cc3 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/register/TestRegisters.py @@ -0,0 +1,350 @@ +""" +Test the 'register' command. +""" + +from __future__ import print_function + + + +import os, sys, time +import re +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class RegisterCommandsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + self.has_teardown = False + + def tearDown(self): + self.dbg.GetSelectedTarget().GetProcess().Destroy() + TestBase.tearDown(self) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + def test_register_commands(self): + """Test commands related to registers, in particular vector registers.""" + self.build() + self.common_setup() + + # verify that logging does not assert + self.log_enable("registers") + + self.expect("register read -a", MISSING_EXPECTED_REGISTERS, + substrs = ['registers were unavailable'], matching = False) + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + self.runCmd("register read xmm0") + self.runCmd("register read ymm15") # may be available + elif self.getArchitecture() in ['arm']: + self.runCmd("register read s0") + self.runCmd("register read q15") # may be available + + self.expect("register read -s 3", substrs = ['invalid register set index: 3'], error = True) + + @skipIfiOSSimulator + @skipIfTargetAndroid(archs=["i386"]) # Writing of mxcsr register fails, presumably due to a kernel/hardware problem + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + def test_fp_register_write(self): + """Test commands that write to registers, in particular floating-point registers.""" + self.build() + self.fp_register_write() + + @skipIfiOSSimulator + @expectedFailureAndroid(archs=["i386"]) # "register read fstat" always return 0xffff + @skipIfFreeBSD #llvm.org/pr25057 + @skipIf(archs=no_match(['amd64', 'i386', 'x86_64'])) + def test_fp_special_purpose_register_read(self): + """Test commands that read fpu special purpose registers.""" + self.build() + self.fp_special_purpose_register_read() + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) + def test_register_expressions(self): + """Test expression evaluation with commands related to registers.""" + self.build() + self.common_setup() + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + gpr = "eax" + vector = "xmm0" + elif self.getArchitecture() in ['arm']: + gpr = "r0" + vector = "q0" + + self.expect("expr/x $%s" % gpr, substrs = ['unsigned int', ' = 0x']) + self.expect("expr $%s" % vector, substrs = ['vector_type']) + self.expect("expr (unsigned int)$%s[0]" % vector, substrs = ['unsigned int']) + + if self.getArchitecture() in ['amd64', 'x86_64']: + self.expect("expr -- ($rax & 0xffffffff) == $eax", substrs = ['true']) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'x86_64'])) + def test_convenience_registers(self): + """Test convenience registers.""" + self.build() + self.convenience_registers() + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'x86_64'])) + def test_convenience_registers_with_process_attach(self): + """Test convenience registers after a 'process attach'.""" + self.build() + self.convenience_registers_with_process_attach(test_16bit_regs=False) + + @skipIfiOSSimulator + @skipIf(archs=no_match(['amd64', 'x86_64'])) + def test_convenience_registers_16bit_with_process_attach(self): + """Test convenience registers after a 'process attach'.""" + self.build() + self.convenience_registers_with_process_attach(test_16bit_regs=True) + + def common_setup(self): + exe = os.path.join(os.getcwd(), "a.out") + + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Break in main(). + lldbutil.run_break_set_by_symbol (self, "main", num_expected_locations=-1) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', 'stop reason = breakpoint']) + + # platform specific logging of the specified category + def log_enable(self, category): + # This intentionally checks the host platform rather than the target + # platform as logging is host side. + self.platform = "" + if sys.platform.startswith("darwin"): + self.platform = "" # TODO: add support for "log enable darwin registers" + + if sys.platform.startswith("freebsd"): + self.platform = "freebsd" + + if sys.platform.startswith("linux"): + self.platform = "linux" + + if sys.platform.startswith("netbsd"): + self.platform = "netbsd" + + if self.platform != "": + self.log_file = os.path.join(os.getcwd(), 'TestRegisters.log') + self.runCmd("log enable " + self.platform + " " + str(category) + " registers -v -f " + self.log_file, RUN_SUCCEEDED) + if not self.has_teardown: + def remove_log(self): + if os.path.exists(self.log_file): + os.remove(self.log_file) + self.has_teardown = True + self.addTearDownHook(remove_log) + + def write_and_read(self, frame, register, new_value, must_exist = True): + value = frame.FindValue(register, lldb.eValueTypeRegister) + if must_exist: + self.assertTrue(value.IsValid(), "finding a value for register " + register) + elif not value.IsValid(): + return # If register doesn't exist, skip this test + + self.runCmd("register write " + register + " \'" + new_value + "\'") + self.expect("register read " + register, substrs = [register + ' = ', new_value]) + + def fp_special_purpose_register_read(self): + exe = os.path.join(os.getcwd(), "a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Launch the process and stop. + self.expect ("run", PROCESS_STOPPED, substrs = ['stopped']) + + # Check stop reason; Should be either signal SIGTRAP or EXC_BREAKPOINT + output = self.res.GetOutput() + matched = False + substrs = ['stop reason = EXC_BREAKPOINT', 'stop reason = signal SIGTRAP'] + for str1 in substrs: + matched = output.find(str1) != -1 + with recording(self, False) as sbuf: + print("%s sub string: %s" % ('Expecting', str1), file=sbuf) + print("Matched" if matched else "Not Matched", file=sbuf) + if matched: + break + self.assertTrue(matched, STOPPED_DUE_TO_SIGNAL) + + process = target.GetProcess() + self.assertTrue(process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + + thread = process.GetThreadAtIndex(0) + self.assertTrue(thread.IsValid(), "current thread is valid") + + currentFrame = thread.GetFrameAtIndex(0) + self.assertTrue(currentFrame.IsValid(), "current frame is valid") + + # Extract the value of fstat and ftag flag at the point just before + # we start pushing floating point values on st% register stack + value = currentFrame.FindValue("fstat", lldb.eValueTypeRegister) + error = lldb.SBError() + reg_value_fstat_initial = value.GetValueAsUnsigned(error, 0) + + self.assertTrue(error.Success(), "reading a value for fstat") + value = currentFrame.FindValue("ftag", lldb.eValueTypeRegister) + error = lldb.SBError() + reg_value_ftag_initial = value.GetValueAsUnsigned(error, 0) + + self.assertTrue(error.Success(), "reading a value for ftag") + fstat_top_pointer_initial = (reg_value_fstat_initial & 0x3800)>>11 + + # Execute 'si' aka 'thread step-inst' instruction 5 times and with + # every execution verify the value of fstat and ftag registers + for x in range(0,5): + # step into the next instruction to push a value on 'st' register stack + self.runCmd ("si", RUN_SUCCEEDED) + + # Verify fstat and save it to be used for verification in next execution of 'si' command + if not (reg_value_fstat_initial & 0x3800): + self.expect("register read fstat", + substrs = ['fstat' + ' = ', str("0x%0.4x" %((reg_value_fstat_initial & ~(0x3800))| 0x3800))]) + reg_value_fstat_initial = ((reg_value_fstat_initial & ~(0x3800))| 0x3800) + fstat_top_pointer_initial = 7 + else : + self.expect("register read fstat", + substrs = ['fstat' + ' = ', str("0x%0.4x" % (reg_value_fstat_initial - 0x0800))]) + reg_value_fstat_initial = (reg_value_fstat_initial - 0x0800) + fstat_top_pointer_initial -= 1 + + # Verify ftag and save it to be used for verification in next execution of 'si' command + self.expect("register read ftag", + substrs = ['ftag' + ' = ', str("0x%0.2x" % (reg_value_ftag_initial | (1<< fstat_top_pointer_initial)))]) + reg_value_ftag_initial = reg_value_ftag_initial | (1<< fstat_top_pointer_initial) + + def fp_register_write(self): + exe = os.path.join(os.getcwd(), "a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + lldbutil.run_break_set_by_symbol (self, "main", num_expected_locations=-1) + + # Launch the process, and do not stop at the entry point. + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + + process = target.GetProcess() + self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) + + thread = process.GetThreadAtIndex(0) + self.assertTrue(thread.IsValid(), "current thread is valid") + + currentFrame = thread.GetFrameAtIndex(0) + self.assertTrue(currentFrame.IsValid(), "current frame is valid") + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + reg_list = [ + # reg value must-have + ("fcw", "0x0000ff0e", False), + ("fsw", "0x0000ff0e", False), + ("ftw", "0x0000ff0e", False), + ("ip", "0x0000ff0e", False), + ("dp", "0x0000ff0e", False), + ("mxcsr", "0x0000ff0e", False), + ("mxcsrmask", "0x0000ff0e", False), + ] + + st0regname = None + if currentFrame.FindRegister("st0").IsValid(): + st0regname = "st0" + elif currentFrame.FindRegister("stmm0").IsValid(): + st0regname = "stmm0" + if st0regname is not None: + # reg value must-have + reg_list.append((st0regname, "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00}", True)) + reg_list.append(("xmm0", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True)) + reg_list.append(("xmm15", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", False)) + elif self.getArchitecture() in ['arm']: + reg_list = [ + # reg value must-have + ("fpscr", "0xfbf79f9f", True), + ("s0", "1.25", True), + ("s31", "0.75", True), + ("d1", "123", True), + ("d17", "987", False), + ("q1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), + ("q14", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", False), + ] + + for (reg, val, must) in reg_list: + self.write_and_read(currentFrame, reg, val, must) + + if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: + self.runCmd("register write " + st0regname + " \"{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}\"") + self.expect("register read " + st0regname + " --format f", substrs = [st0regname + ' = 0']) + + has_avx = False + registerSets = currentFrame.GetRegisters() # Returns an SBValueList. + for registerSet in registerSets: + if 'advanced vector extensions' in registerSet.GetName().lower(): + has_avx = True + break + + if has_avx: + new_value = "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x0d 0x0e 0x0f}" + self.write_and_read(currentFrame, "ymm0", new_value) + self.write_and_read(currentFrame, "ymm7", new_value) + self.expect("expr $ymm0", substrs = ['vector_type']) + else: + self.runCmd("register read ymm0") + + def convenience_registers(self): + """Test convenience registers.""" + self.common_setup() + + # The command "register read -a" does output a derived register like eax... + self.expect("register read -a", matching=True, + substrs = ['eax']) + + # ...however, the vanilla "register read" command should not output derived registers like eax. + self.expect("register read", matching=False, + substrs = ['eax']) + + # Test reading of rax and eax. + self.expect("register read rax eax", + substrs = ['rax = 0x', 'eax = 0x']) + + # Now write rax with a unique bit pattern and test that eax indeed represents the lower half of rax. + self.runCmd("register write rax 0x1234567887654321") + self.expect("register read rax 0x1234567887654321", + substrs = ['0x1234567887654321']) + + def convenience_registers_with_process_attach(self, test_16bit_regs): + """Test convenience registers after a 'process attach'.""" + exe = os.path.join(os.getcwd(), "a.out") + + # Spawn a new process + pid = self.spawnSubprocess(exe, ['wait_for_attach']).pid + self.addTearDownHook(self.cleanupSubprocesses) + + if self.TraceOn(): + print("pid of spawned process: %d" % pid) + + self.runCmd("process attach -p %d" % pid) + + # Check that "register read eax" works. + self.runCmd("register read eax") + + if self.getArchitecture() in ['amd64', 'x86_64']: + self.expect("expr -- ($rax & 0xffffffff) == $eax", + substrs = ['true']) + + if test_16bit_regs: + self.expect("expr -- $ax == (($ah << 8) | $al)", + substrs = ['true']) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/a.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/register/a.cpp new file mode 100644 index 00000000000..fbacec1918e --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/register/a.cpp @@ -0,0 +1,44 @@ +//===-- a.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include + +long double +return_long_double (long double value) +{ +#if defined (__i386__) || defined (__x86_64__) + float a=2, b=4,c=8, d=16, e=32, f=64, k=128, l=256, add=0; + __asm__ ( + "int3 ;" + "flds %1 ;" + "flds %2 ;" + "flds %3 ;" + "flds %4 ;" + "flds %5 ;" + "flds %6 ;" + "flds %7 ;" + "faddp ;" : "=g" (add) : "g" (a), "g" (b), "g" (c), "g" (d), "g" (e), "g" (f), "g" (k), "g" (l) ); // Set break point at this line. +#endif // #if defined (__i386__) || defined (__x86_64__) + return value; +} + +long double +outer_return_long_double (long double value) +{ + long double val = return_long_double(value); + val *= 2 ; + return val; +} + +long double +outermost_return_long_double (long double value) +{ + long double val = outer_return_long_double(value); + val *= 2 ; + return val; +} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile deleted file mode 100644 index 901ed77822a..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp -CXXFLAGS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd -LDFLAGS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd -include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py deleted file mode 100644 index 22907b1a96a..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Test the MPX registers. -""" - -from __future__ import print_function - -import os, sys, time -import re -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class RegisterCommandsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - self.has_teardown = False - - def tearDown(self): - self.dbg.GetSelectedTarget().GetProcess().Destroy() - TestBase.tearDown(self) - - @skipIfiOSSimulator - @skipIf(compiler="clang") - @expectedFailureAll(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) - @skipIf(archs=no_match(['amd64', 'i386', 'x86_64'])) - def test_mpx_registers_with_example_code(self): - """Test MPX registers with example code.""" - self.build() - self.mpx_registers_with_example_code() - - def mpx_registers_with_example_code(self): - """Test MPX registers after running example code.""" - self.line = line_number('main.cpp', '// Set a break point here.') - - exe = os.path.join(os.getcwd(), "a.out") - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - self.runCmd('settings set target.inline-breakpoint-strategy always') - self.addTearDownHook( - lambda: self.runCmd("settings set target.inline-breakpoint-strategy always")) - - lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1) - self.runCmd("run", RUN_SUCCEEDED) - - self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs = ["stop reason = breakpoint 1."]) - - self.expect("register read -s 3", - substrs = ['bnd0 = {0x0000000000000010 0xffffffffffffffe6}', - 'bnd1 = {0x0000000000000020 0xffffffffffffffd6}', - 'bnd2 = {0x0000000000000030 0xffffffffffffffc6}', - 'bnd3 = {0x0000000000000040 0xffffffffffffffb6}', - 'bndcfgu = {0x01 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}', - 'bndstatus = {0x02 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}']) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp deleted file mode 100644 index 1366d964e0f..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp +++ /dev/null @@ -1,69 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -//// -//// The LLVM Compiler Infrastructure -//// -//// This file is distributed under the University of Illinois Open Source -//// License. See LICENSE.TXT for details. -//// -////===----------------------------------------------------------------------===// -// - -#include -#include - -int -main(int argc, char const *argv[]) -{ - unsigned int rax, rbx, rcx, rdx; - - // Check if XSAVE is enabled. - if (!__get_cpuid(1, &rax, &rbx, &rcx, &rdx) || (rcx & bit_OSXSAVE) != bit_OSXSAVE) - return -1; - - // Check if MPX is enabled. - if (__get_cpuid_max(0, NULL) > 7) - { - __cpuid_count(7, 0, rax, rbx, rcx, rdx); - if ((rbx & bit_MPX) != bit_MPX) - return -1; - } - else - return -1; - -// Run MPX test code. -#if defined(__x86_64__) - asm("mov $16, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd0\n\t" - "mov $32, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd1\n\t" - "mov $48, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd2\n\t" - "mov $64, %rax\n\t" - "mov $9, %rdx\n\t" - "bndmk (%rax,%rdx), %bnd3\n\t" - "bndstx %bnd3, (%rax) \n\t" - "nop\n\t"); -#endif -#if defined(__i386__) - asm("mov $16, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd0\n\t" - "mov $32, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd1\n\t" - "mov $48, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd2\n\t" - "mov $64, %eax\n\t" - "mov $9, %edx\n\t" - "bndmk (%eax,%edx), %bnd3\n\t" - "bndstx %bnd3, (%eax)\n\t" - "nop\n\t"); -#endif - asm("nop\n\t"); // Set a break point here. - - return 0; -} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/register/main.cpp new file mode 100644 index 00000000000..156515768dd --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/register/main.cpp @@ -0,0 +1,36 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include + +#include +#include + +long double outermost_return_long_double (long double my_long_double); + +int main (int argc, char const *argv[]) +{ + lldb_enable_attach(); + + char my_string[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 0}; + double my_double = 1234.5678; + long double my_long_double = 1234.5678; + + // For simplicity assume that any cmdline argument means wait for attach. + if (argc > 1) + { + volatile int wait_for_attach=1; + while (wait_for_attach) + std::this_thread::sleep_for(std::chrono::microseconds(1)); + } + + printf("my_string=%s\n", my_string); + printf("my_double=%g\n", my_double); + outermost_return_long_double (my_long_double); + return 0; +} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/Makefile deleted file mode 100644 index 3c6deff2d97..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp a.cpp - -include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/TestRegisters.py b/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/TestRegisters.py deleted file mode 100644 index 10665af44fd..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/TestRegisters.py +++ /dev/null @@ -1,368 +0,0 @@ -""" -Test the 'register' command. -""" - -from __future__ import print_function - - - -import os, sys, time -import re -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -class RegisterCommandsTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - def setUp(self): - TestBase.setUp(self) - self.has_teardown = False - - def tearDown(self): - self.dbg.GetSelectedTarget().GetProcess().Destroy() - TestBase.tearDown(self) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - def test_register_commands(self): - """Test commands related to registers, in particular vector registers.""" - self.build() - self.common_setup() - - # verify that logging does not assert - self.log_enable("registers") - - self.expect("register read -a", MISSING_EXPECTED_REGISTERS, - substrs = ['registers were unavailable'], matching = False) - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - self.runCmd("register read xmm0") - self.runCmd("register read ymm15") # may be available - self.runCmd("register read bnd0") # may be available - elif self.getArchitecture() in ['arm']: - self.runCmd("register read s0") - self.runCmd("register read q15") # may be available - - self.expect("register read -s 4", substrs = ['invalid register set index: 4'], error = True) - - @skipIfiOSSimulator - @skipIfTargetAndroid(archs=["i386"]) # Writing of mxcsr register fails, presumably due to a kernel/hardware problem - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - def test_fp_register_write(self): - """Test commands that write to registers, in particular floating-point registers.""" - self.build() - self.fp_register_write() - - @skipIfiOSSimulator - @expectedFailureAndroid(archs=["i386"]) # "register read fstat" always return 0xffff - @skipIfFreeBSD #llvm.org/pr25057 - @skipIf(archs=no_match(['amd64', 'i386', 'x86_64'])) - def test_fp_special_purpose_register_read(self): - """Test commands that read fpu special purpose registers.""" - self.build() - self.fp_special_purpose_register_read() - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'arm', 'i386', 'x86_64'])) - def test_register_expressions(self): - """Test expression evaluation with commands related to registers.""" - self.build() - self.common_setup() - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - gpr = "eax" - vector = "xmm0" - elif self.getArchitecture() in ['arm']: - gpr = "r0" - vector = "q0" - - self.expect("expr/x $%s" % gpr, substrs = ['unsigned int', ' = 0x']) - self.expect("expr $%s" % vector, substrs = ['vector_type']) - self.expect("expr (unsigned int)$%s[0]" % vector, substrs = ['unsigned int']) - - if self.getArchitecture() in ['amd64', 'x86_64']: - self.expect("expr -- ($rax & 0xffffffff) == $eax", substrs = ['true']) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'x86_64'])) - def test_convenience_registers(self): - """Test convenience registers.""" - self.build() - self.convenience_registers() - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'x86_64'])) - def test_convenience_registers_with_process_attach(self): - """Test convenience registers after a 'process attach'.""" - self.build() - self.convenience_registers_with_process_attach(test_16bit_regs=False) - - @skipIfiOSSimulator - @skipIf(archs=no_match(['amd64', 'x86_64'])) - def test_convenience_registers_16bit_with_process_attach(self): - """Test convenience registers after a 'process attach'.""" - self.build() - self.convenience_registers_with_process_attach(test_16bit_regs=True) - - def common_setup(self): - exe = os.path.join(os.getcwd(), "a.out") - - self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - - # Break in main(). - lldbutil.run_break_set_by_symbol (self, "main", num_expected_locations=-1) - - self.runCmd("run", RUN_SUCCEEDED) - - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', 'stop reason = breakpoint']) - - # platform specific logging of the specified category - def log_enable(self, category): - # This intentionally checks the host platform rather than the target - # platform as logging is host side. - self.platform = "" - if sys.platform.startswith("darwin"): - self.platform = "" # TODO: add support for "log enable darwin registers" - - if sys.platform.startswith("freebsd"): - self.platform = "freebsd" - - if sys.platform.startswith("linux"): - self.platform = "linux" - - if sys.platform.startswith("netbsd"): - self.platform = "netbsd" - - if self.platform != "": - self.log_file = os.path.join(os.getcwd(), 'TestRegisters.log') - self.runCmd("log enable " + self.platform + " " + str(category) + " registers -v -f " + self.log_file, RUN_SUCCEEDED) - if not self.has_teardown: - def remove_log(self): - if os.path.exists(self.log_file): - os.remove(self.log_file) - self.has_teardown = True - self.addTearDownHook(remove_log) - - def write_and_read(self, frame, register, new_value, must_exist = True): - value = frame.FindValue(register, lldb.eValueTypeRegister) - if must_exist: - self.assertTrue(value.IsValid(), "finding a value for register " + register) - elif not value.IsValid(): - return # If register doesn't exist, skip this test - - self.runCmd("register write " + register + " \'" + new_value + "\'") - self.expect("register read " + register, substrs = [register + ' = ', new_value]) - - def fp_special_purpose_register_read(self): - exe = os.path.join(os.getcwd(), "a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - # Launch the process and stop. - self.expect ("run", PROCESS_STOPPED, substrs = ['stopped']) - - # Check stop reason; Should be either signal SIGTRAP or EXC_BREAKPOINT - output = self.res.GetOutput() - matched = False - substrs = ['stop reason = EXC_BREAKPOINT', 'stop reason = signal SIGTRAP'] - for str1 in substrs: - matched = output.find(str1) != -1 - with recording(self, False) as sbuf: - print("%s sub string: %s" % ('Expecting', str1), file=sbuf) - print("Matched" if matched else "Not Matched", file=sbuf) - if matched: - break - self.assertTrue(matched, STOPPED_DUE_TO_SIGNAL) - - process = target.GetProcess() - self.assertTrue(process.GetState() == lldb.eStateStopped, - PROCESS_STOPPED) - - thread = process.GetThreadAtIndex(0) - self.assertTrue(thread.IsValid(), "current thread is valid") - - currentFrame = thread.GetFrameAtIndex(0) - self.assertTrue(currentFrame.IsValid(), "current frame is valid") - - # Extract the value of fstat and ftag flag at the point just before - # we start pushing floating point values on st% register stack - value = currentFrame.FindValue("fstat", lldb.eValueTypeRegister) - error = lldb.SBError() - reg_value_fstat_initial = value.GetValueAsUnsigned(error, 0) - - self.assertTrue(error.Success(), "reading a value for fstat") - value = currentFrame.FindValue("ftag", lldb.eValueTypeRegister) - error = lldb.SBError() - reg_value_ftag_initial = value.GetValueAsUnsigned(error, 0) - - self.assertTrue(error.Success(), "reading a value for ftag") - fstat_top_pointer_initial = (reg_value_fstat_initial & 0x3800)>>11 - - # Execute 'si' aka 'thread step-inst' instruction 5 times and with - # every execution verify the value of fstat and ftag registers - for x in range(0,5): - # step into the next instruction to push a value on 'st' register stack - self.runCmd ("si", RUN_SUCCEEDED) - - # Verify fstat and save it to be used for verification in next execution of 'si' command - if not (reg_value_fstat_initial & 0x3800): - self.expect("register read fstat", - substrs = ['fstat' + ' = ', str("0x%0.4x" %((reg_value_fstat_initial & ~(0x3800))| 0x3800))]) - reg_value_fstat_initial = ((reg_value_fstat_initial & ~(0x3800))| 0x3800) - fstat_top_pointer_initial = 7 - else : - self.expect("register read fstat", - substrs = ['fstat' + ' = ', str("0x%0.4x" % (reg_value_fstat_initial - 0x0800))]) - reg_value_fstat_initial = (reg_value_fstat_initial - 0x0800) - fstat_top_pointer_initial -= 1 - - # Verify ftag and save it to be used for verification in next execution of 'si' command - self.expect("register read ftag", - substrs = ['ftag' + ' = ', str("0x%0.2x" % (reg_value_ftag_initial | (1<< fstat_top_pointer_initial)))]) - reg_value_ftag_initial = reg_value_ftag_initial | (1<< fstat_top_pointer_initial) - - def fp_register_write(self): - exe = os.path.join(os.getcwd(), "a.out") - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - lldbutil.run_break_set_by_symbol (self, "main", num_expected_locations=-1) - - # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple (None, None, self.get_process_working_directory()) - - process = target.GetProcess() - self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) - - thread = process.GetThreadAtIndex(0) - self.assertTrue(thread.IsValid(), "current thread is valid") - - currentFrame = thread.GetFrameAtIndex(0) - self.assertTrue(currentFrame.IsValid(), "current frame is valid") - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - reg_list = [ - # reg value must-have - ("fcw", "0x0000ff0e", False), - ("fsw", "0x0000ff0e", False), - ("ftw", "0x0000ff0e", False), - ("ip", "0x0000ff0e", False), - ("dp", "0x0000ff0e", False), - ("mxcsr", "0x0000ff0e", False), - ("mxcsrmask", "0x0000ff0e", False), - ] - - st0regname = None - if currentFrame.FindRegister("st0").IsValid(): - st0regname = "st0" - elif currentFrame.FindRegister("stmm0").IsValid(): - st0regname = "stmm0" - if st0regname is not None: - # reg value must-have - reg_list.append((st0regname, "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00}", True)) - reg_list.append(("xmm0", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True)) - reg_list.append(("xmm15", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", False)) - elif self.getArchitecture() in ['arm']: - reg_list = [ - # reg value must-have - ("fpscr", "0xfbf79f9f", True), - ("s0", "1.25", True), - ("s31", "0.75", True), - ("d1", "123", True), - ("d17", "987", False), - ("q1", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}", True), - ("q14", "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f}", False), - ] - - for (reg, val, must) in reg_list: - self.write_and_read(currentFrame, reg, val, must) - - if self.getArchitecture() in ['amd64', 'i386', 'x86_64']: - self.runCmd("register write " + st0regname + " \"{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}\"") - self.expect("register read " + st0regname + " --format f", substrs = [st0regname + ' = 0']) - - has_avx = False - has_mpx = False - registerSets = currentFrame.GetRegisters() # Returns an SBValueList. - for registerSet in registerSets: - if 'advanced vector extensions' in registerSet.GetName().lower(): - has_avx = True - if 'memory protection extension' in registerSet.GetName().lower(): - has_mpx = True - - if has_avx: - new_value = "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x0d 0x0e 0x0f}" - self.write_and_read(currentFrame, "ymm0", new_value) - self.write_and_read(currentFrame, "ymm7", new_value) - self.expect("expr $ymm0", substrs = ['vector_type']) - else: - self.runCmd("register read ymm0") - - if has_mpx: - # Test write and read for bnd0. - new_value_w = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10}" - self.runCmd("register write bnd0 \'" + new_value_w + "\'") - new_value_r = "{0x0807060504030201 0x100f0e0d0c0b0a09}" - self.expect("register read bnd0", substrs = ['bnd0 = ', new_value_r]) - self.expect("expr $bnd0", substrs = ['vector_type']) - - # Test write and for bndstatus. - new_value = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08}" - self.write_and_read(currentFrame, "bndstatus", new_value) - self.expect("expr $bndstatus", substrs = ['vector_type']) - else: - self.runCmd("register read bnd0") - - def convenience_registers(self): - """Test convenience registers.""" - self.common_setup() - - # The command "register read -a" does output a derived register like eax... - self.expect("register read -a", matching=True, - substrs = ['eax']) - - # ...however, the vanilla "register read" command should not output derived registers like eax. - self.expect("register read", matching=False, - substrs = ['eax']) - - # Test reading of rax and eax. - self.expect("register read rax eax", - substrs = ['rax = 0x', 'eax = 0x']) - - # Now write rax with a unique bit pattern and test that eax indeed represents the lower half of rax. - self.runCmd("register write rax 0x1234567887654321") - self.expect("register read rax 0x1234567887654321", - substrs = ['0x1234567887654321']) - - def convenience_registers_with_process_attach(self, test_16bit_regs): - """Test convenience registers after a 'process attach'.""" - exe = os.path.join(os.getcwd(), "a.out") - - # Spawn a new process - pid = self.spawnSubprocess(exe, ['wait_for_attach']).pid - self.addTearDownHook(self.cleanupSubprocesses) - - if self.TraceOn(): - print("pid of spawned process: %d" % pid) - - self.runCmd("process attach -p %d" % pid) - - # Check that "register read eax" works. - self.runCmd("register read eax") - - if self.getArchitecture() in ['amd64', 'x86_64']: - self.expect("expr -- ($rax & 0xffffffff) == $eax", - substrs = ['true']) - - if test_16bit_regs: - self.expect("expr -- $ax == (($ah << 8) | $al)", - substrs = ['true']) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/a.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/a.cpp deleted file mode 100644 index fbacec1918e..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/a.cpp +++ /dev/null @@ -1,44 +0,0 @@ -//===-- a.cpp ------------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#include - -long double -return_long_double (long double value) -{ -#if defined (__i386__) || defined (__x86_64__) - float a=2, b=4,c=8, d=16, e=32, f=64, k=128, l=256, add=0; - __asm__ ( - "int3 ;" - "flds %1 ;" - "flds %2 ;" - "flds %3 ;" - "flds %4 ;" - "flds %5 ;" - "flds %6 ;" - "flds %7 ;" - "faddp ;" : "=g" (add) : "g" (a), "g" (b), "g" (c), "g" (d), "g" (e), "g" (f), "g" (k), "g" (l) ); // Set break point at this line. -#endif // #if defined (__i386__) || defined (__x86_64__) - return value; -} - -long double -outer_return_long_double (long double value) -{ - long double val = return_long_double(value); - val *= 2 ; - return val; -} - -long double -outermost_return_long_double (long double value) -{ - long double val = outer_return_long_double(value); - val *= 2 ; - return val; -} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/main.cpp deleted file mode 100644 index 156515768dd..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/register/register_command/main.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===-- main.cpp ------------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#include - -#include -#include - -long double outermost_return_long_double (long double my_long_double); - -int main (int argc, char const *argv[]) -{ - lldb_enable_attach(); - - char my_string[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 0}; - double my_double = 1234.5678; - long double my_long_double = 1234.5678; - - // For simplicity assume that any cmdline argument means wait for attach. - if (argc > 1) - { - volatile int wait_for_attach=1; - while (wait_for_attach) - std::this_thread::sleep_for(std::chrono::microseconds(1)); - } - - printf("my_string=%s\n", my_string); - printf("my_double=%g\n", my_double); - outermost_return_long_double (my_long_double); - return 0; -} -- cgit v1.2.3