1"""Test that importing modules in C works as expected.""" 2 3 4 5import os 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class CModulesTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 @expectedFailureAll( 18 oslist=["freebsd", "linux"], 19 bugnumber="http://llvm.org/pr23456 'fopen' has unknown return type") 20 @expectedFailureAll( 21 oslist=["windows"], 22 bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows") 23 @skipIf(macos_version=["<", "10.12"]) 24 @expectedFailureNetBSD 25 def test_expr(self): 26 self.build() 27 exe = self.getBuildArtifact("a.out") 28 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 29 30 # Break inside the foo function which takes a bar_ptr argument. 31 lldbutil.run_break_set_by_file_and_line( 32 self, "main.c", self.line, num_expected_locations=1, loc_exact=True) 33 34 self.runCmd("run", RUN_SUCCEEDED) 35 36 # The stop reason of the thread should be breakpoint. 37 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 38 substrs=['stopped', 39 'stop reason = breakpoint']) 40 41 # The breakpoint should have a hit count of 1. 42 lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1) 43 44 # Enable logging of the imported AST. 45 log_file = self.getBuildArtifact("lldb-ast-log.txt") 46 self.runCmd("log enable lldb ast -f '%s'" % log_file) 47 48 self.expect( 49 "expr -l objc++ -- @import Darwin; 3", 50 VARIABLES_DISPLAYED_CORRECTLY, 51 substrs=[ 52 "int", 53 "3"]) 54 55 # This expr command imports __sFILE with definition 56 # (FILE is a typedef to __sFILE.) 57 self.expect( 58 "expr *fopen(\"/dev/zero\", \"w\")", 59 VARIABLES_DISPLAYED_CORRECTLY, 60 substrs=[ 61 "FILE", 62 "_close"]) 63 64 # Check that the AST log contains exactly one definition of __sFILE. 65 f = open(log_file) 66 log_lines = f.readlines() 67 f.close() 68 os.remove(log_file) 69 self.assertEqual(" ".join(log_lines).count("struct __sFILE definition"), 70 1) 71 72 self.expect("expr *myFile", VARIABLES_DISPLAYED_CORRECTLY, 73 substrs=["a", "5", "b", "9"]) 74 75 self.expect( 76 "expr MIN((uint64_t)2, (uint64_t)3)", 77 VARIABLES_DISPLAYED_CORRECTLY, 78 substrs=[ 79 "uint64_t", 80 "2"]) 81 82 self.expect("expr stdin", VARIABLES_DISPLAYED_CORRECTLY, 83 substrs=["(FILE *)", "0x"]) 84 85 def setUp(self): 86 # Call super's setUp(). 87 TestBase.setUp(self) 88 # Find the line number to break inside main(). 89 self.line = line_number('main.c', '// Set breakpoint 0 here.') 90