Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/Utility/AuxVector.cpp
39644 views
//===-- AuxVector.cpp -----------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "AuxVector.h"9#include <optional>1011AuxVector::AuxVector(const lldb_private::DataExtractor &data) {12ParseAuxv(data);13}1415void AuxVector::ParseAuxv(const lldb_private::DataExtractor &data) {16lldb::offset_t offset = 0;17const size_t value_type_size = data.GetAddressByteSize() * 2;18while (data.ValidOffsetForDataOfSize(offset, value_type_size)) {19// We're not reading an address but an int that could be 32 or 64 bit20// depending on the address size, which is what GetAddress does.21const uint64_t type = data.GetAddress(&offset);22const uint64_t value = data.GetAddress(&offset);23if (type == AUXV_AT_NULL)24break;25if (type == AUXV_AT_IGNORE)26continue;2728m_auxv_entries[type] = value;29}30}3132std::optional<uint64_t>33AuxVector::GetAuxValue(enum EntryType entry_type) const {34auto it = m_auxv_entries.find(static_cast<uint64_t>(entry_type));35if (it != m_auxv_entries.end())36return it->second;37return std::nullopt;38}3940void AuxVector::DumpToLog(lldb_private::Log *log) const {41if (!log)42return;4344log->PutCString("AuxVector: ");45for (auto entry : m_auxv_entries) {46LLDB_LOGF(log, " %s [%" PRIu64 "]: %" PRIx64,47GetEntryName(static_cast<EntryType>(entry.first)), entry.first,48entry.second);49}50}5152const char *AuxVector::GetEntryName(EntryType type) const {53const char *name = "AT_???";5455#define ENTRY_NAME(_type) \56_type: \57name = &#_type[5]58switch (type) {59case ENTRY_NAME(AUXV_AT_NULL); break;60case ENTRY_NAME(AUXV_AT_IGNORE); break;61case ENTRY_NAME(AUXV_AT_EXECFD); break;62case ENTRY_NAME(AUXV_AT_PHDR); break;63case ENTRY_NAME(AUXV_AT_PHENT); break;64case ENTRY_NAME(AUXV_AT_PHNUM); break;65case ENTRY_NAME(AUXV_AT_PAGESZ); break;66case ENTRY_NAME(AUXV_AT_BASE); break;67case ENTRY_NAME(AUXV_AT_FLAGS); break;68case ENTRY_NAME(AUXV_AT_ENTRY); break;69case ENTRY_NAME(AUXV_AT_NOTELF); break;70case ENTRY_NAME(AUXV_AT_UID); break;71case ENTRY_NAME(AUXV_AT_EUID); break;72case ENTRY_NAME(AUXV_AT_GID); break;73case ENTRY_NAME(AUXV_AT_EGID); break;74case ENTRY_NAME(AUXV_AT_CLKTCK); break;75case ENTRY_NAME(AUXV_AT_PLATFORM); break;76case ENTRY_NAME(AUXV_AT_HWCAP); break;77case ENTRY_NAME(AUXV_AT_FPUCW); break;78case ENTRY_NAME(AUXV_AT_DCACHEBSIZE); break;79case ENTRY_NAME(AUXV_AT_ICACHEBSIZE); break;80case ENTRY_NAME(AUXV_AT_UCACHEBSIZE); break;81case ENTRY_NAME(AUXV_AT_IGNOREPPC); break;82case ENTRY_NAME(AUXV_AT_SECURE); break;83case ENTRY_NAME(AUXV_AT_BASE_PLATFORM); break;84case ENTRY_NAME(AUXV_AT_RANDOM); break;85case ENTRY_NAME(AUXV_AT_HWCAP2); break;86case ENTRY_NAME(AUXV_AT_EXECFN); break;87case ENTRY_NAME(AUXV_AT_SYSINFO); break;88case ENTRY_NAME(AUXV_AT_SYSINFO_EHDR); break;89case ENTRY_NAME(AUXV_AT_L1I_CACHESHAPE); break;90case ENTRY_NAME(AUXV_AT_L1D_CACHESHAPE); break;91case ENTRY_NAME(AUXV_AT_L2_CACHESHAPE); break;92case ENTRY_NAME(AUXV_AT_L3_CACHESHAPE); break;93}94#undef ENTRY_NAME9596return name;97}9899100