From df5bbb2e7d465699616d1fdbfdb76fa2b0bd1ee9 Mon Sep 17 00:00:00 2001 From: anon Date: Fri, 1 Sep 2023 16:52:22 +0200 Subject: [PATCH] . --- debug/regex.pretty_print.py | 54 +++++++++++++++++++++++++++++++++++ src/vector.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ src/vector.h | 33 ++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 debug/regex.pretty_print.py create mode 100644 src/vector.c create mode 100644 src/vector.h diff --git a/debug/regex.pretty_print.py b/debug/regex.pretty_print.py new file mode 100644 index 0000000..43f3646 --- /dev/null +++ b/debug/regex.pretty_print.py @@ -0,0 +1,54 @@ +class RegexPrinter: + def __init__(self, val): + self.val = val + def to_string(self): + # Init + s = "{" + # Regular shit + s += "accepting_state = " + str(self.val['accepting_state']) + ", str = " + str(self.val['str']) + ",\n" + # Delta + delta_t_ptr_ptr = gdb.lookup_type("delta_t").pointer().pointer() + dt = self.val['delta_table'] + s += "delta_table = {\n" + for i in range(0, dt['element_count']): + s += "\t" + s += ( + str( + ( + dt['data'].cast(delta_t_ptr_ptr) + + + i + ).dereference().dereference() + ) + ) + s += ",\n" + s = s[:-2] + s += "\n },\n" + # Offshoot + offshoot_t_ptr_ptr = gdb.lookup_type("offshoot_t").pointer().pointer() + dt = self.val['catch_table'] + s += "offshoot_table = { \n" + for i in range(0, dt['element_count']): + s += "\t" + s += ( + str( + ( + dt['data'].cast(offshoot_t_ptr_ptr) + + + i + ).dereference().dereference() + ) + ) + s += ",\n" + s = s[:-2] + s += "\n }\n" + # Closour + s += "}" + return s + +def regex_lookup(val): + if str(val.type) == 'regex_t' or str(val.type) == 'const regex_t': + return RegexPrinter(val) + return None + +gdb.pretty_printers.append(regex_lookup) diff --git a/src/vector.c b/src/vector.c new file mode 100644 index 0000000..3cfe9f8 --- /dev/null +++ b/src/vector.c @@ -0,0 +1,68 @@ +/* vector.c + * Copyright 2023 Anon Anonson, Ognjen 'xolatile' Milan Robovic, Emil Williams + * SPDX Identifier: GPL-3.0-only / NO WARRANTY / NO GUARANTEE */ + +#include "vector.h" + +#include +#include +#include +#include + +void vector_init(vector_t * vector, + size_t element_size, + size_t element_count) { + assert(element_size); + + vector->data = NULL; + vector->element_size = element_size; + vector->element_count = element_count; + + vector->data = calloc(vector->element_count, vector->element_size); + + assert(vector->data); +} + +void vector_push(vector_t * vector, + void * data) { + assert(vector); + + vector->element_count += 1; + + vector->data = realloc(vector->data, + vector->element_size * vector->element_count); + + assert(vector->data); + + memcpy(&vector->data[(vector->element_count - 1) * vector->element_size], + data, + vector->element_size); +} + +void vector_pop(vector_t * vector) { + assert(vector); // UNUSED +} + +void * vector_get(const vector_t * const vector, + const size_t element) { + assert(vector); + assert(element < vector->element_count); + + return &vector->data[vector->element_size * element]; +} + +void vector_set(vector_t * vector, + void * data, + size_t element) { + assert(vector); + assert(element >= vector->element_count); + + memcpy(&vector->data[vector->element_size * element], + data, + vector->element_size); +} + +void vector_free(vector_t * vector) { + free(vector->data); +} + diff --git a/src/vector.h b/src/vector.h new file mode 100644 index 0000000..170e56b --- /dev/null +++ b/src/vector.h @@ -0,0 +1,33 @@ +#ifndef VECTOR_H +#define VECTOR_H + +#include + +// TODO: Handle error warnings? +// TODO: Implement more useful functions? + +typedef struct { + char * data; + size_t element_size; + size_t element_count; +} vector_t; + +extern void vector_init(vector_t * vector, + size_t element_size, + size_t element_count); + +extern void vector_push(vector_t * vector, + void * data); + +extern void vector_pop(vector_t * vector); + +extern void * vector_get(const vector_t * const vector, + const size_t element); + +extern void vector_set(vector_t * vector, + void * data, + size_t element); + +extern void vector_free(vector_t * vector); + +#endif