Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/bindings/headers.swig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/API/SBCommunication.h"
#include "lldb/API/SBCompileUnit.h"
#include "lldb/API/SBCoreDumpOptions.h"
#include "lldb/API/SBData.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBDeclaration.h"
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions lldb/bindings/interfaces.swig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
%include "./interface/SBCommandReturnObjectDocstrings.i"
%include "./interface/SBCommunicationDocstrings.i"
%include "./interface/SBCompileUnitDocstrings.i"
%include "./interface/SBCoreDumpOptionsDocstrings.i"
%include "./interface/SBDataDocstrings.i"
%include "./interface/SBDebuggerDocstrings.i"
%include "./interface/SBDeclarationDocstrings.i"
Expand Down Expand Up @@ -101,6 +102,7 @@
%include "lldb/API/SBCommandReturnObject.h"
%include "lldb/API/SBCommunication.h"
%include "lldb/API/SBCompileUnit.h"
%include "lldb/API/SBCoreDumpOptions.h"
%include "lldb/API/SBData.h"
%include "lldb/API/SBDebugger.h"
%include "lldb/API/SBDeclaration.h"
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/API/LLDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/API/SBCommunication.h"
#include "lldb/API/SBCompileUnit.h"
#include "lldb/API/SBCoreDumpOptions.h"
#include "lldb/API/SBData.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBDeclaration.h"
Expand Down
68 changes: 68 additions & 0 deletions lldb/include/lldb/API/SBCoreDumpOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//===-- 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 {
Copy link
Collaborator

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? SBCoreDumpOptions seems like they would be used to dump a core dump to the terminal?

public:
SBCoreDumpOptions();
SBCoreDumpOptions(const lldb::SBCoreDumpOptions &rhs);
~SBCoreDumpOptions() = default;

const SBCoreDumpOptions &operator=(const lldb::SBCoreDumpOptions &rhs);

/// Set the plugin name.
///
/// \param plugin Name of the object file plugin.
SBError SetPluginName(const char *plugin);

/// Get the Core dump plugin name, if set.
///
/// \return The name of the plugin, or null if not set.
const char *GetPluginName() const;

/// Set the Core dump style.
///
/// \param style The style of the core dump.
void SetStyle(lldb::SaveCoreStyle style);

/// Get the Core dump style, if set.
///
/// \return The core dump style, or undefined if not set.
lldb::SaveCoreStyle GetStyle() const;

/// Set the output file path
///
/// \param output_file a
/// \class SBFileSpec object that describes the output file.
void SetOutputFile(SBFileSpec output_file);

/// Get the output file spec
///
/// \return The output file spec.
SBFileSpec GetOutputFile() const;

/// Reset all options.
void Clear();

protected:
friend class SBProcess;
lldb_private::CoreDumpOptions &ref() const;

private:
std::unique_ptr<lldb_private::CoreDumpOptions> m_opaque_up;
}; // SBCoreDumpOptions
} // namespace lldb

