summaryrefslogtreecommitdiffstats
path: root/tapset/context.stp
blob: a93b36b3f1d373c92aad90dcc5f8fee4cc20f46e (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
// context tapset
// Copyright (C) 2005, 2006 Red Hat Inc.
//
// 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);
	}
%}

function backtrace:string () %{
	if (CONTEXT->regs) {
                /* XXX: this won't be necessary when runtime and translator */
		/* agree on what a string is. */
		String str = _stp_string_init (0);
		_stp_stack_sprint (str, CONTEXT->regs, 0);	
		strlcpy (THIS->__retvalue, _stp_string_ptr(str), MAXSTRINGLEN);
	} else 
		strlcpy (THIS->__retvalue, "", MAXSTRINGLEN);
%}

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

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

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

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

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

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

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

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

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

function cpuid:long () %{
	THIS->__retvalue = current->thread_info->cpu;
%}

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

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

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

function probefunc:string () %{
	char *start = strstr(CONTEXT->probe_point, "function(\"");
	if (start) {
		char *ptr = start+10;
		char *dst = THIS->__retvalue;
		int len = MAXSTRINGLEN;
		while (*ptr != '@' && --len > 0 && *ptr)
			*dst++ = *ptr++;
		*dst = 0;
	}
%}

function is_return:long () %{
	char *ptr = strrchr(CONTEXT->probe_point, '.');
	if (ptr) {
		if (strcmp(ptr+1,"return") == 0)
			THIS->__retvalue = 1;
	}
%}

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

function returnval:long () %{
	if (CONTEXT->regs) {
#if defined (__i386__)
		THIS->__retvalue = CONTEXT->regs->eax;
#elif defined (__x86_64__)
		THIS->__retvalue = CONTEXT->regs->rax;
#elif defined (__powerpc64__)
		THIS->__retvalue = CONTEXT->regs->gpr[3];
#elif defined (__ia64__)
		THIS->__retvalue = CONTEXT->regs->r8;
#elif defined (__sparc64__)
		THIS->__retvalue = CONTEXT->regs->u_regs[UREG_RETPC];
#else
		THIS->__retvalue = -1;
#endif
	} else
		THIS->__retvalue = -1;
%}