Re: [PATCH] MI error messages

Nick Roberts
2005-06-22T11:06:32Z

Nick Roberts writes:
> I'll look at submitting a revised patch for mi-cmd-stack.c and mi-cmd-var.c

I've defined two functions:

enum mi_cmd_result
mi_error (char* message)
{
mi_error_message = xstrprintf ("%s", message);
return MI_CMD_ERROR;
}

enum mi_cmd_result
mi_usage_error (char* message)
{
mi_error_message = xstrprintf (_("Usage: %s"), message);
return MI_CMD_ERROR;
}

and used them in mi-cmd-var.c as shown below.

WDYT?

Nick

*** mi/mi-cmd-var.c.~1.21.~ 2005-06-21 09:02:37.000000000 +1200
--- mi/mi-cmd-var.c 2005-06-22 22:56:03.000000000 +1200
***************
*** 52,58 ****
{
/* mi_error_message = xstrprintf ("mi_cmd_var_create: Usage:
...."); return MI_CMD_ERROR; */
! error (_("mi_cmd_var_create: Usage: NAME FRAME EXPRESSION."));
}

name = xstrdup (argv[0]);
--- 52,58 ----
{
/* mi_error_message = xstrprintf ("mi_cmd_var_create: Usage:
...."); return MI_CMD_ERROR; */
! return mi_usage_error ("-var-create NAME FRAME EXPRESSION.");
}

name = xstrdup (argv[0]);
***************
*** 71,77 ****
name = varobj_gen_name ();
}
else if (!isalpha (*name))
! error (_("mi_cmd_var_create: name of object must begin with a letter"));

if (strcmp (frame, "*") == 0)
var_type = USE_CURRENT_FRAME;
--- 71,77 ----
name = varobj_gen_name ();
}
else if (!isalpha (*name))
! return mi_error (_("Name of object must begin with a letter."));

if (strcmp (frame, "*") == 0)
var_type = USE_CURRENT_FRAME;
***************
*** 91,98 ****
var = varobj_create (name, expr, frameaddr, var_type);

if (var == NULL)
! error (_("mi_cmd_var_create: unable to create variable object"));
!
ui_out_field_string (uiout, "name", name);
ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
type = varobj_get_type (var);
--- 91,101 ----
var = varobj_create (name, expr, frameaddr, var_type);

if (var == NULL)
! {
! mi_error_message
! = xstrprintf (_("No symbol %s in current context."), expr);
! return MI_CMD_ERROR;
! }
ui_out_field_string (uiout, "name", name);
ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
type = varobj_get_type (var);
***************
*** 119,125 ****
struct cleanup *old_cleanups;

if (argc < 1 || argc > 2)
! error (_("mi_cmd_var_delete: Usage: [-c] EXPRESSION."));

