180814287SRaphael Isemann //===-- RegisterUtilities.cpp ---------------------------------------------===// 2bc8cc867SPavel Labath // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6bc8cc867SPavel Labath // 7bc8cc867SPavel Labath //===----------------------------------------------------------------------===// 8bc8cc867SPavel Labath 9bc8cc867SPavel Labath #include "Plugins/Process/elf-core/RegisterUtilities.h" 10bc8cc867SPavel Labath #include "llvm/ADT/STLExtras.h" 11bc8cc867SPavel Labath 12bc8cc867SPavel Labath using namespace lldb_private; 13bc8cc867SPavel Labath 14bc8cc867SPavel Labath static llvm::Optional<uint32_t> getNoteType(const llvm::Triple & Triple,llvm::ArrayRef<RegsetDesc> RegsetDescs)15bc8cc867SPavel LabathgetNoteType(const llvm::Triple &Triple, 16bc8cc867SPavel Labath llvm::ArrayRef<RegsetDesc> RegsetDescs) { 17bc8cc867SPavel Labath for (const auto &Entry : RegsetDescs) { 18bc8cc867SPavel Labath if (Entry.OS != Triple.getOS()) 19bc8cc867SPavel Labath continue; 20bc8cc867SPavel Labath if (Entry.Arch != llvm::Triple::UnknownArch && 21bc8cc867SPavel Labath Entry.Arch != Triple.getArch()) 22bc8cc867SPavel Labath continue; 23bc8cc867SPavel Labath return Entry.Note; 24bc8cc867SPavel Labath } 25bc8cc867SPavel Labath return llvm::None; 26bc8cc867SPavel Labath } 27bc8cc867SPavel Labath getRegset(llvm::ArrayRef<CoreNote> Notes,const llvm::Triple & Triple,llvm::ArrayRef<RegsetDesc> RegsetDescs)28bc8cc867SPavel LabathDataExtractor lldb_private::getRegset(llvm::ArrayRef<CoreNote> Notes, 29bc8cc867SPavel Labath const llvm::Triple &Triple, 30bc8cc867SPavel Labath llvm::ArrayRef<RegsetDesc> RegsetDescs) { 31bc8cc867SPavel Labath auto TypeOr = getNoteType(Triple, RegsetDescs); 32bc8cc867SPavel Labath if (!TypeOr) 33bc8cc867SPavel Labath return DataExtractor(); 34bc8cc867SPavel Labath uint32_t Type = *TypeOr; 35bc8cc867SPavel Labath auto Iter = llvm::find_if( 36bc8cc867SPavel Labath Notes, [Type](const CoreNote &Note) { return Note.info.n_type == Type; }); 37*14f44303SJan Kratochvil return Iter == Notes.end() ? DataExtractor() : DataExtractor(Iter->data); 38bc8cc867SPavel Labath } 39