[Go to site: main page, start]

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
16
17#include "Utils.h"
18
19using namespace lldb;
20
23
24 m_opaque_up = std::make_unique<lldb_private::SaveCoreOptions>();
25}
26
32
34
37 LLDB_INSTRUMENT_VA(this, rhs);
38
39 if (this != &rhs)
40 m_opaque_up = clone(rhs.m_opaque_up);
41 return *this;
42}
43
45 LLDB_INSTRUMENT_VA(this, name);
46 return SBError(m_opaque_up->SetPluginName(name));
47}
48
50 LLDB_INSTRUMENT_VA(this, style);
51 m_opaque_up->SetStyle(style);
52}
53
55 LLDB_INSTRUMENT_VA(this, file_spec);
56 m_opaque_up->SetOutputFile(file_spec.ref());
57}
58
61 const auto name = m_opaque_up->GetPluginName();
62 if (!name)
63 return nullptr;
64 return lldb_private::ConstString(name.value()).GetCString();
65}
66
69 const auto file_spec = m_opaque_up->GetOutputFile();
70 if (file_spec)
71 return SBFileSpec(file_spec.value());
72 return SBFileSpec();
73}
74
79
81 LLDB_INSTRUMENT_VA(this, process);
82 return m_opaque_up->SetProcess(process.GetSP());
83}
84
87 return SBProcess(m_opaque_up->GetProcess());
88}
89
91 LLDB_INSTRUMENT_VA(this, thread);
92 return m_opaque_up->AddThread(thread.GetSP());
93}
94
96 LLDB_INSTRUMENT_VA(this, thread);
97 return m_opaque_up->RemoveThread(thread.GetSP());
98}
99
102 LLDB_INSTRUMENT_VA(this, region);
103 // Currently add memory region can't fail, so we always return a success
104 // SBerror, but because these API's live forever, this is the most future
105 // proof thing to do.
106 m_opaque_up->AddMemoryRegionToSave(region.ref());
107 return SBError();
108}
109
111 LLDB_INSTRUMENT_VA(this);
112 lldb::ThreadCollectionSP threadcollection_sp =
113 std::make_shared<lldb_private::ThreadCollection>(
114 m_opaque_up->GetThreadsToSave());
115 return SBThreadCollection(threadcollection_sp);
116}
117
119 LLDB_INSTRUMENT_VA(this);
120 m_opaque_up->Clear();
121}
122
125 llvm::Expected<uint64_t> expected_bytes =
126 m_opaque_up->GetCurrentSizeInBytes();
127 if (!expected_bytes) {
128 error =
129 SBError(lldb_private::Status::FromError(expected_bytes.takeError()));
130 return 0;
131 }
132 // Clear the error, so if the clearer uses it we set it to success.
133 error.Clear();
134 return *expected_bytes;
135}
136
138 LLDB_INSTRUMENT_VA(this);
139 llvm::Expected<lldb_private::CoreFileMemoryRanges> memory_ranges =
140 m_opaque_up->GetMemoryRegionsToSave();
141 if (!memory_ranges) {
142 llvm::consumeError(memory_ranges.takeError());
143 return SBMemoryRegionInfoList();
144 }
145
146 SBMemoryRegionInfoList memory_region_infos;
147 for (const auto &range : *memory_ranges) {
148 SBMemoryRegionInfo region_info(
149 nullptr, range.GetRangeBase(), range.GetRangeEnd(),
150 range.data.lldb_permissions, /*mapped=*/true);
151 memory_region_infos.Append(region_info);
152 }
153
154 return memory_region_infos;
155}
156
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.
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
SBMemoryRegionInfoList GetMemoryRegionsToSave() const
Get an unsorted copy of all memory regions to save.
SBProcess GetProcess() const
Get the process to save, if the process is not set an invalid SBProcess will be returned.
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:136
class LLDB_API SBFileSpec
Definition SBDefines.h:75
class LLDB_API SBMemoryRegionInfoList
Definition SBDefines.h:89
class LLDB_API SBError
Definition SBDefines.h:69
std::shared_ptr< lldb_private::ThreadCollection > ThreadCollectionSP