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