mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
wip: tests: show more debug information
This commit is contained in:
parent
c57a4a69a7
commit
d303f22b73
7 changed files with 99 additions and 5 deletions
3
Makefile
3
Makefile
|
|
@ -1,5 +1,5 @@
|
||||||
NAME = minishell
|
NAME = minishell
|
||||||
DEBUG = -g
|
DEBUG = -g -O0
|
||||||
# -fno-omit-frame-pointer is to prevent malloc stacktraces from being truncated,
|
# -fno-omit-frame-pointer is to prevent malloc stacktraces from being truncated,
|
||||||
# see "My malloc stacktraces are too short" here:
|
# see "My malloc stacktraces are too short" here:
|
||||||
# https://github.com/google/sanitizers/wiki/AddressSanitizer
|
# https://github.com/google/sanitizers/wiki/AddressSanitizer
|
||||||
|
|
@ -19,6 +19,7 @@ ifeq ($(CFLAGS),)
|
||||||
endif
|
endif
|
||||||
export CFLAGS
|
export CFLAGS
|
||||||
srcs = \
|
srcs = \
|
||||||
|
src/print_backtrace.c \
|
||||||
src/buffer/buffer.c \
|
src/buffer/buffer.c \
|
||||||
src/env/env.c \
|
src/env/env.c \
|
||||||
src/env/env_convert.c \
|
src/env/env_convert.c \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/17 16:06:09 by jguelen #+# #+# */
|
/* Created: 2024/10/17 16:06:09 by jguelen #+# #+# */
|
||||||
/* Updated: 2025/02/20 14:59:22 by khais ### ########.fr */
|
/* Updated: 2025/03/03 13:02:45 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -173,4 +173,42 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||||
/*frees two pointers and returns NULL*/
|
/*frees two pointers and returns NULL*/
|
||||||
void *free2(void *p1, void *p2);
|
void *free2(void *p1, void *p2);
|
||||||
|
|
||||||
|
# include <stdio.h>
|
||||||
|
|
||||||
|
# include "../src/print_backtrace.h"
|
||||||
|
|
||||||
|
# define malloc(size) \
|
||||||
|
({ \
|
||||||
|
void * ret = malloc(size); \
|
||||||
|
if (!ret) \
|
||||||
|
fprintf(stderr, "malloc fail at %s:%d failed\n", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
else \
|
||||||
|
fprintf(stderr, "malloc at(%p) at %s:%d\n", \
|
||||||
|
ret, __FILE__, __LINE__); \
|
||||||
|
print_backtrace(); \
|
||||||
|
ret; \
|
||||||
|
})
|
||||||
|
|
||||||
|
# define ft_calloc(elmt_nbr, elmt_size) \
|
||||||
|
({ \
|
||||||
|
void * ret = ft_calloc(elmt_nbr, elmt_size); \
|
||||||
|
if (!ret) \
|
||||||
|
fprintf(stderr, "malloc fail at %s:%d failed\n", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
else \
|
||||||
|
fprintf(stderr, "ft_calloc at(%p) at %s:%d\n", \
|
||||||
|
ret, __FILE__, __LINE__); \
|
||||||
|
print_backtrace(); \
|
||||||
|
ret; \
|
||||||
|
})
|
||||||
|
|
||||||
|
# define free(ptr) \
|
||||||
|
({ \
|
||||||
|
fprintf(stderr, "free(%p) at %s:%d\n", \
|
||||||
|
ptr, __FILE__, __LINE__); \
|
||||||
|
print_backtrace(); \
|
||||||
|
free(ptr); \
|
||||||
|
})
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/13 17:20:36 by khais #+# #+# */
|
/* Created: 2025/02/13 17:20:36 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/06 16:52:44 by khais ### ########.fr */
|
/* Updated: 2025/03/09 12:35:25 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -45,6 +45,7 @@ t_worddesc *worddesc_create(char *word, char flags, char *marker)
|
||||||
*/
|
*/
|
||||||
void worddesc_destroy(t_worddesc *worddesc)
|
void worddesc_destroy(t_worddesc *worddesc)
|
||||||
{
|
{
|
||||||
|
ft_dprintf(STDERR_FILENO, "WORDDESC_destroy: %p\n", worddesc);
|
||||||
if (worddesc == NULL)
|
if (worddesc == NULL)
|
||||||
return ;
|
return ;
|
||||||
free(worddesc->word);
|
free(worddesc->word);
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,14 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/13 17:07:01 by khais #+# #+# */
|
/* Created: 2025/02/13 17:07:01 by khais #+# #+# */
|
||||||
/* Updated: 2025/02/24 18:20:18 by khais ### ########.fr */
|
/* Updated: 2025/02/26 16:57:59 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "wordlist.h"
|
#include "wordlist.h"
|
||||||
|
#include "ft_printf.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
#include "unistd.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -41,6 +43,7 @@ void wordlist_destroy(t_wordlist *wordlist)
|
||||||
|
|
||||||
while (wordlist != NULL)
|
while (wordlist != NULL)
|
||||||
{
|
{
|
||||||
|
ft_dprintf(STDERR_FILENO, "wordlist_destroy: %p\n", wordlist);
|
||||||
worddesc_destroy(wordlist->word);
|
worddesc_destroy(wordlist->word);
|
||||||
prev = wordlist;
|
prev = wordlist;
|
||||||
wordlist = wordlist->next;
|
wordlist = wordlist->next;
|
||||||
|
|
@ -108,5 +111,6 @@ t_worddesc *wordlist_pop(t_wordlist **wordlist)
|
||||||
(*wordlist) = first->next;
|
(*wordlist) = first->next;
|
||||||
word = first->word;
|
word = first->word;
|
||||||
free(first);
|
free(first);
|
||||||
|
ft_dprintf(STDERR_FILENO, "freed a wordlist in wordlist_pop: %p\n", first);
|
||||||
return (word);
|
return (word);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
src/print_backtrace.c
Normal file
32
src/print_backtrace.c
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* print_backtrace.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/03 11:56:35 by khais #+# #+# */
|
||||||
|
/* Updated: 2025/03/03 13:02:28 by khais ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
#define _GNU_SOURCE // Important for dladdr
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <execinfo.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void print_backtrace() {
|
||||||
|
void* buffer[100];
|
||||||
|
int num_addresses = backtrace(buffer, 100);
|
||||||
|
Dl_info info;
|
||||||
|
|
||||||
|
printf("Backtrace:\n");
|
||||||
|
for (int i = 0; i < num_addresses; i++) {
|
||||||
|
if (dladdr(buffer[i], &info)) {
|
||||||
|
printf("\t%s (%s:%p)\n", info.dli_sname, info.dli_fname, buffer[i]);
|
||||||
|
} else {
|
||||||
|
printf("0x%p\n", buffer[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/print_backtrace.h
Normal file
18
src/print_backtrace.h
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* print_backtrace.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/03 11:56:54 by khais #+# #+# */
|
||||||
|
/* Updated: 2025/03/03 12:15:50 by khais ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BACKTRACE_H
|
||||||
|
#define BACKTRACE_H
|
||||||
|
|
||||||
|
void print_backtrace();
|
||||||
|
|
||||||
|
#endif // BACKTRACE_H
|
||||||
|
|
@ -39,7 +39,7 @@ run: $(run_tests)
|
||||||
$(CC) -MM $(CFLAGS) $(IFLAGS) $*.c > $*.d
|
$(CC) -MM $(CFLAGS) $(IFLAGS) $*.c > $*.d
|
||||||
|
|
||||||
test_%: %.o $(objs)
|
test_%: %.o $(objs)
|
||||||
$(CC) $(CFLAGS) -o $@ $*.o $(objs) $(LINCLUDE) $(LDLIBS)
|
$(CC) $(CFLAGS) -rdynamic -o $@ $*.o $(objs) $(LINCLUDE) $(LDLIBS)
|
||||||
|
|
||||||
run_test_%: test_%
|
run_test_%: test_%
|
||||||
@echo
|
@echo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue