[lldb] Rewrite Scalar::GetBytes
authorPavel Labath <pavel@labath.sk>
Thu, 25 Jun 2020 13:18:02 +0000 (15:18 +0200)
committerPavel Labath <pavel@labath.sk>
Thu, 25 Jun 2020 13:31:48 +0000 (15:31 +0200)
commitd0fa52cc3797fd8805d24a04e6b8198154cd7b53
tree836f8ace4240a4d38c513be0c7c67f99ce043424
parent324cda2073d1eba1758ab7529af3f3880d6f18c6
[lldb] Rewrite Scalar::GetBytes

This function was modifying and returning pointers to static storage,
which meant that any two accesses to different Scalar objects could
potentially race (depending on which types the objects were storing and
the host endianness).

In the new version the user is responsible for providing a buffer into
which this method will store its binary representation. The main caller
(RegisterValue::GetBytes) already has one such buffer handy, so this did
not require any major rewrites.

To make that work, I've needed to mark the RegisterValue value buffer
mutable -- not an ideal solution, but definitely better than modifying
global storage. This could be further improved by changing
RegisterValue::GetBytes to take a buffer too.
lldb/include/lldb/Utility/RegisterValue.h
lldb/include/lldb/Utility/Scalar.h
lldb/source/Utility/RegisterValue.cpp
lldb/source/Utility/Scalar.cpp
lldb/unittests/Utility/ScalarTest.cpp