Main Page | Modules | Directories | File List | Globals | Related Pages

sym.c

00001 #ifndef _SYM_C_ /* -*- linux-c -*- */
00002 #define _SYM_C_
00003 
00004 #include "string.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 
00023 /** Write addresses symbolically into a String
00024  * @param str String
00025  * @param address The address to lookup.
00026  * @note Symbolic lookups should not normally be done within
00027  * a probe because it is too time-consuming. Use at module exit time.
00028  */
00029 
00030 String _stp_symbol_sprint (String str, unsigned long address)
00031 { 
00032         char *modname;
00033         const char *name;
00034         unsigned long offset, size;
00035         char namebuf[KSYM_NAME_LEN+1];
00036 
00037         name = _stp_kallsyms_lookup(address, &size, &offset, &modname, namebuf);
00038 
00039         _stp_sprintf (str, "0x%lx : ", address);
00040         if (modname)
00041                 _stp_sprintf (str, "%s+%#lx/%#lx [%s]", name, offset, size, modname);
00042         else
00043                 _stp_sprintf (str, "%s+%#lx/%#lx", name, offset, size);
00044         return str;
00045 }
00046 
00047 
00048 /** Print addresses symbolically to the print buffer.
00049  * @param address The address to lookup.
00050  * @note Symbolic lookups should not normally be done within
00051  * a probe because it is too time-consuming. Use at module exit time.
00052  */
00053 
00054 void _stp_symbol_print (unsigned long address)
00055 {
00056         char *modname;
00057         const char *name;
00058         unsigned long offset, size;
00059         char namebuf[KSYM_NAME_LEN+1];
00060 
00061         name = _stp_kallsyms_lookup(address, &size, &offset, &modname, namebuf);
00062 
00063         _stp_printf ("0x%lx : ", address);
00064         if (modname)
00065                 _stp_printf ("%s+%#lx/%#lx [%s]", name, offset, size, modname);
00066         else
00067                 _stp_printf ("%s+%#lx/%#lx", name, offset, size);
00068 }
00069 
00070 /** @} */
00071 #endif /* _SYM_C_ */