link-tests: test unwind info emitter via c++ exceptions

This commit is contained in:
Jakub Konka
2023-01-20 20:57:40 +01:00
parent 835a60a34f
commit e0ccbff87d
6 changed files with 172 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#include "all.h"
#include <cstdio>
#include <cstring>
SimpleString::SimpleString(size_t max_size)
: max_size{ max_size }, length{} {
if (max_size == 0) {
throw Error{ "Max size must be at least 1." };
}
buffer = new char[max_size];
buffer[0] = 0;
}
SimpleString::~SimpleString() {
delete[] buffer;
}
void SimpleString::print(const char* tag) const {
printf("%s: %s", tag, buffer);
}
bool SimpleString::append_line(const char* x) {
const auto x_len = strlen(x);
if (x_len + length + 2 > max_size) return false;
std::strncpy(buffer + length, x, max_size - length);
length += x_len;
buffer[length++] = '\n';
buffer[length] = 0;
return true;
}