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 @skipIfRemote 20 def test(self): 21 22 corefile = self.getBuildArtifact("process.core") 23 self.build() 24 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( 25 self, "// break here", lldb.SBFileSpec("main.c")) 26 27 frame = thread.GetFrameAtIndex(0) 28 stack_int = frame.GetValueForVariablePath("stack_int") 29 heap_int = frame.GetValueForVariablePath("*heap_int") 30 stack_str = frame.GetValueForVariablePath("stack_str") 31 heap_str = frame.GetValueForVariablePath("heap_str") 32 self.assertEqual(stack_int.GetValueAsUnsigned(), 5) 33 self.assertEqual(heap_int.GetValueAsUnsigned(), 10) 34 self.assertEqual(stack_str.summary, '"stack string"') 35 self.assertEqual(heap_str.summary, '"heap string"') 36 37 self.runCmd("process save-core -s stack " + corefile) 38 process.Kill() 39 self.dbg.DeleteTarget(target) 40 41 # Now load the corefile 42 target = self.dbg.CreateTarget('') 43 process = target.LoadCore(corefile) 44 thread = process.GetSelectedThread() 45 self.assertTrue(process.IsValid()) 46 self.assertTrue(process.GetSelectedThread().IsValid()) 47 if self.TraceOn(): 48 self.runCmd("image list") 49 self.runCmd("bt") 50 self.runCmd("fr v") 51 num_modules = target.GetNumModules() 52 # We should only have the a.out binary and possibly 53 # the libdyld.dylib. Extra libraries loaded means 54 # extra LC_NOTE and unnecessarily large corefile. 55 self.assertTrue(num_modules == 1 or num_modules == 2) 56 57 # The heap variables should be unavailable now. 58 frame = thread.GetFrameAtIndex(0) 59 stack_int = frame.GetValueForVariablePath("stack_int") 60 heap_int = frame.GetValueForVariablePath("*heap_int") 61 stack_str = frame.GetValueForVariablePath("stack_str") 62 heap_str = frame.GetValueForVariablePath("heap_str") 63 64 ## The heap SBValues both come back as IsValid()==true, 65 ## which I'm not so sure is a great/correct thing -- 66 ## it hides the memory read error that actually happened, 67 ## and we don't have a real value. 68 self.assertEqual(stack_int.GetValueAsUnsigned(), 5) 69 self.assertEqual(heap_int.GetValueAsUnsigned(), 0) 70 self.assertEqual(stack_str.summary, '"stack string"') 71 self.assertEqual(heap_str.summary, '""') 72