Skip to content

Commit 29cb63f

Browse files
committed
Reapply "[LLDB][SBSaveCore] Fix bug where default values are not propagated. (llvm#101770)"
This reverts commit 86f7374.
1 parent 6f7bb20 commit 29cb63f

File tree

13 files changed

+45
-21
lines changed

13 files changed

+45
-21
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class PluginManager {
194194
GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name);
195195

196196
static Status SaveCore(const lldb::ProcessSP &process_sp,
197-
const lldb_private::SaveCoreOptions &core_options);
197+
lldb_private::SaveCoreOptions &core_options);
198198

199199
// ObjectContainer
200200
static bool RegisterPlugin(

lldb/include/lldb/lldb-private-interfaces.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef ObjectFile *(*ObjectFileCreateMemoryInstance)(
5757
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
5858
const lldb::ProcessSP &process_sp, lldb::addr_t offset);
5959
typedef bool (*ObjectFileSaveCore)(const lldb::ProcessSP &process_sp,
60-
const lldb_private::SaveCoreOptions &options,
60+
lldb_private::SaveCoreOptions &options,
6161
Status &error);
6262
typedef EmulateInstruction *(*EmulateInstructionCreateInstance)(
6363
const ArchSpec &arch, InstructionType inst_type);

lldb/source/Core/PluginManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
702702
}
703703

