Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [commit] target_open (target, ...)
@ 2003-10-22 21:38 Andrew Cagney
  2003-10-23  2:36 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Cagney @ 2003-10-22 21:38 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 220 bytes --]

Hello,

This patch adds "struct target_ops" to target_open (now a function), and 
a target vector method "to_xopen" that also takes a "struct target_ops".

It then updates all the corresponding calls.

committed,
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 5318 bytes --]

2003-10-22  Andrew Cagney  <cagney@redhat.com>

	* target.c (target_close): New function.
	(debug_to_close): Use "target_close".
	(push_target): Use "target_close".
	(unpush_target): Use "target_close".
	(pop_target): Use "target_close".
	* target.h (struct target_ops): Add "to_xclose".
	(target_open): Delete macro.  Move comment to "to_open".
	(target_close): Replace macro with function that takes a target.
	* top.c (quit_target): Pass "current_target" to "target_close".

Index: target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.60
diff -u -r1.60 target.c
--- target.c	21 Oct 2003 21:29:55 -0000	1.60
+++ target.c	22 Oct 2003 20:56:00 -0000
@@ -672,8 +672,7 @@
       struct target_ops *tmp = (*cur);
       (*cur) = (*cur)->beneath;
       tmp->beneath = NULL;
-      if (tmp->to_close)
-	(tmp->to_close) (0);
+      target_close (tmp, 0);
     }
 
   /* We have removed all targets in our stratum, now add the new one.  */
@@ -698,8 +697,7 @@
   struct target_ops **cur;
   struct target_ops *tmp;
 
-  if (t->to_close)
-    t->to_close (0);		/* Let it clean up */
+  target_close (t, 0);
 
   /* Look for the specified target.  Note that we assume that a target
      can only occur once in the target stack. */
@@ -726,7 +724,7 @@
 void
 pop_target (void)
 {
-  (current_target.to_close) (0);	/* Let it clean up */
+  target_close (&current_target, 0);	/* Let it clean up */
   if (unpush_target (target_stack) == 1)
     return;
 
@@ -1600,9 +1598,17 @@
 static void
 debug_to_close (int quitting)
 {
-  debug_target.to_close (quitting);
-
+  target_close (&debug_target, quitting);
   fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
+}
+
+void
+target_close (struct target_ops *targ, int quitting)
+{
+  if (targ->to_xclose != NULL)
+    targ->to_xclose (targ, quitting);
+  else if (targ->to_close != NULL)
+    targ->to_close (quitting);
 }
 
 static void
Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.45
diff -u -r1.45 target.h
--- target.h	17 Oct 2003 20:17:51 -0000	1.45
+++ target.h	22 Oct 2003 20:56:00 -0000
@@ -266,7 +266,15 @@
     char *to_doc;		/* Documentation.  Does not include trailing
 				   newline, and starts with a one-line descrip-
 				   tion (probably similar to to_longname).  */
+    /* The open routine takes the rest of the parameters from the
+       command, and (if successful) pushes a new target onto the
+       stack.  Targets should supply this routine, if only to provide
+       an error message.  */
     void (*to_open) (char *, int);
+    /* Old targets with a static target vector provide "to_close".
+       New re-entrant targets provide "to_xclose" and that is expected
+       to xfree everything (including the "struct target_ops").  */
+    void (*to_xclose) (struct target_ops *targ, int quitting);
     void (*to_close) (int);
     void (*to_attach) (char *, int);
     void (*to_post_attach) (int);
@@ -413,26 +421,16 @@
 #define	target_shortname	(current_target.to_shortname)
 #define	target_longname		(current_target.to_longname)
 
-/* The open routine takes the rest of the parameters from the command,
-   and (if successful) pushes a new target onto the stack.
-   Targets should supply this routine, if only to provide an error message.  */
-
-#define	target_open(name, from_tty)					\
-  do {									\
-    dcache_invalidate (target_dcache);					\
-    (*current_target.to_open) (name, from_tty);				\
-  } while (0)
-
-/* Does whatever cleanup is required for a target that we are no longer
-   going to be calling.  Argument says whether we are quitting gdb and
-   should not get hung in case of errors, or whether we want a clean
-   termination even if it takes a while.  This routine is automatically
-   always called just before a routine is popped off the target stack.
-   Closing file descriptors and freeing memory are typical things it should
-   do.  */
+/* Does whatever cleanup is required for a target that we are no
+   longer going to be calling.  QUITTING indicates that GDB is exiting
+   and should not get hung on an error (otherwise it is important to
+   perform clean termination, even if it takes a while).  This routine
+   is automatically always called when popping the target off the
+   target stack (to_beneath is undefined).  Closing file descriptors
+   and freeing all memory allocated memory are typical things it
+   should do.  */
 
-#define	target_close(quitting)	\
-     (*current_target.to_close) (quitting)
+void target_close (struct target_ops *targ, int quitting);
 
 /* Attaches to a process on the target side.  Arguments are as passed
    to the `attach' command by the user.  This routine can be called
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.81
diff -u -r1.81 top.c
--- top.c	10 Oct 2003 07:13:11 -0000	1.81
+++ top.c	22 Oct 2003 20:56:00 -0000
@@ -1461,7 +1461,7 @@
     }
 
   /* UDI wants this, to kill the TIP.  */
-  target_close (1);
+  target_close (&current_target, 1);
 
   /* Save the history information if it is appropriate to do so.  */
   if (write_history_p && history_filename)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit] target_open (target, ...)
  2003-10-22 21:38 [commit] target_open (target, ...) Andrew Cagney
