@@ -82,35 +82,65 @@ Scalar::Type Scalar::PromoteToMaxType(Scalar &lhs, Scalar &rhs) {
8282 return Scalar::e_void;
8383}
8484
85- bool Scalar::GetData (DataExtractor &data, size_t limit_byte_size ) const {
85+ bool Scalar::GetData (DataExtractor &data) const {
8686 size_t byte_size = GetByteSize ();
8787 if (byte_size == 0 ) {
8888 data.Clear ();
8989 return false ;
9090 }
9191 auto buffer_up = std::make_unique<DataBufferHeap>(byte_size, 0 );
9292 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 ());
106122 }
123+ return true ;
107124 }
108125
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);
110133 data.SetByteOrder (endian::InlHostByteOrder ());
134+
111135 return true ;
112136}
113137
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+
114144void Scalar::GetBytes (llvm::MutableArrayRef<uint8_t > storage) const {
115145 assert (storage.size () >= GetByteSize ());
116146
0 commit comments