00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 void dlog (const char *fmt, ...)
00017 {
00018 va_list args;
00019 printk("STP: ");
00020 va_start(args, fmt);
00021 vprintk(fmt, args);
00022 va_end(args);
00023 }
00024
00025
00026
00027
00028
00029
00030
00031 static const char * (*_stp_kallsyms_lookup)(unsigned long addr,
00032 unsigned long *symbolsize,
00033 unsigned long *offset,
00034 char **modname, char *namebuf)=(void *)KALLSYMS_LOOKUP;
00035
00036
00037 #define STP_BUF_LEN 8191
00038
00039
00040 static char _stp_pbuf[STP_BUF_LEN+1];
00041 static int _stp_pbuf_len = STP_BUF_LEN;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 void _stp_print_buf (const char *fmt, ...)
00056 {
00057 int num;
00058 va_list args;
00059 char *buf = _stp_pbuf + STP_BUF_LEN - _stp_pbuf_len;
00060 va_start(args, fmt);
00061 num = vscnprintf(buf, _stp_pbuf_len, fmt, args);
00062 va_end(args);
00063 if (num > 0)
00064 _stp_pbuf_len -= num;
00065 }
00066
00067
00068
00069
00070
00071
00072 void _stp_print_buf_init (void)
00073 {
00074 _stp_pbuf_len = STP_BUF_LEN;
00075 _stp_pbuf[0] = 0;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085 void _stp_print_symbol(const char *fmt, unsigned long address)
00086 {
00087 char *modname;
00088 const char *name;
00089 unsigned long offset, size;
00090 char namebuf[KSYM_NAME_LEN+1];
00091
00092 name = _stp_kallsyms_lookup(address, &size, &offset, &modname, namebuf);
00093
00094 if (!name)
00095 _stp_print_buf("0x%lx", address);
00096 else {
00097 if (modname)
00098 _stp_print_buf("%s+%#lx/%#lx [%s]", name, offset,
00099 size, modname);
00100 else
00101 _stp_print_buf("%s+%#lx/%#lx", name, offset, size);
00102 }
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 unsigned long cur_ret_addr (struct pt_regs *regs)
00113 {
00114 #ifdef __x86_64__
00115 unsigned long *ra = (unsigned long *)regs->rsp;
00116 #else
00117 unsigned long *ra = (unsigned long *)regs->esp;
00118 #endif
00119 if (ra)
00120 return *ra;
00121 else
00122 return 0;
00123 }