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