name = xstrdup (argv[0]);
/* Add cleanup for name. Must be free_current_contents as
--- 122,128 ----
struct cleanup *old_cleanups;

if (argc < 1 || argc > 2)
! return mi_usage_error ("-var-delete [-c] EXPRESSION.");

name = xstrdup (argv[0]);
/* Add cleanup for name. Must be free_current_contents as
***************
*** 131,139 ****
if (argc == 1)
{
if (strcmp (name, "-c") == 0)
! error (_("mi_cmd_var_delete: Missing required argument after '-c': variable object name"));
if (*name == '-')
! error (_("mi_cmd_var_delete: Illegal variable object name"));
}

/* If we have 2 arguments they must be '-c' followed by a string
--- 134,142 ----
if (argc == 1)
{
if (strcmp (name, "-c") == 0)
! return mi_error (_("Missing required argument after '-c': variable object name."));
if (*name == '-')
! return mi_error (_("Illegal variable object name."));
}

/* If we have 2 arguments they must be '-c' followed by a string
***************
*** 142,148 ****
{
expr = xstrdup (argv[1]);
if (strcmp (name, "-c") != 0)
! error (_("mi_cmd_var_delete: Invalid option."));
children_only_p = 1;
xfree (name);
name = xstrdup (expr);
--- 145,151 ----
{
expr = xstrdup (argv[1]);
if (strcmp (name, "-c") != 0)
! return mi_error (_("Invalid option."));
children_only_p = 1;
xfree (name);
name = xstrdup (expr);
***************
*** 155,161 ****
var = varobj_get_handle (name);

if (var == NULL)
! error (_("mi_cmd_var_delete: Variable object not found."));

numdel = varobj_delete (var, NULL, children_only_p);

--- 158,164 ----
var = varobj_get_handle (name);

if (var == NULL)
! return mi_error (_("Variable object not found."));

numdel = varobj_delete (var, NULL, children_only_p);

***************
*** 174,190 ****
char *formspec;

if (argc != 2)
! error (_("mi_cmd_var_set_format: Usage: NAME FORMAT."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);

if (var == NULL)
! error (_("mi_cmd_var_set_format: Variable object not found"));

formspec = xstrdup (argv[1]);
if (formspec == NULL)
! error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));

len = strlen (formspec);

--- 177,193 ----
char *formspec;

if (argc != 2)
! return mi_usage_error ("-var-set-format NAME FORMAT.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);

if (var == NULL)
! return mi_error (_("Variable object not found."));

formspec = xstrdup (argv[1]);
if (formspec == NULL)
! return mi_error (_("Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"."));

len = strlen (formspec);

***************
*** 199,205 ****
else if (strncmp (formspec, "octal", len) == 0)
format = FORMAT_OCTAL;
else
! error (_("mi_cmd_var_set_format: Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));

/* Set the format of VAR to given format */
varobj_set_display_format (var, format);
--- 202,208 ----
else if (strncmp (formspec, "octal", len) == 0)
format = FORMAT_OCTAL;
else
! return mi_error (_("Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"."));

/* Set the format of VAR to given format */
varobj_set_display_format (var, format);
***************
*** 216,227 ****
struct varobj *var;

if (argc != 1)
! error (_("mi_cmd_var_show_format: Usage: NAME."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! error (_("mi_cmd_var_show_format: Variable object not found"));

format = varobj_get_display_format (var);

--- 219,230 ----
struct varobj *var;

if (argc != 1)
! return mi_usage_error ("-var-show-format NAME.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! return mi_error (_("Variable object not found."));

format = varobj_get_display_format (var);

***************
*** 236,247 ****
struct varobj *var;

if (argc != 1)
! error (_("mi_cmd_var_info_num_children: Usage: NAME."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! error (_("mi_cmd_var_info_num_children: Variable object not found"));

ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
return MI_CMD_DONE;
--- 239,250 ----
struct varobj *var;

if (argc != 1)
! return mi_usage_error ("-var-info-num-children NAME.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! return mi_error (_("Variable object not found"));

ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
return MI_CMD_DONE;
***************
*** 259,271 ****
enum print_values print_values;

if (argc != 1 && argc != 2)
! error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME"));

/* Get varobj handle, if a valid var obj name was specified */
if (argc == 1) var = varobj_get_handle (argv[0]);
else var = varobj_get_handle (argv[1]);
if (var == NULL)
! error (_("Variable object not found"));

numchild = varobj_list_children (var, &childlist);
ui_out_field_int (uiout, "numchild", numchild);
--- 262,274 ----
enum print_values print_values;

if (argc != 1 && argc != 2)
! return mi_usage_error ("-var-list-children [PRINT_VALUES] NAME.");

/* Get varobj handle, if a valid var obj name was specified */
if (argc == 1) var = varobj_get_handle (argv[0]);
else var = varobj_get_handle (argv[1]);
if (var == NULL)
! return mi_error (_("Variable object not found."));

numchild = varobj_list_children (var, &childlist);
ui_out_field_int (uiout, "numchild", numchild);
***************
*** 277,283 ****
|| strcmp (argv[0], "--all-values") == 0)
print_values = PRINT_ALL_VALUES;
else
! error (_("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\""));
else print_values = PRINT_NO_VALUES;

if (numchild <= 0)
--- 280,286 ----
|| strcmp (argv[0], "--all-values") == 0)
print_values = PRINT_ALL_VALUES;
else
! return mi_error (_("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\"."));
else print_values = PRINT_NO_VALUES;

if (numchild <= 0)
***************
*** 315,326 ****
struct varobj *var;

if (argc != 1)
! error (_("mi_cmd_var_info_type: Usage: NAME."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! error (_("mi_cmd_var_info_type: Variable object not found"));

ui_out_field_string (uiout, "type", varobj_get_type (var));
return MI_CMD_DONE;
--- 318,329 ----
struct varobj *var;

if (argc != 1)
! return mi_usage_error ("-var-info-type NAME.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! return mi_error (_("Variable object not found."));

ui_out_field_string (uiout, "type", varobj_get_type (var));
return MI_CMD_DONE;
***************
*** 333,344 ****
struct varobj *var;

if (argc != 1)
! error (_("mi_cmd_var_info_expression: Usage: NAME."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! error (_("mi_cmd_var_info_expression: Variable object not found"));

lang = varobj_get_language (var);

--- 336,347 ----
struct varobj *var;

if (argc != 1)
! return mi_usage_error ("-var-info-expression NAME.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! return mi_error (_("Variable object not found."));

lang = varobj_get_language (var);

***************
*** 355,366 ****
struct varobj *var;

if (argc != 1)
! error (_("mi_cmd_var_show_attributes: Usage: NAME."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! error (_("mi_cmd_var_show_attributes: Variable object not found"));

attr = varobj_get_attributes (var);
/* FIXME: define masks for attributes */
--- 358,369 ----
struct varobj *var;

if (argc != 1)
! return mi_usage_error ("-var-show-attributes NAME.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! return mi_error (_("Variable object not found."));

attr = varobj_get_attributes (var);
/* FIXME: define masks for attributes */
***************
*** 379,390 ****
struct varobj *var;

if (argc != 1)
! error (_("mi_cmd_var_evaluate_expression: Usage: NAME."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! error (_("mi_cmd_var_evaluate_expression: Variable object not found"));

ui_out_field_string (uiout, "value", varobj_get_value (var));
return MI_CMD_DONE;
--- 382,393 ----
struct varobj *var;

if (argc != 1)
! return mi_usage_error ("-var-evaluate-expression NAME.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! return mi_error (_("Variable object not found."));

ui_out_field_string (uiout, "value", varobj_get_value (var));
return MI_CMD_DONE;
***************
*** 397,417 ****
char *expression;

if (argc != 2)
! error (_("mi_cmd_var_assign: Usage: NAME EXPRESSION."));

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! error (_("mi_cmd_var_assign: Variable object not found"));

/* FIXME: define masks for attributes */
if (!(varobj_get_attributes (var) & 0x00000001))
! error (_("mi_cmd_var_assign: Variable object is not editable"));

expression = xstrdup (argv[1]);

if (!varobj_set_value (var, expression))
! error (_("mi_cmd_var_assign: Could not assign expression to varible object"));

ui_out_field_string (uiout, "value", varobj_get_value (var));
return MI_CMD_DONE;
--- 400,420 ----
char *expression;

if (argc != 2)
! return mi_usage_error ("-var-assign NAME EXPRESSION.");

/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (argv[0]);
if (var == NULL)
! return mi_error (_("Variable object not found"));

/* FIXME: define masks for attributes */
if (!(varobj_get_attributes (var) & 0x00000001))
! return mi_error (_("Variable object is not editable."));

expression = xstrdup (argv[1]);

if (!varobj_set_value (var, expression))
! return mi_error (_("Could not assign expression to variable object."));

ui_out_field_string (uiout, "value", varobj_get_value (var));
return MI_CMD_DONE;
***************
*** 428,434 ****
int nv;

if (argc != 1)
! error (_("mi_cmd_var_update: Usage: NAME."));

name = argv[0];

--- 431,437 ----
int nv;

if (argc != 1)
! return mi_usage_error ("-var-update NAME.");

name = argv[0];

***************
*** 461,467 ****
/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (name);
if (var == NULL)
! error (_("mi_cmd_var_update: Variable object not found"));

if (mi_version (uiout) <= 1)
cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
--- 464,470 ----
/* Get varobj handle, if a valid var obj name was specified */
var = varobj_get_handle (name);
if (var == NULL)
! return mi_error (_("Variable object not found."));

if (mi_version (uiout) <= 1)
cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");