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