[lldb] Use llvm::byteswap in DumpRegisterValue
authorDavid Spickett <david.spickett@linaro.org>
Tue, 18 Apr 2023 08:15:50 +0000 (08:15 +0000)
committerDavid Spickett <david.spickett@linaro.org>
Tue, 18 Apr 2023 08:18:59 +0000 (08:18 +0000)
7978abd5aef1ba84d7a1cefbc3443245acff2c48 fixed a build issue
on MSVC with some code I previously added, by adding some
ifdefs.

Now I realise that I should have been using llvm::byteswap
in the first place, which does exactly that.

lldb/source/Core/DumpRegisterValue.cpp

index 3e59fb1..463aa59 100644 (file)
 #include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
-
-#if !defined(__has_builtin)
-#define __has_builtin(x) 0
-#endif
-
-#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
-#define bswap_32(x) __builtin_bswap32(x)
-#define bswap_64(x) __builtin_bswap64(x)
-#elif defined(_MSC_VER)
-#define bswap_32(x) _byteswap_ulong(x)
-#define bswap_64(x) _byteswap_uint64(x)
-#else
-#include <byteswap.h>
-#endif
+#include "llvm/ADT/bit.h"
 
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
-static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
-
 template <typename T>
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,
                             lldb_private::ExecutionContextScope *exe_scope,
@@ -55,7 +39,7 @@ static void dump_type_value(lldb_private::CompilerType &fields_type, T value,
 
   // Then we need to match the target's endian on a byte level as well.
   if (lldb_private::endian::InlHostByteOrder() != target_order)
-    value = swap_value(value);
+    value = llvm::byteswap(value);
 
   lldb_private::DataExtractor data_extractor{
       &value, sizeof(T), lldb_private::endian::InlHostByteOrder(), 8};