summaryrefslogtreecommitdiff
path: root/source/Plugins/Process/elf-core/RegisterUtilities.cpp
blob: 3837abadd0f6c29b35c406d2a523cbd525adea54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//===-- RegisterUtilities.cpp -----------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "Plugins/Process/elf-core/RegisterUtilities.h"
#include "llvm/ADT/STLExtras.h"

using namespace lldb_private;

static llvm::Optional<uint32_t>
getNoteType(const llvm::Triple &Triple,
            llvm::ArrayRef<RegsetDesc> RegsetDescs) {
  for (const auto &Entry : RegsetDescs) {
    if (Entry.OS != Triple.getOS())
      continue;
    if (Entry.Arch != llvm::Triple::UnknownArch &&
        Entry.Arch != Triple.getArch())
      continue;
    return Entry.Note;
  }
  return llvm::None;
}

DataExtractor lldb_private::getRegset(llvm::ArrayRef<CoreNote> Notes,
                                      const llvm::Triple &Triple,
                                      llvm::ArrayRef<RegsetDesc> RegsetDescs) {
  auto TypeOr = getNoteType(Triple, RegsetDescs);
  if (!TypeOr)
    return DataExtractor();
  uint32_t Type = *TypeOr;
  auto Iter = llvm::find_if(
      Notes, [Type](const CoreNote &Note) { return Note.info.n_type == Type; });
  return Iter == Notes.end() ? DataExtractor() : Iter->data;
}