Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

sym.c

00001 #ifndef _SYM_C_ /* -*- linux-c -*- */
00002 #define _SYM_C_
00003 
00004 #include "scbuf.c"
00005 
00006 /** @file sym.c
00007  * @addtogroup sym Symbolic Functions
00008  * Symbolic Lookup Functions
00009  * @{
00010  */
00011 
00012 /** Lookup symbol.
00013  * This simply calls the kernel function kallsyms_lookup().
00014  * That function is not exported, so this workaround is required.
00015  * See the kernel source, kernel/kallsyms.c for more information.
00016  */
00017 static const char * (*_stp_kallsyms_lookup)(unsigned long addr,
00018                             unsigned long *symbolsize,
00019                             unsigned long *offset,
00020                             char **modname, char *namebuf)=(void *)KALLSYMS_LOOKUP;
00021 
00022 static void __stp_symbol_print (unsigned long address, void (*prtfunc)(const char *fmt, ...))
00023 {
00024         char *modname;
00025         const char *name;
00026         unsigned long offset, size;
00027         char namebuf[KSYM_NAME_LEN+1];
00028 
00029         name = _stp_kallsyms_lookup(address, &size, &offset, &modname, namebuf);
00030 
00031         (*prtfunc)("0x%lx : ", address);
00032         if (modname)
00033                 (*prtfunc)("%s+%#lx/%#lx [%s]", name, offset, size, modname);
00034         else
00035                 (*prtfunc)("%s+%#lx/%#lx", name, offset, size);
00036 }
00037 
00038 /** Print addresses symbolically into a string
00039  * @param address The address to lookup.
00040  * @note Symbolic lookups should not be done within
00041  * a probe because it is too time-consuming. Use at module exit time.
00042  * @note Uses scbuf.
00043  */
00044 
00045 char * _stp_symbol_sprint (unsigned long address)
00046 { 
00047         char *ptr = _stp_scbuf_cur();
00048         __stp_symbol_print (address, _stp_sprint);
00049         return ptr;
00050 }
00051 
00052 
00053 /** Print addresses symbolically to the trace buffer.
00054  * @param address The address to lookup.
00055  * @note Symbolic lookups should not be done within
00056  * a probe because it is too time-consuming. Use at module exit time.
00057  */
00058 
00059 void _stp_symbol_print (unsigned long address)
00060 {
00061         __stp_symbol_print (address, _stp_print);
00062 }
00063 
00064 /** @} */
00065 #endif /* _SYM_C_ */