-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[LLDB][SaveCore] Add SBSaveCoreOptions Object, and SBProcess::SaveCore() overload #98403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
4752ada
3acae92
e842579
2673674
92bc0b3
d4d702d
117d71a
06c0538
21df337
b2f6d60
1785ad3
6edb284
1e95cc7
d555d84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| //===-- SBCoreDumpOptions.h -------------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLDB_API_SBCOREDUMPOPTIONS_H | ||
| #define LLDB_API_SBCOREDUMPOPTIONS_H | ||
|
|
||
| #include "lldb/API/SBDefines.h" | ||
| #include "lldb/Symbol/CoreDumpOptions.h" | ||
|
|
||
| namespace lldb { | ||
|
|
||
| class LLDB_API SBCoreDumpOptions { | ||
| public: | ||
| SBCoreDumpOptions(const char *filePath); | ||
|
||
| SBCoreDumpOptions(const lldb::SBCoreDumpOptions &rhs); | ||
| ~SBCoreDumpOptions() = default; | ||
|
|
||
| const SBCoreDumpOptions &operator=(const lldb::SBCoreDumpOptions &rhs); | ||
|
|
||
| /// Set the Core dump plugin name. | ||
| /// | ||
| /// \param plugin Name of the object file plugin. | ||
| void SetCoreDumpPluginName(const char *plugin); | ||
Jlalond marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Jlalond marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Get the Core dump plugin name, if set. | ||
| /// | ||
| /// \return The name of the plugin, or nullopt if not set. | ||
| const std::optional<const char *> GetCoreDumpPluginName() const; | ||
|
||
|
|
||
| /// Set the Core dump style. | ||
| /// | ||
| /// \param style The style of the core dump. | ||
| void SetCoreDumpStyle(lldb::SaveCoreStyle style); | ||
|
|
||
| /// Get the Core dump style, if set. | ||
| /// | ||
| /// \return The core dump style, or nullopt if not set. | ||
| const std::optional<lldb::SaveCoreStyle> GetCoreDumpStyle() const; | ||
|
||
|
|
||
| /// Get the output file path | ||
| /// | ||
| /// \return The output file path. | ||
| const char *GetOutputFile() const; | ||
|
||
|
|
||
| protected: | ||
| friend class SBProcess; | ||
| lldb_private::CoreDumpOptions &Ref() const; | ||
Jlalond marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| std::unique_ptr<lldb_private::CoreDumpOptions> m_opaque_up; | ||
| }; // SBCoreDumpOptions | ||
| } // namespace lldb | ||
|
|
||
| #endif // LLDB_API_SBCOREDUMPOPTIONS_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,9 +191,7 @@ class PluginManager { | |
| GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name); | ||
|
|
||
| static Status SaveCore(const lldb::ProcessSP &process_sp, | ||
| const FileSpec &outfile, | ||
| lldb::SaveCoreStyle &core_style, | ||
| llvm::StringRef plugin_name); | ||
| lldb_private::CoreDumpOptions &core_options); | ||
|
||
|
|
||
| // ObjectContainer | ||
| static bool RegisterPlugin( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| //===-- CoreDumpOptions.h ---------------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_COREDUMPOPTIONS_H | ||
| #define LLDB_SOURCE_PLUGINS_OBJECTFILE_COREDUMPOPTIONS_H | ||
|
|
||
| #include "lldb/Utility/FileSpec.h" | ||
| #include "lldb/lldb-forward.h" | ||
| #include "lldb/lldb-types.h" | ||
|
|
||
| #include <optional> | ||
| #include <string> | ||
|
|
||
| namespace lldb_private { | ||
|
|
||
| class CoreDumpOptions { | ||
|
||
| public: | ||
| CoreDumpOptions(const lldb_private::FileSpec &fspec) | ||
|
||
| : m_core_dump_file(std::move(fspec)){}; | ||
| ~CoreDumpOptions() = default; | ||
|
|
||
| void SetCoreDumpPluginName(llvm::StringRef name); | ||
| std::optional<llvm::StringRef> GetCoreDumpPluginName() const; | ||
|
||
|
|
||
| void SetCoreDumpStyle(lldb::SaveCoreStyle style); | ||
| lldb::SaveCoreStyle GetCoreDumpStyle() const; | ||
|
|
||
| const lldb_private::FileSpec &GetOutputFile() const; | ||
|
||
|
|
||
| private: | ||
| std::optional<std::string> m_core_dump_plugin_name; | ||
|
||
| const lldb_private::FileSpec m_core_dump_file; | ||
|
||
| lldb::SaveCoreStyle m_core_dump_style = lldb::eSaveCoreUnspecified; | ||
|
||
| }; | ||
| } // namespace lldb_private | ||
|
|
||
| #endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_COREDUMPOPTIONS_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| #ifndef LLDB_LLDB_PRIVATE_INTERFACES_H | ||
| #define LLDB_LLDB_PRIVATE_INTERFACES_H | ||
|
|
||
| #include "lldb/Symbol/CoreDumpOptions.h" | ||
| #include "lldb/lldb-enumerations.h" | ||
| #include "lldb/lldb-forward.h" | ||
| #include "lldb/lldb-private-enumerations.h" | ||
|
|
@@ -55,8 +56,7 @@ typedef ObjectFile *(*ObjectFileCreateMemoryInstance)( | |
| const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, | ||
| const lldb::ProcessSP &process_sp, lldb::addr_t offset); | ||
| typedef bool (*ObjectFileSaveCore)(const lldb::ProcessSP &process_sp, | ||
| const FileSpec &outfile, | ||
| lldb::SaveCoreStyle &core_style, | ||
| lldb_private::CoreDumpOptions &core_options, | ||
|
||
| Status &error); | ||
| typedef EmulateInstruction *(*EmulateInstructionCreateInstance)( | ||
| const ArchSpec &arch, InstructionType inst_type); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //===-- SBCoreDumpOptions.cpp -----------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "lldb/API/SBCoreDumpOptions.h" | ||
| #include "lldb/Host/FileSystem.h" | ||
| #include "lldb/Symbol/CoreDumpOptions.h" | ||
| #include "lldb/Utility/Instrumentation.h" | ||
|
|
||
| #include "Utils.h" | ||
|
|
||
| using namespace lldb; | ||
|
|
||
| SBCoreDumpOptions::SBCoreDumpOptions(const char *filePath) { | ||
| LLDB_INSTRUMENT_VA(this, filePath); | ||
| lldb_private::FileSpec fspec(filePath); | ||
| lldb_private::FileSystem::Instance().Resolve(fspec); | ||
| m_opaque_up = std::make_unique<lldb_private::CoreDumpOptions>(fspec); | ||
| } | ||
|
|
||
| SBCoreDumpOptions::SBCoreDumpOptions(const SBCoreDumpOptions &rhs) { | ||
| LLDB_INSTRUMENT_VA(this, rhs); | ||
|
|
||
| m_opaque_up = clone(rhs.m_opaque_up); | ||
| } | ||
|
|
||
| const SBCoreDumpOptions & | ||
| SBCoreDumpOptions::operator=(const SBCoreDumpOptions &rhs) { | ||
| LLDB_INSTRUMENT_VA(this, rhs); | ||
|
|
||
| if (this != &rhs) | ||
| m_opaque_up = clone(rhs.m_opaque_up); | ||
| return *this; | ||
| } | ||
|
|
||
| void SBCoreDumpOptions::SetCoreDumpPluginName(const char *name) { | ||
| m_opaque_up->SetCoreDumpPluginName(name); | ||
| } | ||
|
|
||
| void SBCoreDumpOptions::SetCoreDumpStyle(lldb::SaveCoreStyle style) { | ||
| m_opaque_up->SetCoreDumpStyle(style); | ||
| } | ||
|
|
||
| const std::optional<const char *> | ||
| SBCoreDumpOptions::GetCoreDumpPluginName() const { | ||
| const auto &name = m_opaque_up->GetCoreDumpPluginName(); | ||
|
||
| if (name->empty()) | ||
| return std::nullopt; | ||
| return name->data(); | ||
| } | ||
|
|
||
| const char *SBCoreDumpOptions::GetOutputFile() const { | ||
| return m_opaque_up->GetOutputFile().GetFilename().AsCString(); | ||
| } | ||
|
||
|
|
||
| const std::optional<lldb::SaveCoreStyle> | ||
|
||
| SBCoreDumpOptions::GetCoreDumpStyle() const { | ||
| return m_opaque_up->GetCoreDumpStyle(); | ||
| } | ||
|
|
||
| lldb_private::CoreDumpOptions &SBCoreDumpOptions::Ref() const { | ||
| return *m_opaque_up.get(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
|
|
||
| #include "lldb/API/SBBroadcaster.h" | ||
| #include "lldb/API/SBCommandReturnObject.h" | ||
| #include "lldb/API/SBCoreDumpOptions.h" | ||
| #include "lldb/API/SBDebugger.h" | ||
| #include "lldb/API/SBEvent.h" | ||
| #include "lldb/API/SBFile.h" | ||
|
|
@@ -1222,7 +1223,17 @@ lldb::SBError SBProcess::SaveCore(const char *file_name) { | |
| lldb::SBError SBProcess::SaveCore(const char *file_name, | ||
| const char *flavor, | ||
| SaveCoreStyle core_style) { | ||
| LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style); | ||
| SBCoreDumpOptions options(file_name); | ||
|
||
| options.SetCoreDumpPluginName(flavor); | ||
| options.SetCoreDumpStyle(core_style); | ||
| return SaveCore(options); | ||
| } | ||
|
|
||
| lldb::SBError SBProcess::SaveCore(SBCoreDumpOptions &options) { | ||
|
|
||
| LLDB_INSTRUMENT_VA(this, options.GetOutputFile(), | ||
| options.GetCoreDumpPluginName(), | ||
| options.GetCoreDumpStyle()); | ||
Jlalond marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| lldb::SBError error; | ||
| ProcessSP process_sp(GetSP()); | ||
|
|
@@ -1239,10 +1250,7 @@ lldb::SBError SBProcess::SaveCore(const char *file_name, | |
| return error; | ||
| } | ||
|
|
||
| FileSpec core_file(file_name); | ||
| FileSystem::Instance().Resolve(core_file); | ||
| error.ref() = PluginManager::SaveCore(process_sp, core_file, core_style, | ||
| flavor); | ||
| error.ref() = PluginManager::SaveCore(process_sp, options.Ref()); | ||
|
|
||
| return error; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1304,9 +1304,11 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed { | |
| FileSpec output_file(command.GetArgumentAtIndex(0)); | ||
| FileSystem::Instance().Resolve(output_file); | ||
| SaveCoreStyle corefile_style = m_options.m_requested_save_core_style; | ||
| Status error = | ||
| PluginManager::SaveCore(process_sp, output_file, corefile_style, | ||
| m_options.m_requested_plugin_name); | ||
| CoreDumpOptions core_dump_options(output_file); | ||
| core_dump_options.SetCoreDumpPluginName( | ||
| m_options.m_requested_plugin_name); | ||
| core_dump_options.SetCoreDumpStyle(corefile_style); | ||
| Status error = PluginManager::SaveCore(process_sp, core_dump_options); | ||
|
||
| if (error.Success()) { | ||
| if (corefile_style == SaveCoreStyle::eSaveCoreDirtyOnly || | ||
| corefile_style == SaveCoreStyle::eSaveCoreStackOnly) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| #include "lldb/Host/FileSystem.h" | ||
| #include "lldb/Host/HostInfo.h" | ||
| #include "lldb/Interpreter/OptionValueProperties.h" | ||
| #include "lldb/Symbol/CoreDumpOptions.h" | ||
| #include "lldb/Target/Process.h" | ||
| #include "lldb/Utility/FileSpec.h" | ||
| #include "lldb/Utility/Status.h" | ||
|
|
@@ -689,12 +690,11 @@ PluginManager::GetObjectFileCreateMemoryCallbackForPluginName( | |
| } | ||
|
|
||
| Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp, | ||
| const FileSpec &outfile, | ||
| lldb::SaveCoreStyle &core_style, | ||
| llvm::StringRef plugin_name) { | ||
| if (plugin_name.empty()) { | ||
| lldb_private::CoreDumpOptions &options) { | ||
|
||
| if (options.GetCoreDumpPluginName()->empty()) { | ||
Jlalond marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Try saving core directly from the process plugin first. | ||
| llvm::Expected<bool> ret = process_sp->SaveCore(outfile.GetPath()); | ||
| llvm::Expected<bool> ret = | ||
| process_sp->SaveCore(options.GetOutputFile().GetPath()); | ||
| if (!ret) | ||
| return Status(ret.takeError()); | ||
| if (ret.get()) | ||
|
|
@@ -705,14 +705,18 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp, | |
| Status error; | ||
| auto &instances = GetObjectFileInstances().GetInstances(); | ||
Jlalond marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (auto &instance : instances) { | ||
| if (plugin_name.empty() || instance.name == plugin_name) { | ||
| if (instance.save_core && | ||
| instance.save_core(process_sp, outfile, core_style, error)) | ||
| if (options.GetCoreDumpPluginName()->empty() || | ||
Jlalond marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| instance.name == options.GetCoreDumpPluginName()) { | ||
| if (instance.save_core && instance.save_core(process_sp, options, error)) | ||
| return error; | ||
| } | ||
| } | ||
| error.SetErrorString( | ||
| "no ObjectFile plugins were able to save a core for this process"); | ||
|
|
||
| // Check to see if any of the object file plugins tried and failed to save. | ||
| // If none ran, set the error message. | ||
| if (error.Success()) | ||
| error.SetErrorString( | ||
| "no ObjectFile plugins were able to save a core for this process"); | ||
| return error; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6519,8 +6519,10 @@ struct page_object { | |
| }; | ||
|
|
||
| bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp, | ||
| const FileSpec &outfile, | ||
| lldb::SaveCoreStyle &core_style, Status &error) { | ||
| lldb_private::CoreDumpOptions &core_options, | ||
|
||
| Status &error) { | ||
| auto core_style = core_options.GetCoreDumpStyle(); | ||
| const auto outfile = core_options.GetOutputFile(); | ||
Jlalond marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!process_sp) | ||
| return false; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,8 +62,7 @@ class ObjectFileMachO : public lldb_private::ObjectFile { | |
| lldb_private::ModuleSpecList &specs); | ||
|
|
||
| static bool SaveCore(const lldb::ProcessSP &process_sp, | ||
| const lldb_private::FileSpec &outfile, | ||
| lldb::SaveCoreStyle &core_style, | ||
| lldb_private::CoreDumpOptions &core_options, | ||
|
||
| lldb_private::Status &error); | ||
|
|
||
| static bool MagicBytesMatch(lldb::DataBufferSP data_sp, lldb::addr_t offset, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change the name to
SBSaveCoreOptions?SBCoreDumpOptionsseems like they would be used to dump a core dump to the terminal?