Skip to content

Commit b2e941d

Browse files
committed
Fix docstrings and implement dmpots suggestions
1 parent 7aef618 commit b2e941d

File tree

6 files changed

+73
-90
lines changed

6 files changed

+73
-90
lines changed

lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Note that currently ELF Core files are not supported."
4646
) lldb::SBSaveCoreOptions::SetProcess;
4747

4848
%feature("docstring", "
49-
Get the process to save. If undefined, an invalid SBProcess will be returned."
49+
Get the process to save. If a process is not defined, whether by calling clear or by not setting a process, an invalid process will be returned."
5050
) lldb::SBSaveCoreOptions::GetProcess;
5151

5252
%feature("docstring", "
@@ -69,7 +69,7 @@ Note that currently ELF Core files are not supported."
6969

7070
%feature("docstring", "
7171
Get an SBMemoryRegionInfoList of all the Regions that LLDB will attempt to write into the Core. Note, reading from these
72-
regions can fail, and it's guaraunteed every region will be present. If called without a valid process or style set an empty
72+
regions can fail, and it's not guaraunteed every region will be present in the resulting core. If called without a valid process or style set an empty
7373
collection will be returned."
7474
) lldb::SBSaveCoreOptions::GetMemoryRegionsToSave;
7575

lldb/source/API/SBSaveCoreOptions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ lldb::SBMemoryRegionInfoList SBSaveCoreOptions::GetMemoryRegionsToSave() {
142142
return SBMemoryRegionInfoList();
143143
}
144144

145-
SBMemoryRegionInfoList m_memory_region_infos;
145+
SBMemoryRegionInfoList memory_region_infos;
146146
for (const auto &range : *memory_ranges) {
147147
SBMemoryRegionInfo region_info(
148148
nullptr, range.GetRangeBase(), range.GetRangeEnd(),
149149
range.data.lldb_permissions, /*mapped=*/true);
150-
m_memory_region_infos.Append(region_info);
150+
memory_region_infos.Append(region_info);
151151
}
152152

153-
return m_memory_region_infos;
153+
return memory_region_infos;
154154
}
155155

156156
lldb_private::SaveCoreOptions &SBSaveCoreOptions::ref() const {

lldb/source/Core/PluginManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,13 +965,11 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
965965
return error;
966966
}
967967

968-
// Set the process sp if not already set.
969-
ProcessSP options_sp = options.GetProcess();
970-
if (!options_sp)
968+
if (!options.GetProcess())
971969
options.SetProcess(process_sp);
972970

