Skip to content

Commit df4f828

Browse files
authored
[lldb][NFC] Replace lldb's DWARFFormValue::ValueType with llvm's (llvm#109853)
1 parent cace986 commit df4f828

File tree

2 files changed

+34
-44
lines changed

2 files changed

+34
-44
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace lldb_private::plugin::dwarf;
2525
void DWARFFormValue::Clear() {
2626
m_unit = nullptr;
2727
m_form = dw_form_t(0);
28-
m_value = ValueTypeTag();
28+
m_value = ValueType();
2929
}
3030

3131
bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data,
@@ -44,68 +44,68 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data,
4444
switch (m_form) {
4545
case DW_FORM_addr:
4646
assert(m_unit);
47-
m_value.value.uval =
47+
m_value.uval =
4848
data.GetMaxU64(offset_ptr, DWARFUnit::GetAddressByteSize(m_unit));
4949
break;
5050
case DW_FORM_block1:
51-
m_value.value.uval = data.GetU8(offset_ptr);
51+
m_value.uval = data.GetU8(offset_ptr);
5252
is_block = true;
5353
break;
5454
case DW_FORM_block2:
55-
m_value.value.uval = data.GetU16(offset_ptr);
55+
m_value.uval = data.GetU16(offset_ptr);
5656
is_block = true;
5757
break;
5858
case DW_FORM_block4:
59-
m_value.value.uval = data.GetU32(offset_ptr);
59+
m_value.uval = data.GetU32(offset_ptr);
6060
is_block = true;
6161
break;
6262
case DW_FORM_data16:
63-
m_value.value.uval = 16;
63+
m_value.uval = 16;
6464
is_block = true;
6565
break;
6666
case DW_FORM_exprloc:
6767
case DW_FORM_block:
68-
m_value.value.uval = data.GetULEB128(offset_ptr);
68+
m_value.uval = data.GetULEB128(offset_ptr);
6969
is_block = true;
7070
break;
7171
case DW_FORM_string:
72-
m_value.value.cstr = data.GetCStr(offset_ptr);
72+
m_value.cstr = data.GetCStr(offset_ptr);
7373
break;
7474
case DW_FORM_sdata:
75-
m_value.value.sval = data.GetSLEB128(offset_ptr);
75+
m_value.sval = data.GetSLEB128(offset_ptr);
7676
break;
7777
case DW_FORM_strp:
7878
case DW_FORM_line_strp:
7979
case DW_FORM_sec_offset:
80-
m_value.value.uval = data.GetMaxU64(offset_ptr, 4);
80+
m_value.uval = data.GetMaxU64(offset_ptr, 4);
8181
break;
8282
case DW_FORM_addrx1:
8383
case DW_FORM_strx1:
8484
case DW_FORM_ref1:
8585
case DW_FORM_data1:
8686
case DW_FORM_flag:
87-
m_value.value.uval = data.GetU8(offset_ptr);
87+
m_value.uval = data.GetU8(offset_ptr);
8888
break;
8989
case DW_FORM_addrx2:
9090
case DW_FORM_strx2:
9191
case DW_FORM_ref2:
9292
case DW_FORM_data2:
93-
m_value.value.uval = data.GetU16(offset_ptr);
93+
m_value.uval = data.GetU16(offset_ptr);
9494
break;
9595
case DW_FORM_addrx3:
9696
case DW_FORM_strx3:
97-
m_value.value.uval = data.GetMaxU64(offset_ptr, 3);
97+
m_value.uval = data.GetMaxU64(offset_ptr, 3);
9898
break;
9999
case DW_FORM_addrx4:
100100
case DW_FORM_strx4:
101101
case DW_FORM_ref4:
102102
case DW_FORM_data4:
103-
m_value.value.uval = data.GetU32(offset_ptr);
103+
m_value.uval = data.GetU32(offset_ptr);
104104
break;
105105
case DW_FORM_data8:
106106
case DW_FORM_ref8:
107107
case DW_FORM_ref_sig8:
108-
m_value.value.uval = data.GetU64(offset_ptr);
108+
m_value.uval = data.GetU64(offset_ptr);
109109
break;
110110
case DW_FORM_addrx:
111111
case DW_FORM_loclistx:
@@ -115,32 +115,32 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data,
115115
case DW_FORM_ref_udata:
116116
case DW_FORM_GNU_str_index:
117117
case DW_FORM_GNU_addr_index:
118-
m_value.value.uval = data.GetULEB128(offset_ptr);
118+
m_value.uval = data.GetULEB128(offset_ptr);
119119
break;
120120
case DW_FORM_ref_addr:
121121
assert(m_unit);
122122
if (m_unit->GetVersion() <= 2)
123123
ref_addr_size = m_unit->GetAddressByteSize();
124124
else
125125
ref_addr_size = 4;
126-
m_value.value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);
126+
m_value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);
127127
break;
128128
case DW_FORM_indirect:
129129
m_form = static_cast<dw_form_t>(data.GetULEB128(offset_ptr));
130130
indirect = true;
131131
break;
132132
case DW_FORM_flag_present:
133-
m_value.value.uval = 1;
133+
m_value.uval = 1;
134134
break;
135135
default:
136136
return false;
137137
}
138138
} while (indirect);
139139

