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" 11f190ce62SKazu Hirata #include <optional> 12bc8cc867SPavel Labath 13bc8cc867SPavel Labath using namespace lldb_private; 14bc8cc867SPavel Labath 15*2fe83274SKazu Hirata static std::optional<uint32_t> getNoteType(const llvm::Triple & Triple,llvm::ArrayRef<RegsetDesc> RegsetDescs)16bc8cc867SPavel LabathgetNoteType(const llvm::Triple &Triple, 17bc8cc867SPavel Labath llvm::ArrayRef<RegsetDesc> RegsetDescs) { 18bc8cc867SPavel Labath for (const auto &Entry : RegsetDescs) { 19bc8cc867SPavel Labath if (Entry.OS != Triple.getOS()) 20bc8cc867SPavel Labath continue; 21bc8cc867SPavel Labath if (Entry.Arch != llvm::Triple::UnknownArch && 22bc8cc867SPavel Labath Entry.Arch != Triple.getArch()) 23bc8cc867SPavel Labath continue; 24bc8cc867SPavel Labath return Entry.Note; 25bc8cc867SPavel Labath } 26343523d0SKazu Hirata return std::nullopt; 27bc8cc867SPavel Labath } 28bc8cc867SPavel Labath getRegset(llvm::ArrayRef<CoreNote> Notes,const llvm::Triple & Triple,llvm::ArrayRef<RegsetDesc> RegsetDescs)29bc8cc867SPavel LabathDataExtractor lldb_private::getRegset(llvm::ArrayRef<CoreNote> Notes, 30bc8cc867SPavel Labath const llvm::Triple &Triple, 31bc8cc867SPavel Labath llvm::ArrayRef<RegsetDesc> RegsetDescs) { 32bc8cc867SPavel Labath auto TypeOr = getNoteType(Triple, RegsetDescs); 33bc8cc867SPavel Labath if (!TypeOr) 34bc8cc867SPavel Labath return DataExtractor(); 35bc8cc867SPavel Labath uint32_t Type = *TypeOr; 36bc8cc867SPavel Labath auto Iter = llvm::find_if( 37bc8cc867SPavel Labath Notes, [Type](const CoreNote &Note) { return Note.info.n_type == Type; }); 3814f44303SJan Kratochvil return Iter == Notes.end() ? DataExtractor() : DataExtractor(Iter->data); 39bc8cc867SPavel Labath } 40