Author: Jonas Devlieghere Date: 2020-01-29T14:08:21-08:00 New Revision: 91aa67bf290bc7f877b1b90128284863bc31aa43
URL: https://github.com/llvm/llvm-project/commit/91aa67bf290bc7f877b1b90128284863bc31aa43 DIFF: https://github.com/llvm/llvm-project/commit/91aa67bf290bc7f877b1b90128284863bc31aa43.diff LOG: [lldb/Reproducers] Add (de)serialization overload for char** This patch adds an overload to serialize and deserialize char** types. This is necessary for things like the SBLaunchInfo ctor. We serialize the array length followed by each individual item. Added: Modified: lldb/include/lldb/Utility/ReproducerInstrumentation.h lldb/source/Utility/ReproducerInstrumentation.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Utility/ReproducerInstrumentation.h b/lldb/include/lldb/Utility/ReproducerInstrumentation.h index 2698338a38bb..ca92f9f2f6e6 100644 --- a/lldb/include/lldb/Utility/ReproducerInstrumentation.h +++ b/lldb/include/lldb/Utility/ReproducerInstrumentation.h @@ -375,6 +375,7 @@ class Deserializer { /// Partial specialization for C-style strings. We read the string value /// instead of treating it as pointer. template <> const char *Deserializer::Deserialize<const char *>(); +template <> const char **Deserializer::Deserialize<const char **>(); template <> char *Deserializer::Deserialize<char *>(); /// Helpers to auto-synthesize function replay code. It deserializes the replay @@ -604,6 +605,22 @@ class Serializer { m_stream.write(0x0); } + void Serialize(const char **t) { + // Compute the size of the array. + const char *const *temp = t; + size_t size = 0; + while (*temp++) + size++; + Serialize(size); + + // Serialize the content of the array. + while (*t) { + m_stream << *t; + m_stream.write(0x0); + ++t; + } + } + /// Serialization stream. llvm::raw_ostream &m_stream; diff --git a/lldb/source/Utility/ReproducerInstrumentation.cpp b/lldb/source/Utility/ReproducerInstrumentation.cpp index 46def9f59d7b..fb39fec41d43 100644 --- a/lldb/source/Utility/ReproducerInstrumentation.cpp +++ b/lldb/source/Utility/ReproducerInstrumentation.cpp @@ -9,6 +9,7 @@ #include "lldb/Utility/ReproducerInstrumentation.h" #include "lldb/Utility/Reproducer.h" #include <stdio.h> +#include <stdlib.h> using namespace lldb_private; using namespace lldb_private::repro; @@ -39,6 +40,15 @@ template <> const char *Deserializer::Deserialize<const char *>() { return str; } +template <> const char **Deserializer::Deserialize<const char **>() { + size_t size = Deserialize<size_t>(); + const char **r = + reinterpret_cast<const char **>(calloc(size + 1, sizeof(char *))); + for (size_t i = 0; i < size; ++i) + r[i] = Deserialize<const char *>(); + return r; +} + bool Registry::Replay(const FileSpec &file) { auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath()); if (auto err = error_or_file.getError()) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits