1 //===-- DumpRegisterValue.cpp -----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/DumpRegisterValue.h"
10 #include "lldb/Core/DumpDataExtractor.h"
11 #include "lldb/Utility/DataExtractor.h"
12 #include "lldb/Utility/RegisterValue.h"
13 #include "lldb/Utility/StreamString.h"
14 #include "lldb/lldb-private-types.h"
18 bool lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s,
19 const RegisterInfo *reg_info,
20 bool prefix_with_name,
21 bool prefix_with_alt_name, Format format,
22 uint32_t reg_name_right_align_at) {
24 if (reg_val.GetData(data)) {
25 bool name_printed = false;
26 // For simplicity, alignment of the register name printing applies only in
27 // the most common case where:
29 // prefix_with_name^prefix_with_alt_name is true
31 StreamString format_string;
32 if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name))
33 format_string.Printf("%%%us", reg_name_right_align_at);
35 format_string.Printf("%%s");
36 std::string fmt = format_string.GetString();
37 if (prefix_with_name) {
39 s->Printf(fmt.c_str(), reg_info->name);
41 } else if (reg_info->alt_name) {
42 s->Printf(fmt.c_str(), reg_info->alt_name);
43 prefix_with_alt_name = false;
47 if (prefix_with_alt_name) {
50 if (reg_info->alt_name) {
51 s->Printf(fmt.c_str(), reg_info->alt_name);
53 } else if (!name_printed) {
54 // No alternate name but we were asked to display a name, so show the
56 s->Printf(fmt.c_str(), reg_info->name);
63 if (format == eFormatDefault)
64 format = reg_info->format;
66 DumpDataExtractor(data, s,
67 0, // Offset in "data"
68 format, // Format to use when dumping
69 reg_info->byte_size, // item_byte_size
71 UINT32_MAX, // num_per_line
72 LLDB_INVALID_ADDRESS, // base_addr
74 0); // item_bit_offset