LLDB mainline
SaveCoreOptions.cpp
Go to the documentation of this file.
1//===-- SaveCoreOptions.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
11#include "lldb/Target/Process.h"
12#include "lldb/Target/Thread.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
19 if (!name || !name[0]) {
20 m_plugin_name = std::nullopt;
21 return error;
22 }
23
26 "plugin name '%s' is not a valid ObjectFile plugin name", name);
27 return error;
28 }
29
30 m_plugin_name = name;
31 return error;
32}
33
35
37
38std::optional<std::string> SaveCoreOptions::GetPluginName() const {
39 return m_plugin_name;
40}
41
43 return m_style.value_or(lldb::eSaveCoreUnspecified);
44}
45
46const std::optional<lldb_private::FileSpec>
48 return m_file;
49}
50
53 if (!process_sp) {
55 m_process_sp.reset();
56 return error;
57 }
58
59 if (!process_sp->IsValid()) {
60 error = Status::FromErrorString("Cannot assign an invalid process.");
61 return error;
62 }
63
64 // Don't clear any process specific data if the process is the same.
65 if (m_process_sp == process_sp)
66 return error;
67
69 m_process_sp = process_sp;
70 return error;
71}
72
75 if (!thread_sp) {
76 error = Status::FromErrorString("invalid thread");
77 return error;
78 }
79
80 if (m_process_sp) {
81 if (m_process_sp != thread_sp->GetProcess()) {
83 "Cannot add a thread from a different process.");
84 return error;
85 }
86 } else {
87 m_process_sp = thread_sp->GetProcess();
88 }
89
90 m_threads_to_save.insert(thread_sp->GetID());
91 return error;
92}
93
95 return thread_sp && m_threads_to_save.erase(thread_sp->GetID()) > 0;
96}
97
99 // If the user specified no threads to save, then we save all threads.
100 if (m_threads_to_save.empty())
101 return true;
102 return m_threads_to_save.count(tid) > 0;
103}
104
106 return !m_threads_to_save.empty();
107}
108
110 const lldb_private::MemoryRegionInfo &region) {
111 m_regions_to_save.Insert(region.GetRange(), /*combine=*/true);
112}
113
115 return m_regions_to_save;
116}
117
119 lldb::ProcessSP process_sp) const {
121 std::string error_str;
123 error_str += "Cannot save a full core with a subset of threads\n";
124
125 if (m_process_sp && m_process_sp != process_sp)
126 error_str += "Cannot save core for process using supplied core options. "
127 "Options were constructed targeting a different process. \n";
128
129 if (!error_str.empty())
130 error = Status(error_str);
131
132 return error;
133}
134
136 // Deliberately not following the formatter style here to indicate that
137 // this method will be expanded in the future.
138 m_threads_to_save.clear();
139}
140
142 m_file = std::nullopt;
143 m_plugin_name = std::nullopt;
144 m_style = std::nullopt;
145 m_threads_to_save.clear();
146 m_process_sp.reset();
148}
static llvm::raw_ostream & error(Stream &strm)
A file utility class.
Definition: FileSpec.h:56
static bool IsRegisteredObjectFilePluginName(llvm::StringRef name)
void Insert(const Entry &entry, bool combine)
Definition: RangeMap.h:185
Status SetProcess(lldb::ProcessSP process_sp)
lldb_private::Status SetPluginName(const char *name)
bool RemoveThread(lldb::ThreadSP thread_sp)
const std::optional< lldb_private::FileSpec > GetOutputFile() const
lldb::SaveCoreStyle GetStyle() const
Status AddThread(lldb::ThreadSP thread_sp)
std::optional< std::string > m_plugin_name
void SetStyle(lldb::SaveCoreStyle style)
void AddMemoryRegionToSave(const lldb_private::MemoryRegionInfo &region)
std::optional< std::string > GetPluginName() const
const MemoryRanges & GetCoreFileMemoryRanges() const
std::optional< lldb::SaveCoreStyle > m_style
void SetOutputFile(lldb_private::FileSpec file)
std::unordered_set< lldb::tid_t > m_threads_to_save
Status EnsureValidConfiguration(lldb::ProcessSP process_sp) const
bool ShouldThreadBeSaved(lldb::tid_t tid) const
std::optional< lldb_private::FileSpec > m_file
An error handling class.
Definition: Status.h:115
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:138
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
@ eSaveCoreUnspecified
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
uint64_t tid_t
Definition: lldb-types.h:84