[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.
This commit is contained in:
Jonas Devlieghere 2020-01-29 14:06:20 -08:00
parent 6cb830de6e
commit 91aa67bf29
2 changed files with 27 additions and 0 deletions

View File

@ -375,6 +375,7 @@ private:
/// 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 @@ private:
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;

View File

@ -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())