1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
"""
Test saving a core file (or mini dump).
"""
import os
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class ProcessSaveCoreTestCase(TestBase):
@skipIfRemote
@skipUnlessWindows
def test_cannot_save_core_unless_process_stopped(self):
"""Test that SaveCore fails if the process isn't stopped."""
self.build()
exe = self.getBuildArtifact("a.out")
core = self.getBuildArtifact("core.dmp")
target = self.dbg.CreateTarget(exe)
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertNotEqual(process.GetState(), lldb.eStateStopped)
options = lldb.SBSaveCoreOptions()
options.SetOutputFile(lldb.SBFileSpec(core))
error = process.SaveCore(core)
self.assertTrue(error.Fail())
@skipIfRemote
@skipUnlessWindows
def test_save_windows_mini_dump(self):
"""Test that we can save a Windows mini dump."""
self.build()
exe = self.getBuildArtifact("a.out")
core = self.getBuildArtifact("core.dmp")
try:
target = self.dbg.CreateTarget(exe)
breakpoint = target.BreakpointCreateByName("bar")
process = target.LaunchSimple(
None, None, self.get_process_working_directory()
)
self.assertState(process.GetState(), lldb.eStateStopped)
self.assertTrue(process.SaveCore(core))
self.assertTrue(os.path.isfile(core))
self.assertSuccess(process.Kill())
# To verify, we'll launch with the mini dump, and ensure that we see
# the executable in the module list.
target = self.dbg.CreateTarget(None)
process = target.LoadCore(core)
files = [
target.GetModuleAtIndex(i).GetFileSpec()
for i in range(0, target.GetNumModules())
]
paths = [os.path.join(f.GetDirectory(), f.GetFilename()) for f in files]
self.assertIn(exe, paths)
finally:
# Clean up the mini dump file.
self.assertTrue(self.dbg.DeleteTarget(target))
if os.path.isfile(core):
os.unlink(core)
@skipUnlessPlatform(["freebsd", "netbsd"])
def test_save_core_via_process_plugin(self):
self.build()
exe = self.getBuildArtifact("a.out")
core = self.getBuildArtifact("a.out.core")
try:
target = self.dbg.CreateTarget(exe)
breakpoint = target.BreakpointCreateByName("bar")
process = target.LaunchSimple(
None, None, self.get_process_working_directory()
)
self.assertState(process.GetState(), lldb.eStateStopped)
self.assertTrue(process.SaveCore(core))
self.assertTrue(os.path.isfile(core))
self.assertSuccess(process.Kill())
pid = process.GetProcessID()
target = self.dbg.CreateTarget(None)
process = target.LoadCore(core)
self.assertTrue(process, PROCESS_IS_VALID)
self.assertEqual(process.GetProcessID(), pid)
finally:
self.assertTrue(self.dbg.DeleteTarget(target))
try:
os.unlink(core)
except OSError:
pass
def test_help(self):
"""Test that help shows an option in plugin-names and style."""
self.expect(
"help process save-core",
substrs=["process save-core", "<plugin>", "Values:", "minidump"],
)
self.expect(
"help process save-core",
substrs=[
"process save-core",
"<corefile-style>",
"Values:",
"full",
"stack",
],
)
|