Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Runtime Dwarf2 CFI engine cleanup
@ 2003-01-06 12:55 Michal Ludvig
  2003-02-03 16:23 ` Elena Zannoni
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Ludvig @ 2003-01-06 12:55 UTC (permalink / raw)
  To: GDB Patches

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

Hi all,
the attached is a fix for the problem described here:
http://sources.redhat.com/ml/gdb/2002-12/msg00246.html

I've created a new function cleanup_cfi() in dwarf2cfi.c that deletes 
all CIEs and FDEs of objfiles removed later by objfile_purge_solibs().
So far it works fine but I don't know how should I correctly call it.
For now I put the call directly to run_command():

static void
run_command (char *args, int from_tty)
{
   [...]
   clear_breakpoint_hit_counts ();

   cleanup_cfi ();    /* <=== HERE */

   objfile_purge_solibs ();

   do_run_cleanups (NULL);

   reopen_exec_file ();
   reread_symbols ();
   [...]
}

I know it isn't the right solution because it would require linking of 
dwarf2cfi.o to all targets. If I would wrap it by #ifdef X86_64 ... 
#endif it still isn't perfect, because other archs will hopefully use 
CFI in the future as well.

I was thinking about defining something like USE_DWARF2CFI for each 
target that use it in their config/whatever file...? Is it a way to go?

I can't attach this function to run_cleanup_chain, because I need to 
call cleanup_cfi() before objfile_purge_solibs() and also because 
do_run_cleanups() finally destroys the contents of run_cleanup_chain and 
finally because I don't know how (when/where) to attach cleanup_cfi() to 
run_cleanup_chain.

Could someone please tell me what is the cleanest way to call 
cleanup_cfi()? Thanks.

Michal Ludvig
-- 
* SuSE CR, s.r.o     * mludvig@suse.cz
* (+420) 296.545.373 * http://www.suse.cz

[-- Attachment #2: rerun-3.diff --]
[-- Type: text/plain, Size: 2562 bytes --]

Index: dwarf2cfi.h
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
retrieving revision 1.16
diff -u -p -r1.16 dwarf2cfi.h
--- dwarf2cfi.h	19 Jul 2002 09:40:51 -0000	1.16
+++ dwarf2cfi.h	20 Dec 2002 15:14:21 -0000
@@ -64,6 +64,12 @@ struct cie_unit
 
   /* Next in chain.  */
   struct cie_unit *next;
+
+  /* Keep or destroy this CIE on a new run? */
+  int keep;
+
+  /* How many FDEs refer to this CIE? */
+  int refs;
 };
 
 /* Frame Description Entry.  */
Index: dwarf2cfi.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
retrieving revision 1.16
diff -u -p -r1.16 dwarf2cfi.c
--- dwarf2cfi.c	19 Jul 2002 09:40:51 -0000	1.16
+++ dwarf2cfi.c	20 Dec 2002 15:14:21 -0000
@@ -317,6 +326,86 @@ frame_state_alloc (void)
     (struct frame_state_reg *) obstack_alloc (&unwind_tmp_obstack, regs_size);
   memset (fs->regs.reg, 0, regs_size);
   return fs;
+}
+
+void
+cleanup_cfi (void *name)
+{
+  struct objfile *ofp;
+  struct cie_unit *cie, *cie_prev;
+  int fde_index=0, fde_free=0;
+  
+  cie = cie_chunks;
+  while (cie)
+  {
+	  cie->refs = 0;
+	  cie->keep = 0;
+	  cie = cie->next;
+  }
+
+  /* Mark all unwanted CIEs. */
+  ALL_OBJFILES (ofp)
+  {
+	  if (!(ofp->flags & OBJF_USERLOADED) && (ofp->flags & OBJF_SHARED))
+		  printf ("\tRemoving %s...\n", ofp->name);
+	  else
+	  {
+		  printf ("\tKeeping %s...\n", ofp->name);
+		  cie = cie_chunks;
+		  while(cie)
+		  {
+			  if (cie->objfile == ofp)
+				  cie->keep = 1;
+			  cie = cie->next;
+		  }
+	  }
+  }
+
+  /* Remove all FDEs pointing to unwanted CIEs. */
+  for (fde_index = 0, fde_free=0; 
+	fde_index < fde_chunks.elems; 
+	fde_index++, fde_free++)
+  {
+	  if (!fde_chunks.array[fde_index]->cie_ptr->keep)
+	  {
+		  fde_free--;
+		  continue;
+	  }
+	  else if (fde_free < fde_index)
+		  fde_chunks.array[fde_free] = fde_chunks.array[fde_index];
+	  fde_chunks.array[fde_free]->cie_ptr->refs++;
+  }
+  fde_chunks.elems = fde_free;
+
+  /* Remove all unwanted CIEs. */
+  cie = cie_chunks;
+  cie_prev = NULL;
+  while (cie)
+  {
+	  struct cie_unit *cie_tmp;
+	  
+	  if (! cie->keep || !cie->refs)
+	  {
+		  cie_tmp = cie;
+		  if (cie_prev == NULL)
+		  {
+			  cie_chunks = cie->next;
+			  cie = cie_chunks;
+		  }
+		  else 
+		  {
+			  cie_prev->next = cie->next;
+			  cie = cie->next;
+		  }
+		  /* cie_prev must remain unchanged. */
+		  xfree (cie_tmp);
+	  }
+	  else
+	  {
+		  cie_prev = cie;
+		  cie = cie->next;
+	  }
+  }
 }
 
 static void

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

* Re: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-01-06 12:55 [RFA] Runtime Dwarf2 CFI engine cleanup Michal Ludvig
@ 2003-02-03 16:23 ` Elena Zannoni
  2003-02-10 12:30   ` Michal Ludvig
  0 siblings, 1 reply; 12+ messages in thread
From: Elena Zannoni @ 2003-02-03 16:23 UTC (permalink / raw)
  To: Michal Ludvig; +Cc: GDB Patches

Michal Ludvig writes:
 > Hi all,
 > the attached is a fix for the problem described here:
 > http://sources.redhat.com/ml/gdb/2002-12/msg00246.html
 > 
 > I've created a new function cleanup_cfi() in dwarf2cfi.c that deletes 
 > all CIEs and FDEs of objfiles removed later by objfile_purge_solibs().
 > So far it works fine but I don't know how should I correctly call it.


I have tried your function, and it does fixes some weird errors which occur
on rerun. 

I just tried by using the hack of defining GDB_TARGET_IS_X86_64, which
is definitely a bad thing.

I think that the best way is to define a gdbarch method, just like it
was done for gdbarch_dwarf2_build_frame_info.

In the patch below, you cannot use printf's. Use printf_filtered. But
maybe, better yet, using a warning here would be more appropriate.

Watch out for the non-GNU indentation and spacing.

elena

 > For now I put the call directly to run_command():
 > 
 > static void
 > run_command (char *args, int from_tty)
 > {
 >    [...]
 >    clear_breakpoint_hit_counts ();
 > 
 >    cleanup_cfi ();    /* <=== HERE */
 > 
 >    objfile_purge_solibs ();
 > 
 >    do_run_cleanups (NULL);
 > 
 >    reopen_exec_file ();
 >    reread_symbols ();
 >    [...]
 > }
 > 
 > I know it isn't the right solution because it would require linking of 
 > dwarf2cfi.o to all targets. If I would wrap it by #ifdef X86_64 ... 
 > #endif it still isn't perfect, because other archs will hopefully use 
 > CFI in the future as well.
 > 
 > I was thinking about defining something like USE_DWARF2CFI for each 
 > target that use it in their config/whatever file...? Is it a way to go?
 > 
 > I can't attach this function to run_cleanup_chain, because I need to 
 > call cleanup_cfi() before objfile_purge_solibs() and also because 
 > do_run_cleanups() finally destroys the contents of run_cleanup_chain and 
 > finally because I don't know how (when/where) to attach cleanup_cfi() to 
 > run_cleanup_chain.
 > 
 > Could someone please tell me what is the cleanest way to call 
 > cleanup_cfi()? Thanks.
 > 
 > Michal Ludvig
 > -- 
 > * SuSE CR, s.r.o     * mludvig@suse.cz
 > * (+420) 296.545.373 * http://www.suse.cz
 > Index: dwarf2cfi.h
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
 > retrieving revision 1.16
 > diff -u -p -r1.16 dwarf2cfi.h
 > --- dwarf2cfi.h	19 Jul 2002 09:40:51 -0000	1.16
 > +++ dwarf2cfi.h	20 Dec 2002 15:14:21 -0000
 > @@ -64,6 +64,12 @@ struct cie_unit
 >  
 >    /* Next in chain.  */
 >    struct cie_unit *next;
 > +
 > +  /* Keep or destroy this CIE on a new run? */
 > +  int keep;
 > +
 > +  /* How many FDEs refer to this CIE? */
 > +  int refs;
 >  };
 >  
 >  /* Frame Description Entry.  */
 > Index: dwarf2cfi.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
 > retrieving revision 1.16
 > diff -u -p -r1.16 dwarf2cfi.c
 > --- dwarf2cfi.c	19 Jul 2002 09:40:51 -0000	1.16
 > +++ dwarf2cfi.c	20 Dec 2002 15:14:21 -0000
 > @@ -317,6 +326,86 @@ frame_state_alloc (void)
 >      (struct frame_state_reg *) obstack_alloc (&unwind_tmp_obstack, regs_size);
 >    memset (fs->regs.reg, 0, regs_size);
 >    return fs;
 > +}
 > +
 > +void
 > +cleanup_cfi (void *name)
 > +{
 > +  struct objfile *ofp;
 > +  struct cie_unit *cie, *cie_prev;
 > +  int fde_index=0, fde_free=0;
 > +  
 > +  cie = cie_chunks;
 > +  while (cie)
 > +  {
 > +	  cie->refs = 0;
 > +	  cie->keep = 0;
 > +	  cie = cie->next;
 > +  }
 > +
 > +  /* Mark all unwanted CIEs. */
 > +  ALL_OBJFILES (ofp)
 > +  {
 > +	  if (!(ofp->flags & OBJF_USERLOADED) && (ofp->flags & OBJF_SHARED))
 > +		  printf ("\tRemoving %s...\n", ofp->name);
 > +	  else
 > +	  {
 > +		  printf ("\tKeeping %s...\n", ofp->name);
 > +		  cie = cie_chunks;
 > +		  while(cie)
 > +		  {
 > +			  if (cie->objfile == ofp)
 > +				  cie->keep = 1;
 > +			  cie = cie->next;
 > +		  }
 > +	  }
 > +  }
 > +
 > +  /* Remove all FDEs pointing to unwanted CIEs. */
 > +  for (fde_index = 0, fde_free=0; 
 > +	fde_index < fde_chunks.elems; 
 > +	fde_index++, fde_free++)
 > +  {
 > +	  if (!fde_chunks.array[fde_index]->cie_ptr->keep)
 > +	  {
 > +		  fde_free--;
 > +		  continue;
 > +	  }
 > +	  else if (fde_free < fde_index)
 > +		  fde_chunks.array[fde_free] = fde_chunks.array[fde_index];
 > +	  fde_chunks.array[fde_free]->cie_ptr->refs++;
 > +  }
 > +  fde_chunks.elems = fde_free;
 > +
 > +  /* Remove all unwanted CIEs. */
 > +  cie = cie_chunks;
 > +  cie_prev = NULL;
 > +  while (cie)
 > +  {
 > +	  struct cie_unit *cie_tmp;
 > +	  
 > +	  if (! cie->keep || !cie->refs)
 > +	  {
 > +		  cie_tmp = cie;
 > +		  if (cie_prev == NULL)
 > +		  {
 > +			  cie_chunks = cie->next;
 > +			  cie = cie_chunks;
 > +		  }
 > +		  else 
 > +		  {
 > +			  cie_prev->next = cie->next;
 > +			  cie = cie->next;
 > +		  }
 > +		  /* cie_prev must remain unchanged. */
 > +		  xfree (cie_tmp);
 > +	  }
 > +	  else
 > +	  {
 > +		  cie_prev = cie;
 > +		  cie = cie->next;
 > +	  }
 > +  }
 >  }
 >  
 >  static void


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

* Re: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-03 16:23 ` Elena Zannoni
@ 2003-02-10 12:30   ` Michal Ludvig
  2003-02-26 15:35     ` PING: " Michal Ludvig
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Ludvig @ 2003-02-10 12:30 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: GDB Patches

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

