1"""Test that lldb can create a stack-only corefile, and load the main binary.""" 2 3import os 4import re 5import subprocess 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12class TestStackCorefile(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 16 @skipIfOutOfTreeDebugserver # newer debugserver required for these qMemoryRegionInfo types 17 @no_debug_info_test 18 @skipUnlessDarwin 19 def test(self): 20 21 corefile = self.getBuildArtifact("process.core") 22 self.build() 23 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( 24 self, "// break here", lldb.SBFileSpec("main.c")) 25 26 frame = thread.GetFrameAtIndex(0) 27 stack_int = frame.GetValueForVariablePath("stack_int") 28 heap_int = frame.GetValueForVariablePath("*heap_int") 29 stack_str = frame.GetValueForVariablePath("stack_str") 30 heap_str = frame.GetValueForVariablePath("heap_str") 31 self.assertEqual(stack_int.GetValueAsUnsigned(), 5) 32 self.assertEqual(heap_int.GetValueAsUnsigned(), 10) 33 self.assertEqual(stack_str.summary, '"stack string"') 34 self.assertEqual(heap_str.summary, '"heap string"') 35 36 self.runCmd("process save-core -s stack " + corefile) 37 process.Kill() 38 self.dbg.DeleteTarget(target) 39 40 # Now load the corefile 41 target = self.dbg.CreateTarget('') 42 process = target.LoadCore(corefile) 43 thread = process.GetSelectedThread() 44 self.assertTrue(process.IsValid()) 45 self.assertTrue(process.GetSelectedThread().IsValid()) 46 if self.TraceOn(): 47 self.runCmd("image list") 48 self.runCmd("bt") 49 self.runCmd("fr v") 50 num_modules = target.GetNumModules() 51 # We should only have the a.out binary and possibly 52 # the libdyld.dylib. Extra libraries loaded means 53 # extra LC_NOTE and unnecessarily large corefile. 54 self.assertTrue(num_modules == 1 or num_modules == 2) 55 56 # The heap variables should be unavailable now. 57 frame = thread.GetFrameAtIndex(0) 58 stack_int = frame.GetValueForVariablePath("stack_int") 59 heap_int = frame.GetValueForVariablePath("*heap_int") 60 stack_str = frame.GetValueForVariablePath("stack_str") 61 heap_str = frame.GetValueForVariablePath("heap_str") 62 63 ## The heap SBValues both come back as IsValid()==true, 64 ## which I'm not so sure is a great/correct thing -- 65 ## it hides the memory read error that actually happened, 66 ## and we don't have a real value. 67 self.assertEqual(stack_int.GetValueAsUnsigned(), 5) 68 self.assertEqual(heap_int.GetValueAsUnsigned(), 0) 69 self.assertEqual(stack_str.summary, '"stack string"') 70 self.assertEqual(heap_str.summary, '""') 71