mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 12:26:29 +00:00
Estimated hours taken: 5
Branches: main
Fix up some places in the trace directory where there were (potential)
mismatches between the sizes of types used to represent natural numbers.
Much of the existing code in the trace directory assumed that
sizeof(int) == sizeof(MR_Unsigned), which is not true on our 64-bit
machines. Zoltan's recent change to MR_trace_is_natural_number() broke
that assumption in a lot of places. (I committed a workaround for that
yesterday.)
This diff addresses the above problem by changing the types of many of
things that represent natural numbers from int to MR_Unsigned.
This should make the trace code more robust on 64-bit machines and
help avoid a recurrence of problems like the above.
NOTE: this change does not change slot numbers into unsigned values since
they still use negative values as sentinels. I will address slot numbers
in as part of a separate change.
trace/mercury_trace.h:
Add typedefs for MR_Unsigned for several commonly used quantities
within the trace code. For I/O action numbers we just re-use
the type MR_IoActionNum from the runtime, rather than defining
a new typedef here.
trace/mercury_trace_tables.h:
Change the type of the `match_proc_max' and `match_proc_next' fields
of the MR_MatchesInfo structure into MR_Unsigned instead of int.
trace/mercury_trace_cmd_parameter.[ch]:
Change the type of the global variables, MR_scroll_{limit,next}
and MR_num_context_lines into MR_Unsigned instead of int.
trace/mercury_trace_util.[ch]:
Restore Zoltan's change that made the type of the second argument of
MR_trace_is_natural_number() into MR_Unsigned. The places that
caused this to break on 64-bit machines have now been fixed.
Update the documentation of MR_trace_is_natural_number();
Delete MR_trace_is_unsigned() since that now duplicates
MR_trace_is_natural_number().
Add a new function MR_trace_is_nonneg_int() which is similar
to the above functions except that it stores its result in
an int. (This is needed for handling slot numbers which are
still represented using ints.)
trace/mercury_trace_cmd_developer.c:
Refactor some code so that we don't need to use -1 as a sentinel
value.
trace/mercury_trace_cmd_help.c:
Use MR_trace_is_nonneg_int() instead of MR_trace_is_natural_number()
to handle slot numbers.
runtime/mercury_trace_base.[ch]:
Change the type of the first argument of MR_trace_get_action()
from int to MR_IoActionNum.
trace/mercury_trace_alias.c:
trace/mercury_trace_cmd_backward.c:
trace/mercury_trace_cmd_breakpoint.c:
trace/mercury_trace_cmd_browsing.c:
trace/mercury_trace_cmd_dd.c:
trace/mercury_trace_cmd_exp.c:
trace/mercury_trace_cmd_forward.c:
trace/mercury_stack_trace.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_spy.[ch]:
trace/mercury_trace_vars.[ch]:
Use MR_Unsigned instead of int to represent natural numbers.
153 lines
4.2 KiB
C
153 lines
4.2 KiB
C
/*
|
|
** vim: ts=4 sw=4 expandtab
|
|
*/
|
|
/*
|
|
** Copyright (C) 1998-2007 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 implements the mdb commands in the "help" category.
|
|
**
|
|
** The structure of these files is:
|
|
**
|
|
** - all the #includes
|
|
** - local macros and declarations of local static functions
|
|
** - one function for each command in the category
|
|
** - any auxiliary functions
|
|
** - any command argument strings
|
|
** - option processing functions.
|
|
*/
|
|
|
|
#include "mercury_std.h"
|
|
#include "mercury_getopt.h"
|
|
|
|
#include "mercury_array_macros.h"
|
|
#include "mercury_trace_internal.h"
|
|
#include "mercury_trace_cmds.h"
|
|
#include "mercury_trace_cmd_help.h"
|
|
#include "mercury_trace_help.h"
|
|
#include "mercury_trace_util.h"
|
|
|
|
/****************************************************************************/
|
|
|
|
/* The initial number of lines in documentation entries. */
|
|
#define MR_INIT_DOC_CHARS 800
|
|
|
|
static const char *MR_trace_read_help_text(void);
|
|
|
|
/****************************************************************************/
|
|
|
|
MR_Next
|
|
MR_trace_cmd_document_category(char **words, int word_count,
|
|
MR_TraceCmdInfo *cmd, MR_EventInfo *event_info, MR_Code **jumpaddr)
|
|
{
|
|
int slot;
|
|
const char *msg;
|
|
const char *help_text;
|
|
|
|
help_text = MR_trace_read_help_text();
|
|
if (word_count != 3) {
|
|
MR_trace_usage_cur_cmd();
|
|
} else if (! MR_trace_is_nonneg_int(words[1], &slot)) {
|
|
MR_trace_usage_cur_cmd();
|
|
} else {
|
|
msg = MR_trace_add_cat(words[2], slot, help_text);
|
|
if (msg != NULL) {
|
|
fflush(MR_mdb_out);
|
|
fprintf(MR_mdb_err,
|
|
"Document category `%s' not added: %s.\n", words[2], msg);
|
|
}
|
|
}
|
|
|
|
return KEEP_INTERACTING;
|
|
}
|
|
|
|
MR_Next
|
|
MR_trace_cmd_document(char **words, int word_count, MR_TraceCmdInfo *cmd,
|
|
MR_EventInfo *event_info, MR_Code **jumpaddr)
|
|
{
|
|
int slot;
|
|
const char *msg;
|
|
const char *help_text;
|
|
|
|
help_text = MR_trace_read_help_text();
|
|
if (word_count != 4) {
|
|
MR_trace_usage_cur_cmd();
|
|
} else if (! MR_trace_is_nonneg_int(words[2], &slot)) {
|
|
MR_trace_usage_cur_cmd();
|
|
} else {
|
|
msg = MR_trace_add_item(words[1], words[3], slot, help_text);
|
|
if (msg != NULL) {
|
|
fflush(MR_mdb_out);
|
|
fprintf(MR_mdb_err,
|
|
"Document item `%s' in category `%s' not added: %s.\n",
|
|
words[3], words[1], msg);
|
|
}
|
|
}
|
|
|
|
return KEEP_INTERACTING;
|
|
}
|
|
|
|
MR_Next
|
|
MR_trace_cmd_help(char **words, int word_count, MR_TraceCmdInfo *cmd,
|
|
MR_EventInfo *event_info, MR_Code **jumpaddr)
|
|
{
|
|
if (word_count == 1) {
|
|
MR_trace_help();
|
|
} else if (word_count == 2) {
|
|
MR_trace_help_word(words[1]);
|
|
} else if (word_count == 3) {
|
|
MR_trace_help_cat_item(words[1], words[2]);
|
|
} else {
|
|
MR_trace_usage_cur_cmd();
|
|
}
|
|
|
|
return KEEP_INTERACTING;
|
|
}
|
|
|
|
/****************************************************************************/
|
|
|
|
/*
|
|
** Read lines until we find one that contains only "end".
|
|
** Return the lines concatenated together.
|
|
** The memory returned is allocated with MR_malloc();
|
|
** it is the caller's responsibility to MR_free() it when appropriate.
|
|
*/
|
|
|
|
static const char *
|
|
MR_trace_read_help_text(void)
|
|
{
|
|
char *text;
|
|
char *doc_chars = NULL;
|
|
int doc_char_max = 0;
|
|
int next_char_slot;
|
|
int line_len;
|
|
int i;
|
|
|
|
next_char_slot = 0;
|
|
while ((text = MR_trace_getline("cat> ", MR_mdb_in, MR_mdb_out)) != NULL) {
|
|
if (MR_streq(text, "end")) {
|
|
MR_free(text);
|
|
break;
|
|
}
|
|
|
|
line_len = strlen(text);
|
|
MR_ensure_big_enough(next_char_slot + line_len + 2, doc_char, char,
|
|
MR_INIT_DOC_CHARS);
|
|
for (i = 0; i < line_len; i++) {
|
|
doc_chars[next_char_slot + i] = text[i];
|
|
}
|
|
|
|
next_char_slot += line_len;
|
|
doc_chars[next_char_slot] = '\n';
|
|
next_char_slot += 1;
|
|
MR_free(text);
|
|
}
|
|
|
|
MR_ensure_big_enough(next_char_slot, doc_char, char, MR_INIT_DOC_CHARS);
|
|
doc_chars[next_char_slot] = '\0';
|
|
return doc_chars;
|
|
}
|