This is the mail archive of the gdb-patches@sourceware.org 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]

don't call target_close in pop_target


Anyone knows why pop_target calls target_close itself ?

... since unpush_target will do it too anyway.

Looking through the history, pop_target has been doing this as
far back as I can see, but so has unpush_target.

I can't find any reason or place where calling target_close twice does any
good.  Due to this fact, target_close implementations have to make sure the
target isn't closed already, which isn't that nice.

No regressions on x86-pc-linux-gnu against a native gdbserver.

-- 
Pedro Alves
2008-11-04  Pedro Alves  <pedro@codesourcery.com>

	* target.c (unpush_target): Rename to ...
	(unpush_target_1) ... this.  Make static.  Add 'quitting'
	argument.  Pass it to target_close.
	(unpush_target): Rewrite as wrapper to unpush_target_1.
	(pop_target): Don't close the target here.  Pass 'quitting' to
	unpush_target_1.

---
 gdb/target.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

Index: src/gdb/target.c
===================================================================
--- src.orig/gdb/target.c	2008-11-04 17:42:53.000000000 +0000
+++ src/gdb/target.c	2008-11-04 17:53:14.000000000 +0000
@@ -758,11 +758,8 @@ push_target (struct target_ops *t)
   return (t != target_stack);
 }
 
-/* Remove a target_ops vector from the stack, wherever it may be.
-   Return how many times it was removed (0 or 1).  */
-
-int
-unpush_target (struct target_ops *t)
+static int
+unpush_target_1 (struct target_ops *t, int quitting)
 {
   struct target_ops **cur;
   struct target_ops *tmp;
@@ -789,7 +786,7 @@ unpush_target (struct target_ops *t)
      pushing and popping of targets work to support target overlays
      and inheritance").  This doesn't make much sense - only open
      targets should be closed.  */
-  target_close (t, 0);
+  target_close (t, quitting);
 
   /* Unchain the target */
   tmp = (*cur);
@@ -801,11 +798,19 @@ unpush_target (struct target_ops *t)
   return 1;
 }
 
+/* Remove a target_ops vector from the stack, wherever it may be.
+   Return how many times it was removed (0 or 1).  */
+
+int
+unpush_target (struct target_ops *t)
+{
+  return unpush_target_1 (t, 0);
+}
+
 void
 pop_target (void)
 {
-  target_close (target_stack, 0);	/* Let it clean up */
-  if (unpush_target (target_stack) == 1)
+  if (unpush_target_1 (target_stack, 0) == 1) /* Let it clean up */
     return;
 
   fprintf_unfiltered (gdb_stderr,
@@ -819,8 +824,7 @@ pop_all_targets_above (enum strata above
 {
   while ((int) (current_target.to_stratum) > (int) above_stratum)
     {
-      target_close (target_stack, quitting);
-      if (!unpush_target (target_stack))
+      if (!unpush_target_1 (target_stack, quitting))
 	{
 	  fprintf_unfiltered (gdb_stderr,
 			      "pop_all_targets couldn't find target %s\n",

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