d561af02d307b9808971bc502c79279fa169287c
[openbsd] /
1 """
2 Test saving a core file (or mini dump).
3 """
4
5
6 import os
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class ProcessSaveCoreTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     @not_remote_testsuite_ready
18     @skipUnlessWindows
19     def test_cannot_save_core_unless_process_stopped(self):
20         """Test that SaveCore fails if the process isn't stopped."""
21         self.build()
22         exe = self.getBuildArtifact("a.out")
23         core = self.getBuildArtifact("core.dmp")
24         target = self.dbg.CreateTarget(exe)
25         process = target.LaunchSimple(
26             None, None, self.get_process_working_directory())
27         self.assertNotEqual(process.GetState(), lldb.eStateStopped)
28         error = process.SaveCore(core)
29         self.assertTrue(error.Fail())
30
31     @not_remote_testsuite_ready
32     @skipUnlessWindows
33     def test_save_windows_mini_dump(self):
34         """Test that we can save a Windows mini dump."""
35         self.build()
36         exe = self.getBuildArtifact("a.out")
37         core = self.getBuildArtifact("core.dmp")
38         try:
39             target = self.dbg.CreateTarget(exe)
40             breakpoint = target.BreakpointCreateByName("bar")
41             process = target.LaunchSimple(
42                 None, None, self.get_process_working_directory())
43             self.assertEqual(process.GetState(), lldb.eStateStopped)
44             self.assertTrue(process.SaveCore(core))
45             self.assertTrue(os.path.isfile(core))
46             self.assertTrue(process.Kill().Success())
47
48             # To verify, we'll launch with the mini dump, and ensure that we see
49             # the executable in the module list.
50             target = self.dbg.CreateTarget(None)
51             process = target.LoadCore(core)
52             files = [
53                 target.GetModuleAtIndex(i).GetFileSpec() for i in range(
54                     0, target.GetNumModules())]
55             paths = [
56                 os.path.join(
57                     f.GetDirectory(),
58                     f.GetFilename()) for f in files]
59             self.assertTrue(exe in paths)
60
61         finally:
62             # Clean up the mini dump file.
63             self.assertTrue(self.dbg.DeleteTarget(target))
64             if (os.path.isfile(core)):
65                 os.unlink(core)