Elena Zannoni wrote:
> Michal Ludvig writes:
>  > Hi all,
>  > the attached is a fix for the problem described here:
>  > http://sources.redhat.com/ml/gdb/2002-12/msg00246.html
>  > 
>  > I've created a new function cleanup_cfi() in dwarf2cfi.c that deletes 
>  > all CIEs and FDEs of objfiles removed later by objfile_purge_solibs().
>  > So far it works fine but I don't know how should I correctly call it.
> 
> 
> I have tried your function, and it does fixes some weird errors which occur
> on rerun. 
> 
> I just tried by using the hack of defining GDB_TARGET_IS_X86_64, which
> is definitely a bad thing.
> 
> I think that the best way is to define a gdbarch method, just like it
> was done for gdbarch_dwarf2_build_frame_info.

How about adding dwarf2cfi.o to all targets? When there is for example 
mipsread.o compiled into gdb on x86-64 (why? because there is no option 
to say what features a given target needs.) than dwarf2cfi.o could go 
there as well...
I hope more and more targets will use it in the near future.

The attached is a version that adds dwarf2cfi.o for all targets. If it's 
unacceptable this way I'll provide gdbarch-ed version instead. But I 
think that gdbarch_*() functions are good for the case when on different 
targets a different functions are called to do a given task (eg. read 
register). But in this case you must call cleanup_cfi() in all targets 
that use CFI. No option. Calling it shouldn't depend on setting gdbarch 
value. Instead it should depend on linking dwarf2cfi.o into the gdb.

