grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / debug / enumeratesymbolsa.c
blob06771a4b641687e1009877ffc1146d326ba0c74b
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <libraries/debug.h>
10 #include <proto/kernel.h>
11 #include <proto/exec.h>
12 #include <aros/debug.h>
14 #include "debug_intern.h"
16 static void EnumerateModules(struct Hook * handler, struct Library * DebugBase);
18 /*****************************************************************************
20 NAME */
21 #include <proto/debug.h>
23 AROS_LH2(void, EnumerateSymbolsA,
25 /* SYNOPSIS */
26 AROS_LHA(struct Hook *, handler, A0),
27 AROS_LHA(struct TagItem *, tags, A1),
29 /* LOCATION */
30 struct Library *, DebugBase, 8, Debug)
32 /* FUNCTION
33 Function will call the handler hook for all symbols from kickstart and
34 loaded modules that match the given search criteria.
36 The message that is passed to hook contains a pointer to struct SymbolInfo.
38 INPUTS
40 RESULT
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
52 ******************************************************************************/
54 AROS_LIBFUNC_INIT
56 struct DebugBase *debugBase = DBGBASE(DebugBase);
57 BOOL super;
59 /* We can be called in supervisor mode. No semaphores in the case! */
60 super = KrnIsSuper();
61 if (!super)
62 ObtainSemaphoreShared(&debugBase->db_ModSem);
64 EnumerateModules(handler, DebugBase);
66 if (!super)
67 ReleaseSemaphore(&debugBase->db_ModSem);
69 AROS_LIBFUNC_EXIT
72 static inline void callhook(struct Hook * handler, CONST_STRPTR modname, CONST_STRPTR symname,
73 APTR start, APTR end)
75 struct SymbolInfo sinfo = {0};
77 sinfo.si_Size = sizeof(struct SymbolInfo);
78 sinfo.si_ModuleName = modname;
79 sinfo.si_SymbolName = symname;
80 sinfo.si_SymbolStart = start;
81 sinfo.si_SymbolEnd = end;
83 CALLHOOKPKT(handler, NULL, &sinfo);
86 static void EnumerateModules(struct Hook * handler, struct Library * DebugBase)
88 struct DebugBase *debugBase = DBGBASE(DebugBase);
89 module_t *mod;
91 ForeachNode(&debugBase->db_Modules, mod)
93 dbg_sym_t *sym = mod->m_symbols;
94 ULONG i;
96 D(bug("[Debug] Checking module %s\n", mod->m_name));
98 for (i = 0; i < mod->m_symcnt; i++)
100 APTR highest = sym[i].s_highest;
102 /* Symbols with zero length have zero in s_highest */
103 if (!highest)
104 highest = sym[i].s_lowest;
106 callhook(handler, mod->m_name, sym[i].s_name, sym[i].s_lowest, sym[i].s_highest);