From: Jason Molenda <jason-swarelist@molenda.com>
To: gdb-patches@sources.redhat.com
Subject: PATCH: Add type_sprint() function to return type in string form
Date: Fri, 18 Apr 2003 22:24:00 -0000 [thread overview]
Message-ID: <20030418152426.A93348@molenda.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1859 bytes --]
There are a few places in gdb where code prints an error message
with a type included in it. The only way for these functions to
print a type is with type_print(), which takes a ui_file stream to
print its output to. This means they either have to send the output
to gdb_stderr, or build up a fake memory ui_file and retrieve the
contents.
This patch adds a type_sprint() which does the latter and returns the
xmalloc()'ed string.
The current code gives bogus data to an MI client. We had a bug that
gave this output at Apple:
-> 64-var-list-children "var7" 2
<- 64^error,msg="."
-> 65-exec-status
<- (gdb)
<- &"Type TWindow has no component named TWindow"
<- 65^done,status="stopped"
This happens because this particular error reporter looked like this:
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 (".");
Similar code shows up in a few places, so it made sense to create a
single function to format a type into a string and return the string.
I can drop the ada-lang.c part of the patch if that will complicate
the approval, but given that this code is clearly derived from
gdbtypes.c, I don't think the change is particularly controversial.
This patch adds no new testsuite failures on RHL7.1 (gcc 2.96, stabs).
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.
[-- Attachment #2: pa.txt --]
[-- Type: text/plain, Size: 6433 bytes --]
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 <jimb@redhat.com>
* 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 ? "<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 ? "<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
next reply other threads:[~2003-04-18 22:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-18 22:24 Jason Molenda [this message]
2003-04-22 3:26 ` Daniel Jacobowitz
2003-04-22 16:48 ` Andrew Cagney
2003-04-22 16:55 ` Daniel Jacobowitz
2003-04-22 17:29 ` Andrew Cagney
2003-04-22 17:33 ` Daniel Jacobowitz
2003-04-22 19:21 ` Andrew Cagney
2003-04-22 19:28 ` Daniel Jacobowitz
2003-04-22 20:16 ` Andrew Cagney
2003-04-22 20:22 ` Daniel Jacobowitz
2003-04-22 20:35 ` Jason Molenda
2003-04-22 21:15 ` Andrew Cagney
2003-04-22 19:55 ` Kevin Buettner
2003-04-23 14:23 ` Jason Molenda
2003-04-23 17:37 ` Andrew Cagney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030418152426.A93348@molenda.com \
--to=jason-swarelist@molenda.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox