Make an mdb error message more informative.

trace/mercury_trace_internal.c:
    Whe printing the "there is no such variable" message at
    conditional break points, print the name of the variable.
    The original message can be misread to mean that there
    is nothing at *the selected path*; the new one cannot.

trace/mercury_trace_spy.c:
trace/mercury_trace_spy.h:
    Add a mechanism to enable the above change.

tests/debugger/cond.exp:
    Expect the updated error message.
This commit is contained in:
Zoltan Somogyi
2025-06-12 10:16:50 +02:00
parent e3ce587da6
commit 672582375c
4 changed files with 34 additions and 12 deletions

View File

@@ -106,14 +106,16 @@ mdb> condition Y^1^2 = 1
Y ^1^2 = 1
mdb> continue
mdb: couldn't evaluate break point condition
Y ^1^2 = 1: there is no such variable.
Y ^1^2 = 1.
The error is: there is no variable named Y.
E15: C15 CALL pred cond.r/2-0 (det)
mdb> condition -p Y^1^2 = 1
0: + stop interface pred cond.r/2-0 (det)
-p Y ^1^2 = 1
mdb> continue
mdb: couldn't evaluate break point condition
Y ^1^2 = 1: there is no such variable.
Y ^1^2 = 1.
The error is: there is no variable named Y.
E16: C16 CALL pred cond.r/2-0 (det)
mdb> delete *
0: E stop interface pred cond.r/2-0 (det)
@@ -159,7 +161,8 @@ mdb> condition X^4 = 1
X ^4 = 1
mdb> continue
mdb: couldn't evaluate break point condition
X ^4 = 1: the path 4 does not exist.
X ^4 = 1.
The error is: the path 4 does not exist.
E22: C21 CALL pred cond.r/2-0 (det)
mdb> print
r(1, _)

View File

@@ -213,11 +213,22 @@ MR_trace_event_internal(MR_TraceCmdInfo *cmd, MR_bool interactive,
MR_trace_listing_path_ensure_init();
if (MR_spy_point_cond_problem != NULL) {
const char *cond_var_name;
fprintf(MR_mdb_err, "mdb: couldn't evaluate break point condition\n");
fprintf(MR_mdb_err, " ");
MR_print_spy_cond(MR_mdb_err, MR_spy_point_cond_bad);
MR_print_spy_cond(MR_mdb_err, MR_spy_point_cond_bad, &cond_var_name);
fprintf(MR_mdb_err, ".\n");
fprintf(MR_mdb_err, "The error is: %s.\n", MR_spy_point_cond_problem);
if (MR_streq(MR_spy_point_cond_problem, "there is no such variable") &&
cond_var_name != NULL)
{
fprintf(MR_mdb_err,
"The error is: there is no variable named %s.\n",
cond_var_name);
} else {
fprintf(MR_mdb_err,
"The error is: %s.\n", MR_spy_point_cond_problem);
}
MR_spy_point_cond_bad = NULL;
MR_spy_point_cond_problem = NULL;
}

View File

@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1998-2002, 2005-2008, 2011 The University of Melbourne.
// Copyright (C) 2014-2016, 2018 The Mercury team.
// Copyright (C) 2014-2016, 2018, 2025 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This file contains code to manage spy points for both
@@ -1076,6 +1076,7 @@ MR_print_spy_point(FILE *fp, int spy_point_num, MR_bool verbose)
MR_SpyPoint *point;
MR_SpyCond *cond;
MR_TracePort port;
const char *ignored_cond_var_name;
point = MR_spy_points[spy_point_num];
fprintf(fp, "%2d: %1s %-5s %-9s ",
@@ -1157,7 +1158,7 @@ MR_print_spy_point(FILE *fp, int spy_point_num, MR_bool verbose)
fprintf(fp, "-p ");
}
MR_print_spy_cond(fp, cond);
MR_print_spy_cond(fp, cond, &ignored_cond_var_name);
fprintf(fp, "\n");
}
@@ -1216,24 +1217,28 @@ MR_print_spy_point(FILE *fp, int spy_point_num, MR_bool verbose)
}
void
MR_print_spy_cond(FILE *fp, MR_SpyCond *cond)
MR_print_spy_cond(FILE *fp, MR_SpyCond *cond, const char **name)
{
switch (cond->MR_cond_var_spec.MR_var_spec_kind) {
case MR_VAR_SPEC_NUMBER:
fprintf(fp, "%" MR_INTEGER_LENGTH_MODIFIER "u",
cond->MR_cond_var_spec.MR_var_spec_number);
*name = NULL;
break;
case MR_VAR_SPEC_NAME:
fprintf(fp, "%s", cond->MR_cond_var_spec.MR_var_spec_name);
*name = cond->MR_cond_var_spec.MR_var_spec_name;
fprintf(fp, "%s", *name);
break;
case MR_VAR_SPEC_HELD_NAME:
fprintf(fp, "$%s", cond->MR_cond_var_spec.MR_var_spec_name);
*name = cond->MR_cond_var_spec.MR_var_spec_name;
fprintf(fp, "$%s", *name);
break;
case MR_VAR_SPEC_ATTRIBUTE:
fprintf(fp, "!%s", cond->MR_cond_var_spec.MR_var_spec_name);
*name = NULL;
break;
}

View File

@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1998-2001, 2005-2007 The University of Melbourne.
// Copyright (C) 2016, 2018 The Mercury team.
// Copyright (C) 2016, 2018, 2025 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This file contains the declarations of the types and functions that
@@ -187,8 +187,11 @@ extern void MR_delete_spy_point(int point_table_slot);
extern void MR_print_spy_point(FILE *fp, int i, MR_bool verbose);
// Print the given spy point condition in a user-friendly manner.
// If the condition involves a named variable, set *name to point to that name.
// Otherwise, set it to NULL.
extern void MR_print_spy_cond(FILE *fp, MR_SpyCond *cond);
extern void MR_print_spy_cond(FILE *fp, MR_SpyCond *cond,
const char **name);
// Print the set of current spy points (including those that are currently
// disabled) to fp in a format that, when sourced by mdb, recreates those