1 //===-- RegisterUtilities.cpp ---------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "Plugins/Process/elf-core/RegisterUtilities.h" 10 #include "llvm/ADT/STLExtras.h" 11 #include <optional> 12 13 using namespace lldb_private; 14 15 static std::optional<uint32_t> getNoteType(const llvm::Triple & Triple,llvm::ArrayRef<RegsetDesc> RegsetDescs)16getNoteType(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 std::nullopt; 27 } 28 getRegset(llvm::ArrayRef<CoreNote> Notes,const llvm::Triple & Triple,llvm::ArrayRef<RegsetDesc> RegsetDescs)29DataExtractor 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() : DataExtractor(Iter->data); 39 } 40