Index: ChangeLog =================================================================== RCS file: /cvs/src/src/gdb/ChangeLog,v retrieving revision 1.4107 diff -u -p -r1.4107 ChangeLog --- ChangeLog 18 Apr 2003 20:20:21 -0000 1.4107 +++ ChangeLog 18 Apr 2003 22:15:24 -0000 @@ -1,3 +1,14 @@ +2003-04-18 Jason Molenda (jmolenda@apple.com) + + * typeprint.c (type_sprint): New function to return string form + of types. Use as type_print, sans a stream. + * value.h (type_sprint): Add prototype. + * ada-lang.c (ada_lookup_struct_elt_type): Use type_sprint() when + building error message. + * gdbtypes.c (lookup_struct_elt_type): Ditto. + * varobj.c (varobj_get_type): Use type_sprint() to get the type + in a string form. + 2003-04-18 Jim Blandy * s390-tdep.c (s390_frame_align): New function. Index: ada-lang.c =================================================================== RCS file: /cvs/src/src/gdb/ada-lang.c,v retrieving revision 1.23 diff -u -p -r1.23 ada-lang.c --- ada-lang.c 2 Apr 2003 03:02:46 -0000 1.23 +++ ada-lang.c 18 Apr 2003 22:15:24 -0000 @@ -5610,6 +5610,7 @@ ada_lookup_struct_elt_type (struct type int *dispp) { int i; + char *type_for_printing; if (name == NULL) goto BadName; @@ -5628,9 +5629,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_for_printing = type_sprint (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); @@ -5690,10 +5691,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 ? "" : name); + type_for_printing = type_sprint (type, "", -1); + make_cleanup (xfree, type_for_printing); + error ("Type %s has no component named %s", type_for_printing, + name == 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 18 Apr 2003 22:15:25 -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_for_printing = type_sprint (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_for_printing = type_sprint (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 18 Apr 2003 22:15:25 -0000 @@ -109,6 +109,27 @@ type_print (struct type *type, char *var LA_PRINT_TYPE (type, varstring, stream, show, 0); } +/* Returns a xmalloc'ed string of the type name instead of printing it + to STREAM. */ + +char * +type_sprint (struct type *type, char *varstring, int show) +{ + struct ui_file *stb; + struct cleanup *wipe; + long length; + char *type_name; + + stb = mem_fileopen (); + wipe = make_cleanup_ui_file_delete (stb); + + type_print (type, varstring, stb, show); + type_name = ui_file_xstrdup (stb, &length); + do_cleanups (wipe); + + return type_name; +} + /* 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.45 diff -u -p -r1.45 value.h --- value.h 12 Apr 2003 17:41:26 -0000 1.45 +++ value.h 18 Apr 2003 22:15:25 -0000 @@ -498,6 +498,8 @@ extern void modify_field (char *addr, LO extern void type_print (struct type * type, char *varstring, struct ui_file * stream, int show); +extern char *type_sprint (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 18 Apr 2003 22:15:25 -0000 @@ -728,27 +728,17 @@ char * varobj_get_type (struct varobj *var) { struct value *val; - struct cleanup *old_chain; - struct ui_file *stb; - char *thetype; - long length; /* 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; + return (type_sprint (VALUE_TYPE (val), "", -1)); } enum varobj_languages