2006-07-21 Andrew Stubbs <andrew.stubbs@st.com>
* cli/cli-cmds.c (source_verbose, trace_commands): New variables. (source_script): New function. (source_verbose_cleanup): New function. (source_command): Move old contents to source_script. Make function static. Parse -v option and call source_script. (init_cli_cmds): Update source command help. Add 'set trace-commands' command. * cli/cli-script.c (command_next_depth): New static variable. (suppress_next_print_command_trace): New static variable. (reset_command_nest_depth): New function. (print_command_trace): New function. (execute_control_command): Split the continue_control and break_control cases, add calls to print_command_trace and count the nest depth. (while_command): Set suppress_next_print_command_trace. (if_command): Likewise. * top.c (execute_command): Call print_command_trace. * cli/cli-cmds.h (source_verbose, trace_commands): New extern variables. (source_command): Change to source_script. * main.c (captued_main): Use source_script instead of source_command. * top.h (source_command): Change to source_script. * event-top.c (display_gdb_prompt): Call reset_command_nest_depth. * cli/cli-script.h (print_command_trace): Export. (reset_command_nest_depth): Likewise. docs/ * gdb.texinfo (Optional warnings and messages): Add 'set/show trace-commands'. (Command files): Add '-v' to source command. testsuite/ * gdb.base/default.exp: Update source command error message. * gdb.base/help.exp: Update 'help source' message.
This commit is contained in:
parent
3e4cf9243a
commit
16026cd75d
14 changed files with 221 additions and 15 deletions
|
@ -46,9 +46,15 @@ static struct cleanup * setup_user_args (char *p);
|
|||
|
||||
static void validate_comname (char *);
|
||||
|
||||
/* Level of control structure. */
|
||||
/* Level of control structure when reading. */
|
||||
static int control_level;
|
||||
|
||||
/* Level of control structure when executing. */
|
||||
static int command_nest_depth = 1;
|
||||
|
||||
/* This is to prevent certain commands being printed twice. */
|
||||
static int suppress_next_print_command_trace = 0;
|
||||
|
||||
/* Structure for arguments to user defined functions. */
|
||||
#define MAXUSERARGS 10
|
||||
struct user_args
|
||||
|
@ -293,6 +299,46 @@ execute_user_command (struct cmd_list_element *c, char *args)
|
|||
do_cleanups (old_chain);
|
||||
}
|
||||
|
||||
/* This function is called every time GDB prints a prompt.
|
||||
It ensures that errors and the like to not confuse the command tracing. */
|
||||
|
||||
void
|
||||
reset_command_nest_depth (void)
|
||||
{
|
||||
command_nest_depth = 1;
|
||||
|
||||
/* Just in case. */
|
||||
suppress_next_print_command_trace = 0;
|
||||
}
|
||||
|
||||
/* Print the command, prefixed with '+' to represent the call depth.
|
||||
This is slightly complicated because this function may be called
|
||||
from execute_command and execute_control_command. Unfortunately
|
||||
execute_command also prints the top level control commands.
|
||||
In these cases execute_command will call execute_control_command
|
||||
via while_command or if_command. Inner levels of 'if' and 'while'
|
||||
are dealt with directly. Therefore we can use these functions
|
||||
to determine whether the command has been printed already or not. */
|
||||
void
|
||||
print_command_trace (const char *cmd)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (suppress_next_print_command_trace)
|
||||
{
|
||||
suppress_next_print_command_trace = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!source_verbose && !trace_commands)
|
||||
return;
|
||||
|
||||
for (i=0; i < command_nest_depth; i++)
|
||||
printf_filtered ("+");
|
||||
|
||||
printf_filtered ("%s\n", cmd);
|
||||
}
|
||||
|
||||
enum command_control_type
|
||||
execute_control_command (struct command_line *cmd)
|
||||
{
|
||||
|
@ -322,7 +368,16 @@ execute_control_command (struct command_line *cmd)
|
|||
break;
|
||||
|
||||
case continue_control:
|
||||
print_command_trace ("loop_continue");
|
||||
|
||||
/* Return for "continue", and "break" so we can either
|
||||
continue the loop at the top, or break out. */
|
||||
ret = cmd->control_type;
|
||||
break;
|
||||
|
||||
case break_control:
|
||||
print_command_trace ("loop_break");
|
||||
|
||||
/* Return for "continue", and "break" so we can either
|
||||
continue the loop at the top, or break out. */
|
||||
ret = cmd->control_type;
|
||||
|
@ -330,6 +385,10 @@ execute_control_command (struct command_line *cmd)
|
|||
|
||||
case while_control:
|
||||
{
|
||||
char *buffer = alloca (strlen (cmd->line) + 7);
|
||||
sprintf (buffer, "while %s", cmd->line);
|
||||
print_command_trace (buffer);
|
||||
|
||||
/* Parse the loop control expression for the while statement. */
|
||||
new_line = insert_args (cmd->line);
|
||||
if (!new_line)
|
||||
|
@ -362,7 +421,9 @@ execute_control_command (struct command_line *cmd)
|
|||
current = *cmd->body_list;
|
||||
while (current)
|
||||
{
|
||||
command_nest_depth++;
|
||||
ret = execute_control_command (current);
|
||||
command_nest_depth--;
|
||||
|
||||
/* If we got an error, or a "break" command, then stop
|
||||
looping. */
|
||||
|
@ -391,6 +452,10 @@ execute_control_command (struct command_line *cmd)
|
|||
|
||||
case if_control:
|
||||
{
|
||||
char *buffer = alloca (strlen (cmd->line) + 4);
|
||||
sprintf (buffer, "if %s", cmd->line);
|
||||
print_command_trace (buffer);
|
||||
|
||||
new_line = insert_args (cmd->line);
|
||||
if (!new_line)
|
||||
break;
|
||||
|
@ -417,7 +482,9 @@ execute_control_command (struct command_line *cmd)
|
|||
/* Execute commands in the given arm. */
|
||||
while (current)
|
||||
{
|
||||
command_nest_depth++;
|
||||
ret = execute_control_command (current);
|
||||
command_nest_depth--;
|
||||
|
||||
/* If we got an error, get out. */
|
||||
if (ret != simple_control)
|
||||
|
@ -454,6 +521,7 @@ while_command (char *arg, int from_tty)
|
|||
if (command == NULL)
|
||||
return;
|
||||
|
||||
suppress_next_print_command_trace = 1;
|
||||
execute_control_command (command);
|
||||
free_command_lines (&command);
|
||||
}
|
||||
|
@ -472,6 +540,7 @@ if_command (char *arg, int from_tty)
|
|||
if (command == NULL)
|
||||
return;
|
||||
|
||||
suppress_next_print_command_trace = 1;
|
||||
execute_control_command (command);
|
||||
free_command_lines (&command);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue