PATCH: Add type_sprint() function to return type in string form
Jason Molenda
jason-swarelist@molenda.com
Wed Apr 23 14:23:00 GMT 2003
Hi all, here's the follow-up patch incorporating the comments.
I didn't have time to make a test case for this. I want to at least
elicit the error message before I commit this, so I'll get something
together tomorrow night or the night after. I don't know how easy
it will be to add to the testsuite, but I'll at least do something
by hand to get the error.
Jason
2003-04-23 Jason Molenda (jmolenda at apple dot com)
* typeprint.c (type_xasprint): New function to return human-readable
string representation of a type.
* value.h (type_xasprint): Add prototype.
* ada-lang.c (ada_lookup_struct_elt_type): Use type_xasprint() when
building error message.
* gdbtypes.c (lookup_struct_elt_type): Ditto.
* varobj.c (varobj_get_type): Use type_xasprint() to get the type
in a string form.
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.4122
diff -u -p -r1.4122 ChangeLog
--- ChangeLog 22 Apr 2003 23:18:26 -0000 1.4122
+++ ChangeLog 23 Apr 2003 08:28:41 -0000
@@ -1,3 +1,14 @@
+2003-04-23 Jason Molenda (jmolenda at apple dot com)
+
+ * typeprint.c (type_xasprint): New function to return human-readable
+ string representation of a type.
+ * value.h (type_xasprint): Add prototype.
+ * ada-lang.c (ada_lookup_struct_elt_type): Use type_xasprint() when
+ building error message.
+ * gdbtypes.c (lookup_struct_elt_type): Ditto.
+ * varobj.c (varobj_get_type): Use type_xasprint() to get the type
+ in a string form.
+
2003-04-22 Kevin Buettner <kevinb@redhat.com>
* dwarf2loc.c (dwarf2_evaluate_loc_desc): Invoke DWARF2_REG_TO_REGNUM
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.24
diff -u -p -r1.24 ada-lang.c
--- ada-lang.c 21 Apr 2003 16:48:37 -0000 1.24
+++ ada-lang.c 23 Apr 2003 08:28:42 -0000
@@ -5611,6 +5611,7 @@ ada_lookup_struct_elt_type (struct type
int *dispp)
{
int i;
+ char *type_for_printing;
if (name == NULL)
goto BadName;
@@ -5629,9 +5630,9 @@ ada_lookup_struct_elt_type (struct type
{
target_terminal_ours ();
gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- error (" is not a structure or union type");
+ type_xasprint (&type_for_printing, type, "", -1);
+ make_cleanup (xfree, type_for_printing);
+ error ("Type %s is not a structure or union type", type_for_printing);
}
type = to_static_fixed_type (type);
@@ -5691,10 +5692,10 @@ BadName:
{
target_terminal_ours ();
gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- fprintf_unfiltered (gdb_stderr, " has no component named ");
- error ("%s", name == NULL ? "<null>" : name);
+ type_xasprint (&type_for_printing, type, "", -1);
+ make_cleanup (xfree, type_for_printing);
+ error ("Type %s has no component named %s", type_for_printing,
+ name == NULL ? "<null>" : name);
}
return NULL;
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.71
diff -u -p -r1.71 gdbtypes.c
--- gdbtypes.c 7 Feb 2003 21:44:00 -0000 1.71
+++ gdbtypes.c 23 Apr 2003 08:28:44 -0000
@@ -1218,6 +1218,7 @@ struct type *
lookup_struct_elt_type (struct type *type, char *name, int noerr)
{
int i;
+ char *type_for_printing;
for (;;)
{
@@ -1233,9 +1234,9 @@ lookup_struct_elt_type (struct type *typ
{
target_terminal_ours ();
gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- error (" is not a structure or union type.");
+ type_xasprint (&type_for_printing, type, "", -1);
+ make_cleanup (xfree, type_for_printing);
+ error ("Type %s is not a structure or union type", type_for_printing);
}
#if 0
@@ -1281,11 +1282,10 @@ lookup_struct_elt_type (struct type *typ
target_terminal_ours ();
gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "Type ");
- type_print (type, "", gdb_stderr, -1);
- fprintf_unfiltered (gdb_stderr, " has no component named ");
- fputs_filtered (name, gdb_stderr);
- error (".");
+ type_xasprint (&type_for_printing, type, "", -1);
+ make_cleanup (xfree, type_for_printing);
+ error ("Type %s has no component named %s", type_for_printing, name);
+
return (struct type *) -1; /* For lint */
}
Index: typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/typeprint.c,v
retrieving revision 1.17
diff -u -p -r1.17 typeprint.c
--- typeprint.c 25 Feb 2003 21:36:21 -0000 1.17
+++ typeprint.c 23 Apr 2003 08:28:45 -0000
@@ -109,6 +109,25 @@ type_print (struct type *type, char *var
LA_PRINT_TYPE (type, varstring, stream, show, 0);
}
+/* Sets BUF to an xmalloc'ed string of the type name, instead of printing it
+ to STREAM like type_print() does. */
+
+void
+type_xasprint (char **buf, struct type *type, char *varstring, int show)
+{
+ struct ui_file *stb;
+ struct cleanup *wipe;
+ long length;
+
+ *buf = NULL;
+ stb = mem_fileopen ();
+ wipe = make_cleanup_ui_file_delete (stb);
+
+ type_print (type, varstring, stb, show);
+ *buf = ui_file_xstrdup (stb, &length);
+ do_cleanups (wipe);
+}
+
/* Print type of EXP, or last thing in value history if EXP == NULL.
show is passed to type_print. */
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.46
diff -u -p -r1.46 value.h
--- value.h 21 Apr 2003 16:48:40 -0000 1.46
+++ value.h 23 Apr 2003 08:28:45 -0000
@@ -498,6 +498,9 @@ extern void modify_field (char *addr, LO
extern void type_print (struct type * type, char *varstring,
struct ui_file * stream, int show);
+extern void type_xasprint (char **buf, struct type *type,
+ char *varstring, int show);
+
extern char *baseclass_addr (struct type *type, int index, char *valaddr,
struct value **valuep, int *errp);
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.38
diff -u -p -r1.38 varobj.c
--- varobj.c 4 Dec 2002 00:05:54 -0000 1.38
+++ varobj.c 23 Apr 2003 08:28:46 -0000
@@ -728,27 +728,19 @@ char *
varobj_get_type (struct varobj *var)
{
struct value *val;
- struct cleanup *old_chain;
- struct ui_file *stb;
- char *thetype;
- long length;
+ char *type_string;
/* For the "fake" variables, do not return a type. (It's type is
NULL, too.) */
if (CPLUS_FAKE_CHILD (var))
return NULL;
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
/* To print the type, we simply create a zero ``struct value *'' and
cast it to our type. We then typeprint this variable. */
val = value_zero (var->type, not_lval);
- type_print (VALUE_TYPE (val), "", stb, -1);
- thetype = ui_file_xstrdup (stb, &length);
- do_cleanups (old_chain);
- return thetype;
+ type_xasprint (&type_string, VALUE_TYPE (val), "", -1);
+ return (type_string);
}
enum varobj_languages
More information about the Gdb-patches
mailing list