From a3bcf58f3701243a9c57f5a44a76d4f42dbac364 Mon Sep 17 00:00:00 2001 From: SergeyRyabinin Date: Mon, 26 Feb 2024 19:43:33 +0000 Subject: [PATCH] Add Variant debug browser (for convinient value observe value in a debugger) --- include/aws/crt/Variant.h | 29 +++++++++++++++++++++++++++++ tests/CMakeLists.txt | 2 ++ 2 files changed, 31 insertions(+) diff --git a/include/aws/crt/Variant.h b/include/aws/crt/Variant.h index 415286bc8..ed2886eb0 100644 --- a/include/aws/crt/Variant.h +++ b/include/aws/crt/Variant.h @@ -83,6 +83,32 @@ namespace Aws static const bool value = ContainsType(); }; } // namespace Checker +#if defined(DEBUG_BUILD) + namespace VariantDebug + { + template class VariantDebugBrowser + { + public: + VariantDebugBrowser(char *storage) { InitTuple<0, Ts...>(storage); } + std::tuple::type...> as_tuple; + + private: + template + void InitTuple(char *storage) + { + First *value = reinterpret_cast(storage); + std::get(as_tuple) = value; + InitTuple(storage); + } + + template void InitTuple(char *storage) + { + Last *value = reinterpret_cast(storage); + std::get(as_tuple) = value; + } + }; + } // namespace VariantDebug +#endif /* defined(DEBUG_BUILD) */ } // namespace VariantDetail template class VariantAlternative; @@ -366,6 +392,9 @@ namespace Aws alignas(VariantDetail::ParameterPackSize::AlignAsPack()) char m_storage[STORAGE_SIZE]; VariantDetail::Index::VariantIndex m_index = -1; +#if defined(DEBUG_BUILD) + VariantDetail::VariantDebug::VariantDebugBrowser browser = m_storage; +#endif /* defined(DEBUG_BUILD) */ void Destroy() { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3b6ae9baa..4e6a2e009 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -274,6 +274,8 @@ if(AWS_WARNINGS_ARE_ERRORS) endif() endif() +target_compile_definitions(${TEST_BINARY_NAME} PRIVATE $<$:DEBUG_BUILD>) + add_custom_command(TARGET ${TEST_BINARY_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources $)