| Johnny Chen | ea920fe | 2010-08-24 18:21:23 +0000 | [diff] [blame] | 1 | """Show bitfields and check that they display correctly.""" |
| 2 | |
| 3 | import os, time |
| 4 | import unittest2 |
| 5 | import lldb |
| 6 | from lldbtest import * |
| 7 | |
| 8 | class TestBitfields(TestBase): |
| 9 | |
| 10 | mydir = "bitfields" |
| 11 | |
| 12 | @unittest2.expectedFailure |
| Johnny Chen | f2b1419 | 2010-08-24 18:46:00 +0000 | [diff] [blame] | 13 | def test_variable_list_for_bitfields(self): |
| Johnny Chen | 9d2bd83 | 2010-08-24 20:48:28 +0000 | [diff] [blame] | 14 | """Test 'variable list ...' on a variable with bitfields.""" |
| Johnny Chen | ea920fe | 2010-08-24 18:21:23 +0000 | [diff] [blame] | 15 | exe = os.path.join(os.getcwd(), "a.out") |
| 16 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 17 | |
| 18 | # Break inside the main. |
| 19 | self.expect("breakpoint set -f main.c -l 42", BREAKPOINT_CREATED, |
| 20 | startstr = "Breakpoint created: 1: file ='main.c', line = 42, locations = 1") |
| 21 | |
| 22 | self.runCmd("run", RUN_STOPPED) |
| 23 | |
| 24 | # The stop reason of the thread should be breakpoint. |
| 25 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 26 | substrs = ['state is Stopped', |
| 27 | 'stop reason = breakpoint']) |
| 28 | |
| 29 | # The breakpoint should have a hit count of 1. |
| 30 | self.expect("breakpoint list", BREAKPOINT_HIT_ONCE, |
| 31 | substrs = [' resolved, hit count = 1']) |
| 32 | |
| 33 | # This should display correctly. |
| 34 | self.expect("variable list bits", VARIABLES_DISPLAYED_CORRECTLY, |
| 35 | substrs = ['(uint32_t:1) b1 = 0x00000001,', |
| 36 | '(uint32_t:2) b2 = 0x00000003,', |
| 37 | '(uint32_t:3) b3 = 0x00000007,', |
| 38 | '(uint32_t:4) b4 = 0x0000000f,', |
| 39 | '(uint32_t:5) b5 = 0x0000001f,', |
| 40 | '(uint32_t:6) b6 = 0x0000003f,', |
| 41 | '(uint32_t:7) b7 = 0x0000007f,', |
| 42 | '(uint32_t:4) four = 0x0000000f']) |
| 43 | |
| 44 | # And so should this. |
| 45 | # rdar://problem/8348251 |
| 46 | self.expect("variable list", VARIABLES_DISPLAYED_CORRECTLY, |
| 47 | substrs = ['(uint32_t:1) b1 = 0x00000001,', |
| 48 | '(uint32_t:2) b2 = 0x00000003,', |
| 49 | '(uint32_t:3) b3 = 0x00000007,', |
| 50 | '(uint32_t:4) b4 = 0x0000000f,', |
| 51 | '(uint32_t:5) b5 = 0x0000001f,', |
| 52 | '(uint32_t:6) b6 = 0x0000003f,', |
| 53 | '(uint32_t:7) b7 = 0x0000007f,', |
| 54 | '(uint32_t:4) four = 0x0000000f']) |
| 55 | |
| Johnny Chen | 827edff | 2010-08-27 00:15:48 +0000 | [diff] [blame^] | 56 | def test_bitfields_variable_python(self): |
| 57 | """Use Python APIs to inspect a bitfields variable.""" |
| 58 | exe = os.path.join(os.getcwd(), "a.out") |
| 59 | |
| 60 | target = self.dbg.CreateTarget(exe) |
| 61 | self.assertTrue(target.IsValid(), VALID_TARGET) |
| 62 | |
| 63 | breakpoint = target.BreakpointCreateByLocation("main.c", 42) |
| 64 | self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) |
| 65 | |
| 66 | self.runCmd("run", RUN_STOPPED) |
| 67 | # This does not work, and results in the process stopped at dyld_start? |
| 68 | #process = target.LaunchProcess([''], [''], os.ctermid(), False) |
| 69 | |
| 70 | # The stop reason of the thread should be breakpoint. |
| 71 | thread = target.GetProcess().GetThreadAtIndex(0) |
| 72 | self.assertTrue(thread.GetStopReason() == Enum("Breakpoint"), |
| 73 | STOPPED_DUE_TO_BREAKPOINT) |
| 74 | |
| 75 | # The breakpoint should have a hit count of 1. |
| 76 | self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) |
| 77 | |
| 78 | # Lookup the "bits" variable which contains 8 bitfields. |
| 79 | frame = thread.GetFrameAtIndex(0) |
| 80 | bits = frame.LookupVar("bits") |
| 81 | self.DebugSBValue(frame, bits) |
| 82 | self.assertTrue(bits.GetTypeName() == "Bits" and |
| 83 | bits.GetNumChildren() == 8 and |
| 84 | bits.GetByteSize() == 4, |
| 85 | "(Bits)bits with byte size of 4 and 8 children") |
| 86 | |
| 87 | b1 = bits.GetChildAtIndex(0) |
| 88 | self.DebugSBValue(frame, b1) |
| 89 | self.assertTrue(b1.GetName() == "b1" and |
| 90 | b1.GetTypeName() == "uint32_t:1" and |
| 91 | b1.IsInScope(frame) and |
| 92 | int(b1.GetValue(frame), 16) == 0x01, |
| 93 | 'bits.b1 has type uint32_t:1, is in scope, and == 0x01') |
| 94 | |
| 95 | b7 = bits.GetChildAtIndex(6) |
| 96 | self.DebugSBValue(frame, b7) |
| 97 | self.assertTrue(b7.GetName() == "b7" and |
| 98 | b7.GetTypeName() == "uint32_t:7" and |
| 99 | b7.IsInScope(frame) and |
| 100 | int(b7.GetValue(frame), 16) == 0x7f, |
| 101 | 'bits.b7 has type uint32_t:7, is in scope, and == 0x7f') |
| 102 | |
| 103 | four = bits.GetChildAtIndex(7) |
| 104 | self.DebugSBValue(frame, four) |
| 105 | self.assertTrue(four.GetName() == "four" and |
| 106 | four.GetTypeName() == "uint32_t:4" and |
| 107 | four.IsInScope(frame) and |
| 108 | int(four.GetValue(frame), 16) == 0x0f, |
| 109 | 'bits.four has type uint32_t:4, is in scope, and == 0x0f') |
| 110 | |
| Johnny Chen | ea920fe | 2010-08-24 18:21:23 +0000 | [diff] [blame] | 111 | |
| 112 | if __name__ == '__main__': |
| 113 | import atexit |
| 114 | lldb.SBDebugger.Initialize() |
| 115 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 116 | unittest2.main() |