#endif // LLDB_API_SBCOREDUMPOPTIONS_H
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class LLDB_API SBCommandPluginInterface;
class LLDB_API SBCommandReturnObject;
class LLDB_API SBCommunication;
class LLDB_API SBCompileUnit;
class LLDB_API SBCoreDumpOptions;
class LLDB_API SBData;
class LLDB_API SBDebugger;
class LLDB_API SBDeclaration;
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBError.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LLDB_API SBError {
friend class SBBreakpointName;
friend class SBCommandReturnObject;
friend class SBCommunication;
friend class SBCoreDumpOptions;
friend class SBData;
friend class SBDebugger;
friend class SBFile;
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBFileSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class LLDB_API SBFileSpec {
friend class SBTarget;
friend class SBThread;
friend class SBTrace;
friend class SBCoreDumpOptions;

SBFileSpec(const lldb_private::FileSpec &fspec);

Expand Down
6 changes: 6 additions & 0 deletions lldb/include/lldb/API/SBProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ class LLDB_API SBProcess {
/// \param[in] file_name - The name of the file to save the core file to.
lldb::SBError SaveCore(const char *file_name);

/// Save the state of the process with the desired settings
/// as defined in the options object.
///
/// \param[in] options - The options to use when saving the core file.
lldb::SBError SaveCore(SBCoreDumpOptions &options);

/// Query the address load_addr and store the details of the memory
/// region that contains it in the supplied SBMemoryRegionInfo object.
/// To iterate over all memory regions use GetMemoryRegionList.
Expand Down
6 changes: 3 additions & 3 deletions lldb/include/lldb/Core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class PluginManager {

static bool UnregisterPlugin(ObjectFileCreateInstance create_callback);

static bool IsRegisteredPluginName(const char *name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function name needs to be more complete to say we are searching for a valid object file plug-in name because we have many different kinds of plugins use the same type as the way names are stored, so use llvm::StringRef:

static bool IsRegisteredObjectFilePluginName(llvm::StringRef name);


static ObjectFileCreateInstance
GetObjectFileCreateCallbackAtIndex(uint32_t idx);

Expand All @@ -191,9 +193,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);
const lldb_private::CoreDumpOptions &core_options);

// ObjectContainer
static bool RegisterPlugin(
Expand Down
44 changes: 44 additions & 0 deletions lldb/include/lldb/Symbol/CoreDumpOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===-- 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we rename SBCoreDumpOptions to SBSaveCoreOptions, this should become SaveCoreOptions

public:
CoreDumpOptions(){};
~CoreDumpOptions() = default;

lldb_private::Status SetPluginName(const char *name);
std::optional<std::string> GetPluginName() const;

void SetStyle(lldb::SaveCoreStyle style);
lldb::SaveCoreStyle GetStyle() const;

void SetOutputFile(lldb_private::FileSpec file);
const std::optional<lldb_private::FileSpec> GetOutputFile() const;

void Clear();

private:
std::optional<std::string> m_plugin_name;
std::optional<lldb_private::FileSpec> m_file;
std::optional<lldb::SaveCoreStyle> m_style;
};
} // namespace lldb_private

#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_COREDUMPOPTIONS_H
4 changes: 2 additions & 2 deletions lldb/include/lldb/lldb-private-interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
const lldb_private::CoreDumpOptions &options,
Status &error);
typedef EmulateInstruction *(*EmulateInstructionCreateInstance)(
const ArchSpec &arch, InstructionType inst_type);
Expand Down
1 change: 1 addition & 0 deletions lldb/source/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
SBCommandReturnObject.cpp
SBCommunication.cpp
SBCompileUnit.cpp
SBCoreDumpOptions.cpp
SBData.cpp
SBDebugger.cpp
SBDeclaration.cpp
Expand Down
76 changes: 76 additions & 0 deletions lldb/source/API/SBCoreDumpOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//===-- 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/API/SBError.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Symbol/CoreDumpOptions.h"
#include "lldb/Utility/Instrumentation.h"

#include "Utils.h"

using namespace lldb;

SBCoreDumpOptions::SBCoreDumpOptions() {
LLDB_INSTRUMENT_VA(this)

m_opaque_up = std::make_unique<lldb_private::CoreDumpOptions>();
}

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;
}

SBError SBCoreDumpOptions::SetPluginName(const char *name) {
lldb_private::Status error = m_opaque_up->SetPluginName(name);
return SBError(error);
}

void SBCoreDumpOptions::SetStyle(lldb::SaveCoreStyle style) {
m_opaque_up->SetStyle(style);
}

void SBCoreDumpOptions::SetOutputFile(lldb::SBFileSpec file_spec) {
m_opaque_up->SetOutputFile(file_spec.ref());
}

const char *SBCoreDumpOptions::GetPluginName() const {
const auto name = m_opaque_up->GetPluginName();
if (!name)
return nullptr;
return lldb_private::ConstString(name.value()).GetCString();
}

SBFileSpec SBCoreDumpOptions::GetOutputFile() const {
const auto file_spec = m_opaque_up->GetOutputFile();
if (file_spec)
return SBFileSpec(file_spec.value());
return SBFileSpec();
}

lldb::SaveCoreStyle SBCoreDumpOptions::GetStyle() const {
return m_opaque_up->GetStyle();
}

lldb_private::CoreDumpOptions &SBCoreDumpOptions::ref() const {
return *m_opaque_up.get();
}

void SBCoreDumpOptions::Clear() { m_opaque_up->Clear(); }
17 changes: 12 additions & 5 deletions lldb/source/API/SBProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1222,7 +1223,16 @@ 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;
options.SetOutputFile(SBFileSpec(file_name));
options.SetPluginName(flavor);
options.SetStyle(core_style);
return SaveCore(options);
}

lldb::SBError SBProcess::SaveCore(SBCoreDumpOptions &options) {

LLDB_INSTRUMENT_VA(this, options);

lldb::SBError error;
ProcessSP process_sp(GetSP());
Expand All @@ -1239,10 +1249,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;
}
Expand Down
Loading