Skip to content

Instantly share code, notes, and snippets.

@bb010g
Created October 5, 2021 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bb010g/9676de9453e9ff51eed1a696b27bcdcb to your computer and use it in GitHub Desktop.
Save bb010g/9676de9453e9ff51eed1a696b27bcdcb to your computer and use it in GitHub Desktop.
mrsh `state->last_status` test, tracing internal execution
bb010g ~/.../c/mrsh % ./build/mrsh -c 'true; foo="`true``false`$? `printf "%s\n" "$?"``false`"; printf "%s\n" "$? $foo"' 2>&1
main (post mrsh_parse_line): program
├─command_list ─ pipeline
│ └─simple_command
│ └─name ─ word_string [1:1 → 1:5] true
├─command_list ─ pipeline
│ └─simple_command
│ └─assignment
│ ├─name foo
│ └─value ─ word_list (quoted)
│ ├─word_command (quoted) ─ program
│ │ └─command_list ─ pipeline
│ │ └─simple_command
│ │ └─name ─ word_string [1:1 → 1:5] true
│ ├─word_command (quoted) ─ program
│ │ └─command_list ─ pipeline
│ │ └─simple_command
│ │ └─name ─ word_string [1:1 → 1:6] false
│ ├─word_parameter
│ │ └─name ?
│ ├─word_string [1:27 → 1:28]
│ ├─word_command (quoted) ─ program
│ │ └─command_list ─ pipeline
│ │ └─simple_command
│ │ ├─name ─ word_string [1:1 → 1:7] printf
│ │ ├─argument 1 ─ word_list (quoted)
│ │ │ └─word_string [1:9 → 1:13] %s\n
│ │ └─argument 2 ─ word_list (quoted)
│ │ └─word_parameter
│ │ └─name ?
│ └─word_command (quoted) ─ program
│ └─command_list ─ pipeline
│ └─simple_command
│ └─name ─ word_string [1:1 → 1:6] false
└─command_list ─ pipeline
└─simple_command
├─name ─ word_string [1:58 → 1:64] printf
├─argument 1 ─ word_list (quoted)
│ └─word_string [1:66 → 1:70] %s\n
└─argument 2 ─ word_list (quoted)
├─word_parameter
│ └─name ?
├─word_string [1:75 → 1:76]
└─word_parameter
└─name foo
mrsh_run_program (pre run_command_list_array): state->last_status = 0; state->exit = -1;
run_command_list_array (pre run_and_or_list loop): state->last_status = 0; state->exit = -1;
run_command_list_array (!list->ampersand, pre run_and_or_list): i = 0; state->last_status = 0; state->exit = -1;
run_command (pre switch (cmd->type)): cmd->type = 0;
run_command (MRSH_SIMPLE_COMMAND, pre run_simple_command);
run_simple_command (sc->name != NULL, pre expand_word(ctx, sc->name, &args));
run_simple_command (sc->name != NULL, post expand_word(ctx, sc->name, &args)): ret = 0;
run_simple_command (sc->name != NULL, pre expand_assignmets);
run_simple_command (sc->name != NULL, pre expand_assignmets): ret = 0;
run_simple_command (sc->name != NULL, pre run_builtin);
run_simple_command (sc->name != NULL, post run_builtin): ret = 0;
run_simple_command (sc->name != NULL, post run_command or run_builtin or run_process): ret = 0;
run_command (post switch (cmd->type)): cmd->type = 0; ret = 0;
run_command_list_array (!list->ampersand, post run_and_or_list): i = 0; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, pre propagation): i = 0; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, post propagation): i = 0; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (!list->ampersand, pre run_and_or_list): i = 1; state->last_status = 0; state->exit = -1;
run_command (pre switch (cmd->type)): cmd->type = 0;
run_command (MRSH_SIMPLE_COMMAND, pre run_simple_command);
run_simple_command (sc->name == NULL, pre expand_assignments): ctx->state->last_status = 0;
expand_assignments (pre run_word): ctx->state->last_status = 0;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 0; ctx->state->last_status = 0;
run_word_command:
program
└─command_list ─ pipeline
└─simple_command
└─name ─ word_string [0:0 → 0:0] true
run_word_command (child, pre mrsh_run_program): ctx->state->last_status = 0; ctx->state->exit = -1;
mrsh_run_program (pre run_command_list_array): state->last_status = 0; state->exit = -1;
run_command_list_array (pre run_and_or_list loop): state->last_status = 0; state->exit = -1;
run_command_list_array (!list->ampersand, pre run_and_or_list): i = 0; state->last_status = 0; state->exit = -1;
run_command (pre switch (cmd->type)): cmd->type = 0;
run_command (MRSH_SIMPLE_COMMAND, pre run_simple_command);
run_simple_command (sc->name != NULL, pre expand_word(ctx, sc->name, &args));
run_simple_command (sc->name != NULL, post expand_word(ctx, sc->name, &args)): ret = 0;
run_simple_command (sc->name != NULL, pre expand_assignmets);
run_simple_command (sc->name != NULL, pre expand_assignmets): ret = 0;
run_simple_command (sc->name != NULL, pre run_builtin);
run_simple_command (sc->name != NULL, post run_builtin): ret = 0;
run_simple_command (sc->name != NULL, post run_command or run_builtin or run_process): ret = 0;
run_command (post switch (cmd->type)): cmd->type = 0; ret = 0;
run_command_list_array (!list->ampersand, post run_and_or_list): i = 0; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, pre propagation): i = 0; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, post propagation): i = 0; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list loop): ret = 0; state->last_status = 0; state->exit = -1;
mrsh_run_program (post run_command_list_array): ret = 0; state->last_status = 0; state->exit = -1;
mrsh_run_program (post run_pending_traps): state->last_status = 0; state->exit = -1;
run_word_command (child, post mrsh_run_program): ctx->state->last_status = 0; ctx->state->exit = 0;
run_word_command (pre job_wait_process(process)): ctx->state->last_status = 0; ctx->state->exit = -1;
run_word_command (post job_wait_process(process)): status = 0; ctx->state->last_status = 0; ctx->state->exit = -1;
run_word_command (post propagation): status = 0; ctx->state->last_status = 0; ctx->state->exit = -1;
_run_word (MRSH_WORD_COMMAND): ret = 0; ctx->state->last_status = 0; ctx->state->exit = -1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 0; ret = 0; ctx->state->last_status = 0;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 1; ctx->state->last_status = 0;
run_word_command:
program
└─command_list ─ pipeline
└─simple_command
└─name ─ word_string [0:0 → 0:0] false
run_word_command (child, pre mrsh_run_program): ctx->state->last_status = 0; ctx->state->exit = -1;
mrsh_run_program (pre run_command_list_array): state->last_status = 0; state->exit = -1;
run_command_list_array (pre run_and_or_list loop): state->last_status = 0; state->exit = -1;
run_command_list_array (!list->ampersand, pre run_and_or_list): i = 0; state->last_status = 0; state->exit = -1;
run_command (pre switch (cmd->type)): cmd->type = 0;
run_command (MRSH_SIMPLE_COMMAND, pre run_simple_command);
run_simple_command (sc->name != NULL, pre expand_word(ctx, sc->name, &args));
run_simple_command (sc->name != NULL, post expand_word(ctx, sc->name, &args)): ret = 0;
run_simple_command (sc->name != NULL, pre expand_assignmets);
run_simple_command (sc->name != NULL, pre expand_assignmets): ret = 0;
run_simple_command (sc->name != NULL, pre run_builtin);
run_simple_command (sc->name != NULL, post run_builtin): ret = 1;
run_simple_command (sc->name != NULL, post run_command or run_builtin or run_process): ret = 1;
run_command (post switch (cmd->type)): cmd->type = 0; ret = 1;
run_command_list_array (!list->ampersand, post run_and_or_list): i = 0; ret = 1; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, pre propagation): i = 0; ret = 1; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, post propagation): i = 0; ret = 1; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list loop): ret = 1; state->last_status = 1; state->exit = -1;
mrsh_run_program (post run_command_list_array): ret = 1; state->last_status = 1; state->exit = -1;
mrsh_run_program (post run_pending_traps): state->last_status = 1; state->exit = -1;
run_word_command (child, post mrsh_run_program): ctx->state->last_status = 1; ctx->state->exit = 1;
run_word_command (pre job_wait_process(process)): ctx->state->last_status = 0; ctx->state->exit = -1;
run_word_command (post job_wait_process(process)): status = 1; ctx->state->last_status = 0; ctx->state->exit = -1;
run_word_command (post propagation): status = 1; ctx->state->last_status = 1; ctx->state->exit = -1;
_run_word (MRSH_WORD_COMMAND): ret = 1; ctx->state->last_status = 1; ctx->state->exit = -1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 1; ret = 1; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 2; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 2; ret = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 3; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 3; ret = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 4; ctx->state->last_status = 1;
run_word_command:
program
└─command_list ─ pipeline
└─simple_command
├─name ─ word_string [0:0 → 0:0] printf
├─argument 1 ─ word_list (quoted)
│ └─word_string [0:0 → 0:0] %s\n
└─argument 2 ─ word_list (quoted)
└─word_parameter
└─name ?
run_word_command (child, pre mrsh_run_program): ctx->state->last_status = 1; ctx->state->exit = -1;
mrsh_run_program (pre run_command_list_array): state->last_status = 1; state->exit = -1;
run_command_list_array (pre run_and_or_list loop): state->last_status = 1; state->exit = -1;
run_command_list_array (!list->ampersand, pre run_and_or_list): i = 0; state->last_status = 1; state->exit = -1;
run_command (pre switch (cmd->type)): cmd->type = 0;
run_command (MRSH_SIMPLE_COMMAND, pre run_simple_command);
run_simple_command (sc->name != NULL, pre expand_word(ctx, sc->name, &args));
run_simple_command (sc->name != NULL, post expand_word(ctx, sc->name, &args)): ret = 0;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 0;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 0; ret = 0; ctx->state->last_status = 1;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 0; ret = 0;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 1;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 0; ret = 0; ctx->state->last_status = 1;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 1; ret = 0;
run_simple_command (sc->name != NULL, pre expand_assignmets);
run_simple_command (sc->name != NULL, pre expand_assignmets): ret = 0;
run_simple_command (sc->name != NULL, pre run_process);
run_simple_command (sc->name != NULL, post run_process): ret = 0;
run_simple_command (sc->name != NULL, post run_command or run_builtin or run_process): ret = 0;
run_command (post switch (cmd->type)): cmd->type = 0; ret = 0;
run_command_list_array (!list->ampersand, post run_and_or_list): i = 0; ret = 0; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list, pre propagation): i = 0; ret = 0; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list, post propagation): i = 0; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list loop): ret = 0; state->last_status = 0; state->exit = -1;
mrsh_run_program (post run_command_list_array): ret = 0; state->last_status = 0; state->exit = -1;
mrsh_run_program (post run_pending_traps): state->last_status = 0; state->exit = -1;
run_word_command (child, post mrsh_run_program): ctx->state->last_status = 0; ctx->state->exit = 0;
run_word_command (pre job_wait_process(process)): ctx->state->last_status = 1; ctx->state->exit = -1;
run_word_command (post job_wait_process(process)): status = 0; ctx->state->last_status = 1; ctx->state->exit = -1;
run_word_command (post propagation): status = 0; ctx->state->last_status = 0; ctx->state->exit = -1;
_run_word (MRSH_WORD_COMMAND): ret = 0; ctx->state->last_status = 0; ctx->state->exit = -1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 4; ret = 0; ctx->state->last_status = 0;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 5; ctx->state->last_status = 0;
run_word_command:
program
└─command_list ─ pipeline
└─simple_command
└─name ─ word_string [0:0 → 0:0] false
run_word_command (child, pre mrsh_run_program): ctx->state->last_status = 0; ctx->state->exit = -1;
mrsh_run_program (pre run_command_list_array): state->last_status = 0; state->exit = -1;
run_command_list_array (pre run_and_or_list loop): state->last_status = 0; state->exit = -1;
run_command_list_array (!list->ampersand, pre run_and_or_list): i = 0; state->last_status = 0; state->exit = -1;
run_command (pre switch (cmd->type)): cmd->type = 0;
run_command (MRSH_SIMPLE_COMMAND, pre run_simple_command);
run_simple_command (sc->name != NULL, pre expand_word(ctx, sc->name, &args));
run_simple_command (sc->name != NULL, post expand_word(ctx, sc->name, &args)): ret = 0;
run_simple_command (sc->name != NULL, pre expand_assignmets);
run_simple_command (sc->name != NULL, pre expand_assignmets): ret = 0;
run_simple_command (sc->name != NULL, pre run_builtin);
run_simple_command (sc->name != NULL, post run_builtin): ret = 1;
run_simple_command (sc->name != NULL, post run_command or run_builtin or run_process): ret = 1;
run_command (post switch (cmd->type)): cmd->type = 0; ret = 1;
run_command_list_array (!list->ampersand, post run_and_or_list): i = 0; ret = 1; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, pre propagation): i = 0; ret = 1; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list, post propagation): i = 0; ret = 1; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list loop): ret = 1; state->last_status = 1; state->exit = -1;
mrsh_run_program (post run_command_list_array): ret = 1; state->last_status = 1; state->exit = -1;
mrsh_run_program (post run_pending_traps): state->last_status = 1; state->exit = -1;
run_word_command (child, post mrsh_run_program): ctx->state->last_status = 1; ctx->state->exit = 1;
run_word_command (pre job_wait_process(process)): ctx->state->last_status = 0; ctx->state->exit = -1;
run_word_command (post job_wait_process(process)): status = 1; ctx->state->last_status = 0; ctx->state->exit = -1;
run_word_command (post propagation): status = 1; ctx->state->last_status = 1; ctx->state->exit = -1;
_run_word (MRSH_WORD_COMMAND): ret = 1; ctx->state->last_status = 1; ctx->state->exit = -1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 5; ret = 1; ctx->state->last_status = 1;
expand_assignments (post run_word): ret = 1; ctx->state->last_status = 1;
run_simple_command (sc->name == NULL, post expand_assignments): ret = 1; ctx->state->last_status = 1;
run_simple_command (sc->name == NULL, pre run_assignments): ret = 1; ctx->state->last_status = 1;
run_assignments (pre mrsh_env_set loop);
run_assignments (post mrsh_env_set loop);
run_simple_command (sc->name == NULL, post run_assignments): ret = 1; run_ret = 0; ctx->state->last_status = 1;
run_command (post switch (cmd->type)): cmd->type = 0; ret = 1;
run_command_list_array (!list->ampersand, post run_and_or_list): i = 1; ret = 1; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list, pre propagation): i = 1; ret = 1; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list, post propagation): i = 1; ret = 1; state->last_status = 1; state->exit = -1;
run_command_list_array (!list->ampersand, pre run_and_or_list): i = 2; state->last_status = 1; state->exit = -1;
run_command (pre switch (cmd->type)): cmd->type = 0;
run_command (MRSH_SIMPLE_COMMAND, pre run_simple_command);
run_simple_command (sc->name != NULL, pre expand_word(ctx, sc->name, &args));
run_simple_command (sc->name != NULL, post expand_word(ctx, sc->name, &args)): ret = 0;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 0;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 0; ret = 0; ctx->state->last_status = 1;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 0; ret = 0;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 1;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 0; ret = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 1; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 1; ret = 0; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, pre _run_word): i = 2; ctx->state->last_status = 1;
_run_word (MRSH_WORD_LIST, post _run_word): i = 2; ret = 0; ctx->state->last_status = 1;
run_simple_command (sc->name != NULL, pre expand_word(ctx, arg, &args)): i = 1; ret = 0;
run_simple_command (sc->name != NULL, pre expand_assignmets);
run_simple_command (sc->name != NULL, pre expand_assignmets): ret = 0;
run_simple_command (sc->name != NULL, pre run_process);
1 1 1
run_simple_command (sc->name != NULL, post run_process): ret = 0;
run_simple_command (sc->name != NULL, post run_command or run_builtin or run_process): ret = 0;
run_command (post switch (cmd->type)): cmd->type = 0; ret = 0;
run_command_list_array (!list->ampersand, post run_and_or_list): i = 2; ret = 0; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list, pre propagation): i = 2; ret = 0; state->last_status = 1; state->exit = -1;
run_command_list_array (post run_and_or_list, post propagation): i = 2; ret = 0; state->last_status = 0; state->exit = -1;
run_command_list_array (post run_and_or_list loop): ret = 0; state->last_status = 0; state->exit = -1;
mrsh_run_program (post run_command_list_array): ret = 0; state->last_status = 0; state->exit = -1;
mrsh_run_program (post run_pending_traps): state->last_status = 0; state->exit = -1;
main (mrsh_parser_eof(parser)): state->exit = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment