LLDB  mainline
DumpRegisterValue.cpp
Go to the documentation of this file.
1 //===-- DumpRegisterValue.cpp -----------------------------------*- C++ -*-===//
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 
15 
16 using namespace lldb;
17 
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  DataExtractor data;
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:
28  //
29  // prefix_with_name^prefix_with_alt_name is true
30  //
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);
34  else
35  format_string.Printf("%%s");
36  std::string fmt = format_string.GetString();
37  if (prefix_with_name) {
38  if (reg_info->name) {
39  s->Printf(fmt.c_str(), reg_info->name);
40  name_printed = true;
41  } else if (reg_info->alt_name) {
42  s->Printf(fmt.c_str(), reg_info->alt_name);
43  prefix_with_alt_name = false;
44  name_printed = true;
45  }
46  }
47  if (prefix_with_alt_name) {
48  if (name_printed)
49  s->PutChar('/');
50  if (reg_info->alt_name) {
51  s->Printf(fmt.c_str(), reg_info->alt_name);
52  name_printed = true;
53  } else if (!name_printed) {
54  // No alternate name but we were asked to display a name, so show the
55  // main name
56  s->Printf(fmt.c_str(), reg_info->name);
57  name_printed = true;
58  }
59  }
60  if (name_printed)
61  s->PutCString(" = ");
62 
63  if (format == eFormatDefault)
64  format = reg_info->format;
65 
66  DumpDataExtractor(data, s,
67  0, // Offset in "data"
68  format, // Format to use when dumping
69  reg_info->byte_size, // item_byte_size
70  1, // item_count
71  UINT32_MAX, // num_per_line
72  LLDB_INVALID_ADDRESS, // base_addr
73  0, // item_bit_size
74  0); // item_bit_offset
75  return true;
76  }
77  return false;
78 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
An data extractor class.
Definition: DataExtractor.h:47
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool DumpRegisterValue(const RegisterValue &reg_val, Stream *s, const RegisterInfo *reg_info, bool prefix_with_name, bool prefix_with_alt_name, lldb::Format format, uint32_t reg_name_right_align_at=0)
#define UINT32_MAX
Definition: lldb-defines.h:31
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
lldb::offset_t DumpDataExtractor(const DataExtractor &DE, Stream *s, lldb::offset_t offset, lldb::Format item_format, size_t item_byte_size, size_t item_count, size_t num_per_line, uint64_t base_addr, uint32_t item_bit_size, uint32_t item_bit_offset, ExecutionContextScope *exe_scope=nullptr)
Dumps item_count objects into the stream s.
size_t PutChar(char ch)
Definition: Stream.cpp:103
bool GetData(DataExtractor &data) const
Definition: SBAddress.h:15