debug: show command about to be executed in debug mode

This commit is contained in:
Khaïs COLIN 2025-04-08 16:18:57 +02:00
parent 204ed35ff4
commit 81febcfcdd
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
8 changed files with 65 additions and 3 deletions

View file

@ -47,6 +47,7 @@ srcs = \
src/executing/simple_cmd/builtins.c \ src/executing/simple_cmd/builtins.c \
src/executing/simple_cmd/builtin_unset.c \ src/executing/simple_cmd/builtin_unset.c \
src/executing/simple_cmd/simple_cmd_execute.c \ src/executing/simple_cmd/simple_cmd_execute.c \
src/executing/simple_cmd/simple_cmd_execute_debug.c \
src/executing/simple_cmd/subprocess.c \ src/executing/simple_cmd/subprocess.c \
src/ft_errno.c \ src/ft_errno.c \
src/get_command.c \ src/get_command.c \

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */ /* Created: 2025/03/27 16:21:56 by khais #+# #+# */
/* Updated: 2025/04/07 17:56:56 by khais ### ########.fr */ /* Updated: 2025/04/08 16:12:36 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,6 +25,7 @@
#include "../../postprocess/expansion/expand_vars.h" #include "../../postprocess/expansion/expand_vars.h"
#include "../../postprocess/fieldsplit/fieldsplit.h" #include "../../postprocess/fieldsplit/fieldsplit.h"
#include "../../postprocess/expansion/expand_wildcard.h" #include "../../postprocess/expansion/expand_wildcard.h"
#include "simple_cmd_execute_debug.h"
static void command_not_found(t_simple_cmd *cmd) static void command_not_found(t_simple_cmd *cmd)
{ {
@ -91,6 +92,7 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
return ; return ;
if (post_process_command(cmd, app) == NULL) if (post_process_command(cmd, app) == NULL)
return ; return ;
simple_cmd_execute_debug(cmd, app);
if (handle_redirections(cmd, app) == NULL) if (handle_redirections(cmd, app) == NULL)
return ; return ;
if (execute_builtin(cmd, app) != BUILTIN_INVALID) if (execute_builtin(cmd, app) != BUILTIN_INVALID)

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simple_cmd_execute_debug.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/10 15:36:26 by khais #+# #+# */
/* Updated: 2025/04/10 15:37:29 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "simple_cmd_execute_debug.h"
#include "libft.h"
#include "../../parser/simple_cmd/simple_cmd.h"
void simple_cmd_execute_debug(t_simple_cmd *cmd, t_minishell *app)
{
if (app->debug)
{
ft_printf("about to execute\n");
simple_cmd_root_debug(cmd);
}
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simple_cmd_execute_debug.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/10 15:36:08 by khais #+# #+# */
/* Updated: 2025/04/10 15:36:44 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SIMPLE_CMD_EXECUTE_DEBUG_H
# define SIMPLE_CMD_EXECUTE_DEBUG_H
# include "../../minishell.h"
void simple_cmd_execute_debug(t_simple_cmd *cmd, t_minishell *app);
#endif // SIMPLE_CMD_EXECUTE_DEBUG_H

View file

@ -44,8 +44,9 @@ static void debug_command(t_cmd *cmd, t_minishell *app)
{ {
t_buffer *indent; t_buffer *indent;
if (app->debug == false) if (app->debug == false || cmd == NULL)
return ; return ;
ft_printf("parsed command\n");
indent = ft_buffer_new(); indent = ft_buffer_new();
cmd_debug(cmd, indent, true); cmd_debug(cmd, indent, true);
ft_buffer_free(indent); ft_buffer_free(indent);

View file

@ -54,3 +54,12 @@ void simple_cmd_debug(t_simple_cmd *cmd, t_buffer *leader, bool is_last)
redirect_debug(cmd->redirections, leader, true); redirect_debug(cmd->redirections, leader, true);
dedent(leader, is_last); dedent(leader, is_last);
} }
void simple_cmd_root_debug(t_simple_cmd *cmd)
{
t_buffer *leader;
leader = ft_buffer_new();
simple_cmd_debug(cmd, leader, true);
ft_buffer_free(leader);
}

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/21 12:24:57 by khais #+# #+# */ /* Created: 2025/02/21 12:24:57 by khais #+# #+# */
/* Updated: 2025/03/28 14:52:45 by khais ### ########.fr */ /* Updated: 2025/04/10 15:33:10 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,5 +22,6 @@ t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words);
void simple_cmd_destroy(t_simple_cmd *cmd); void simple_cmd_destroy(t_simple_cmd *cmd);
void simple_cmd_debug(t_simple_cmd *cmd, t_buffer *leader, void simple_cmd_debug(t_simple_cmd *cmd, t_buffer *leader,
bool is_last); bool is_last);
void simple_cmd_root_debug(t_simple_cmd *cmd);
#endif #endif

View file

@ -586,6 +586,7 @@ EOF
expecting <<EOF expecting <<EOF
[dbg: 1] [dbg: 1]
[exec: 0] [exec: 0]
parsed command
╰─ t_simple_cmd ╰─ t_simple_cmd
├─ line = 0 ├─ line = 0
├─ t_wordlist ├─ t_wordlist
@ -615,6 +616,7 @@ EOF
expecting <<EOF expecting <<EOF
[dbg: 1] [dbg: 1]
[exec: 0] [exec: 0]
parsed command
╰─ t_simple_cmd ╰─ t_simple_cmd
├─ line = 0 ├─ line = 0
├─ t_wordlist ├─ t_wordlist
@ -674,6 +676,7 @@ EOF
expecting <<EOF expecting <<EOF
[dbg: 1] [dbg: 1]
[exec: 0] [exec: 0]
parsed command
╰─ t_simple_cmd ╰─ t_simple_cmd
├─ line = 0 ├─ line = 0
├─ t_wordlist ├─ t_wordlist
@ -733,6 +736,7 @@ EOF
expecting <<EOF expecting <<EOF
[dbg: 1] [dbg: 1]
[exec: 0] [exec: 0]
parsed command
╰─ t_simple_cmd ╰─ t_simple_cmd
├─ line = 0 ├─ line = 0
├─ t_wordlist ├─ t_wordlist