summaryrefslogtreecommitdiffstats
path: root/runtime/sym.c
blob: 8566295443689a8e66c30ce4547698b0f40a1e82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _SYM_C_ /* -*- linux-c -*- */
#define _SYM_C_

#include "string.c"

/** @file sym.c
 * @addtogroup sym Symbolic Functions
 * Symbolic Lookup Functions
 * @{
 */

/** Lookup symbol.
 * This simply calls the kernel function kallsyms_lookup().
 * That function is not exported, so this workaround is required.
 * See the kernel source, kernel/kallsyms.c for more information.
 */
static const char * (*_stp_kallsyms_lookup)(unsigned long addr,
			    unsigned long *symbolsize,
			    unsigned long *offset,
			    char **modname, char *namebuf)=(void *)KALLSYMS_LOOKUP;


/** Print addresses symbolically into a string
 * @param address The address to lookup.
 * @note Symbolic lookups should not be done within
 * a probe because it is too time-consuming. Use at module exit time.
 * @note Uses scbuf.
 */

String _stp_symbol_sprint (String str, unsigned long address)
{ 
	char *modname;
        const char *name;
        unsigned long offset, size;
        char namebuf[KSYM_NAME_LEN+1];

        name = _stp_kallsyms_lookup(address, &size, &offset, &modname, namebuf);

	_stp_sprintf (str, "0x%lx : ", address);
	if (modname)
		_stp_sprintf (str, "%s+%#lx/%#lx [%s]", name, offset, size, modname);
	else
		_stp_sprintf (str, "%s+%#lx/%#lx", name, offset, size);
	return str;
}


/** Print addresses symbolically to the trace buffer.
 * @param address The address to lookup.
 * @note Symbolic lookups should not be done within
 * a probe because it is too time-consuming. Use at module exit time.
 */

void _stp_symbol_print (unsigned long address)
{
	char *modname;
        const char *name;
        unsigned long offset, size;
        char namebuf[KSYM_NAME_LEN+1];

        name = _stp_kallsyms_lookup(address, &size, &offset, &modname, namebuf);

	_stp_printf ("0x%lx : ", address);
	if (modname)
		_stp_printf ("%s+%#lx/%#lx [%s]", name, offset, size, modname);
	else
		_stp_printf ("%s+%#lx/%#lx", name, offset, size);
}

/** @} */
#endif /* _SYM_C_ */