2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <aros/kernel.h>
10 #include <aros/libcall.h>
11 #include <exec/lists.h>
12 #include <proto/exec.h>
16 #include "debug_intern.h"
18 static module_t
* FindModule(BPTR segList
, struct Library
* DebugBase
);
19 static LONG
FindIndex(module_t
* mod
, BPTR segList
);
20 static VOID
RemoveSegmentRange(module_t
* mod
, LONG firstidx
, LONG count
);
22 /*****************************************************************************
25 #include <proto/debug.h>
27 AROS_LH1(void, UnregisterModule
,
30 AROS_LHA(BPTR
, segList
, A0
),
33 struct Library
*, DebugBase
, 6, Debug
)
36 Remove previously registered module from the debug information database
39 segList - DOS segment list for the module to remove
45 The function correctly supports partial removal of the module
46 (when an existing seglist is broken and only a part of the module
57 ******************************************************************************/
62 LONG i
= 0, rangestart
= -1;
64 D(bug("[Debug] UnregisterModule(0x%p)\n", segList
));
65 ObtainSemaphore(&DBGBASE(DebugBase
)->db_ModSem
);
69 if (mod
== NULL
) /* Search for new module */
70 mod
= FindModule(segList
, DebugBase
);
74 if (rangestart
== -1) /* Search for new index */
75 i
= rangestart
= FindIndex(mod
, segList
);
77 /* Optimization assumes order of segments is similar to order of DOS segments */
78 if ((i
>= mod
->m_segcnt
) || (mod
->m_segments
[i
]->s_seg
!= segList
))
80 /* Order broken, clear ordered segments */
81 RemoveSegmentRange(mod
, rangestart
, (i
- rangestart
));
84 i
= rangestart
= FindIndex(mod
, segList
);
90 /* Advance to next DOS segment */
91 segList
= *(BPTR
*)BADDR(segList
);
94 if (mod
!= NULL
&& rangestart
> -1)
95 RemoveSegmentRange(mod
, rangestart
, (i
- rangestart
));
97 ReleaseSemaphore(&DBGBASE(DebugBase
)->db_ModSem
);
102 static module_t
* FindModule(BPTR segList
, struct Library
* DebugBase
)
107 ForeachNode(&DBGBASE(DebugBase
)->db_Modules
, mod
)
109 for (i
= 0; i
< mod
->m_segcnt
; i
++)
111 if (mod
->m_segments
[i
]->s_seg
== segList
)
121 static LONG
FindIndex(module_t
* mod
, BPTR segList
)
125 for (i
= 0; i
< mod
->m_segcnt
; i
++)
127 if (mod
->m_segments
[i
]->s_seg
== segList
)
136 static VOID
RemoveSegmentRange(module_t
* mod
, LONG firstidx
, LONG count
)
138 struct segment
* seg
;
141 for (i
= 0 ; i
< count
; i
++)
143 seg
= mod
->m_segments
[i
+ firstidx
];
145 FreeMem(seg
, sizeof(struct segment
));
147 /* If module's segment count reached 0, remove the whole
148 module information */
149 if (--mod
->m_segcnt
== 0)
151 D(bug("[Debug] Removing module %s\n", mod
->m_name
));
153 /* Free associated symbols */
154 if (mod
->m_symbols
) {
155 D(bug("[Debug] Removing symbol table 0x%p\n", mod
->m_symbols
));
156 FreeVec(mod
->m_symbols
);
159 /* Free associated string tables */
161 D(bug("[Debug] Removing symbol name table 0x%p\n", mod
->m_str
));
165 D(bug("[Debug] Removing section name table 0x%p\n", mod
->m_str
));
166 FreeVec(mod
->m_shstr
);
169 Remove((struct Node
*)mod
);
170 FreeVec(mod
->m_segments
);
171 #if AROS_MODULES_DEBUG
172 FreeVec(mod
->m_seggdbhlp
);
174 /* Free module descriptor at last */
181 /* "Shrink" array of segments so that at any given time the array is valid for
184 for (i
= firstidx
;i
< mod
->m_segcnt
; i
++)
185 mod
->m_segments
[i
] = mod
->m_segments
[i
+ count
];