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: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2024/05/07 13:14:07 by maiboyer ### ########.fr #
# Updated: 2024/05/08 16:01:18 by maiboyer ### ########.fr #
# #
# **************************************************************************** #
@ -27,14 +27,14 @@ NAME = minishell
# All (make all)
all:
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME)
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME)
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME)
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
bonus:
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME)
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME) bonus
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME)
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd) bonus
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
# Header
header:

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
/* Updated: 2024/05/08 15:27:45 by maiboyer ### ########.fr */
/* Updated: 2024/05/08 15:36:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -164,7 +164,6 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
if (install_signal())
return (1);
utils = (t_utils){};
*(t_u8 volatile *)NULL = 5;
utils.env = create_env_map();
utils.parser = create_myparser();
utils.name_shell = "\001\x1B[93m\002"

View file

@ -6,13 +6,14 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 13:22:14 by maiboyer #+# #+# */
/* Updated: 2024/05/08 15:28:15 by maiboyer ### ########.fr */
/* Updated: 2024/05/08 15:33:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/signal_handler.h"
#include "me/types.h"
#include "readline/readline.h"
#include "me/printf/printf.h"
#include <stdlib.h>
#include <stdio.h>
@ -55,7 +56,7 @@ void sigsegv_handle(int sig, siginfo_t *info, void *ucontext)
(void)(sig);
(void)(info);
(void)(ucontext);
printf("SEGFAULT!!!\n");
me_eprintf("SEGFAULT!!!\n");
print_trace();
exit(139);
}

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);
}