> In the patch below, you cannot use printf's. Use printf_filtered. But
> maybe, better yet, using a warning here would be more appropriate.

It isn't a warning, just an informational message. Now it's printed only 
when info_verbose is set.

> Watch out for the non-GNU indentation and spacing.

Reindented.

OK to commit?

Michal Ludvig
-- 
* SuSE CR, s.r.o     * mludvig@suse.cz
* (+420) 296.545.373 * http://www.suse.cz

[-- Attachment #2: rerun-cfi4all-2.diff --]
[-- Type: text/plain, Size: 4897 bytes --]

2003-02-10  Michal Ludvig  <mludvig@suse.cz>

	* dwarf2cfi.c (struct cie_unit): New items 'keep' and 'refs'.
	(cleanup_cfi): New function.
	* infcmd.c (run_command): Call cleanup_cfi().
	* Makefile.in: Link dwarf2cfi.[co] to all targets.
	* config/i386/x86-64linux.mt: Remove dwarf2cfi.o from
	TDEPFILES.

Index: dwarf2cfi.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
retrieving revision 1.31
diff -u -p -r1.31 dwarf2cfi.c
--- dwarf2cfi.c	10 Feb 2003 11:50:20 -0000	1.31
+++ dwarf2cfi.c	10 Feb 2003 12:10:21 -0000
@@ -64,6 +64,12 @@ struct cie_unit
 
   struct objfile *objfile;
 
+  /* Keep or destroy this CIE on new run? */
+  int keep;
+
+  /* How many FDEs refer to this CIE? */
+  int refs;
+
   /* Next in chain.  */
   struct cie_unit *next;
 };
@@ -289,6 +295,90 @@ frame_state_alloc (void)
     (struct frame_state_reg *) obstack_alloc (&unwind_tmp_obstack, regs_size);
   memset (fs->regs.reg, 0, regs_size);
   return fs;
+}
+
+void
+cleanup_cfi (void *name)
+{
+  struct objfile *ofp;
+  struct cie_unit *cie, *cie_prev;
+  int fde_index = 0, fde_free = 0;
+
+  cie = cie_chunks;
+  while (cie)
+    {
+      cie->refs = 0;
+      cie->keep = 0;
+      cie = cie->next;
+    }
+
+  /* Mark all unwanted CIEs. */
+  ALL_OBJFILES (ofp)
+  {
+    if (!(ofp->flags & OBJF_USERLOADED) && (ofp->flags & OBJF_SHARED))
+      {
+	if (info_verbose)
+	  printf_filtered ("\tRemoving %s...\n", ofp->name);
+      }
+    else
+      {
+	if (info_verbose)
+	  printf_filtered ("\tKeeping %s...\n", ofp->name);
+
+	cie = cie_chunks;
+	while (cie)
+	  {
+	    if (cie->objfile == ofp)
+	      cie->keep = 1;
+	    cie = cie->next;
+	  }
+      }
+  }
+
+  /* Remove all FDEs pointing to unwanted CIEs. */
+  for (fde_index = 0, fde_free = 0;
+       fde_index < fde_chunks.elems; fde_index++, fde_free++)
+    {
+      if (!fde_chunks.array[fde_index]->cie_ptr->keep)
+	{
+	  fde_free--;
+	  continue;
+	}
+      else if (fde_free < fde_index)
+	fde_chunks.array[fde_free] = fde_chunks.array[fde_index];
+      fde_chunks.array[fde_free]->cie_ptr->refs++;
+    }
+  fde_chunks.elems = fde_free;
+
+  /* Remove all unwanted CIEs. */
+  cie = cie_chunks;
+  cie_prev = NULL;
+  while (cie)
+    {
+      struct cie_unit *cie_tmp;
+
+      if (!cie->keep || !cie->refs)
+	{
+	  cie_tmp = cie;
+	  if (cie_prev == NULL)
+	    {
+	      cie_chunks = cie->next;
+	      cie = cie_chunks;
+	    }
+	  else
+	    {
+	      cie_prev->next = cie->next;
+	      cie = cie->next;
+	    }
+	  /* cie_prev must remain unchanged. */
+	  xfree (cie_tmp);
+	}
+      else
+	{
+	  cie_prev = cie;
+	  cie = cie->next;
+	}
+    }
 }
 
 static void
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.72
diff -u -p -r1.72 infcmd.c
--- infcmd.c	1 Feb 2003 17:28:40 -0000	1.72
+++ infcmd.c	10 Feb 2003 12:10:21 -0000
@@ -401,6 +401,8 @@ Start it from the beginning? "))
 
   clear_breakpoint_hit_counts ();
 
+  cleanup_cfi ();
+
   /* Purge old solib objfiles. */
   objfile_purge_solibs ();
 
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.328
diff -u -p -r1.328 Makefile.in
--- Makefile.in	7 Feb 2003 05:33:44 -0000	1.328
+++ Makefile.in	10 Feb 2003 12:10:21 -0000
@@ -514,7 +514,7 @@ SFILES = ada-exp.y ada-lang.c ada-typepr
 	charset.c cli-out.c coffread.c complaints.c completer.c corefile.c \
 	cp-abi.c cp-support.c cp-valprint.c \
 	dbxread.c demangle.c disasm.c doublest.c \
-	dummy-frame.c dwarfread.c dwarf2read.c \
+	dummy-frame.c dwarfread.c dwarf2read.c dwarf2cfi.c \
 	elfread.c environ.c eval.c event-loop.c event-top.c expprint.c \
 	f-exp.y f-lang.c f-typeprint.c f-valprint.c findvar.c frame.c \
 	frame-unwind.c \
@@ -835,7 +835,7 @@ COMMON_OBS = version.o blockframe.o brea
 	gdb-events.o \
 	exec.o bcache.o objfiles.o minsyms.o maint.o demangle.o \
 	dbxread.o coffread.o elfread.o \
-	dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \
+	dwarfread.o dwarf2read.o dwarf2cfi.o mipsread.o stabsread.o corefile.o \
 	c-lang.o f-lang.o \
 	ui-out.o cli-out.o \
 	varobj.o wrapper.o \
Index: config/i386/x86-64linux.mt
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/x86-64linux.mt,v
retrieving revision 1.6
diff -u -p -r1.6 x86-64linux.mt
--- config/i386/x86-64linux.mt	21 Dec 2002 21:09:58 -0000	1.6
+++ config/i386/x86-64linux.mt	10 Feb 2003 12:10:21 -0000
@@ -1,6 +1,6 @@
 # Target: AMD x86-64 running GNU/Linux
-TDEPFILES= x86-64-tdep.o x86-64-linux-tdep.o dwarf2cfi.o \
-	i386-tdep.o i387-tdep.o \
+TDEPFILES= x86-64-tdep.o x86-64-linux-tdep.o \
+	i386-tdep.o i386-linux-tdep.o i387-tdep.o \
 	solib.o solib-svr4.o solib-legacy.o
 
 GDB_MULTI_ARCH=GDB_MULTI_ARCH_TM

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

* PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-10 12:30   ` Michal Ludvig
@ 2003-02-26 15:35     ` Michal Ludvig
  2003-02-26 15:47       ` Daniel Jacobowitz
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Ludvig @ 2003-02-26 15:35 UTC (permalink / raw)
  To: Michal Ludvig; +Cc: Elena Zannoni, GDB Patches, Andrew Cagney

Michal Ludvig wrote:
> Elena Zannoni wrote:
> 
>> Michal Ludvig writes:
>>  > Hi all,
>>  > the attached is a fix for the problem described here:
>>  > http://sources.redhat.com/ml/gdb/2002-12/msg00246.html
>>  >  > I've created a new function cleanup_cfi() in dwarf2cfi.c that 
>> deletes  > all CIEs and FDEs of objfiles removed later by 
>> objfile_purge_solibs().
>>  > So far it works fine but I don't know how should I correctly call it.
>>
>> I have tried your function, and it does fixes some weird errors which 
>> occur
>> on rerun.
>> I just tried by using the hack of defining GDB_TARGET_IS_X86_64, which
>> is definitely a bad thing.
>>
>> I think that the best way is to define a gdbarch method, just like it
>> was done for gdbarch_dwarf2_build_frame_info.
> 
> 
> How about adding dwarf2cfi.o to all targets? When there is for example 
> mipsread.o compiled into gdb on x86-64 (why? because there is no option 
> to say what features a given target needs.) than dwarf2cfi.o could go 
> there as well...
> I hope more and more targets will use it in the near future.
> 
> The attached is a version that adds dwarf2cfi.o for all targets. If it's 
> unacceptable this way I'll provide gdbarch-ed version instead. But I 
> think that gdbarch_*() functions are good for the case when on different 
> targets a different functions are called to do a given task (eg. read 
> register). But in this case you must call cleanup_cfi() in all targets 
> that use CFI. No option. Calling it shouldn't depend on setting gdbarch 
> value. Instead it should depend on linking dwarf2cfi.o into the gdb.
> 
>> In the patch below, you cannot use printf's. Use printf_filtered. But
>> maybe, better yet, using a warning here would be more appropriate.
> 
> 
> It isn't a warning, just an informational message. Now it's printed only 
> when info_verbose is set.
> 
>> Watch out for the non-GNU indentation and spacing.
> 
> 
> Reindented.
> 
> OK to commit?
> 
> Michal Ludvig

Could someone *please* comment on this two months old patch?
Can I at least commit the dwarf2cfi.c part (proven to be stable since 
it's in use in our GDB package), so that it could eventually be 
triggered by adding one single line to infcmd.c?
Without this patch the CFI engine is very unstable. Is there a reason 
why not to commit it?

Ad triggering cleanup_cfi() - there are several possibilities:
1) Add dwarf2cfi.o to all targets in Makefile.in and call cleanup_cfi() 
from run_command() w/o obstructions.
2) To all targets that use CFI add macro USE_DWARF2CFI to their 
config/what/ever.h and wrap call to cleanup_cfi() by appropriate ifdefs.
3) Create gdbarch_whatever(_p) to call it. I don't think it's a good 
idea - there is no point in setting this macro to something else or 
unsetting it.
[in order of preference]

I would really like to get rid of this pending patch from my todo list.

Thanks in advance

Michal Ludvig

> ------------------------------------------------------------------------
> 
> 2003-02-10  Michal Ludvig  <mludvig@suse.cz>
> 
> 	* dwarf2cfi.c (struct cie_unit): New items 'keep' and 'refs'.
> 	(cleanup_cfi): New function.
> 	* infcmd.c (run_command): Call cleanup_cfi().
> 	* Makefile.in: Link dwarf2cfi.[co] to all targets.
> 	* config/i386/x86-64linux.mt: Remove dwarf2cfi.o from
> 	TDEPFILES.
> 
> Index: dwarf2cfi.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
> retrieving revision 1.31
> diff -u -p -r1.31 dwarf2cfi.c
> --- dwarf2cfi.c	10 Feb 2003 11:50:20 -0000	1.31
> +++ dwarf2cfi.c	10 Feb 2003 12:10:21 -0000
> @@ -64,6 +64,12 @@ struct cie_unit
>  
>    struct objfile *objfile;
>  
> +  /* Keep or destroy this CIE on new run? */
> +  int keep;
> +
> +  /* How many FDEs refer to this CIE? */
> +  int refs;
> +
>    /* Next in chain.  */
>    struct cie_unit *next;
>  };
> @@ -289,6 +295,90 @@ frame_state_alloc (void)
>      (struct frame_state_reg *) obstack_alloc (&unwind_tmp_obstack, regs_size);
>    memset (fs->regs.reg, 0, regs_size);
>    return fs;
> +}
> +
> +void
> +cleanup_cfi (void *name)
> +{
> +  struct objfile *ofp;
> +  struct cie_unit *cie, *cie_prev;
> +  int fde_index = 0, fde_free = 0;
> +
> +  cie = cie_chunks;
> +  while (cie)
> +    {
> +      cie->refs = 0;
> +      cie->keep = 0;
> +      cie = cie->next;
> +    }
> +
> +  /* Mark all unwanted CIEs. */
> +  ALL_OBJFILES (ofp)
> +  {
> +    if (!(ofp->flags & OBJF_USERLOADED) && (ofp->flags & OBJF_SHARED))
> +      {
> +	if (info_verbose)
> +	  printf_filtered ("\tRemoving %s...\n", ofp->name);
> +      }
> +    else
> +      {
> +	if (info_verbose)
> +	  printf_filtered ("\tKeeping %s...\n", ofp->name);
> +
> +	cie = cie_chunks;
> +	while (cie)
> +	  {
> +	    if (cie->objfile == ofp)
> +	      cie->keep = 1;
> +	    cie = cie->next;
> +	  }
> +      }
> +  }
> +
> +  /* Remove all FDEs pointing to unwanted CIEs. */
> +  for (fde_index = 0, fde_free = 0;
> +       fde_index < fde_chunks.elems; fde_index++, fde_free++)
> +    {
> +      if (!fde_chunks.array[fde_index]->cie_ptr->keep)
> +	{
> +	  fde_free--;
> +	  continue;
> +	}
> +      else if (fde_free < fde_index)
> +	fde_chunks.array[fde_free] = fde_chunks.array[fde_index];
> +      fde_chunks.array[fde_free]->cie_ptr->refs++;
> +    }
> +  fde_chunks.elems = fde_free;
> +
> +  /* Remove all unwanted CIEs. */
> +  cie = cie_chunks;
> +  cie_prev = NULL;
> +  while (cie)
> +    {
> +      struct cie_unit *cie_tmp;
> +
> +      if (!cie->keep || !cie->refs)
> +	{
> +	  cie_tmp = cie;
> +	  if (cie_prev == NULL)
> +	    {
> +	      cie_chunks = cie->next;
> +	      cie = cie_chunks;
> +	    }
> +	  else
> +	    {
> +	      cie_prev->next = cie->next;
> +	      cie = cie->next;
> +	    }
> +	  /* cie_prev must remain unchanged. */
> +	  xfree (cie_tmp);
> +	}
> +      else
> +	{
> +	  cie_prev = cie;
> +	  cie = cie->next;
> +	}
> +    }
>  }
>  
>  static void
> Index: infcmd.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/infcmd.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 infcmd.c
> --- infcmd.c	1 Feb 2003 17:28:40 -0000	1.72
> +++ infcmd.c	10 Feb 2003 12:10:21 -0000
> @@ -401,6 +401,8 @@ Start it from the beginning? "))
>  
>    clear_breakpoint_hit_counts ();
>  
> +  cleanup_cfi ();
> +
>    /* Purge old solib objfiles. */
>    objfile_purge_solibs ();
>  
> Index: Makefile.in
> ===================================================================
> RCS file: /cvs/src/src/gdb/Makefile.in,v
> retrieving revision 1.328
> diff -u -p -r1.328 Makefile.in
> --- Makefile.in	7 Feb 2003 05:33:44 -0000	1.328
> +++ Makefile.in	10 Feb 2003 12:10:21 -0000
> @@ -514,7 +514,7 @@ SFILES = ada-exp.y ada-lang.c ada-typepr
>  	charset.c cli-out.c coffread.c complaints.c completer.c corefile.c \
>  	cp-abi.c cp-support.c cp-valprint.c \
>  	dbxread.c demangle.c disasm.c doublest.c \
> -	dummy-frame.c dwarfread.c dwarf2read.c \
> +	dummy-frame.c dwarfread.c dwarf2read.c dwarf2cfi.c \
>  	elfread.c environ.c eval.c event-loop.c event-top.c expprint.c \
>  	f-exp.y f-lang.c f-typeprint.c f-valprint.c findvar.c frame.c \
>  	frame-unwind.c \
> @@ -835,7 +835,7 @@ COMMON_OBS = version.o blockframe.o brea
>  	gdb-events.o \
>  	exec.o bcache.o objfiles.o minsyms.o maint.o demangle.o \
>  	dbxread.o coffread.o elfread.o \
> -	dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \
> +	dwarfread.o dwarf2read.o dwarf2cfi.o mipsread.o stabsread.o corefile.o \
>  	c-lang.o f-lang.o \
>  	ui-out.o cli-out.o \
>  	varobj.o wrapper.o \
> Index: config/i386/x86-64linux.mt
> ===================================================================
> RCS file: /cvs/src/src/gdb/config/i386/x86-64linux.mt,v
> retrieving revision 1.6
> diff -u -p -r1.6 x86-64linux.mt
> --- config/i386/x86-64linux.mt	21 Dec 2002 21:09:58 -0000	1.6
> +++ config/i386/x86-64linux.mt	10 Feb 2003 12:10:21 -0000
> @@ -1,6 +1,6 @@
>  # Target: AMD x86-64 running GNU/Linux
> -TDEPFILES= x86-64-tdep.o x86-64-linux-tdep.o dwarf2cfi.o \
> -	i386-tdep.o i387-tdep.o \
> +TDEPFILES= x86-64-tdep.o x86-64-linux-tdep.o \
> +	i386-tdep.o i386-linux-tdep.o i387-tdep.o \
>  	solib.o solib-svr4.o solib-legacy.o
>  
>  GDB_MULTI_ARCH=GDB_MULTI_ARCH_TM


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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-26 15:35     ` PING: " Michal Ludvig
@ 2003-02-26 15:47       ` Daniel Jacobowitz
  2003-02-26 18:20         ` Andrew Cagney
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Jacobowitz @ 2003-02-26 15:47 UTC (permalink / raw)
  To: Michal Ludvig; +Cc: Elena Zannoni, GDB Patches, Andrew Cagney

