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