way better backtrace !
This commit is contained in:
parent
99f1e58812
commit
09b2f62fc3
6 changed files with 33 additions and 20 deletions
14
Makefile
14
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# 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 all)
|
||||||
all:
|
all:
|
||||||
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME)
|
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
|
||||||
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME)
|
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
|
||||||
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME)
|
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
|
||||||
|
|
||||||
bonus:
|
bonus:
|
||||||
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME)
|
@$(MAKE) --no-print-directory header OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
|
||||||
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME) bonus
|
@$(MAKE) --no-print-directory -f./Minishell.mk OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd) bonus
|
||||||
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME)
|
@$(MAKE) --no-print-directory footer OBJDIRNAME=$(OBJDIRNAME) BASE_PATH=$(shell pwd)
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
header:
|
header:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* 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())
|
if (install_signal())
|
||||||
return (1);
|
return (1);
|
||||||
utils = (t_utils){};
|
utils = (t_utils){};
|
||||||
*(t_u8 volatile *)NULL = 5;
|
|
||||||
utils.env = create_env_map();
|
utils.env = create_env_map();
|
||||||
utils.parser = create_myparser();
|
utils.parser = create_myparser();
|
||||||
utils.name_shell = "\001\x1B[93m\002"
|
utils.name_shell = "\001\x1B[93m\002"
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,14 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/02 13:22:14 by maiboyer #+# #+# */
|
/* 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 "app/signal_handler.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "readline/readline.h"
|
#include "readline/readline.h"
|
||||||
|
#include "me/printf/printf.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
@ -55,7 +56,7 @@ void sigsegv_handle(int sig, siginfo_t *info, void *ucontext)
|
||||||
(void)(sig);
|
(void)(sig);
|
||||||
(void)(info);
|
(void)(info);
|
||||||
(void)(ucontext);
|
(void)(ucontext);
|
||||||
printf("SEGFAULT!!!\n");
|
me_eprintf("SEGFAULT!!!\n");
|
||||||
print_trace();
|
print_trace();
|
||||||
exit(139);
|
exit(139);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# 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_DIR = output/src
|
||||||
GENERIC_INCLUDE = output/include
|
GENERIC_INCLUDE = output/include
|
||||||
|
|
||||||
|
|
||||||
|
BASE_PATH ?= $(shell pwd)
|
||||||
NAME = libme.a
|
NAME = libme.a
|
||||||
LIB_NAME ?=
|
LIB_NAME ?=
|
||||||
TARGET = $(BUILD_DIR)/$(NAME)
|
TARGET = $(BUILD_DIR)/$(NAME)
|
||||||
CC ?= clang
|
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 =
|
BONUS_FILES =
|
||||||
LIBS_NAME =
|
LIBS_NAME =
|
||||||
SUBJECT_URL =
|
SUBJECT_URL =
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/10 19:33:46 by maix #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,20 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
|
/* 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 "me/types.h"
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define PRINT_BACKTRACE
|
#define PRINT_BACKTRACE
|
||||||
|
#ifndef BASE_PATH
|
||||||
|
# define BASE_PATH "/no_base_path_defined/"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(PRINT_BACKTRACE) || defined(BACKTRACE_DEEP)
|
#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;
|
t_i32 p;
|
||||||
|
|
||||||
p = 0;
|
p = 0;
|
||||||
printf("[bt] #%zu\t", i);
|
fprintf(stderr, "[bt] #%zu\t", i);
|
||||||
while (messages[i][p] != '(' && messages[i][p] != ' '
|
while (messages[i][p] != '(' && messages[i][p] != ' '
|
||||||
&& messages[i][p] != 0)
|
&& messages[i][p] != 0)
|
||||||
++p;
|
++p;
|
||||||
fflush(stdout);
|
fflush(stderr);
|
||||||
snprintf(syscom, 1024, "addr2line %p -e %.*s -sipf", trace[i], p,
|
snprintf(syscom, \
|
||||||
messages[i]);
|
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);
|
(void)system(syscom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +59,7 @@ void print_trace(void)
|
||||||
size = backtrace(trace, BACKTRACE_DEEP);
|
size = backtrace(trace, BACKTRACE_DEEP);
|
||||||
messages = backtrace_symbols(trace, size);
|
messages = backtrace_symbols(trace, size);
|
||||||
i = 1;
|
i = 1;
|
||||||
printf("[bt] Execution path:\n");
|
fprintf(stderr, "[bt] Execution path:\n");
|
||||||
if (size >= 3)
|
if (size >= 3)
|
||||||
size -= 3;
|
size -= 3;
|
||||||
while (i < size)
|
while (i < size)
|
||||||
|
|
@ -65,6 +75,7 @@ static void print_trace(void)
|
||||||
|
|
||||||
void me_abort(void)
|
void me_abort(void)
|
||||||
{
|
{
|
||||||
|
me_eprintf("Abort:\n");
|
||||||
print_trace();
|
print_trace();
|
||||||
me_exit(1);
|
me_exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue