way better backtrace !

This commit is contained in:
Maieul BOYER 2024-05-08 16:07:23 +02:00
parent 99f1e58812
commit 09b2f62fc3
No known key found for this signature in database
6 changed files with 33 additions and 20 deletions

View file

@ -6,7 +6,7 @@
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
# Updated: 2024/05/08 15:01:24 by maiboyer ### ########.fr #
# Updated: 2024/05/08 16:06:05 by maiboyer ### ########.fr #
# #
# **************************************************************************** #
@ -17,11 +17,13 @@ LIBS_DIR = .
GENERIC_DIR = output/src
GENERIC_INCLUDE = output/include
BASE_PATH ?= $(shell pwd)
NAME = libme.a
LIB_NAME ?=
TARGET = $(BUILD_DIR)/$(NAME)
CC ?= clang
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"'
BONUS_FILES =
LIBS_NAME =
SUBJECT_URL =

View file

@ -6,7 +6,7 @@
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 19:33:46 by maix #+# #+# */
/* Updated: 2023/12/11 15:10:07 by maiboyer ### ########.fr */
/* Updated: 2024/05/08 15:43:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,16 +6,20 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
/* Updated: 2024/05/08 15:22:04 by maiboyer ### ########.fr */
/* Updated: 2024/05/08 16:06:58 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/printf/printf.h"
#include "me/types.h"
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#define PRINT_BACKTRACE
#ifndef BASE_PATH
# define BASE_PATH "/no_base_path_defined/"
#endif
#if defined(PRINT_BACKTRACE) || defined(BACKTRACE_DEEP)
@ -29,13 +33,19 @@ static void print_trace_inner(void **trace, t_str *messages, t_usize i)
t_i32 p;
p = 0;
printf("[bt] #%zu\t", i);
fprintf(stderr, "[bt] #%zu\t", i);
while (messages[i][p] != '(' && messages[i][p] != ' '
&& messages[i][p] != 0)
++p;
fflush(stdout);
snprintf(syscom, 1024, "addr2line %p -e %.*s -sipf", trace[i], p,
messages[i]);
fflush(stderr);
snprintf(syscom, \
1024, \
"addr2line %p -e %.*s -ipf | 1>&2 rg \"^(.*) at %s(.*)\"'$' " \
"--replace '$1 at $2' --color never", \
trace[i], \
p, \
messages[i], \
BASE_PATH);
(void)system(syscom);
}
@ -49,7 +59,7 @@ void print_trace(void)
size = backtrace(trace, BACKTRACE_DEEP);
messages = backtrace_symbols(trace, size);
i = 1;
printf("[bt] Execution path:\n");
fprintf(stderr, "[bt] Execution path:\n");
if (size >= 3)
size -= 3;
while (i < size)
@ -65,6 +75,7 @@ static void print_trace(void)
void me_abort(void)
{
me_eprintf("Abort:\n");
print_trace();
me_exit(1);
}