Skip to content

Commit eee687a

Browse files
Aj0SKwerat
authored andcommitted
[lldb] Add minidump save-core functionality to ELF object files
This change adds save-core functionality into the ObjectFileELF that enables saving minidump of a stopped process. This change is mainly targeting Linux running on x86_64 machines. Minidump should contain basic information needed to examine state of threads, local variables and stack traces. Full support for other platforms is not so far implemented. API tests are using LLDB's MinidumpParser. This relands commit aafa05e, reverted in 1f986f6. Failed tests were fixed. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D108233
1 parent 42ae7eb commit eee687a

File tree

14 files changed

+1206
-10
lines changed

14 files changed

+1206
-10
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ class PluginManager {
192192

193193
static Status SaveCore(const lldb::ProcessSP &process_sp,
194194
const FileSpec &outfile,
195-
lldb::SaveCoreStyle &core_style);
195+
lldb::SaveCoreStyle &core_style,
196+
const ConstString plugin_name);
196197

197198
// ObjectContainer
198199
static bool

lldb/source/API/SBProcess.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,8 @@ lldb::SBError SBProcess::SaveCore(const char *file_name) {
12281228

12291229
FileSpec core_file(file_name);
12301230
SaveCoreStyle core_style = SaveCoreStyle::eSaveCoreFull;
1231-
error.ref() = PluginManager::SaveCore(process_sp, core_file, core_style);
1231+
error.ref() =
1232+
PluginManager::SaveCore(process_sp, core_file, core_style, ConstString());
12321233
return LLDB_RECORD_RESULT(error);
12331234
}
12341235

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,12 +1180,13 @@ static constexpr OptionEnumValues SaveCoreStyles() {
11801180
class CommandObjectProcessSaveCore : public CommandObjectParsed {
11811181
public:
11821182
CommandObjectProcessSaveCore(CommandInterpreter &interpreter)
1183-
: CommandObjectParsed(interpreter, "process save-core",
1184-
"Save the current process as a core file using an "
1185-
"appropriate file type.",
1186-
"process save-core [-s corefile-style] FILE",
1187-
eCommandRequiresProcess | eCommandTryTargetAPILock |
1188-
eCommandProcessMustBeLaunched) {}
1183+
: CommandObjectParsed(
1184+
interpreter, "process save-core",
1185+
"Save the current process as a core file using an "
1186+
"appropriate file type.",
1187+
"process save-core [-s corefile-style -p plugin-name] FILE",
1188+
eCommandRequiresProcess | eCommandTryTargetAPILock |
1189+
eCommandProcessMustBeLaunched) {}
11891190

11901191
~CommandObjectProcessSaveCore() override = default;
11911192

@@ -1208,6 +1209,9 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed {
12081209
Status error;
12091210

12101211
switch (short_option) {
1212+
case 'p':
1213+
m_requested_plugin_name.SetString(option_arg);
1214+
break;
12111215
case 's':
12121216
m_requested_save_core_style =
12131217
(lldb::SaveCoreStyle)OptionArgParser::ToOptionEnum(
@@ -1223,10 +1227,12 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed {
12231227

12241228
void OptionParsingStarting(ExecutionContext *execution_context) override {
12251229
m_requested_save_core_style = eSaveCoreUnspecified;
1230+
m_requested_plugin_name.Clear();
12261231
}
12271232

12281233
// Instance variables to hold the values for command options.
12291234
SaveCoreStyle m_requested_save_core_style;
1235+
ConstString m_requested_plugin_name;
12301236
};
12311237

12321238
protected:
@@ -1237,7 +1243,8 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed {
12371243
FileSpec output_file(command.GetArgumentAtIndex(0));
12381244
SaveCoreStyle corefile_style = m_options.m_requested_save_core_style;
12391245
Status error =
1240-
PluginManager::SaveCore(process_sp, output_file, corefile_style);
1246+
PluginManager::SaveCore(process_sp, output_file, corefile_style,
1247+
m_options.m_requested_plugin_name);
12411248
if (error.Success()) {
12421249
if (corefile_style == SaveCoreStyle::eSaveCoreDirtyOnly ||
12431250
corefile_style == SaveCoreStyle::eSaveCoreStackOnly) {

lldb/source/Commands/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,9 @@ let Command = "process save_core" in {
749749
def process_save_core_style : Option<"style", "s">, Group<1>,
750750
EnumArg<"SaveCoreStyle", "SaveCoreStyles()">, Desc<"Request a specific style "
751751
"of corefile to be saved.">;
752+
def process_save_core_plugin_name : Option<"plugin-name", "p">,
753+
OptionalArg<"Plugin">, Desc<"Specify a plugin name to create the core file."
754+
"This allows core files to be saved in different formats.">;
752755
}
753756

754757
let Command = "process trace save" in {

lldb/source/Core/PluginManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,13 @@ PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
685685

686686
Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
687687
const FileSpec &outfile,
688-
lldb::SaveCoreStyle &core_style) {
688+
lldb::SaveCoreStyle &core_style,
689+
const ConstString plugin_name) {
689690
Status error;
690691
auto &instances = GetObjectFileInstances().GetInstances();
691692
for (auto &instance : instances) {
693+
if (plugin_name && instance.name != plugin_name)
694+
continue;
692695
if (instance.save_core &&
693696
instance.save_core(process_sp, outfile, core_style, error))
694697
return error;

lldb/source/Plugins/ObjectFile/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_subdirectory(Breakpad)
22
add_subdirectory(ELF)
33
add_subdirectory(Mach-O)
4+
add_subdirectory(Minidump)
45
add_subdirectory(PDB)
56
add_subdirectory(PECOFF)
67
add_subdirectory(JIT)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_lldb_library(lldbPluginObjectFileMinidump PLUGIN
2+
ObjectFileMinidump.cpp
3+
MinidumpFileBuilder.cpp
4+
5+
LINK_LIBS
6+
lldbCore
7+
lldbHost
8+
lldbSymbol
9+
lldbTarget
10+
lldbUtility
11+
lldbPluginProcessUtility
12+
LINK_COMPONENTS
13+
Support
14+
)

0 commit comments

Comments
 (0)