1""" 2Test mpx-table command. 3""" 4 5from __future__ import print_function 6 7 8import os 9import time 10import re 11import lldb 12from lldbsuite.test.decorators import * 13from lldbsuite.test.lldbtest import * 14from lldbsuite.test import lldbutil 15 16 17class TestMPXTable(TestBase): 18 19 def setUp(self): 20 TestBase.setUp(self) 21 22 @skipIf(compiler="clang") 23 @skipIf(oslist=no_match(['linux'])) 24 @skipIf(archs=no_match(['i386', 'x86_64'])) 25 @skipIf(compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports 26 #Intel(R) Memory Protection Extensions (Intel(R) MPX). 27 def test_show_command(self): 28 """Test 'mpx-table show' command""" 29 self.build() 30 31 plugin_file = os.path.join(configuration.lldb_libs_dir, "liblldbIntelFeatures.so") 32 if not os.path.isfile(plugin_file): 33 self.skipTest("features plugin missing.") 34 plugin_command = " " 35 seq = ("plugin", "load", plugin_file) 36 plugin_command = plugin_command.join(seq) 37 self.runCmd(plugin_command) 38 39 exe = os.path.join(os.getcwd(), "a.out") 40 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 41 42 self.b1 = line_number('main.cpp', '// Break 1.') 43 self.b2 = line_number('main.cpp', '// Break 2.') 44 self.b3 = line_number('main.cpp', '// Break 3.') 45 self.b4 = line_number('main.cpp', '// Break 4.') 46 lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b1, num_expected_locations=1) 47 lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b2, num_expected_locations=1) 48 lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b3, num_expected_locations=1) 49 lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b4, num_expected_locations=1) 50 self.runCmd("run", RUN_SUCCEEDED) 51 52 target = self.dbg.GetSelectedTarget() 53 process = target.GetProcess() 54 55 if (process.GetState() == lldb.eStateExited): 56 self.skipTest("Intel(R) MPX is not supported.") 57 else: 58 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, 59 substrs = ["stop reason = breakpoint 1."]) 60 61 self.expect("mpx-table show a", 62 substrs = ['lbound = 0x', 63 ', ubound = 0x', 64 '(pointer value = 0x', 65 ', metadata = 0x', 66 ')'], 67 error = False) 68 69 self.expect("continue", STOPPED_DUE_TO_BREAKPOINT, 70 substrs = ["stop reason = breakpoint 2."]) 71 72 # Check that out of scope pointer cannot be reached. 73 # 74 self.expect("mpx-table show a", 75 substrs = ['Invalid pointer.'], 76 error = True) 77 78 self.expect("mpx-table show tmp", 79 substrs = ['lbound = 0x', 80 ', ubound = 0x', 81 '(pointer value = 0x', 82 ', metadata = 0x', 83 ')'], 84 error = False) 85 86 self.expect("continue", STOPPED_DUE_TO_BREAKPOINT, 87 substrs = ["stop reason = breakpoint 3."]) 88 89 # Check that the pointer value is correctly updated. 90 # 91 self.expect("mpx-table show tmp", 92 substrs = ['lbound = 0x', 93 ', ubound = 0x', 94 '(pointer value = 0x2', 95 ', metadata = 0x', 96 ')'], 97 error = False) 98 99 self.expect("continue", STOPPED_DUE_TO_BREAKPOINT, 100 substrs = ["stop reason = breakpoint 4."]) 101 102 # After going back to main(), check that out of scope pointer cannot be 103 # reached. 104 # 105 self.expect("mpx-table show tmp", 106 substrs = ['Invalid pointer.'], 107 error = True) 108 109 self.expect("mpx-table show a", 110 substrs = ['lbound = 0x', 111 ', ubound = 0x', 112 '(pointer value = 0x', 113 ', metadata = 0x', 114 ')'], 115 error = False) 116 117 def test_set_command(self): 118 """Test 'mpx-table set' command""" 119 self.build() 120 121 plugin_file = os.path.join(configuration.lldb_libs_dir, "liblldbIntelFeatures.so") 122 if not os.path.isfile(plugin_file): 123 self.skipTest("features plugin missing.") 124 plugin_command = " " 125 seq = ("plugin", "load", plugin_file) 126 plugin_command = plugin_command.join(seq) 127 self.runCmd(plugin_command) 128 129 exe = os.path.join(os.getcwd(), "a.out") 130 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 131 132 self.b1 = line_number('main.cpp', '// Break 1.') 133 lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b1, num_expected_locations=1) 134 self.runCmd("run", RUN_SUCCEEDED) 135 136 target = self.dbg.GetSelectedTarget() 137 process = target.GetProcess() 138 139 if (process.GetState() == lldb.eStateExited): 140 self.skipTest("Intel(R) MPX is not supported.") 141 else: 142 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, 143 substrs = ["stop reason = breakpoint 1."]) 144 145 # Check that the BT Entry doesn't already contain the test values. 146 # 147 self.expect("mpx-table show a", matching=False, 148 substrs = ['lbound = 0xcafecafe', 149 ', ubound = 0xbeefbeef']) 150 151 # Set the test values. 152 # 153 self.expect("mpx-table set a 0xcafecafe 0xbeefbeef", error = False) 154 155 # Verify that the test values have been correctly written in the BT 156 # entry. 157 # 158 self.expect("mpx-table show a", 159 substrs = ['lbound = 0xcafecafe', 160 ', ubound = 0xbeefbeef'], 161 error = False) 162 163 164