Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / Process / elf-core / RegisterUtilities.cpp
blob7455d78774ee64e207b1949950cc42094523506a
1 //===-- RegisterUtilities.cpp ---------------------------------------------===//
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 "Plugins/Process/elf-core/RegisterUtilities.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include <optional>
13 using namespace lldb_private;
15 static std::optional<uint32_t>
16 getNoteType(const llvm::Triple &Triple,
17 llvm::ArrayRef<RegsetDesc> RegsetDescs) {
18 for (const auto &Entry : RegsetDescs) {
19 if (Entry.OS != Triple.getOS())
20 continue;
21 if (Entry.Arch != llvm::Triple::UnknownArch &&
22 Entry.Arch != Triple.getArch())
23 continue;
24 return Entry.Note;
26 return std::nullopt;
29 DataExtractor lldb_private::getRegset(llvm::ArrayRef<CoreNote> Notes,
30 const llvm::Triple &Triple,
31 llvm::ArrayRef<RegsetDesc> RegsetDescs) {
32 auto TypeOr = getNoteType(Triple, RegsetDescs);
33 if (!TypeOr)
34 return DataExtractor();
35 uint32_t Type = *TypeOr;
36 auto Iter = llvm::find_if(
37 Notes, [Type](const CoreNote &Note) { return Note.info.n_type == Type; });
38 return Iter == Notes.end() ? DataExtractor() : DataExtractor(Iter->data);