140140
if (is_block) {
141-
m_value.data = data.PeekData(*offset_ptr, m_value.value.uval);
141+
m_value.data = data.PeekData(*offset_ptr, m_value.uval);
142142
if (m_value.data != nullptr) {
143-
*offset_ptr += m_value.value.uval;
143+
*offset_ptr += m_value.uval;
144144
}
145145
}
146146

@@ -461,23 +461,23 @@ const char *DWARFFormValue::AsCString() const {
461461
DWARFContext &context = m_unit->GetSymbolFileDWARF().GetDWARFContext();
462462

463463
if (m_form == DW_FORM_string)
464-
return m_value.value.cstr;
464+
return m_value.cstr;
465465
if (m_form == DW_FORM_strp)
466-
return context.getOrLoadStrData().PeekCStr(m_value.value.uval);
466+
return context.getOrLoadStrData().PeekCStr(m_value.uval);
467467

468468
if (m_form == DW_FORM_GNU_str_index || m_form == DW_FORM_strx ||
469469
m_form == DW_FORM_strx1 || m_form == DW_FORM_strx2 ||
470470
m_form == DW_FORM_strx3 || m_form == DW_FORM_strx4) {
471471

472472
std::optional<uint64_t> offset =
473-
m_unit->GetStringOffsetSectionItem(m_value.value.uval);
473+
m_unit->GetStringOffsetSectionItem(m_value.uval);
474474
if (!offset)
475475
return nullptr;
476476
return context.getOrLoadStrData().PeekCStr(*offset);
477477
}
478478

479479
if (m_form == DW_FORM_line_strp)
480-
return context.getOrLoadLineStrData().PeekCStr(m_value.value.uval);
480+
return context.getOrLoadLineStrData().PeekCStr(m_value.uval);
481481

482482
return nullptr;
483483
}
@@ -495,14 +495,14 @@ dw_addr_t DWARFFormValue::Address() const {
495495

496496
uint32_t index_size = m_unit->GetAddressByteSize();
497497
dw_offset_t addr_base = m_unit->GetAddrBase();
498-
lldb::offset_t offset = addr_base + m_value.value.uval * index_size;
498+
lldb::offset_t offset = addr_base + m_value.uval * index_size;
499499
return symbol_file.GetDWARFContext().getOrLoadAddrData().GetMaxU64(
500500
&offset, index_size);
501501
}
502502

503503
std::pair<DWARFUnit *, uint64_t>
504504
DWARFFormValue::ReferencedUnitAndOffset() const {
505-
uint64_t value = m_value.value.uval;
505+
uint64_t value = m_value.uval;
506506
switch (m_form) {
507507
case DW_FORM_ref1:
508508
case DW_FORM_ref2:
@@ -550,7 +550,7 @@ DWARFDIE DWARFFormValue::Reference() const {
550550
}
551551

552552
uint64_t DWARFFormValue::Reference(dw_offset_t base_offset) const {
553-
uint64_t value = m_value.value.uval;
553+
uint64_t value = m_value.uval;
554554
switch (m_form) {
555555
case DW_FORM_ref1:
556556
case DW_FORM_ref2:

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFFORMVALUE_H
1111

1212
#include "DWARFDataExtractor.h"
13-
#include <cstddef>
13+
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1414
#include <optional>
1515

1616
namespace lldb_private::plugin {
@@ -21,17 +21,7 @@ class DWARFDIE;
2121

2222
class DWARFFormValue {
2323
public:
24-
typedef struct ValueTypeTag {
25-
ValueTypeTag() : value() { value.uval = 0; }
26-
27-
union {
28-
uint64_t uval;
29-
int64_t sval;
30-
const char *cstr;
31-
} value;
32-
const uint8_t *data = nullptr;
33-
} ValueType;
34-
24+
typedef llvm::DWARFFormValue::ValueType ValueType;
3525
enum {
3626
eValueTypeInvalid = 0,
3727
eValueTypeUnsigned,
@@ -67,11 +57,11 @@ class DWARFFormValue {
6757
std::pair<DWARFUnit *, uint64_t> ReferencedUnitAndOffset() const;
6858

6959
uint64_t Reference(dw_offset_t offset) const;
70-
bool Boolean() const { return m_value.value.uval != 0; }
71-
uint64_t Unsigned() const { return m_value.value.uval; }
72-
void SetUnsigned(uint64_t uval) { m_value.value.uval = uval; }
73-
int64_t Signed() const { return m_value.value.sval; }
74-
void SetSigned(int64_t sval) { m_value.value.sval = sval; }
60+
bool Boolean() const { return m_value.uval != 0; }
61+
uint64_t Unsigned() const { return m_value.uval; }
62+
void SetUnsigned(uint64_t uval) { m_value.uval = uval; }
63+
int64_t Signed() const { return m_value.sval; }
64+
void SetSigned(int64_t sval) { m_value.sval = sval; }
7565
const char *AsCString() const;
7666
dw_addr_t Address() const;
7767
bool IsValid() const { return m_form != 0; }

0 commit comments

Comments
 (0)