973971
// Make sure the process sp is the same as the one we are using.
974-
if (options_sp && options_sp != process_sp) {
972+
if (options.GetProcess() != process_sp) {
975973
error = Status::FromErrorString(
976974
"Save Core Options configured for a different process.");
977975
return error;

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,17 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
984984

985985
if (current_addr != addr + total_bytes_read) {
986986
LLDB_LOGF(log,
987-
"Current addr is at expected address, 0x%" PRIx64
987+
"Current addr is at unexpected address, 0x%" PRIx64
988988
", expected at 0x%" PRIx64,
989989
current_addr, addr + total_bytes_read);
990+
991+
// Something went wrong and the address is not where it should be
992+
// we'll error out of this Minidump generation.
993+
addDataError = Status::FromErrorStringWithFormat(
994+
"Unexpected address encounterd when reading memory in chunks "
995+
"0x" PRIx64 " expected 0x" PRIx64,
996+
current_addr, addr + total_bytes_read);
997+
return lldb_private::IterationAction::Stop;
990998
}
991999

9921000
// Write to the minidump file with the chunk potentially flushing to

lldb/source/Symbol/SaveCoreOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ llvm::Expected<uint64_t> SaveCoreOptions::GetCurrentSizeInBytes() {
194194
const lldb_private::CoreFileMemoryRanges &core_file_ranges =
195195
*core_file_ranges_maybe;
196196
uint64_t total_in_bytes = 0;
197-
for (auto &core_range : core_file_ranges)
197+
for (const auto &core_range : core_file_ranges)
198198
total_in_bytes += core_range.data.range.size();
199199

200200
return total_in_bytes;

lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump64b.py

Lines changed: 56 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -13,118 +13,95 @@
1313
class ProcessSaveCoreMinidump64bTestCase(TestBase):
1414
def verify_minidump(
1515
self,
16-
core_proc,
17-
live_proc,
1816
options,
1917
):
2018
"""Verify that the minidump is the same byte for byte as the live process."""
21-
# Get the memory regions we saved off in this core, we can't compare to the core
22-
# because we pull from /proc/pid/maps, so even ranges that don't get mapped in will show up
23-
# as ranges in the minidump.
24-
#
25-
# Instead, we have an API that returns to us the number of regions we planned to save from the live process
26-
# and we compare those
27-
memory_regions_to_compare = options.GetMemoryRegionsToSave()
28-
29-
for region in memory_regions_to_compare:
30-
start_addr = region.GetRegionBase()
31-
end_addr = region.GetRegionEnd()
32-
actual_process_read_error = lldb.SBError()
33-
actual = live_proc.ReadMemory(
34-
start_addr, end_addr - start_addr, actual_process_read_error
35-
)
36-
expected_process_read_error = lldb.SBError()
37-
expected = core_proc.ReadMemory(
38-
start_addr, end_addr - start_addr, expected_process_read_error
39-
)
40-
41-
# Both processes could fail to read a given memory region, so if they both pass
42-
# compare, then we'll fail them if the core differs from the live process.
43-
if (
44-
actual_process_read_error.Success()
45-
and expected_process_read_error.Success()
46-
):
47-
self.assertEqual(
48-
actual, expected, "Bytes differ between live process and core"
19+
self.build()
20+
exe = self.getBuildArtifact("a.out")
21+
target = self.dbg.CreateTarget(exe)
22+
core_target = None
23+
live_proc = target.LaunchSimple(
24+
None, None, self.get_process_working_directory()
25+
)
26+
try:
27+
self.assertState(live_proc.GetState(), lldb.eStateStopped)
28+
error = live_proc.SaveCore(options)
29+
self.assertTrue(error.Success(), error.GetCString())
30+
core_target = self.dbg.CreateTarget(None)
31+
core_proc = target.LoadCore(options.GetOutputFile().fullpath)
32+
# Get the memory regions we saved off in this core, we can't compare to the core
33+
# because we pull from /proc/pid/maps, so even ranges that don't get mapped in will show up
34+
# as ranges in the minidump.
35+
#
36+
# Instead, we have an API that returns to us the number of regions we planned to save from the live process
37+
# and we compare those
38+
memory_regions_to_compare = options.GetMemoryRegionsToSave()
39+
40+
for region in memory_regions_to_compare:
41+
start_addr = region.GetRegionBase()
42+
end_addr = region.GetRegionEnd()
43+
actual_process_read_error = lldb.SBError()
44+
actual = live_proc.ReadMemory(
45+
start_addr, end_addr - start_addr, actual_process_read_error
46+
)
47+
expected_process_read_error = lldb.SBError()
48+
expected = core_proc.ReadMemory(
49+
start_addr, end_addr - start_addr, expected_process_read_error
4950
)
5051

51-
# Now we check if the error is the same, error isn't abnormal but they should fail for the same reason
52-
self.assertTrue(
53-
(
52+
# Both processes could fail to read a given memory region, so if they both pass
53+
# compare, then we'll fail them if the core differs from the live process.
54+
if (
5455
actual_process_read_error.Success()
5556
and expected_process_read_error.Success()
57+
):
58+
self.assertEqual(
59+
actual, expected, "Bytes differ between live process and core"
60+
)
61+
62+
# Now we check if the error is the same, error isn't abnormal but they should fail for the same reason
63+
self.assertTrue(
64+
(
65+
actual_process_read_error.Success()
66+
and expected_process_read_error.Success()
67+
)
68+
or (
69+
actual_process_read_error.Fail()
70+
and expected_process_read_error.Fail()
71+
),
72+
f"Address range {hex(start_addr)} - {hex(end_addr)} failed to read from live process and core for different reasons",
5673
)
57-
or (
58-
actual_process_read_error.Fail()
59-
and expected_process_read_error.Fail()
60-
),
61-
f"Address range {hex(start_addr)} - {hex(end_addr)} failed to read from live process and core for different reasons",
62-
)
74+
finally:
75+
self.assertTrue(self.dbg.DeleteTarget(target))
76+
if core_target is not None:
77+
self.assertTrue(self.dbg.DeleteTarget(core_target))
6378

6479
@skipUnlessArch("x86_64")
6580
@skipUnlessPlatform(["linux"])
6681
def test_minidump_save_style_full(self):
6782
"""Test that a full minidump is the same byte for byte."""
68-
69-
self.build()
70-
exe = self.getBuildArtifact("a.out")
7183
minidump_path = self.getBuildArtifact("minidump_full_force64b.dmp")
72-
7384
try:
74-
target = self.dbg.CreateTarget(exe)
75-
live_process = target.LaunchSimple(
76-
None, None, self.get_process_working_directory()
77-
)
78-
self.assertState(live_process.GetState(), lldb.eStateStopped)
7985
options = lldb.SBSaveCoreOptions()
80-
8186
options.SetOutputFile(lldb.SBFileSpec(minidump_path))
8287
options.SetStyle(lldb.eSaveCoreFull)
8388
options.SetPluginName("minidump")
84-
options.SetProcess(live_process)
85-
86-
error = live_process.SaveCore(options)
87-
self.assertTrue(error.Success(), error.GetCString())
88-
89-
target = self.dbg.CreateTarget(None)
90-
core_proc = target.LoadCore(minidump_path)
91-
92-
self.verify_minidump(core_proc, live_process, options)
89+
self.verify_minidump(options)
9390
finally:
94-
self.assertTrue(self.dbg.DeleteTarget(target))
9591
if os.path.isfile(minidump_path):
9692
os.unlink(minidump_path)
9793

9894
@skipUnlessArch("x86_64")
9995
@skipUnlessPlatform(["linux"])
10096
def test_minidump_save_style_mixed_memory(self):
10197
"""Test that a mixed memory minidump is the same byte for byte."""
102-
103-
self.build()
104-
exe = self.getBuildArtifact("a.out")
10598
minidump_path = self.getBuildArtifact("minidump_mixed_force64b.dmp")
106-
10799
try:
108-
target = self.dbg.CreateTarget(exe)
109-
live_process = target.LaunchSimple(
110-
None, None, self.get_process_working_directory()
111-
)
112-
self.assertState(live_process.GetState(), lldb.eStateStopped)
113100
options = lldb.SBSaveCoreOptions()
114-
115101
options.SetOutputFile(lldb.SBFileSpec(minidump_path))
116102
options.SetStyle(lldb.eSaveCoreDirtyOnly)
117103
options.SetPluginName("minidump")
118-
options.SetProcess(live_process)
119-
120-
error = live_process.SaveCore(options)
121-
self.assertTrue(error.Success(), error.GetCString())
122-
123-
target = self.dbg.CreateTarget(None)
124-
core_proc = target.LoadCore(minidump_path)
125-
126-
self.verify_minidump(core_proc, live_process, options)
104+
self.verify_minidump(options)
127105
finally:
128-
self.assertTrue(self.dbg.DeleteTarget(target))
129106
if os.path.isfile(minidump_path):
130107
os.unlink(minidump_path)

0 commit comments

Comments
 (0)