From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1458 invoked by alias); 23 Apr 2003 08:32:20 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 1371 invoked from network); 23 Apr 2003 08:32:17 -0000 Received: from unknown (HELO molenda.com) (192.220.74.81) by sources.redhat.com with SMTP; 23 Apr 2003 08:32:17 -0000 Received: (qmail 53059 invoked by uid 19025); 23 Apr 2003 08:32:17 -0000 Date: Wed, 23 Apr 2003 14:23:00 -0000 From: Jason Molenda To: gdb-patches@sources.redhat.com Subject: Re: PATCH: Add type_sprint() function to return type in string form Message-ID: <20030423013217.A51438@molenda.com> References: <20030418152426.A93348@molenda.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="J2SCkAp4GZ/dPZZf" Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20030418152426.A93348@molenda.com>; from jason-swarelist@molenda.com on Fri, Apr 18, 2003 at 03:24:26PM -0700 X-SW-Source: 2003-04/txt/msg00434.txt.bz2 --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 857 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. --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="pa.txt" Content-length: 6585 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 * 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 ? "" : 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 ? "" : 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 --J2SCkAp4GZ/dPZZf--