On Wed, Feb 26, 2003 at 04:35:20PM +0100, Michal Ludvig wrote:
> Michal Ludvig wrote:
> >Elena Zannoni wrote:
> >
> >>Michal Ludvig writes:
> >> > Hi all,
> >> > the attached is a fix for the problem described here:
> >> > http://sources.redhat.com/ml/gdb/2002-12/msg00246.html
> >> >  > I've created a new function cleanup_cfi() in dwarf2cfi.c that 
> >>deletes  > all CIEs and FDEs of objfiles removed later by 
> >>objfile_purge_solibs().
> >> > So far it works fine but I don't know how should I correctly call it.
> >>
> >>I have tried your function, and it does fixes some weird errors which 
> >>occur
> >>on rerun.
> >>I just tried by using the hack of defining GDB_TARGET_IS_X86_64, which
> >>is definitely a bad thing.
> >>
> >>I think that the best way is to define a gdbarch method, just like it
> >>was done for gdbarch_dwarf2_build_frame_info.
> >
> >
> >How about adding dwarf2cfi.o to all targets? When there is for example 
> >mipsread.o compiled into gdb on x86-64 (why? because there is no option 
> >to say what features a given target needs.) than dwarf2cfi.o could go 
> >there as well...
> >I hope more and more targets will use it in the near future.
> >
> >The attached is a version that adds dwarf2cfi.o for all targets. If it's 
> >unacceptable this way I'll provide gdbarch-ed version instead. But I 
> >think that gdbarch_*() functions are good for the case when on different 
> >targets a different functions are called to do a given task (eg. read 
> >register). But in this case you must call cleanup_cfi() in all targets 
> >that use CFI. No option. Calling it shouldn't depend on setting gdbarch 
> >value. Instead it should depend on linking dwarf2cfi.o into the gdb.
> >
> >>In the patch below, you cannot use printf's. Use printf_filtered. But
> >>maybe, better yet, using a warning here would be more appropriate.
> >
> >
> >It isn't a warning, just an informational message. Now it's printed only 
> >when info_verbose is set.
> >
> >>Watch out for the non-GNU indentation and spacing.
> >
> >
> >Reindented.
> >
> >OK to commit?
> >
> >Michal Ludvig
> 
> Could someone *please* comment on this two months old patch?
> Can I at least commit the dwarf2cfi.c part (proven to be stable since 
> it's in use in our GDB package), so that it could eventually be 
> triggered by adding one single line to infcmd.c?
> Without this patch the CFI engine is very unstable. Is there a reason 
> why not to commit it?
> 
> Ad triggering cleanup_cfi() - there are several possibilities:
> 1) Add dwarf2cfi.o to all targets in Makefile.in and call cleanup_cfi() 
> from run_command() w/o obstructions.
> 2) To all targets that use CFI add macro USE_DWARF2CFI to their 
> config/what/ever.h and wrap call to cleanup_cfi() by appropriate ifdefs.
> 3) Create gdbarch_whatever(_p) to call it. I don't think it's a good 
> idea - there is no point in setting this macro to something else or 
> unsetting it.
> [in order of preference]
> 
> I would really like to get rid of this pending patch from my todo list.
> 
> Thanks in advance


