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]

[RFA]: Fix for sim/common hw_delete()/hw_tree_delete()


Hi!

The hw_delete() function cannot be used today because there are several
problems:

  - We abort in delete_hw_alloc_data() if the hardware device has
    allocated some memory (which it is supposed to free).
  - In hw_delete(), the memory pointed to by 'me->base_of_hw' is freed twice
    (already handled by delete_hw_alloc_data())
  - A device can't set a delete handler (set_hw_delete) because
    the internal definitions of hw is not available.

Note that hw_delete() is not used today and the call to hw_tree_delete()
is commented out in 'sim_hw_uninstall'. After this patch, hw_tree_delete()
works but the hardware device must have freed all the events they have
created. I don't propose to fix 'sim_hw_uninstall' yet because it requires
to fix some simulators first (mips, mn10300). Anyway this patch
is the first step.

Can you approve this patch?

	Stephane


2000-11-24  Stephane Carrez  <Stephane.Carrez@worldnet.fr>

	* hw-base.c (hw_delete): Don't free base_of_hw since it's freed.
	(set_hw_delete): Moved the macro as a function.
	* hw-base.h (set_hw_delete): Declare as external function.
	* hw-alloc.c (delete_hw_alloc_data): Allow to free the memory
	allocated using hw_malloc.
Index: hw-alloc.c
===================================================================
RCS file: /cvs/src/src/sim/common/hw-alloc.c,v
retrieving revision 1.1.1.1
diff -p -r1.1.1.1 hw-alloc.c
*** hw-alloc.c	1999/04/16 01:34:56	1.1.1.1
--- hw-alloc.c	2000/11/24 20:26:18
*************** create_hw_alloc_data (struct hw *me)
*** 42,49 ****
  void
  delete_hw_alloc_data (struct hw *me)
  {
-   if (me->alloc_of_hw != NULL)
-     hw_abort (me, "hw-alloc botch");
    while (me->alloc_of_hw != NULL)
      {
        hw_free (me, me->alloc_of_hw->alloc);
--- 42,47 ----
Index: hw-base.c
===================================================================
RCS file: /cvs/src/src/sim/common/hw-base.c,v
retrieving revision 1.1.1.1
diff -p -r1.1.1.1 hw-base.c
*** hw-base.c	1999/04/16 01:34:57	1.1.1.1
--- hw-base.c	2000/11/24 20:26:20
*************** hw_delete (struct hw *me)
*** 510,517 ****
    delete_hw_alloc_data (me);
  
    /* finally */
-   zfree (me->base_of_hw);
    zfree (me);
  }
  
  
--- 510,522 ----
    delete_hw_alloc_data (me);
  
    /* finally */
    zfree (me);
+ }
+ 
+ void
+ set_hw_delete (struct hw *hw, hw_delete_callback method)
+ {
+   hw->base_of_hw->to_delete = method;
  }
  
  
Index: hw-base.h
===================================================================
RCS file: /cvs/src/src/sim/common/hw-base.h,v
retrieving revision 1.1.1.1
diff -p -r1.1.1.1 hw-base.h
*** hw-base.h	1999/04/16 01:34:57	1.1.1.1
--- hw-base.h	2000/11/24 20:26:20
*************** void hw_delete
*** 54,61 ****
  typedef void (hw_delete_callback)
       (struct hw *me);
  
! #define set_hw_delete(hw, method) \
! ((hw)->base_of_hw->to_delete = (method))
  
  
  /* ALLOC */
--- 54,60 ----
  typedef void (hw_delete_callback)
       (struct hw *me);
  
! extern void set_hw_delete(struct hw* hw, hw_delete_callback method);
  
  
  /* ALLOC */

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