@ 2003-10-23  2:36 ` Daniel Jacobowitz
  2003-10-23  2:55   ` Andrew Cagney
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2003-10-23  2:36 UTC (permalink / raw)
  To: gdb-patches

On Wed, Oct 22, 2003 at 05:38:46PM -0400, Andrew Cagney wrote:
> Hello,
> 
> This patch adds "struct target_ops" to target_open (now a function), and 
> a target vector method "to_xopen" that also takes a "struct target_ops".
> 
> It then updates all the corresponding calls.
> 
> committed,
> Andrew

> 2003-10-22  Andrew Cagney  <cagney@redhat.com>
> 
> 	* target.c (target_close): New function.
> 	(debug_to_close): Use "target_close".
> 	(push_target): Use "target_close".
> 	(unpush_target): Use "target_close".
> 	(pop_target): Use "target_close".
> 	* target.h (struct target_ops): Add "to_xclose".
> 	(target_open): Delete macro.  Move comment to "to_open".
> 	(target_close): Replace macro with function that takes a target.
> 	* top.c (quit_target): Pass "current_target" to "target_close".

Wrong patch?  This is target_close, not target_open.  It also deletes
the target_open macro without adding a new target_open function.

Please don't add 'x'.  There's nothing wrong with having a target_open
function which calls target_ops->to_open.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit] target_open (target, ...)
  2003-10-23  2:36 ` Daniel Jacobowitz
@ 2003-10-23  2:55   ` Andrew Cagney
  2003-10-23  3:04     ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Cagney @ 2003-10-23  2:55 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches


> Wrong patch?  This is target_close, not target_open.  It also deletes
> the target_open macro without adding a new target_open function.

No, a 180 description. s/target_open/target_close/.  The _macro_ 
target_open() is _never_ called.

> Please don't add 'x'.  There's nothing wrong with having a target_open
> function which calls target_ops->to_open.

The vector already contains ->to_open and ->to_close methods so unless 
we've switched to C++, I can't add a second to_close.

Once the existing ->to_close is deprecated, I can rename ->to_xclose.

Andrew



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [commit] target_open (target, ...)
  2003-10-23  2:55   ` Andrew Cagney
@ 2003-10-23  3:04     ` Daniel Jacobowitz
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2003-10-23  3:04 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

On Wed, Oct 22, 2003 at 10:55:25PM -0400, Andrew Cagney wrote:
> 
> >Wrong patch?  This is target_close, not target_open.  It also deletes
> >the target_open macro without adding a new target_open function.
> 
> No, a 180 description. s/target_open/target_close/.  The _macro_ 
> target_open() is _never_ called.

Gotcha.

> >Please don't add 'x'.  There's nothing wrong with having a target_open
> >function which calls target_ops->to_open.
> 
> The vector already contains ->to_open and ->to_close methods so unless 
> we've switched to C++, I can't add a second to_close.
> 
> Once the existing ->to_close is deprecated, I can rename ->to_xclose.

OK.  It'd be nice if you'd explain that sort of thing when posting the
patch, though.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-23  3:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-22 21:38 [commit] target_open (target, ...) Andrew Cagney
2003-10-23  2:36 ` Daniel Jacobowitz
2003-10-23  2:55   ` Andrew Cagney
2003-10-23  3:04     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox