xref: /llvm-project/lldb/source/Plugins/Process/elf-core/RegisterUtilities.cpp (revision bc8cc867a1ed3219fea6c87eda9106689dd2c932)
1 //===-- RegisterUtilities.cpp -----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "Plugins/Process/elf-core/RegisterUtilities.h"
11 #include "llvm/ADT/STLExtras.h"
12 
13 using namespace lldb_private;
14 
15 static llvm::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;
25   }
26   return llvm::None;
27 }
28 
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() : Iter->data;
39 }
40