@@ -82,35 +82,65 @@ Scalar::Type Scalar::PromoteToMaxType(Scalar &lhs, Scalar &rhs) {
82
82
return Scalar::e_void;
83
83
}
84
84
85
- bool Scalar::GetData (DataExtractor &data, size_t limit_byte_size ) const {
85
+ bool Scalar::GetData (DataExtractor &data) const {
86
86
size_t byte_size = GetByteSize ();
87
87
if (byte_size == 0 ) {
88
88
data.Clear ();
89
89
return false ;
90
90
}
91
91
auto buffer_up = std::make_unique<DataBufferHeap>(byte_size, 0 );
92
92
GetBytes (buffer_up->GetData ());
93
- lldb::offset_t offset = 0 ;
94
-
95
- if (limit_byte_size < byte_size) {
96
- if (endian::InlHostByteOrder () == eByteOrderLittle) {
97
- // On little endian systems if we want fewer bytes from the current
98
- // type we just specify fewer bytes since the LSByte is first...
99
- byte_size = limit_byte_size;
100
- } else if (endian::InlHostByteOrder () == eByteOrderBig) {
101
- // On big endian systems if we want fewer bytes from the current type
102
- // have to advance our initial byte pointer and trim down the number of
103
- // bytes since the MSByte is first
104
- offset = byte_size - limit_byte_size;
105
- byte_size = limit_byte_size;
93
+ data.SetData (std::move (buffer_up), 0 , byte_size);
94
+ data.SetByteOrder (endian::InlHostByteOrder ());
95
+ return true ;
96
+ }
97
+
98
+ bool Scalar::GetData (DataExtractor &data, size_t result_byte_size) const {
99
+ size_t byte_size = GetByteSize ();
100
+ if (byte_size == 0 || result_byte_size == 0 ) {
101
+ data.Clear ();
102
+ return false ;
103
+ }
104
+
105
+ if (endian::InlHostByteOrder () == lldb::eByteOrderBig) {
106
+ // On big endian systems if we want fewer bytes from the current type
107
+ // we have to advance our initial byte pointer since the MSByte is
108
+ // first.
109
+ if (result_byte_size <= byte_size) {
110
+ auto buffer_up = std::make_unique<DataBufferHeap>(byte_size, 0 );
111
+ GetBytes (buffer_up->GetData ());
112
+ auto offset = byte_size - result_byte_size;
113
+ data.SetData (std::move (buffer_up), offset, result_byte_size);
114
+ data.SetByteOrder (endian::InlHostByteOrder ());
115
+ } else {
116
+ // Extend created buffer size and insert the data bytes with an offset
117
+ auto buffer_up = std::make_unique<DataBufferHeap>(result_byte_size, 0 );
118
+ auto offset = result_byte_size - byte_size;
119
+ GetBytes (buffer_up->GetBytes () + offset, byte_size);
120
+ data.SetData (std::move (buffer_up), 0 , result_byte_size);
121
+ data.SetByteOrder (endian::InlHostByteOrder ());
106
122
}
123
+ return true ;
107
124
}
108
125
109
- data.SetData (std::move (buffer_up), offset, byte_size);
126
+ // On little endian systems MSBytes get trimmed or extended automatically by
127
+ // size.
128
+ if (byte_size < result_byte_size)
129
+ byte_size = result_byte_size;
130
+ auto buffer_up = std::make_unique<DataBufferHeap>(byte_size, 0 );
131
+ GetBytes (buffer_up->GetData ());
132
+ data.SetData (std::move (buffer_up), 0 , result_byte_size);
110
133
data.SetByteOrder (endian::InlHostByteOrder ());
134
+
111
135
return true ;
112
136
}
113
137
138
+ void Scalar::GetBytes (uint8_t *storage, size_t size) const {
139
+ assert (size >= GetByteSize ());
140
+ llvm::MutableArrayRef<uint8_t > storage_ref (storage, size);
141
+ GetBytes (storage_ref);
142
+ }
143
+
114
144
void Scalar::GetBytes (llvm::MutableArrayRef<uint8_t > storage) const {
115
145
assert (storage.size () >= GetByteSize ());
116
146
0 commit comments