This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch rfc] use typedef opaque type implementations


This patch follows up an earlier thread that pointed out that GDB is pretty broken when it comes to debugging a program that contains multiple struct definitions (e.g., gdb).

The attached patch implements the suggested `fix'. Declare a file-local typedef and then use that. I've applied it to the ui-out code. A quick debug suggests that it works well.

comments?  I'll table this for a week ...
Andrew
Index: ChangeLog
2003-03-02  Andrew Cagney  <cagney at redhat dot com>

	* cli-out.c: Update copyright.
	(cli_out_data): Define typedef.  Use instead of ui_out_data.

Index: mi/ChangeLog
2003-03-02  Andrew Cagney  <cagney at redhat dot com>

	* mi-out.c: Update copyright.
	(mi_out_data): Define typedef.  Use instead of ui_out_data.

Index: tui/ChangeLog
2003-03-02  Andrew Cagney  <cagney at redhat dot com>

	* tui-out.c: Update copyright.
	(tui_out_data): Define typedef.  Use instead of ui_out_data.

Index: cli-out.c
===================================================================
RCS file: /cvs/src/src/gdb/cli-out.c,v
retrieving revision 1.15
diff -u -r1.15 cli-out.c
--- cli-out.c	6 Feb 2003 01:19:12 -0000	1.15
+++ cli-out.c	2 Mar 2003 16:30:56 -0000
@@ -1,6 +1,6 @@
 /* Output generating routines for GDB CLI.
 
-   Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions.
    Written by Fernando Nasser for Cygnus.
@@ -33,6 +33,7 @@
     struct ui_file *stream;
     int suppress_output;
   };
+typedef struct ui_out_data cli_out_data;
 
 /* These are the CLI output functions */
 
@@ -110,7 +111,7 @@
 		 int nr_rows,
 		 const char *tblid)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (nr_rows == 0)
     data->suppress_output = 1;
   else
@@ -124,7 +125,7 @@
 void
 cli_table_body (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   /* first, close the table header line */
@@ -136,7 +137,7 @@
 void
 cli_table_end (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   data->suppress_output = 0;
 }
 
@@ -147,7 +148,7 @@
 		  const char *col_name,
 		  const char *colhdr)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   cli_field_string (uiout, 0, width, alignment, 0, colhdr);
@@ -161,7 +162,7 @@
 	   int level,
 	   const char *id)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 }
@@ -173,7 +174,7 @@
 	 enum ui_out_type type,
 	 int level)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 }
@@ -187,7 +188,7 @@
 {
   char buffer[20];		/* FIXME: how many chars long a %d can become? */
 
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   sprintf (buffer, "%d", value);
@@ -201,7 +202,7 @@
 		enum ui_align alignment,
 		const char *fldname)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   cli_field_string (uiout, fldno, width, alignment, fldname, "");
@@ -221,7 +222,7 @@
   int before = 0;
   int after = 0;
 
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 
@@ -268,7 +269,7 @@
 	       const char *format,
 	       va_list args)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 
@@ -281,7 +282,7 @@
 void
 cli_spaces (struct ui_out *uiout, int numspaces)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   print_spaces_filtered (numspaces, data->stream);
@@ -290,7 +291,7 @@
 void
 cli_text (struct ui_out *uiout, const char *string)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   fputs_filtered (string, data->stream);
@@ -300,7 +301,7 @@
 cli_message (struct ui_out *uiout, int verbosity,
 	     const char *format, va_list args)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   if (ui_out_get_verblvl (uiout) >= verbosity)
@@ -310,7 +311,7 @@
 void
 cli_wrap_hint (struct ui_out *uiout, char *identstring)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   wrap_here (identstring);
@@ -319,7 +320,7 @@
 void
 cli_flush (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   gdb_flush (data->stream);
 }
 
@@ -334,7 +335,7 @@
 	       const char *fldname,
 	       const char *format,...)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   va_list args;
 
   va_start (args, format);
@@ -348,7 +349,7 @@
 static void
 field_separator (void)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   fputc_filtered (' ', data->stream);
 }
 
@@ -359,7 +360,7 @@
 {
   int flags = ui_source_list;
 
-  struct ui_out_data *data = XMALLOC (struct ui_out_data);
+  cli_out_data *data = XMALLOC (cli_out_data);
   data->stream = stream;
   data->suppress_output = 0;
   return ui_out_new (&cli_ui_out_impl, data, flags);
@@ -368,7 +369,7 @@
 struct ui_file *
 cli_out_set_stream (struct ui_out *uiout, struct ui_file *stream)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  cli_out_data *data = ui_out_data (uiout);
   struct ui_file *old = data->stream;
   data->stream = stream;
   return old;
Index: mi/mi-out.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-out.c,v
retrieving revision 1.25
diff -u -r1.25 mi-out.c
--- mi/mi-out.c	1 Oct 2002 21:15:43 -0000	1.25
+++ mi/mi-out.c	2 Mar 2003 16:31:10 -0000
@@ -1,6 +1,6 @@
 /* MI Command Set - output generating routines.
 
-   Copyright 2000, 2002 Free Software Foundation, Inc.
+   Copyright 2000, 2002, 2003 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions (a Red Hat company).
 
@@ -32,6 +32,7 @@
     int mi_version;
     struct ui_file *buffer;
   };
+typedef struct ui_out_data mi_out_data;
 
 /* These are the MI output functions */
 
@@ -107,7 +108,7 @@
 		int nr_rows,
 		const char *tblid)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   mi_open (uiout, tblid, ui_out_type_tuple);
   mi_field_int (uiout, -1/*fldno*/, -1/*width*/, -1/*alin*/,
 		"nr_rows", nr_rows);
@@ -121,7 +122,7 @@
 void
 mi_table_body (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   /* close the table header line if there were any headers */
@@ -134,7 +135,7 @@
 void
 mi_table_end (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   data->suppress_output = 0;
   mi_close (uiout, ui_out_type_list); /* body */
   mi_close (uiout, ui_out_type_tuple);
@@ -147,7 +148,7 @@
 		 const char *col_name,
 		 const char *colhdr)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   mi_open (uiout, NULL, ui_out_type_tuple);
@@ -166,7 +167,7 @@
 	  int level,
 	  const char *id)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   mi_open (uiout, id, type);
@@ -179,7 +180,7 @@
 	enum ui_out_type type,
 	int level)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   mi_close (uiout, type);
@@ -192,7 +193,7 @@
               enum ui_align alignment, const char *fldname, int value)
 {
   char buffer[20];		/* FIXME: how many chars long a %d can become? */
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 
@@ -206,7 +207,7 @@
 mi_field_skip (struct ui_out *uiout, int fldno, int width,
                enum ui_align alignment, const char *fldname)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   mi_field_string (uiout, fldno, width, alignment, fldname, "");
@@ -223,7 +224,7 @@
 		 const char *fldname,
 		 const char *string)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   field_separator (uiout);
@@ -244,7 +245,7 @@
 	      const char *format,
 	      va_list args)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   field_separator (uiout);
@@ -282,7 +283,7 @@
 void
 mi_flush (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   gdb_flush (data->buffer);
 }
 
@@ -296,7 +297,7 @@
 out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
 	       char *format,...)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   va_list args;
 
   field_separator (uiout);
@@ -318,7 +319,7 @@
 static void
 field_separator (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   if (data->suppress_field_separator)
     data->suppress_field_separator = 0;
   else
@@ -330,7 +331,7 @@
 	 const char *name,
 	 enum ui_out_type type)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   field_separator (uiout);
   data->suppress_field_separator = 1;
   if (name)
@@ -352,7 +353,7 @@
 mi_close (struct ui_out *uiout,
 	  enum ui_out_type type)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   switch (type)
     {
     case ui_out_type_tuple:
@@ -372,7 +373,7 @@
 void
 mi_out_buffered (struct ui_out *uiout, char *string)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   fprintf_unfiltered (data->buffer, "%s", string);
 }
 
@@ -381,7 +382,7 @@
 void
 mi_out_rewind (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   ui_file_rewind (data->buffer);
 }
 
@@ -397,7 +398,7 @@
 mi_out_put (struct ui_out *uiout,
 	    struct ui_file *stream)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   ui_file_put (data->buffer, do_write, stream);
   ui_file_rewind (data->buffer);
 }
@@ -407,7 +408,7 @@
 int
 mi_version (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  mi_out_data *data = ui_out_data (uiout);
   return data->mi_version;
 }
 
@@ -417,7 +418,7 @@
 mi_out_new (int mi_version)
 {
   int flags = 0;
-  struct ui_out_data *data = XMALLOC (struct ui_out_data);
+  mi_out_data *data = XMALLOC (mi_out_data);
   data->suppress_field_separator = 0;
   data->suppress_output = 0;
   data->mi_version = mi_version;
Index: tui/tui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tui-out.c,v
retrieving revision 1.3
diff -u -r1.3 tui-out.c
--- tui/tui-out.c	1 Sep 2002 16:12:52 -0000	1.3
+++ tui/tui-out.c	2 Mar 2003 16:31:20 -0000
@@ -1,6 +1,7 @@
 /* Output generating routines for GDB CLI.
 
-   Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
+   Inc.
 
    Contributed by Cygnus Solutions.
    Written by Fernando Nasser for Cygnus.
@@ -35,6 +36,7 @@
     int line;
     int start_of_line;
   };
+struct ui_out_data tui_out_data;
 
 /* These are the CLI output functions */
 
@@ -112,7 +114,7 @@
 		 int nr_rows,
 		 const char *tblid)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (nr_rows == 0)
     data->suppress_output = 1;
   else
@@ -126,7 +128,7 @@
 void
 tui_table_body (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   /* first, close the table header line */
@@ -138,7 +140,7 @@
 void
 tui_table_end (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   data->suppress_output = 0;
 }
 
@@ -149,7 +151,7 @@
 		  const char *col_name,
 		  const char *colhdr)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   tui_field_string (uiout, 0, width, alignment, 0, colhdr);
@@ -163,7 +165,7 @@
 	   int level,
 	   const char *id)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 }
@@ -175,7 +177,7 @@
 	 enum ui_out_type type,
 	 int level)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 }
@@ -189,7 +191,7 @@
 {
   char buffer[20];		/* FIXME: how many chars long a %d can become? */
 
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 
@@ -212,7 +214,7 @@
 		enum ui_align alignment,
 		const char *fldname)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   tui_field_string (uiout, fldno, width, alignment, fldname, "");
@@ -232,7 +234,7 @@
   int before = 0;
   int after = 0;
 
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 
@@ -290,7 +292,7 @@
 	       const char *format,
 	       va_list args)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
 
@@ -304,7 +306,7 @@
 void
 tui_spaces (struct ui_out *uiout, int numspaces)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   print_spaces_filtered (numspaces, data->stream);
@@ -313,7 +315,7 @@
 void
 tui_text (struct ui_out *uiout, const char *string)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   data->start_of_line ++;
@@ -335,7 +337,7 @@
 tui_message (struct ui_out *uiout, int verbosity,
 	     const char *format, va_list args)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   if (ui_out_get_verblvl (uiout) >= verbosity)
@@ -345,7 +347,7 @@
 void
 tui_wrap_hint (struct ui_out *uiout, char *identstring)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   if (data->suppress_output)
     return;
   wrap_here (identstring);
@@ -354,7 +356,7 @@
 void
 tui_flush (struct ui_out *uiout)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   gdb_flush (data->stream);
 }
 
@@ -369,7 +371,7 @@
 	       const char *fldname,
 	       const char *format,...)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   va_list args;
 
   va_start (args, format);
@@ -383,7 +385,7 @@
 static void
 field_separator (void)
 {
-  struct ui_out_data *data = ui_out_data (uiout);
+  tui_out_data *data = ui_out_data (uiout);
   fputc_filtered (' ', data->stream);
 }
 
@@ -394,7 +396,7 @@
 {
   int flags = 0;
 
-  struct ui_out_data *data = XMALLOC (struct ui_out_data);
+  tui_out_data *data = XMALLOC (tui_out_data);
   data->stream = stream;
   data->suppress_output = 0;
   data->line = -1;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]