I don't think that the way you're selecting objfiles to unload is ideal
- you're duplicating logic from objfile_purge_solibs.  We need a more
general hook to free objfile-specific information.  However, I believe
that can be addressed separately, and this will definitely fix some
crashes as-is and not introduce any new ones.

I don't have any problem with linking dwarf2cfi.o in for all targets. 
Let's sit on this for another day and see if anyone else objects, and
then you can commit it.

You made a line in Makefile.in too wide; please fix that before you
check it in.

[List: my assumption in approving this is that the dwarf2cfi support is
not part of the dwarf2 reader, so I'm not stepping on anyone's toes. 
If you disagree, please tell me so.]

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-26 15:47       ` Daniel Jacobowitz
@ 2003-02-26 18:20         ` Andrew Cagney
  2003-02-26 18:36           ` Daniel Jacobowitz
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Cagney @ 2003-02-26 18:20 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Michal Ludvig, Elena Zannoni, GDB Patches

> 
> 
> I don't think that the way you're selecting objfiles to unload is ideal
> - you're duplicating logic from objfile_purge_solibs.  We need a more
> general hook to free objfile-specific information.  However, I believe
> that can be addressed separately, and this will definitely fix some
> crashes as-is and not introduce any new ones.
> 
> I don't have any problem with linking dwarf2cfi.o in for all targets. 
> Let's sit on this for another day and see if anyone else objects, and
> then you can commit it.

A quick look at the bigger picture reveals:

- the underlying code needs to be fixed before it is linked into all 
targets.

- if it needs to be modified of changes in another part of gdb then it 
should use an observer.  It should not introduce another hack.

You'll note that Joel and I are currently working through this.  Yes it 
means that the posted patch doesn't go in.  It also means that GDB is 
that bit more (not less) maintainable.

> You made a line in Makefile.in too wide; please fix that before you
> check it in.
> 
> [List: my assumption in approving this is that the dwarf2cfi support is
> not part of the dwarf2 reader, so I'm not stepping on anyone's toes. 
> If you disagree, please tell me so.]

Puzzled expression.

Andrew



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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-26 18:20         ` Andrew Cagney
@ 2003-02-26 18:36           ` Daniel Jacobowitz
  2003-02-26 19:32             ` Andrew Cagney
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Jacobowitz @ 2003-02-26 18:36 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Michal Ludvig, Elena Zannoni, GDB Patches

On Wed, Feb 26, 2003 at 01:22:49PM -0500, Andrew Cagney wrote:
> >
> >
> >I don't think that the way you're selecting objfiles to unload is ideal
> >- you're duplicating logic from objfile_purge_solibs.  We need a more
> >general hook to free objfile-specific information.  However, I believe
> >that can be addressed separately, and this will definitely fix some
> >crashes as-is and not introduce any new ones.
> >
> >I don't have any problem with linking dwarf2cfi.o in for all targets. 
> >Let's sit on this for another day and see if anyone else objects, and
> >then you can commit it.
> 
> A quick look at the bigger picture reveals:
> 
> - the underlying code needs to be fixed before it is linked into all 
> targets.

Why?  The code can be fixed as it is activated for other targets;
linking and use aren't the same thing.  I'd even call this the first
step in fixing it - doesn't break anything and makes it easier for
other targets to test it.

> - if it needs to be modified of changes in another part of gdb then it 
> should use an observer.  It should not introduce another hack.
> 
> You'll note that Joel and I are currently working through this.  Yes it 
> means that the posted patch doesn't go in.  It also means that GDB is 
> that bit more (not less) maintainable.

OK, if that's your preference, Michal please do not check in this
patch.  I think it's a bit silly to reject a patch which fixes a
"break; run; run" segfault on this basis, especially one two months
or more old, though.

This is one of the two major issues I know about that are forcing
Michal to do x86-64 development on 5.3 instead of HEAD.  I applaud your
vision in preserving future maintainability; I'm tired of that vision
interfering with having a working GDB.

> >You made a line in Makefile.in too wide; please fix that before you
> >check it in.
> >
> >[List: my assumption in approving this is that the dwarf2cfi support is
> >not part of the dwarf2 reader, so I'm not stepping on anyone's toes. 
> >If you disagree, please tell me so.]
> 
> Puzzled expression.

This is the problem with vague lines of authority.  It's not always
clear who can approve a patch even to people who do the approving.  I'm
tired of exercising what seems to be pretty clear authority to approve
something and getting prickly mail from someone else overturning my
decision.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-26 18:36           ` Daniel Jacobowitz
@ 2003-02-26 19:32             ` Andrew Cagney
  2003-02-26 19:38               ` Daniel Jacobowitz
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Cagney @ 2003-02-26 19:32 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Michal Ludvig, Elena Zannoni, GDB Patches

>> Puzzled expression.
> 
> 
> This is the problem with vague lines of authority.  It's not always
> clear who can approve a patch even to people who do the approving.  I'm
> tired of exercising what seems to be pretty clear authority to approve
> something and getting prickly mail from someone else overturning my
> decision.

The file is dwarf2*, when originally approved, it was done by a dwarf2 
maintainer.  I'm sorry but, at least here, I'm really struggling to see 
how, this can be somehow vague or ill defined.

Andrew



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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-26 19:32             ` Andrew Cagney
@ 2003-02-26 19:38               ` Daniel Jacobowitz
  2003-02-27  8:14                 ` Michal Ludvig
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Jacobowitz @ 2003-02-26 19:38 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Michal Ludvig, Elena Zannoni, GDB Patches

On Wed, Feb 26, 2003 at 02:34:19PM -0500, Andrew Cagney wrote:
> >>Puzzled expression.
> >
> >
> >This is the problem with vague lines of authority.  It's not always
> >clear who can approve a patch even to people who do the approving.  I'm
> >tired of exercising what seems to be pretty clear authority to approve
> >something and getting prickly mail from someone else overturning my
> >decision.
> 
> The file is dwarf2*, when originally approved, it was done by a dwarf2 
> maintainer.  I'm sorry but, at least here, I'm really struggling to see 
> how, this can be somehow vague or ill defined.

The file is only tangentially related to symbol reading, and was first
approved by a global maintainer.  I'm really struggling to see how this
is vague or ill defined.

[On the other hand, it's definitely very close to the dwarf2 reader;
but those parts are not affected by this patch.  I am merely trying to
make my point.]

In any case I am withdrawing my attempt to be helpful, since obviously
I'm being pushy again instead of helpful.  Michal can go back to
waiting for someone else's response since my "help" has obviously
injured the entire process.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-26 19:38               ` Daniel Jacobowitz
@ 2003-02-27  8:14                 ` Michal Ludvig
  2003-02-27 10:15                   ` Michal Ludvig
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Ludvig @ 2003-02-27  8:14 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: GDB Patches, Andrew Cagney, Elena Zannoni

Daniel Jacobowitz wrote:
> In any case I am withdrawing my attempt to be helpful, since obviously
> I'm being pushy again instead of helpful.  Michal can go back to
> waiting for someone else's response since my "help" has obviously
> injured the entire process.

Thank you very much, anyway! You at least attempted to solve this issue.
Other "responsible" maintainers didn't bother to respond until you 
approved my patch. Then Andrew felt he should step in, revert your 
approval and say NO (why there doesn't come a *constructive* critique 
along with your no, Andrew?). And Elena - apparently the only one who 
could say yes - disappeared... Sigh.

I'm asking once again:
- Can I *at* *least* commit the dwarf2cfi.c part? Without the infcmd.c 
hook? I know it duplicates the solib cleaner logic, but is that a 
showstopper?
- Ad run_command() hook - would something like this be acceptable?

Index: config/i386/tm-x86-64linux.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/tm-x86-64linux.h,v
retrieving revision 1.1
diff -u -p -r1.1 tm-x86-64linux.h
--- config/i386/tm-x86-64linux.h        1 Jul 2002 22:09:52 -0000       1.1
+++ config/i386/tm-x86-64linux.h        27 Feb 2003 08:02:50 -0000
@@ -33,4 +33,6 @@
  #define SVR4_SHARED_LIBS
  #include "solib.h"              /* Support for shared libraries. */

+#define DWARF2CFI_USED
+
  #endif /* #ifndef TM_X86_64LINUX_H */
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.54.6.2
diff -u -p -r1.54.6.2 infcmd.c
--- infcmd.c    25 Sep 2002 20:43:21 -0000      1.54.6.2
+++ infcmd.c    27 Feb 2003 08:02:50 -0000
@@ -390,6 +390,10 @@ Start it from the beginning? "))

    clear_breakpoint_hit_counts ();

+#if defined(DWARF2CFI_USED)
+  cleanup_cfi ();
+#endif
+
    /* Purge old solib objfiles. */
    objfile_purge_solibs ();

Every target that will use the CFI engine will just add one define to 
their tm.h. No need to link dwarf2cfi.o to all targets.

Comments?

Michal Ludvig
-- 
* SuSE CR, s.r.o     * mludvig@suse.cz
* (+420) 296.545.373 * http://www.suse.cz


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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-27  8:14                 ` Michal Ludvig
@ 2003-02-27 10:15                   ` Michal Ludvig
  2003-02-27 14:17                     ` Daniel Jacobowitz
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Ludvig @ 2003-02-27 10:15 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Daniel Jacobowitz, GDB Patches, Elena Zannoni

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

Michal Ludvig wrote:
> Daniel Jacobowitz wrote:
> 
>> In any case I am withdrawing my attempt to be helpful, since obviously
>> I'm being pushy again instead of helpful.  Michal can go back to
>> waiting for someone else's response since my "help" has obviously
>> injured the entire process.
> 
> Thank you very much, anyway! You at least attempted to solve this issue.
> Other "responsible" maintainers didn't bother to respond until you 
> approved my patch. Then Andrew felt he should step in, revert your 
> approval and say NO (why there doesn't come a *constructive* critique 
> along with your no, Andrew?). And Elena - apparently the only one who 
> could say yes - disappeared... Sigh.
> 
> I'm asking once again:
> - Can I *at* *least* commit the dwarf2cfi.c part? Without the infcmd.c 
> hook? I know it duplicates the solib cleaner logic, but is that a 
> showstopper?
> - Ad run_command() hook - would something like this be acceptable?
> 
> Index: config/i386/tm-x86-64linux.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/config/i386/tm-x86-64linux.h,v
> retrieving revision 1.1
> diff -u -p -r1.1 tm-x86-64linux.h
> --- config/i386/tm-x86-64linux.h        1 Jul 2002 22:09:52 -0000       1.1
> +++ config/i386/tm-x86-64linux.h        27 Feb 2003 08:02:50 -0000
> @@ -33,4 +33,6 @@
>  #define SVR4_SHARED_LIBS
>  #include "solib.h"              /* Support for shared libraries. */
> 
> +#define DWARF2CFI_USED
> +
>  #endif /* #ifndef TM_X86_64LINUX_H */
> Index: infcmd.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/infcmd.c,v
> retrieving revision 1.54.6.2
> diff -u -p -r1.54.6.2 infcmd.c
> --- infcmd.c    25 Sep 2002 20:43:21 -0000      1.54.6.2
> +++ infcmd.c    27 Feb 2003 08:02:50 -0000
> @@ -390,6 +390,10 @@ Start it from the beginning? "))
> 
>    clear_breakpoint_hit_counts ();
> 
> +#if defined(DWARF2CFI_USED)
> +  cleanup_cfi ();
> +#endif
> +
>    /* Purge old solib objfiles. */
>    objfile_purge_solibs ();
> 
> Every target that will use the CFI engine will just add one define to 
> their tm.h. No need to link dwarf2cfi.o to all targets.

I've extended this approach a little bit. Now it's enough to define 
USED_DWARF2CFI=1 in config/arch/target.mh file and everything will be 
configured automatically, ie. dwarf2cfi.o will be added to the list of 
files to compile and -DUSED_DWARF2CFI=1 will be added to CFLAGS.
So only those targets that explicitly say "Yes, I want CFI engine" will 
have it and the run_command cleanup hook will go in for them as well.

Is this a way to go?

Michal Ludvig
-- 
* SuSE CR, s.r.o     * mludvig@suse.cz
* (+420) 296.545.373 * http://www.suse.cz

