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 
12 using namespace lldb_private;
13 
14 static llvm::Optional<uint32_t>
15 getNoteType(const llvm::Triple &Triple,
16             llvm::ArrayRef<RegsetDesc> RegsetDescs) {
17   for (const auto &Entry : RegsetDescs) {
18     if (Entry.OS != Triple.getOS())
19       continue;
20     if (Entry.Arch != llvm::Triple::UnknownArch &&
21         Entry.Arch != Triple.getArch())
22       continue;
23     return Entry.Note;
24   }
25   return llvm::None;
26 }
27 
28 DataExtractor lldb_private::getRegset(llvm::ArrayRef<CoreNote> Notes,
29                                       const llvm::Triple &Triple,
30                                       llvm::ArrayRef<RegsetDesc> RegsetDescs) {
31   auto TypeOr = getNoteType(Triple, RegsetDescs);
32   if (!TypeOr)
33     return DataExtractor();
34   uint32_t Type = *TypeOr;
35   auto Iter = llvm::find_if(
36       Notes, [Type](const CoreNote &Note) { return Note.info.n_type == Type; });
37   return Iter == Notes.end() ? DataExtractor() : DataExtractor(Iter->data);
38 }
39