Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test the printing of anonymous and named namespace variables. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class NamespaceTestCase(TestBase): |
| 11 | |
| 12 | mydir = "namespace" |
| 13 | |
| 14 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 15 | def test_with_dsym_and_run_command(self): |
| 16 | """Test that anonymous and named namespace variables display correctly.""" |
| 17 | self.buildDsym() |
| 18 | self.namespace_variable_commands() |
| 19 | |
Johnny Chen | 064d7f5 | 2010-11-12 00:50:45 +0000 | [diff] [blame] | 20 | @unittest2.expectedFailure |
| 21 | # rdar://problem/8659840 |
Johnny Chen | 6df2cd3 | 2010-11-12 01:00:56 +0000 | [diff] [blame^] | 22 | # runCmd: frame variable -c -G i |
| 23 | # runCmd failed! |
| 24 | # error: can't find global variable 'i' |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 25 | def test_with_dwarf_and_run_command(self): |
| 26 | """Test that anonymous and named namespace variables display correctly.""" |
| 27 | self.buildDwarf() |
| 28 | self.namespace_variable_commands() |
| 29 | |
| 30 | def setUp(self): |
| 31 | # Call super's setUp(). |
| 32 | TestBase.setUp(self) |
| 33 | # Find the line numbers for declarations of namespace variables i and j. |
| 34 | self.line_var_i = line_number('main.cpp', |
| 35 | '// Find the line number for anonymous namespace variable i.') |
| 36 | self.line_var_j = line_number('main.cpp', |
| 37 | '// Find the line number for named namespace variable j.') |
| 38 | # And the line number to break at. |
| 39 | self.line_break = line_number('main.cpp', |
| 40 | '// Set break point at this line.') |
| 41 | |
| 42 | def namespace_variable_commands(self): |
| 43 | """Test that anonymous and named namespace variables display correctly.""" |
| 44 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 45 | |
| 46 | self.expect("breakpoint set -f main.cpp -l %d" % self.line_break, |
| 47 | BREAKPOINT_CREATED, |
| 48 | startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" % |
| 49 | self.line_break) |
| 50 | |
| 51 | self.runCmd("run", RUN_SUCCEEDED) |
| 52 | |
| 53 | # The stop reason of the thread should be breakpoint. |
| 54 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 55 | substrs = ['state is stopped', |
| 56 | 'stop reason = breakpoint']) |
| 57 | |
| 58 | self.expect("frame variable -c -G i", |
| 59 | startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i) |
| 60 | # main.cpp:12: (int) (anonymous namespace)::i = 3 |
| 61 | |
| 62 | self.expect("frame variable -c -G j", |
| 63 | startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j) |
| 64 | # main.cpp:19: (int) A::B::j = 4 |
| 65 | |
Johnny Chen | 6df2cd3 | 2010-11-12 01:00:56 +0000 | [diff] [blame^] | 66 | # rdar://problem/8660275 |
| 67 | # test/namespace: 'expression -- i+j' not working |
Johnny Chen | 064d7f5 | 2010-11-12 00:50:45 +0000 | [diff] [blame] | 68 | #self.expect("expression -- i + j", |
| 69 | # startstr = "(int) $0 = 7") |
| 70 | # (int) $0 = 7 |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 71 | |
| 72 | if __name__ == '__main__': |
| 73 | import atexit |
| 74 | lldb.SBDebugger.Initialize() |
| 75 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 76 | unittest2.main() |