]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Core/DumpRegisterValue.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Core / DumpRegisterValue.cpp
1 //===-- DumpRegisterValue.cpp -----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Core/DumpRegisterValue.h"
11 #include "lldb/Core/DumpDataExtractor.h"
12 #include "lldb/Core/RegisterValue.h"
13 #include "lldb/Utility/DataExtractor.h"
14 #include "lldb/Utility/StreamString.h"
15 #include "lldb/lldb-private-types.h"
16
17 using namespace lldb;
18
19 bool lldb_private::DumpRegisterValue(const RegisterValue &reg_val, Stream *s,
20                                      const RegisterInfo *reg_info,
21                                      bool prefix_with_name,
22                                      bool prefix_with_alt_name, Format format,
23                                      uint32_t reg_name_right_align_at) {
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 = 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     return true;
77   }
78   return false;
79 }