[-- Attachment #2: rerun-mfdef-1.diff --]
[-- Type: text/plain, Size: 4506 bytes --]

2003-02-27  Michal Ludvig  <mludvig@suse.cz>

	* config/i386/x86-64linux.mt (TDEPFILES): Remove dwarf2cfi.o
	(USED_DWARF2CFI): New define.
	* Makefile.in: Handle USED_DWARF2CFI define.
	* infcmd.c (run_command): Add cleanup_cfi() if USED_DWARF2CFI
	is defined.
	* dwarf2cfi.c (struct cie_unit): New fields keep, refs.
	(cleanup_cfi): New function.

Index: config/i386/x86-64linux.mt
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/x86-64linux.mt,v
retrieving revision 1.5
diff -u -p -r1.5 x86-64linux.mt
--- config/i386/x86-64linux.mt	1 Jul 2002 22:09:52 -0000	1.5
+++ config/i386/x86-64linux.mt	27 Feb 2003 10:01:03 -0000
@@ -1,7 +1,9 @@
 # Target: AMD x86-64 running GNU/Linux
-TDEPFILES= x86-64-tdep.o x86-64-linux-tdep.o dwarf2cfi.o \
+TDEPFILES= x86-64-tdep.o x86-64-linux-tdep.o \
 	solib.o solib-svr4.o solib-legacy.o
 
 GDB_MULTI_ARCH=GDB_MULTI_ARCH_TM
 
 TM_FILE=tm-x86-64linux.h
+
+USED_DWARF2CFI=1
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.257.2.5
diff -u -p -r1.257.2.5 Makefile.in
--- Makefile.in	25 Nov 2002 22:05:38 -0000	1.257.2.5
+++ Makefile.in	27 Feb 2003 10:01:03 -0000
@@ -414,6 +414,12 @@ ANNOTATE_OBS = annotate.o
 @target_makefile_frag@
 # End of host and target-dependent makefile fragments
 
+# Make a list of linked files depending on target's defines.
+ifeq ($(USED_DWARF2CFI), 1)
+	TDEPFILES+=dwarf2cfi.o
+	CFLAGS+=-DUSED_DWARF2CFI
+endif
+
 # Possibly ignore the simulator.  If the simulator is being ignored, 
 # these expand into SIM= and SIM_OBJ=, overriding the entries from 
 # target_makefile_frag
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.54.6.2
diff -u -p -r1.54.6.2 infcmd.c
--- infcmd.c	25 Sep 2002 20:43:21 -0000	1.54.6.2
+++ infcmd.c	27 Feb 2003 10:01:03 -0000
@@ -390,6 +390,10 @@ Start it from the beginning? "))
 
   clear_breakpoint_hit_counts ();
 
+#if defined(USED_DWARF2CFI)
+  cleanup_cfi ();
+#endif
+
   /* Purge old solib objfiles. */
   objfile_purge_solibs ();
 
Index: dwarf2cfi.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v
retrieving revision 1.16.6.1
diff -u -p -r1.16.6.1 dwarf2cfi.c
--- dwarf2cfi.c	3 Feb 2003 14:40:09 -0000	1.16.6.1
+++ dwarf2cfi.c	27 Feb 2003 10:01:04 -0000
@@ -54,6 +54,12 @@ struct cie_unit
 
   /* Next in chain.  */
   struct cie_unit *next;
+
+  /* Keep or destroy this CIE on new run? */
+  int keep;
+
+  /* How many FDEs refer to this CIE? */
+  int refs;
 };
 
 /* Frame Description Entry.  */
@@ -319,6 +260,90 @@ frame_state_alloc (void)
   return fs;
 }
 
+void
+cleanup_cfi (void *name)
+{
+  struct objfile *ofp;
+  struct cie_unit *cie, *cie_prev;
+  int fde_index = 0, fde_free = 0;
+
+  cie = cie_chunks;
+  while (cie)
+    {
+      cie->refs = 0;
+      cie->keep = 0;
+      cie = cie->next;
+    }
+
+  /* Mark all unwanted CIEs. */
+  ALL_OBJFILES (ofp)
+  {
+    if (!(ofp->flags & OBJF_USERLOADED) && (ofp->flags & OBJF_SHARED))
+      {
+	if (info_verbose)
+	  printf_filtered ("\tRemoving %s...\n", ofp->name);
+      }
+    else
+      {
+	if (info_verbose)
+	  printf_filtered ("\tKeeping %s...\n", ofp->name);
+
+	cie = cie_chunks;
+	while (cie)
+	  {
+	    if (cie->objfile == ofp)
+	      cie->keep = 1;
+	    cie = cie->next;
+	  }
+      }
+  }
+
+  /* Remove all FDEs pointing to unwanted CIEs. */
+  for (fde_index = 0, fde_free = 0;
+       fde_index < fde_chunks.elems; fde_index++, fde_free++)
+    {
+      if (!fde_chunks.array[fde_index]->cie_ptr->keep)
+	{
+	  fde_free--;
+	  continue;
+	}
+      else if (fde_free < fde_index)
+	fde_chunks.array[fde_free] = fde_chunks.array[fde_index];
+      fde_chunks.array[fde_free]->cie_ptr->refs++;
+    }
+  fde_chunks.elems = fde_free;
+
+  /* Remove all unwanted CIEs. */
+  cie = cie_chunks;
+  cie_prev = NULL;
+  while (cie)
+    {
+      struct cie_unit *cie_tmp;
+
+      if (!cie->keep || !cie->refs)
+	{
+	  cie_tmp = cie;
+	  if (cie_prev == NULL)
+	    {
+	      cie_chunks = cie->next;
+	      cie = cie_chunks;
+	    }
+	  else
+	    {
+	      cie_prev->next = cie->next;
+	      cie = cie->next;
+	    }
+	  /* cie_prev must remain unchanged. */
+	  xfree (cie_tmp);
+	}
+      else
+	{
+	  cie_prev = cie;
+	  cie = cie->next;
+	}
+    }
+}
+
 static void
 unwind_tmp_obstack_init (void)
 {

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

* Re: PING: [RFA] Runtime Dwarf2 CFI engine cleanup
  2003-02-27 10:15                   ` Michal Ludvig
@ 2003-02-27 14:17                     ` Daniel Jacobowitz
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Jacobowitz @ 2003-02-27 14:17 UTC (permalink / raw)
  To: Michal Ludvig; +Cc: Andrew Cagney, GDB Patches, Elena Zannoni

On Thu, Feb 27, 2003 at 11:15:01AM +0100, Michal Ludvig wrote:
> Index: Makefile.in
> ===================================================================
> RCS file: /cvs/src/src/gdb/Makefile.in,v
> retrieving revision 1.257.2.5
> diff -u -p -r1.257.2.5 Makefile.in
> --- Makefile.in	25 Nov 2002 22:05:38 -0000	1.257.2.5
> +++ Makefile.in	27 Feb 2003 10:01:03 -0000
> @@ -414,6 +414,12 @@ ANNOTATE_OBS = annotate.o
>  @target_makefile_frag@
>  # End of host and target-dependent makefile fragments
>  
> +# Make a list of linked files depending on target's defines.
> +ifeq ($(USED_DWARF2CFI), 1)
> +	TDEPFILES+=dwarf2cfi.o
> +	CFLAGS+=-DUSED_DWARF2CFI
> +endif
> +

Nope.  First of all, the mh files are on their way out; second of all,
you can't use ifeq in a Makefile, because that's a GNU make-ism.

I'd leave this alone until you can get someone to approve the previous
version, probably using the observer mechanism that Andrew and Joel are
designing.


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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

end of thread, other threads:[~2003-02-27 14:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-06 12:55 [RFA] Runtime Dwarf2 CFI engine cleanup Michal Ludvig
2003-02-03 16:23 ` Elena Zannoni
2003-02-10 12:30   ` Michal Ludvig
2003-02-26 15:35     ` PING: " Michal Ludvig
2003-02-26 15:47       ` Daniel Jacobowitz
2003-02-26 18:20         ` Andrew Cagney
2003-02-26 18:36           ` Daniel Jacobowitz
2003-02-26 19:32             ` Andrew Cagney
2003-02-26 19:38               ` Daniel Jacobowitz
2003-02-27  8:14                 ` Michal Ludvig
2003-02-27 10:15                   ` Michal Ludvig
2003-02-27 14:17                     ` Daniel Jacobowitz

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