Path: blob/main/contrib/llvm-project/lldb/source/Core/DumpRegisterInfo.cpp
96333 views
//===-- DumpRegisterInfo.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 "lldb/Core/DumpRegisterInfo.h"9#include "lldb/Target/RegisterContext.h"10#include "lldb/Target/RegisterFlags.h"11#include "lldb/Utility/Stream.h"1213using namespace lldb;14using namespace lldb_private;1516using SetInfo = std::pair<const char *, uint32_t>;1718void lldb_private::DumpRegisterInfo(Stream &strm, RegisterContext &ctx,19const RegisterInfo &info,20uint32_t terminal_width) {21std::vector<const char *> invalidates;22if (info.invalidate_regs) {23for (uint32_t *inv_regs = info.invalidate_regs;24*inv_regs != LLDB_INVALID_REGNUM; ++inv_regs) {25const RegisterInfo *inv_info =26ctx.GetRegisterInfo(lldb::eRegisterKindLLDB, *inv_regs);27assert(28inv_info &&29"Register invalidate list refers to a register that does not exist.");30invalidates.push_back(inv_info->name);31}32}3334// We include the index here so that you can use it with "register read -s".35std::vector<SetInfo> in_sets;36for (uint32_t set_idx = 0; set_idx < ctx.GetRegisterSetCount(); ++set_idx) {37const RegisterSet *set = ctx.GetRegisterSet(set_idx);38assert(set && "Register set should be valid.");39for (uint32_t reg_idx = 0; reg_idx < set->num_registers; ++reg_idx) {40const RegisterInfo *set_reg_info =41ctx.GetRegisterInfoAtIndex(set->registers[reg_idx]);42assert(set_reg_info && "Register info should be valid.");4344if (set_reg_info == &info) {45in_sets.push_back({set->name, set_idx});46break;47}48}49}5051std::vector<const char *> read_from;52if (info.value_regs) {53for (uint32_t *read_regs = info.value_regs;54*read_regs != LLDB_INVALID_REGNUM; ++read_regs) {55const RegisterInfo *read_info =56ctx.GetRegisterInfo(lldb::eRegisterKindLLDB, *read_regs);57assert(read_info && "Register value registers list refers to a register "58"that does not exist.");59read_from.push_back(read_info->name);60}61}6263DoDumpRegisterInfo(strm, info.name, info.alt_name, info.byte_size,64invalidates, read_from, in_sets, info.flags_type,65terminal_width);66}6768template <typename ElementType>69static void DumpList(Stream &strm, const char *title,70const std::vector<ElementType> &list,71std::function<void(Stream &, ElementType)> emitter) {72if (list.empty())73return;7475strm.EOL();76strm << title;77bool first = true;78for (ElementType elem : list) {79if (!first)80strm << ", ";81first = false;82emitter(strm, elem);83}84}8586void lldb_private::DoDumpRegisterInfo(87Stream &strm, const char *name, const char *alt_name, uint32_t byte_size,88const std::vector<const char *> &invalidates,89const std::vector<const char *> &read_from,90const std::vector<SetInfo> &in_sets, const RegisterFlags *flags_type,91uint32_t terminal_width) {92strm << " Name: " << name;93if (alt_name)94strm << " (" << alt_name << ")";95strm.EOL();9697// Size in bits may seem obvious for the usual 32 or 64 bit registers.98// When we get to vector registers, then scalable vector registers, it is very99// useful to know without the user doing extra work.100strm.Printf(" Size: %d bytes (%d bits)", byte_size, byte_size * 8);101102std::function<void(Stream &, const char *)> emit_str =103[](Stream &strm, const char *s) { strm << s; };104DumpList(strm, "Invalidates: ", invalidates, emit_str);105DumpList(strm, " Read from: ", read_from, emit_str);106107std::function<void(Stream &, SetInfo)> emit_set = [](Stream &strm,108SetInfo info) {109strm.Printf("%s (index %d)", info.first, info.second);110};111DumpList(strm, " In sets: ", in_sets, emit_set);112113if (flags_type) {114strm.Printf("\n\n%s", flags_type->AsTable(terminal_width).c_str());115116std::string enumerators = flags_type->DumpEnums(terminal_width);117if (enumerators.size())118strm << "\n\n" << enumerators;119}120}121122123