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
25 error.SetErrorStringWithFormat(
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.SetErrorString("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.SetErrorString("invalid thread");
77 return error;
78 }
79
80 if (m_process_sp) {
81 if (m_process_sp != thread_sp->GetProcess()) {
82 error.SetErrorString("Cannot add a thread from a different process.");
83 return error;
84 }
85 } else {
86 m_process_sp = thread_sp->GetProcess();
87 }
88
89 m_threads_to_save.insert(thread_sp->GetID());
90 return error;
91}
92
94 return thread_sp && m_threads_to_save.erase(thread_sp->GetID()) > 0;
95}
96
98 // If the user specified no threads to save, then we save all threads.
99 if (m_threads_to_save.empty())
100 return true;
101 return m_threads_to_save.count(tid) > 0;
102}
103
105 lldb::ProcessSP process_sp) const {
107 std::string error_str;
109 error_str += "Cannot save a full core with a subset of threads\n";
110
111 if (m_process_sp && m_process_sp != process_sp)
112 error_str += "Cannot save core for process using supplied core options. "
113 "Options were constructed targeting a different process. \n";
114
115 if (!error_str.empty())
116 error.SetErrorString(error_str);
117
118 return error;
119}
120
122 // Deliberately not following the formatter style here to indicate that
123 // this method will be expanded in the future.
124 m_threads_to_save.clear();
125}
126
128 m_file = std::nullopt;
129 m_plugin_name = std::nullopt;
130 m_style = std::nullopt;
131 m_threads_to_save.clear();
132 m_process_sp.reset();
133}
static llvm::raw_ostream & error(Stream &strm)
A file utility class.
Definition: FileSpec.h:56
static bool IsRegisteredObjectFilePluginName(llvm::StringRef name)
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)
std::optional< std::string > GetPluginName() 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:44
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:446
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
uint64_t tid_t
Definition: lldb-types.h:84