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