704704
Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
705-
const lldb_private::SaveCoreOptions &options) {
705+
lldb_private::SaveCoreOptions &options) {
706706
Status error;
707707
if (!options.GetOutputFile()) {
708708
error.SetErrorString("No output file specified");

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6351,7 +6351,7 @@ static offset_t
63516351
CreateAllImageInfosPayload(const lldb::ProcessSP &process_sp,
63526352
offset_t initial_file_offset,
63536353
StreamString &all_image_infos_payload,
6354-
const lldb_private::SaveCoreOptions &options) {
6354+
lldb_private::SaveCoreOptions &options) {
63556355
Target &target = process_sp->GetTarget();
63566356
ModuleList modules = target.GetImages();
63576357

@@ -6522,16 +6522,17 @@ struct page_object {
65226522
};
65236523

65246524
bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
6525-
const lldb_private::SaveCoreOptions &options,
6525+
lldb_private::SaveCoreOptions &options,
65266526
Status &error) {
6527-
auto core_style = options.GetStyle();
6528-
if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
6529-
core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
65306527
// The FileSpec and Process are already checked in PluginManager::SaveCore.
65316528
assert(options.GetOutputFile().has_value());
65326529
assert(process_sp);
65336530
const FileSpec outfile = options.GetOutputFile().value();
65346531

6532+
// MachO defaults to dirty pages
6533+
if (options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
6534+
options.SetStyle(eSaveCoreDirtyOnly);
6535+
65356536
Target &target = process_sp->GetTarget();
65366537
const ArchSpec target_arch = target.GetArchitecture();
65376538
const llvm::Triple &target_triple = target_arch.GetTriple();

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
6262
lldb_private::ModuleSpecList &specs);
6363

6464
static bool SaveCore(const lldb::ProcessSP &process_sp,
65-
const lldb_private::SaveCoreOptions &options,
65+
lldb_private::SaveCoreOptions &options,
6666
lldb_private::Status &error);
6767

6868
static bool MagicBytesMatch(lldb::DataBufferSP data_sp, lldb::addr_t offset,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class MinidumpFileBuilder {
7676
public:
7777
MinidumpFileBuilder(lldb::FileUP &&core_file,
7878
const lldb::ProcessSP &process_sp,
79-
const lldb_private::SaveCoreOptions &save_core_options)
79+
lldb_private::SaveCoreOptions &save_core_options)
8080
: m_process_sp(process_sp), m_core_file(std::move(core_file)),
8181
m_save_core_options(save_core_options){};
8282

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ size_t ObjectFileMinidump::GetModuleSpecifications(
5656
}
5757

5858
bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP &process_sp,
59-
const lldb_private::SaveCoreOptions &options,
59+
lldb_private::SaveCoreOptions &options,
6060
lldb_private::Status &error) {
6161
// Output file and process_sp are both checked in PluginManager::SaveCore.
6262
assert(options.GetOutputFile().has_value());
6363
assert(process_sp);
6464

6565
// Minidump defaults to stacks only.
66-
SaveCoreStyle core_style = options.GetStyle();
67-
if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
68-
core_style = SaveCoreStyle::eSaveCoreStackOnly;
66+
if (options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
67+
options.SetStyle(SaveCoreStyle::eSaveCoreStackOnly);
6968

7069
llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(
7170
options.GetOutputFile().value(),

lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ObjectFileMinidump : public lldb_private::PluginInterface {
5555

5656
// Saves dump in Minidump file format
5757
static bool SaveCore(const lldb::ProcessSP &process_sp,
58-
const lldb_private::SaveCoreOptions &options,
58+
lldb_private::SaveCoreOptions &options,
5959
lldb_private::Status &error);
6060

6161
private:

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ size_t ObjectFilePECOFF::GetModuleSpecifications(
355355
}
356356

357357
bool ObjectFilePECOFF::SaveCore(const lldb::ProcessSP &process_sp,
358-
const lldb_private::SaveCoreOptions &options,
358+
lldb_private::SaveCoreOptions &options,
359359
lldb_private::Status &error) {
360360
// Outfile and process_sp are validated by PluginManager::SaveCore
361361
assert(options.GetOutputFile().has_value());

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ObjectFilePECOFF : public lldb_private::ObjectFile {
8282
lldb_private::ModuleSpecList &specs);
8383

8484
static bool SaveCore(const lldb::ProcessSP &process_sp,
85-
const lldb_private::SaveCoreOptions &options,
85+
lldb_private::SaveCoreOptions &options,
8686
lldb_private::Status &error);
8787

8888
static bool MagicBytesMatch(lldb::DataBufferSP data_sp);

lldb/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
namespace lldb_private {
2222

2323
bool SaveMiniDump(const lldb::ProcessSP &process_sp,
24-
const SaveCoreOptions &core_options,
25-
lldb_private::Status &error) {
24+
SaveCoreOptions &core_options, lldb_private::Status &error) {
2625
if (!process_sp)
2726
return false;
2827
#ifdef _WIN32

lldb/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
namespace lldb_private {
1515

1616
bool SaveMiniDump(const lldb::ProcessSP &process_sp,
17-
const SaveCoreOptions &core_options,
18-
lldb_private::Status &error);
17+
SaveCoreOptions &core_options, lldb_private::Status &error);
1918

2019
} // namespace lldb_private
2120

lldb/test/API/functionalities/process_save_core/TestProcessSaveCore.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111

1212
class ProcessSaveCoreTestCase(TestBase):
13+
def validate_core_pid(self, pid, core_path):
14+
target = self.dbg.CreateTarget(None)
15+
process = target.LoadCore(core_path)
16+
return process.GetProcessID() == pid
17+
1318
@skipIfRemote
1419
@skipUnlessWindows
1520
def test_cannot_save_core_unless_process_stopped(self):
@@ -88,3 +93,24 @@ def test_save_core_via_process_plugin(self):
8893
os.unlink(core)
8994
except OSError:
9095
pass
96+
97+
@skipUnlessPlatform(["linux"])
98+
def test_save_core_default_values_for_style_minidump(self):
99+
"""Test we can still save a core for minidump when no
100+
core style is specified."""
101+
self.build()
102+
exe = self.getBuildArtifact("a.out")
103+
core = self.getBuildArtifact("core.dmp")
104+
target = self.dbg.CreateTarget(exe)
105+
target.BreakpointCreateByName("bar")
106+
process = target.LaunchSimple(None, None, self.get_process_working_directory())
107+
self.assertState(process.GetState(), lldb.eStateStopped)
108+
pid = process.GetProcessID()
109+
options = lldb.SBSaveCoreOptions()
110+
minidump_path = core + ".minidump"
111+
options.SetOutputFile(lldb.SBFileSpec(minidump_path))
112+
options.SetPluginName("minidump")
113+
error = process.SaveCore(options)
114+
self.assertSuccess(error, error.GetCString())
115+
self.assertTrue(os.path.isfile(minidump_path))
116+
self.assertTrue(self.validate_core_pid(pid, minidump_path))

0 commit comments

Comments
 (0)