LLDB mainline
SBSaveCoreOptions.cpp
Go to the documentation of this file.
1//===-- SBSaveCoreOptions.cpp -----------------------------------*- 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
15
16#include "Utils.h"
17
18using namespace lldb;
19
22
23 m_opaque_up = std::make_unique<lldb_private::SaveCoreOptions>();
24}
25
31
33
36 LLDB_INSTRUMENT_VA(this, rhs);
37
38 if (this != &rhs)
39 m_opaque_up = clone(rhs.m_opaque_up);
40 return *this;
41}
42
44 LLDB_INSTRUMENT_VA(this, name);
45 return SBError(m_opaque_up->SetPluginName(name));
46}
47
49 LLDB_INSTRUMENT_VA(this, style);
50 m_opaque_up->SetStyle(style);
51}
52
54 LLDB_INSTRUMENT_VA(this, file_spec);
55 m_opaque_up->SetOutputFile(file_spec.ref());
56}
57
60 const auto name = m_opaque_up->GetPluginName();
61 if (!name)
62 return nullptr;
63 return lldb_private::ConstString(name.value()).GetCString();
64}
65
68 const auto file_spec = m_opaque_up->GetOutputFile();
69 if (file_spec)
70 return SBFileSpec(file_spec.value());
71 return SBFileSpec();
72}
73
78
80 LLDB_INSTRUMENT_VA(this, process);
81 return m_opaque_up->SetProcess(process.GetSP());
82}
83
88
90 LLDB_INSTRUMENT_VA(this, thread);
91 return m_opaque_up->AddThread(thread.GetSP());
92}
93
95 LLDB_INSTRUMENT_VA(this, thread);
96 return m_opaque_up->RemoveThread(thread.GetSP());
97}
98
101 LLDB_INSTRUMENT_VA(this, region);
102 // Currently add memory region can't fail, so we always return a success
103 // SBerror, but because these API's live forever, this is the most future
104 // proof thing to do.
105 m_opaque_up->AddMemoryRegionToSave(region.ref());
106 return SBError();
107}
108
110 LLDB_INSTRUMENT_VA(this);
111 lldb::ThreadCollectionSP threadcollection_sp =
112 std::make_shared<lldb_private::ThreadCollection>(
113 m_opaque_up->GetThreadsToSave());
114 return SBThreadCollection(threadcollection_sp);
115}
116
118 LLDB_INSTRUMENT_VA(this);
119 m_opaque_up->Clear();
120}
121
124 llvm::Expected<uint64_t> expected_bytes =
125 m_opaque_up->GetCurrentSizeInBytes();
126 if (!expected_bytes) {
127 error =
128 SBError(lldb_private::Status::FromError(expected_bytes.takeError()));
129 return 0;
130 }
131 // Clear the error, so if the clearer uses it we set it to success.
132 error.Clear();
133 return *expected_bytes;
134}
135
137 LLDB_INSTRUMENT_VA(this);
138 llvm::Expected<lldb_private::CoreFileMemoryRanges> memory_ranges =
139 m_opaque_up->GetMemoryRegionsToSave();
140 if (!memory_ranges) {
141 llvm::consumeError(memory_ranges.takeError());
142 return SBMemoryRegionInfoList();
143 }
144
145 SBMemoryRegionInfoList memory_region_infos;
146 for (const auto &range : *memory_ranges) {
147 SBMemoryRegionInfo region_info(
148 nullptr, range.GetRangeBase(), range.GetRangeEnd(),
149 range.data.lldb_permissions, /*mapped=*/true);
150 memory_region_infos.Append(region_info);
151 }
152
153 return memory_region_infos;
154}
155
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT_VA(...)
const lldb_private::FileSpec & ref() const
void Append(lldb::SBMemoryRegionInfo &region)
lldb_private::MemoryRegionInfo & ref()
lldb::ProcessSP GetSP() const
SBThreadCollection GetThreadsToSave() const
Get an unsorted copy of all threads to save.
bool RemoveThread(lldb::SBThread thread)
Remove a thread from the list of threads to save.
void SetStyle(lldb::SaveCoreStyle style)
Set the Core dump style.
const SBSaveCoreOptions & operator=(const lldb::SBSaveCoreOptions &rhs)
void Clear()
Reset all options.
void SetOutputFile(SBFileSpec output_file)
Set the output file path.
lldb_private::SaveCoreOptions & ref() const
uint64_t GetCurrentSizeInBytes(SBError &error)
Get the current total number of bytes the core is expected to have excluding the overhead of the core...
SBError SetProcess(lldb::SBProcess process)
Set the process to save, or unset if supplied with a default constructed process.
SBProcess GetProcess()
Get the process to save, if the process is not set an invalid SBProcess will be returned.
SBMemoryRegionInfoList GetMemoryRegionsToSave()
Get an unsorted copy of all memory regions to save.
SBError AddMemoryRegionToSave(const SBMemoryRegionInfo &region)
Add a memory region to save in the core file.
SBError AddThread(lldb::SBThread thread)
Add a thread to save in the core file.
const char * GetPluginName() const
Get the Core dump plugin name, if set.
lldb::SaveCoreStyle GetStyle() const
Get the Core dump style, if set.
SBError SetPluginName(const char *plugin)
Set the plugin name.
std::unique_ptr< lldb_private::SaveCoreOptions > m_opaque_up
SBFileSpec GetOutputFile() const
Get the output file spec.
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:137
class LLDB_API SBFileSpec
Definition SBDefines.h:75
class LLDB_API SBMemoryRegionInfoList
Definition SBDefines.h:88
class LLDB_API SBError
Definition SBDefines.h:69
std::shared_ptr< lldb_private::ThreadCollection > ThreadCollectionSP