11573Srgrimes//===-- RegisterUtilities.cpp -----------------------------------*- C++ -*-===// 21573Srgrimes// 31573Srgrimes// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41573Srgrimes// See https://llvm.org/LICENSE.txt for license information. 51573Srgrimes// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61573Srgrimes// 71573Srgrimes//===----------------------------------------------------------------------===// 81573Srgrimes 91573Srgrimes#include "Plugins/Process/elf-core/RegisterUtilities.h" 101573Srgrimes#include "llvm/ADT/STLExtras.h" 111573Srgrimes 121573Srgrimesusing namespace lldb_private; 131573Srgrimes 141573Srgrimesstatic llvm::Optional<uint32_t> 151573SrgrimesgetNoteType(const llvm::Triple &Triple, 161573Srgrimes llvm::ArrayRef<RegsetDesc> RegsetDescs) { 171573Srgrimes for (const auto &Entry : RegsetDescs) { 181573Srgrimes if (Entry.OS != Triple.getOS()) 191573Srgrimes continue; 201573Srgrimes if (Entry.Arch != llvm::Triple::UnknownArch && 211573Srgrimes Entry.Arch != Triple.getArch()) 221573Srgrimes continue; 231573Srgrimes return Entry.Note; 241573Srgrimes } 251573Srgrimes return llvm::None; 261573Srgrimes} 271573Srgrimes 281573SrgrimesDataExtractor lldb_private::getRegset(llvm::ArrayRef<CoreNote> Notes, 291573Srgrimes const llvm::Triple &Triple, 301573Srgrimes llvm::ArrayRef<RegsetDesc> RegsetDescs) { 311573Srgrimes auto TypeOr = getNoteType(Triple, RegsetDescs); 321573Srgrimes if (!TypeOr) 331573Srgrimes return DataExtractor(); 341573Srgrimes uint32_t Type = *TypeOr; 351573Srgrimes auto Iter = llvm::find_if( 361573Srgrimes Notes, [Type](const CoreNote &Note) { return Note.info.n_type == Type; }); 371573Srgrimes return Iter == Notes.end() ? DataExtractor() : Iter->data; 381573Srgrimes} 391573Srgrimes