Files
mercury/trace/mercury_trace_command_queue.c
Zoltan Somogyi a1f69d35fc Fix Mantis bug #45, which was that mdb effectively ignored some commands
Estimated hours taken: 1.5
Branches: main

Fix Mantis bug #45, which was that mdb effectively ignored some commands
in .mdbrc files.

trace/mercury_trace_internal.[ch]:
trace/mercury_trace_command_queue.[ch]:
	Move the code for manipulating the command queue from
	mercury_trace_internal.c to a new module. This improves the level of
	abstraction. The ultimate cause of the bug was a lack of abstraction.

	The old code put commands from startup files in the command queue
	in a mixed order: respecting order within each startup file, but
	reversing order among startup files. The cause of the bug was
	that the commands from .mdbrc files were put into the queue
	*after* the commands from the system's standard startup file in time,
	but *before* them in order, so the commands in the standard startup
	file could override commands from .mdbrc files.

	The fix is to consistently put commands in order: from the standard
	system startup file, from .mdbrc, and from the environment.

	Give better names to some functions.

	Provide a mechanism for debugging the command queue mechanism.

trace/mercury_trace_cmd_backward.c:
	Use those better names.

trace/Mmakefile:
	Add the new module.

tests/debugger/mdbrc_test.{m,inp,exp,mdbrc}:
	Add a regression test for this bug, a minimally modified version
	of the bug demo program in Mantis.

tests/debugger/Mmakefile:
	Enable the new test case, which specifies its own .mdbrc file.

tests/Mmake.common:
	Provide a way for a test case to not use the .mdbrc file used by all
	the other debugger tests, so it could specify its own.
2008-02-20 02:59:38 +00:00

141 lines
3.4 KiB
C

/*
** vim: ts=4 sw=4 expandtab
*/
/*
** Copyright (C) 2008 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
/*
** This module looks after a queue of lines containing commands for mdb.
** Its main use is during initialization.
**
** Main author: Zoltan Somogyi.
*/
#include "mercury_imp.h"
#include "mercury_trace_command_queue.h"
#include "mercury_trace_internal.h" /* for MR_trace_echo_queue_commands */
/*
** MR_cmd_queue_head points to the first node in the list, while
** MR_cmd_queue_tail points to the last. It is an invariant that
** if one of these two variables is NULL, the other is NULL as well.
*/
static MR_CmdLines *MR_cmd_queue_head = NULL;
static MR_CmdLines *MR_cmd_queue_tail = NULL;
void
MR_insert_command_line_at_head(const char *line_contents)
{
MR_CmdLines *cmd_line;
cmd_line = MR_NEW(MR_CmdLines);
cmd_line->MR_cmd_line_contents = MR_copy_string(line_contents);
cmd_line->MR_cmd_line_next = MR_cmd_queue_head;
MR_cmd_queue_head = cmd_line;
if (MR_cmd_queue_tail == NULL) {
MR_cmd_queue_tail = MR_cmd_queue_head;
}
}
void
MR_insert_command_line_at_tail(const char *line_contents)
{
MR_CmdLines *cmd_line;
cmd_line = MR_NEW(MR_CmdLines);
cmd_line->MR_cmd_line_contents = MR_copy_string(line_contents);
cmd_line->MR_cmd_line_next = NULL;
if (MR_cmd_queue_tail == NULL) {
MR_cmd_queue_head = cmd_line;
MR_cmd_queue_tail = cmd_line;
} else {
MR_cmd_queue_tail->MR_cmd_line_next = cmd_line;
MR_cmd_queue_tail = cmd_line;
}
}
void
MR_insert_command_lines_at_head(MR_CmdLines *new_lines)
{
MR_CmdLines *last_new_node;
if (new_lines == NULL) {
return;
}
for (last_new_node = new_lines;
last_new_node->MR_cmd_line_next != NULL;
last_new_node = last_new_node->MR_cmd_line_next)
{
/* do nothing */
}
MR_assert(last_new_node->MR_cmd_line_next == NULL);
last_new_node->MR_cmd_line_next = MR_cmd_queue_head;
MR_cmd_queue_head = new_lines;
if (MR_cmd_queue_tail == NULL) {
MR_cmd_queue_tail = last_new_node;
}
}
void
MR_insert_command_lines_at_tail(MR_CmdLines *new_lines)
{
MR_CmdLines *last_new_node;
if (new_lines == NULL) {
return;
}
for (last_new_node = new_lines;
last_new_node->MR_cmd_line_next != NULL;
last_new_node = last_new_node->MR_cmd_line_next)
{
/* do nothing */
}
MR_assert(last_new_node->MR_cmd_line_next == NULL);
if (MR_cmd_queue_tail == NULL) {
MR_cmd_queue_head = new_lines;
MR_cmd_queue_tail = last_new_node;
} else {
MR_cmd_queue_tail->MR_cmd_line_next = new_lines;
MR_cmd_queue_tail = last_new_node;
}
}
char *
MR_trace_getline_command_queue(void)
{
if (MR_cmd_queue_head != NULL) {
MR_CmdLines *old;
char *line_contents;
old = MR_cmd_queue_head;
line_contents = MR_cmd_queue_head->MR_cmd_line_contents;
MR_cmd_queue_head = MR_cmd_queue_head->MR_cmd_line_next;
if (MR_cmd_queue_head == NULL) {
MR_cmd_queue_tail = NULL;
}
if (MR_trace_echo_queue_commands) {
printf("queue command <%s>\n", line_contents);
fflush(stdout);
}
MR_free(old);
return line_contents;
} else {
return NULL;
}
}