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//===----------------------------------------------------------------------===//
8
9#include "Plugins/Process/elf-core/RegisterUtilities.h"
10#include "llvm/ADT/STLExtras.h"
11#include <optional>
12
13using namespace lldb_private;
14
15static std::optional<uint32_t>
16getNoteType(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;
25 }
26 return std::nullopt;
27}
28
29DataExtractor 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 Range&: Notes, P: [Type](const CoreNote &Note) { return Note.info.n_type == Type; });
38 return Iter == Notes.end() ? DataExtractor() : DataExtractor(Iter->data);
39}
40

source code of lldb/source/Plugins/Process/elf-core/RegisterUtilities.cpp