Skip to content

Commit 4120570

Browse files
authored
[LLDB][SaveCore] Add SBSaveCoreOptions Object, and SBProcess::SaveCore() overload (llvm#98403)
This PR adds `SBSaveCoreOptions`, which is a container class for options when LLDB is taking coredumps. For this first iteration this container just keeps parity with the extant API of `file, style, plugin`. In the future this options object can be extended to allow users to take a subset of their core dumps.
1 parent 996d31c commit 4120570

30 files changed

+412
-62
lines changed

lldb/bindings/headers.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lldb/API/SBCommandReturnObject.h"
2222
#include "lldb/API/SBCommunication.h"
2323
#include "lldb/API/SBCompileUnit.h"
24+
#include "lldb/API/SBSaveCoreOptions.h"
2425
#include "lldb/API/SBData.h"
2526
#include "lldb/API/SBDebugger.h"
2627
#include "lldb/API/SBDeclaration.h"

lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i

Whitespace-only changes.

lldb/bindings/interfaces.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
%include "./interface/SBCommandReturnObjectDocstrings.i"
2626
%include "./interface/SBCommunicationDocstrings.i"
2727
%include "./interface/SBCompileUnitDocstrings.i"
28+
%include "./interface/SBSaveCoreOptionsDocstrings.i"
2829
%include "./interface/SBDataDocstrings.i"
2930
%include "./interface/SBDebuggerDocstrings.i"
3031
%include "./interface/SBDeclarationDocstrings.i"
@@ -101,6 +102,7 @@
101102
%include "lldb/API/SBCommandReturnObject.h"
102103
%include "lldb/API/SBCommunication.h"
103104
%include "lldb/API/SBCompileUnit.h"
105+
%include "lldb/API/SBSaveCoreOptions.h"
104106
%include "lldb/API/SBData.h"
105107
%include "lldb/API/SBDebugger.h"
106108
%include "lldb/API/SBDeclaration.h"

lldb/include/lldb/API/LLDB.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "lldb/API/SBQueue.h"
5858
#include "lldb/API/SBQueueItem.h"
5959
#include "lldb/API/SBReproducer.h"
60+
#include "lldb/API/SBSaveCoreOptions.h"
6061
#include "lldb/API/SBSection.h"
6162
#include "lldb/API/SBSourceManager.h"
6263
#include "lldb/API/SBStatisticsOptions.h"

lldb/include/lldb/API/SBDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class LLDB_API SBCommandPluginInterface;
6161
class LLDB_API SBCommandReturnObject;
6262
class LLDB_API SBCommunication;
6363
class LLDB_API SBCompileUnit;
64+
class LLDB_API SBSaveCoreOptions;
6465
class LLDB_API SBData;
6566
class LLDB_API SBDebugger;
6667
class LLDB_API SBDeclaration;

lldb/include/lldb/API/SBError.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class LLDB_API SBError {
7777
friend class SBBreakpointName;
7878
friend class SBCommandReturnObject;
7979
friend class SBCommunication;
80+
friend class SBSaveCoreOptions;
8081
friend class SBData;
8182
friend class SBDebugger;
8283
friend class SBFile;

lldb/include/lldb/API/SBFileSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class LLDB_API SBFileSpec {
7878
friend class SBTarget;
7979
friend class SBThread;
8080
friend class SBTrace;
81+
friend class SBSaveCoreOptions;
8182

8283
SBFileSpec(const lldb_private::FileSpec &fspec);
8384

lldb/include/lldb/API/SBProcess.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ class LLDB_API SBProcess {
378378
/// \param[in] file_name - The name of the file to save the core file to.
379379
lldb::SBError SaveCore(const char *file_name);
380380

381+
/// Save the state of the process with the desired settings
382+
/// as defined in the options object.
383+
///
384+
/// \param[in] options - The options to use when saving the core file.
385+
lldb::SBError SaveCore(SBSaveCoreOptions &options);
386+
381387
/// Query the address load_addr and store the details of the memory
382388
/// region that contains it in the supplied SBMemoryRegionInfo object.
383389
/// To iterate over all memory regions use GetMemoryRegionList.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//===-- SBSaveCoreOptions.h -------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_API_SBSAVECOREOPTIONS_H
10+
#define LLDB_API_SBSAVECOREOPTIONS_H
11+
12+
#include "lldb/API/SBDefines.h"
13+
#include "lldb/Symbol/SaveCoreOptions.h"
14+
15+
namespace lldb {
16+
17+
class LLDB_API SBSaveCoreOptions {
18+
public:
19+
SBSaveCoreOptions();
20+
SBSaveCoreOptions(const lldb::SBSaveCoreOptions &rhs);
21+
~SBSaveCoreOptions() = default;
22+
23+
const SBSaveCoreOptions &operator=(const lldb::SBSaveCoreOptions &rhs);
24+
25+
/// Set the plugin name. Supplying null or empty string will reset
26+
/// the option.
27+
///
28+
/// \param plugin Name of the object file plugin.
29+
SBError SetPluginName(const char *plugin);
30+
31+
/// Get the Core dump plugin name, if set.
32+
///
33+
/// \return The name of the plugin, or null if not set.
34+
const char *GetPluginName() const;
35+
36+
/// Set the Core dump style.
37+
///
38+
/// \param style The style of the core dump.
39+
void SetStyle(lldb::SaveCoreStyle style);
40+
41+
/// Get the Core dump style, if set.
42+
///
43+
/// \return The core dump style, or undefined if not set.
44+
lldb::SaveCoreStyle GetStyle() const;
45+
46+
/// Set the output file path
47+
///
48+
/// \param output_file a
49+
/// \class SBFileSpec object that describes the output file.
50+
void SetOutputFile(SBFileSpec output_file);
51+
52+
/// Get the output file spec
53+
///
54+
/// \return The output file spec.
55+
SBFileSpec GetOutputFile() const;
56+
57+
/// Reset all options.
58+
void Clear();
59+
60+
protected:
61+
friend class SBProcess;
62+
lldb_private::SaveCoreOptions &ref() const;
63+
64+
private:
65+
std::unique_ptr<lldb_private::SaveCoreOptions> m_opaque_up;
66+
}; // SBSaveCoreOptions
67+
} // namespace lldb
68+
69+
#endif // LLDB_API_SBSAVECOREOPTIONS_H

lldb/include/lldb/Core/PluginManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class PluginManager {
178178

179179
static bool UnregisterPlugin(ObjectFileCreateInstance create_callback);
180180

181+
static bool IsRegisteredObjectFilePluginName(llvm::StringRef name);
182+
181183
static ObjectFileCreateInstance
182184
GetObjectFileCreateCallbackAtIndex(uint32_t idx);
183185

@@ -191,9 +193,7 @@ class PluginManager {
191193
GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name);
192194

193195
static Status SaveCore(const lldb::ProcessSP &process_sp,
194-
const FileSpec &outfile,
195-
lldb::SaveCoreStyle &core_style,
196-
llvm::StringRef plugin_name);
196+
const lldb_private::SaveCoreOptions &core_options);
197197

198198
// ObjectContainer
199199
static bool RegisterPlugin(

0 commit comments

Comments
 (0)