Skip to content

Commit

Permalink
Throw error on split debug information; Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spevnev committed Nov 14, 2024
1 parent e72e878 commit 0ee8aa1
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 18 deletions.
11 changes: 6 additions & 5 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ function get_similarity {
# Baselines are generated from gcc, so decrease its similarity for clang:
if [ "$test" = "struct" ]; then result=90;
elif [ "$test" = "packed_struct" ]; then result=90;
elif [ "$test" = "primitives" ]; then result=95;
# Clang doesn't produce DW_AT_subprogram for external functions, i.e. shared libraries
# or different CUs, so cross-CU retrieval of function signature/name doesn't work.
elif [ "$test" = "function" ]; then result=85; fi
elif [ "$test" = "primitives" ]; then result=95; fi
fi

# FILE has different implementation which is up to stdio.h and it often has pointers
# that point out-of-bounds causing uprintf to print garbage from the memory, thus the
# primary goal of the test is to check that there are no errors, i.e. segfaults, leaks.
if [ "$test" = "stdio_file" ]; then result=10; fi
if [ "$test" = "stdio_file" ]; then result=10;
# Clang doesn't produce DW_AT_subprogram for external functions, i.e. shared libraries
# or different CUs, so cross-CU retrieval of function signature/name doesn't work.
# Some GCC versions print "size_t" and some "unsigned long int"
elif [ "$test" = "function" ]; then result=85; fi

echo $result
}
Expand Down
1 change: 0 additions & 1 deletion tests/baselines/packed_struct.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Struct containing all types: {
void *void_ptr = POINTER
int *int_ptr = POINTER (5)
float *null_ptr = NULL
char *ch_ptr = POINTER ("c")
const char *str = POINTER ("str string")
char *const const_str = POINTER ("const_str string")
_Bool b = true
Expand Down
1 change: 0 additions & 1 deletion tests/baselines/primitives.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ sch: 157
void_ptr: POINTER
int_ptr: POINTER (1)
null_ptr: NULL
ch_ptr: POINTER ("c")
str: POINTER ("string")
b: false
void_fun: POINTER (void void_fun())
Expand Down
1 change: 0 additions & 1 deletion tests/baselines/struct.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Struct containing all types: {
void *void_ptr = POINTER
int *int_ptr = POINTER (5)
float *null_ptr = NULL
char *ch_ptr = POINTER ("c")
const char *str = POINTER ("str string")
char *const const_str = POINTER ("const_str string")
_Bool b = true
Expand Down
3 changes: 0 additions & 3 deletions tests/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ int other_fun(char a, float *b, unsigned long c) {

int main(void) {
int i = 1;
char c = 'c';

uint8_t u8 = 255;
uint16_t u16 = 65535;
Expand All @@ -35,7 +34,6 @@ int main(void) {
void *void_ptr = &i;
int *int_ptr = &i;
float *null_ptr = NULL;
char *ch_ptr = &c;

const char *str = "string";

Expand Down Expand Up @@ -63,7 +61,6 @@ int main(void) {
uprintf("void_ptr: %S\n", &void_ptr);
uprintf("int_ptr: %S\n", &int_ptr);
uprintf("null_ptr: %S\n", &null_ptr);
uprintf("ch_ptr: %S\n", &ch_ptr);

uprintf("str: %S\n", &str);

Expand Down
3 changes: 0 additions & 3 deletions tests/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ typedef struct {
void *void_ptr;
int *int_ptr;
float *null_ptr;
char *ch_ptr;

const char *str;
const cstr const_str;
Expand All @@ -50,7 +49,6 @@ int other_fun(char a, float *b, unsigned long c) {

int main(void) {
int i = 5;
char c = 'c';

Struct s = {
.u8 = 255,
Expand All @@ -72,7 +70,6 @@ int main(void) {
.void_ptr = &i,
.int_ptr = &i,
.null_ptr = NULL,
.ch_ptr = &c,

.str = "str string",
.const_str = "const_str string",
Expand Down
7 changes: 3 additions & 4 deletions uprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ static void _upf_parse_dwarf(void) {

uint8_t type = *die;
die += sizeof(type);
_UPF_ASSERT(type == DW_UT_compile);
if (type != DW_UT_compile) _UPF_ERROR("uprintf does NOT support split debug information.");

uint8_t address_size = *die;
_UPF_ASSERT(_upf_state.address_size == 0 || _upf_state.address_size == address_size);
Expand Down Expand Up @@ -3710,11 +3710,10 @@ __attribute__((destructor)) void _upf_fini(void) {
}

__attribute__((noinline)) void _upf_uprintf(const char *file_path, int line, const char *fmt, const char *args_string, ...) {
if (setjmp(_upf_state.jmp_buf) != 0) return;

_UPF_ASSERT(file_path != NULL && line > 0 && fmt != NULL && args_string != NULL);

if (!_upf_state.is_init) _UPF_ERROR("Error during initialization.");
if (setjmp(_upf_state.jmp_buf) != 0) return;
if (!_upf_state.is_init) return;

_upf_state.ptr = _upf_state.buffer;
_upf_state.free = _upf_state.size;
Expand Down

0 comments on commit 0ee8aa1

Please sign in to comment.