.
This commit is contained in:
parent
b81c347b7b
commit
df5bbb2e7d
54
debug/regex.pretty_print.py
Normal file
54
debug/regex.pretty_print.py
Normal file
@ -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)
|
68
src/vector.c
Normal file
68
src/vector.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
33
src/vector.h
Normal file
33
src/vector.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef VECTOR_H
|
||||
#define VECTOR_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
// 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
|
Loading…
Reference in New Issue
Block a user