ada-lang.c: Introduce type_as_string and use it
A couple wrong things here - We should not use target_terminal_ours when all we want is output. We should use target_terminal_ours_for_output instead, which preserves raw/cooked terminal modes, and SIGINT forwarding. - Most importantly, relying on stderr output immediately preceding the error/exception print isn't correct. The exception could be caught and handled, for example; MI frontends won't display the stderr part in an error dialog box. Etc. This commit introduces a type_as_string helper that allows building a full error string including type info. gdb/ChangeLog: 2016-04-12 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string, type_as_string_and_cleanup): New functions. (ada_lookup_struct_elt_type): Use type_as_string_and_cleanup.
This commit is contained in:
parent
75ee59252d
commit
99bbb428d4
|
@ -1,3 +1,9 @@
|
||||||
|
2016-04-12 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
|
* ada-lang.c (type_as_string, type_as_string_and_cleanup): New
|
||||||
|
functions.
|
||||||
|
(ada_lookup_struct_elt_type): Use type_as_string_and_cleanup.
|
||||||
|
|
||||||
2016-04-12 Pedro Alves <palves@redhat.com>
|
2016-04-12 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* ser-base.c (fd_event): Retry read_prim on EINTR.
|
* ser-base.c (fd_event): Retry read_prim on EINTR.
|
||||||
|
|
|
@ -7576,6 +7576,39 @@ ada_value_struct_elt (struct value *arg, char *name, int no_err)
|
||||||
"a value that is not a record."));
|
"a value that is not a record."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return a string representation of type TYPE. Caller must free
|
||||||
|
result. */
|
||||||
|
|
||||||
|
static char *
|
||||||
|
type_as_string (struct type *type)
|
||||||
|
{
|
||||||
|
struct ui_file *tmp_stream = mem_fileopen ();
|
||||||
|
struct cleanup *old_chain;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
tmp_stream = mem_fileopen ();
|
||||||
|
old_chain = make_cleanup_ui_file_delete (tmp_stream);
|
||||||
|
|
||||||
|
type_print (type, "", tmp_stream, -1);
|
||||||
|
str = ui_file_xstrdup (tmp_stream, NULL);
|
||||||
|
|
||||||
|
do_cleanups (old_chain);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return a string representation of type TYPE, and install a cleanup
|
||||||
|
that releases it. */
|
||||||
|
|
||||||
|
static char *
|
||||||
|
type_as_string_and_cleanup (struct type *type)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = type_as_string (type);
|
||||||
|
make_cleanup (xfree, str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
/* Given a type TYPE, look up the type of the component of type named NAME.
|
/* Given a type TYPE, look up the type of the component of type named NAME.
|
||||||
If DISPP is non-null, add its byte displacement from the beginning of a
|
If DISPP is non-null, add its byte displacement from the beginning of a
|
||||||
structure (pointed to by a value) of type TYPE to *DISPP (does not
|
structure (pointed to by a value) of type TYPE to *DISPP (does not
|
||||||
|
@ -7616,22 +7649,15 @@ ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
|
||||||
|| (TYPE_CODE (type) != TYPE_CODE_STRUCT
|
|| (TYPE_CODE (type) != TYPE_CODE_STRUCT
|
||||||
&& TYPE_CODE (type) != TYPE_CODE_UNION))
|
&& TYPE_CODE (type) != TYPE_CODE_UNION))
|
||||||
{
|
{
|
||||||
|
char *type_str;
|
||||||
|
|
||||||
if (noerr)
|
if (noerr)
|
||||||
return NULL;
|
return NULL;
|
||||||
else
|
|
||||||
{
|
type_str = (type != NULL
|
||||||
target_terminal_ours ();
|
? type_as_string_and_cleanup (type)
|
||||||
gdb_flush (gdb_stdout);
|
: _("(null)"));
|
||||||
if (type == NULL)
|
error (_("Type %s is not a structure or union type"), type_str);
|
||||||
error (_("Type (null) is not a structure or union type"));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* XXX: type_sprint */
|
|
||||||
fprintf_unfiltered (gdb_stderr, _("Type "));
|
|
||||||
type_print (type, "", gdb_stderr, -1);
|
|
||||||
error (_(" is not a structure or union type"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type = to_static_fixed_type (type);
|
type = to_static_fixed_type (type);
|
||||||
|
@ -7701,22 +7727,10 @@ ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
|
||||||
BadName:
|
BadName:
|
||||||
if (!noerr)
|
if (!noerr)
|
||||||
{
|
{
|
||||||
target_terminal_ours ();
|
char *name_str = name != NULL ? name : _("<null>");
|
||||||
gdb_flush (gdb_stdout);
|
|
||||||
if (name == NULL)
|
error (_("Type %s has no component named %s"),
|
||||||
{
|
type_as_string_and_cleanup (type), name_str);
|
||||||
/* XXX: type_sprint */
|
|
||||||
fprintf_unfiltered (gdb_stderr, _("Type "));
|
|
||||||
type_print (type, "", gdb_stderr, -1);
|
|
||||||
error (_(" has no component named <null>"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* XXX: type_sprint */
|
|
||||||
fprintf_unfiltered (gdb_stderr, _("Type "));
|
|
||||||
type_print (type, "", gdb_stderr, -1);
|
|
||||||
error (_(" has no component named %s"), name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue