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 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, 43 substrs=[' resolved, hit count = 1']) 44 45 # Enable logging of the imported AST. 46 log_file = self.getBuildArtifact("lldb-ast-log.txt") 47 if configuration.is_reproducer_replay(): 48 log_file = self.getReproducerRemappedPath(log_file) 49 self.runCmd("log enable lldb ast -f '%s'" % log_file) 50 51 self.expect( 52 "expr -l objc++ -- @import Darwin; 3", 53 VARIABLES_DISPLAYED_CORRECTLY, 54 substrs=[ 55 "int", 56 "3"]) 57 58 # This expr command imports __sFILE with definition 59 # (FILE is a typedef to __sFILE.) 60 self.expect( 61 "expr *fopen(\"/dev/zero\", \"w\")", 62 VARIABLES_DISPLAYED_CORRECTLY, 63 substrs=[ 64 "FILE", 65 "_close"]) 66 67 # Check that the AST log contains exactly one definition of __sFILE. 68 f = open(log_file) 69 log_lines = f.readlines() 70 f.close() 71 os.remove(log_file) 72 self.assertEqual(" ".join(log_lines).count("struct __sFILE definition"), 73 1) 74 75 self.expect("expr *myFile", VARIABLES_DISPLAYED_CORRECTLY, 76 substrs=["a", "5", "b", "9"]) 77 78 self.expect( 79 "expr MIN((uint64_t)2, (uint64_t)3)", 80 VARIABLES_DISPLAYED_CORRECTLY, 81 substrs=[ 82 "uint64_t", 83 "2"]) 84 85 self.expect("expr stdin", VARIABLES_DISPLAYED_CORRECTLY, 86 substrs=["(FILE *)", "0x"]) 87 88 def setUp(self): 89 # Call super's setUp(). 90 TestBase.setUp(self) 91 # Find the line number to break inside main(). 92 self.line = line_number('main.c', '// Set breakpoint 0 here.') 93