[mlir][int-range] Limit xor int range inference to i1 (#116968)
[llvm-project.git] / lldb / source / Symbol / SaveCoreOptions.cpp
blob8d9aadece2152dd5526050ea58226452284e523c
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 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/SaveCoreOptions.h"
10 #include "lldb/Core/PluginManager.h"
11 #include "lldb/Target/Process.h"
12 #include "lldb/Target/Thread.h"
14 using namespace lldb;
15 using namespace lldb_private;
17 Status SaveCoreOptions::SetPluginName(const char *name) {
18 Status error;
19 if (!name || !name[0]) {
20 m_plugin_name = std::nullopt;
21 return error;
24 if (!PluginManager::IsRegisteredObjectFilePluginName(name)) {
25 return Status::FromErrorStringWithFormat(
26 "plugin name '%s' is not a valid ObjectFile plugin name", name);
27 return error;
30 m_plugin_name = name;
31 return error;
34 void SaveCoreOptions::SetStyle(lldb::SaveCoreStyle style) { m_style = style; }
36 void SaveCoreOptions::SetOutputFile(FileSpec file) { m_file = file; }
38 std::optional<std::string> SaveCoreOptions::GetPluginName() const {
39 return m_plugin_name;
42 lldb::SaveCoreStyle SaveCoreOptions::GetStyle() const {
43 return m_style.value_or(lldb::eSaveCoreUnspecified);
46 const std::optional<lldb_private::FileSpec>
47 SaveCoreOptions::GetOutputFile() const {
48 return m_file;
51 Status SaveCoreOptions::SetProcess(lldb::ProcessSP process_sp) {
52 Status error;
53 if (!process_sp) {
54 ClearProcessSpecificData();
55 m_process_sp.reset();
56 return error;
59 if (!process_sp->IsValid()) {
60 error = Status::FromErrorString("Cannot assign an invalid process.");
61 return error;
64 // Don't clear any process specific data if the process is the same.
65 if (m_process_sp == process_sp)
66 return error;
68 ClearProcessSpecificData();
69 m_process_sp = process_sp;
70 return error;
73 Status SaveCoreOptions::AddThread(lldb::ThreadSP thread_sp) {
74 Status error;
75 if (!thread_sp) {
76 error = Status::FromErrorString("invalid thread");
77 return error;
80 if (m_process_sp) {
81 if (m_process_sp != thread_sp->GetProcess()) {
82 error = Status::FromErrorString(
83 "Cannot add a thread from a different process.");
84 return error;
86 } else {
87 m_process_sp = thread_sp->GetProcess();
90 m_threads_to_save.insert(thread_sp->GetID());
91 return error;
94 bool SaveCoreOptions::RemoveThread(lldb::ThreadSP thread_sp) {
95 return thread_sp && m_threads_to_save.erase(thread_sp->GetID()) > 0;
98 bool SaveCoreOptions::ShouldThreadBeSaved(lldb::tid_t tid) const {
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;
105 bool SaveCoreOptions::HasSpecifiedThreads() const {
106 return !m_threads_to_save.empty();
109 void SaveCoreOptions::AddMemoryRegionToSave(
110 const lldb_private::MemoryRegionInfo &region) {
111 m_regions_to_save.Insert(region.GetRange(), /*combine=*/true);
114 const MemoryRanges &SaveCoreOptions::GetCoreFileMemoryRanges() const {
115 return m_regions_to_save;
118 Status SaveCoreOptions::EnsureValidConfiguration(
119 lldb::ProcessSP process_sp) const {
120 Status error;
121 std::string error_str;
122 if (!m_threads_to_save.empty() && GetStyle() == lldb::eSaveCoreFull)
123 error_str += "Cannot save a full core with a subset of threads\n";
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";
129 if (!error_str.empty())
130 error = Status(error_str);
132 return error;
135 void SaveCoreOptions::ClearProcessSpecificData() {
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();
141 void SaveCoreOptions::Clear() {
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();
147 m_regions_to_save.Clear();