summaryrefslogtreecommitdiffstats
path: root/tapset/context.stp
blob: 4aa751581934a55885822c82faa5fb3a29e3ff2c (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// context tapset
// Copyright (C) 2005, 2006, 2007 Red Hat Inc.
// Copyright (C) 2006 Intel Corporation.
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.

function print_regs () %{
	if (CONTEXT->regs) {
		_stp_print_regs (CONTEXT->regs);
	}
%}

function print_backtrace () %{
	if (CONTEXT->regs) {
		_stp_stack_print(CONTEXT->regs, 1, CONTEXT->pi);
	} else {
		_stp_printf("Systemtap probe: %s\n", CONTEXT->probe_point);
	}
%}

function backtrace:string () %{ /* pure */
	if (CONTEXT->regs)
		_stp_stack_snprint (THIS->__retvalue, MAXSTRINGLEN, CONTEXT->regs, 0, CONTEXT->pi);	
	else 
		strlcpy (THIS->__retvalue, "", MAXSTRINGLEN);
%}

function execname:string () %{ /* pure */
	strlcpy (THIS->__retvalue, current->comm, MAXSTRINGLEN);
%}

function pid:long () %{ /* pure */
	THIS->__retvalue = current->tgid;
%}

function tid:long () %{ /* pure */
	THIS->__retvalue = current->pid;
%}

function ppid:long () %{ /* pure */
	THIS->__retvalue = current->parent->tgid;
%}

function pexecname:string () %{ /* pure */
	strlcpy (THIS->__retvalue, current->parent->comm, MAXSTRINGLEN);
%}

function gid:long () %{ /* pure */
	THIS->__retvalue = current->gid;		
%}

function egid:long () %{ /* pure */
	THIS->__retvalue = current->egid;		
%}

function uid:long () %{ /* pure */
	THIS->__retvalue = current->uid;		
%}

function euid:long () %{ /* pure */
	THIS->__retvalue = current->euid;		
%}

function cpuid:long () %{ /* pure */
	THIS->__retvalue = smp_processor_id();
%}

function cpu:long () %{ /* pure */
	THIS->__retvalue = smp_processor_id();
%}

function print_stack(stk:string) %{
	char *ptr = THIS->stk;
	char *tok = strsep(&ptr, " ");
	while (tok && *tok) {
		_stp_print_char(' ');
		_stp_symbol_print (simple_strtol(tok, NULL, 16));
		_stp_print_char('\n');
		tok = strsep(&ptr, " ");
	}
%}

function pp:string () %{ /* pure */
	strlcpy (THIS->__retvalue, CONTEXT->probe_point, MAXSTRINGLEN);
%}

function probefunc:string () %{ /* pure */
	char *ptr, *start;

	start = strstr(CONTEXT->probe_point, "function(\"");
	ptr = start + 10; 
	if (!start) {
		start = strstr(CONTEXT->probe_point, "inline(\"");
		ptr = start + 8;
	}

	if (start) {
		int len = MAXSTRINGLEN;
		char *dst = THIS->__retvalue;
		while (*ptr != '@' && --len > 0 && *ptr)
			*dst++ = *ptr++;
		*dst = 0;

	} else if (CONTEXT->regs &&
#if defined (__ia64__)
		((unsigned long)REG_IP(CONTEXT->regs) >= (unsigned long)KERNEL_START)) {
#else
		((unsigned long)REG_IP(CONTEXT->regs) >= (unsigned long)PAGE_OFFSET)) {
#endif
		_stp_symbol_snprint(THIS->__retvalue, MAXSTRINGLEN, REG_IP(CONTEXT->regs));
       	         if (THIS->__retvalue[0] == '.')  /* powerpc symbol has a dot*/
       	         	strlcpy(THIS->__retvalue,THIS->__retvalue + 1,MAXSTRINGLEN);
	} else {
		THIS->__retvalue[0] = '\0';
	}
%}

function probemod:string () %{ /* pure */
	char *ptr, *start;

	start = strstr(CONTEXT->probe_point, "module(\"");
	ptr = start + 8;

	if (start) {
		int len = MAXSTRINGLEN;
		char *dst = THIS->__retvalue;
		while (*ptr != '"' && --len && *ptr)
			*dst++ = *ptr++;
		*dst = 0;
	} else {
		/* XXX: need a PC- and symbol-table-based fallback. */
		THIS->__retvalue[0] = '\0';
	}
%}

function is_return:long () %{ /* pure */
	if (CONTEXT->pi)
		THIS->__retvalue = 1;
	else	
		THIS->__retvalue = 0;	
%}

function target:long () %{ /* pure */
        THIS->__retvalue = _stp_target;
%}

function module_name:string () %{ /* pure */
	strlcpy(THIS->__retvalue, THIS_MODULE->name, MAXSTRINGLEN);
%}

function stp_pid:long () %{ /* pure */
        THIS->__retvalue = _stp_pid;
%}

# return the size of the stack
function stack_size:long () %{ /* pure */
        THIS->__retvalue = THREAD_SIZE;
%}

# return how many bytes are currently used in the stack
function stack_used:long () %{ /* pure */
	char a;
        THIS->__retvalue = THREAD_SIZE - ((long)&a & (THREAD_SIZE-1));
%}

# return how many bytes are currently unused in the stack
function stack_unused:long () %{ /* pure */
	char a;
        THIS->__retvalue = (long)&a & (THREAD_SIZE-1);
%}

# Return the address of the calling function. Works only for
# return probes at this time.
function caller_addr:long () %{ /* pure */
        if (CONTEXT->pi)
		THIS->__retvalue = (int64_t)(long)_stp_ret_addr_r(CONTEXT->pi);
        else
		THIS->__retvalue = 0;
%}

# Return the address and name of the calling function. Works 
# only for return probes at this time.
function caller:string() %{ /* pure */
        if (CONTEXT->pi) 
		_stp_symbol_snprint( THIS->__retvalue, MAXSTRINGLEN, 
			(unsigned long)_stp_ret_addr_r(CONTEXT->pi));
        else
		strlcpy(THIS->__retvalue,"unknown",MAXSTRINGLEN);
%}