xref: /llvm-project/lldb/test/API/macosx/stack-corefile/TestStackCorefile.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
18c31efeeSJason Molenda"""Test that lldb can create a stack-only corefile, and load the main binary."""
28c31efeeSJason Molenda
38c31efeeSJason Molendaimport os
48c31efeeSJason Molendaimport re
58c31efeeSJason Molendaimport subprocess
68c31efeeSJason Molenda
78c31efeeSJason Molendaimport lldb
88c31efeeSJason Molendafrom lldbsuite.test.decorators import *
98c31efeeSJason Molendafrom lldbsuite.test.lldbtest import *
108c31efeeSJason Molendafrom lldbsuite.test import lldbutil
118c31efeeSJason Molenda
128c31efeeSJason Molenda
13*2238dcc3SJonas Devlieghereclass TestStackCorefile(TestBase):
142b30fc2fSJason Molenda    @skipIfOutOfTreeDebugserver  # newer debugserver required for these qMemoryRegionInfo types
158c31efeeSJason Molenda    @no_debug_info_test
168c31efeeSJason Molenda    @skipUnlessDarwin
17065e3c9aSJonas Devlieghere    @skipIfRemote
188c31efeeSJason Molenda    def test(self):
198c31efeeSJason Molenda        corefile = self.getBuildArtifact("process.core")
208c31efeeSJason Molenda        self.build()
218c31efeeSJason Molenda        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
22*2238dcc3SJonas Devlieghere            self, "// break here", lldb.SBFileSpec("main.c")
23*2238dcc3SJonas Devlieghere        )
248c31efeeSJason Molenda
258c31efeeSJason Molenda        frame = thread.GetFrameAtIndex(0)
268c31efeeSJason Molenda        stack_int = frame.GetValueForVariablePath("stack_int")
278c31efeeSJason Molenda        heap_int = frame.GetValueForVariablePath("*heap_int")
288c31efeeSJason Molenda        stack_str = frame.GetValueForVariablePath("stack_str")
298c31efeeSJason Molenda        heap_str = frame.GetValueForVariablePath("heap_str")
308c31efeeSJason Molenda        self.assertEqual(stack_int.GetValueAsUnsigned(), 5)
318c31efeeSJason Molenda        self.assertEqual(heap_int.GetValueAsUnsigned(), 10)
328c31efeeSJason Molenda        self.assertEqual(stack_str.summary, '"stack string"')
338c31efeeSJason Molenda        self.assertEqual(heap_str.summary, '"heap string"')
348c31efeeSJason Molenda
358c31efeeSJason Molenda        self.runCmd("process save-core -s stack " + corefile)
368c31efeeSJason Molenda        process.Kill()
378c31efeeSJason Molenda        self.dbg.DeleteTarget(target)
388c31efeeSJason Molenda
398c31efeeSJason Molenda        # Now load the corefile
40*2238dcc3SJonas Devlieghere        target = self.dbg.CreateTarget("")
418c31efeeSJason Molenda        process = target.LoadCore(corefile)
428c31efeeSJason Molenda        thread = process.GetSelectedThread()
438c31efeeSJason Molenda        self.assertTrue(process.IsValid())
448c31efeeSJason Molenda        self.assertTrue(process.GetSelectedThread().IsValid())
458c31efeeSJason Molenda        if self.TraceOn():
468c31efeeSJason Molenda            self.runCmd("image list")
478c31efeeSJason Molenda            self.runCmd("bt")
488c31efeeSJason Molenda            self.runCmd("fr v")
498c31efeeSJason Molenda        num_modules = target.GetNumModules()
508c31efeeSJason Molenda        #  We should only have the a.out binary and possibly
518c31efeeSJason Molenda        # the libdyld.dylib.  Extra libraries loaded means
528c31efeeSJason Molenda        # extra LC_NOTE and unnecessarily large corefile.
538c31efeeSJason Molenda        self.assertTrue(num_modules == 1 or num_modules == 2)
548c31efeeSJason Molenda
558c31efeeSJason Molenda        # The heap variables should be unavailable now.
568c31efeeSJason Molenda        frame = thread.GetFrameAtIndex(0)
578c31efeeSJason Molenda        stack_int = frame.GetValueForVariablePath("stack_int")
588c31efeeSJason Molenda        heap_int = frame.GetValueForVariablePath("*heap_int")
598c31efeeSJason Molenda        stack_str = frame.GetValueForVariablePath("stack_str")
608c31efeeSJason Molenda        heap_str = frame.GetValueForVariablePath("heap_str")
618c31efeeSJason Molenda
628c31efeeSJason Molenda        ## The heap SBValues both come back as IsValid()==true,
638c31efeeSJason Molenda        ## which I'm not so sure is a great/correct thing --
648c31efeeSJason Molenda        ## it hides the memory read error that actually happened,
658c31efeeSJason Molenda        ## and we don't have a real value.
668c31efeeSJason Molenda        self.assertEqual(stack_int.GetValueAsUnsigned(), 5)
678c31efeeSJason Molenda        self.assertEqual(heap_int.GetValueAsUnsigned(), 0)
688c31efeeSJason Molenda        self.assertEqual(stack_str.summary, '"stack string"')
698c31efeeSJason Molenda        self.assertEqual(heap_str.summary, '""')
70