1//===-- DumpRegisterValue.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 "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"
15
16using namespace lldb;
17
18bool lldb_private::DumpRegisterValue(const RegisterValue &reg_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,
23 ExecutionContextScope *exe_scope) {
24 DataExtractor data;
25 if (reg_val.GetData(data)) {
26 bool name_printed = false;
27 // For simplicity, alignment of the register name printing applies only in
28 // the most common case where:
29 //
30 // prefix_with_name^prefix_with_alt_name is true
31 //
32 StreamString format_string;
33 if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name))
34 format_string.Printf("%%%us", reg_name_right_align_at);
35 else
36 format_string.Printf("%%s");
37 std::string fmt = std::string(format_string.GetString());
38 if (prefix_with_name) {
39 if (reg_info->name) {
40 s->Printf(fmt.c_str(), reg_info->name);
41 name_printed = true;
42 } else if (reg_info->alt_name) {
43 s->Printf(fmt.c_str(), reg_info->alt_name);
44 prefix_with_alt_name = false;
45 name_printed = true;
46 }
47 }
48 if (prefix_with_alt_name) {
49 if (name_printed)
50 s->PutChar('/');
51 if (reg_info->alt_name) {
52 s->Printf(fmt.c_str(), reg_info->alt_name);
53 name_printed = true;
54 } else if (!name_printed) {
55 // No alternate name but we were asked to display a name, so show the
56 // main name
57 s->Printf(fmt.c_str(), reg_info->name);
58 name_printed = true;
59 }
60 }
61 if (name_printed)
62 s->PutCString(" = ");
63
64 if (format == eFormatDefault)
65 format = reg_info->format;
66
67 DumpDataExtractor(data, s,
68 0, // Offset in "data"
69 format, // Format to use when dumping
70 reg_info->byte_size, // item_byte_size
71 1, // item_count
72 UINT32_MAX, // num_per_line
73 LLDB_INVALID_ADDRESS, // base_addr
74 0, // item_bit_size
75 0, // item_bit_offset
76 exe_scope);
77 return true;
78 }
79 return false;
80}
81

source code of lldb/source/Core/DumpRegisterValue.cpp