summaryrefslogtreecommitdiffstats
path: root/runtime/docs/html/stack_8c-source.html
blob: eda90dc4577f1ce8e5f20dfa231d8c040d2022ec (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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>SystemTap: stack.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>stack.c</h1><a href="stack_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef _STACK_C_ </span><span class="comment">/* -*- linux-c -*- */</span>
00002 <span class="preprocessor">#define _STACK_C_</span>
00003 <span class="preprocessor"></span>
00004 <span class="comment"></span>
00005 <span class="comment">/** @file stack.c</span>
00006 <span class="comment"> * @brief Stack Tracing Functions</span>
00007 <span class="comment"> */</span>
00008 <span class="comment"></span>
00009 <span class="comment">/** @addtogroup stack Stack Tracing Functions</span>
00010 <span class="comment"> * @{</span>
00011 <span class="comment"> */</span>
00012 
00013 <span class="preprocessor">#include "sym.c"</span>
00014 
00015 <span class="keyword">static</span> int (*_stp_kta)(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr)=(<span class="keywordtype">void</span> *)KTA;
00016 
00017 <span class="preprocessor">#ifdef __x86_64__</span>
00018 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">void</span> __stp_stack_print (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, <span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00019 {
00020         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr;
00021 
00022         <span class="keywordflow">if</span> (verbose)
00023                 _stp_printf ("trace for %d (%s)\n", current-&gt;pid, current-&gt;comm);
00024 
00025         while (((<span class="keywordtype">long</span>) stack &amp; (THREAD_SIZE-1)) != 0) {
00026                 addr = *stack++;
00027                 <span class="keywordflow">if</span> (_stp_kta(addr)) {
00028                         <span class="keywordflow">if</span> (verbose) {
00029                                 <a class="code" href="group__sym.html#ga2">_stp_symbol_print</a> (addr);
00030                                 <a class="code" href="group__print.html#ga11">_stp_print</a> (<span class="stringliteral">"\n"</span>);
00031                         } <span class="keywordflow">else</span>
00032                                 <a class="code" href="group__print.html#ga3">_stp_printf</a> (<span class="stringliteral">"0x%lx "</span>, addr);
00033                 }
00034         }
00035         <a class="code" href="group__print.html#ga2">_stp_print_flush</a>();
00036 }
00037 
00038 
00039 <span class="keyword">static</span> <span class="keywordtype">void</span> __stp_stack_sprint (String str, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, <span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00040 {
00041         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr;
00042         <span class="keywordflow">while</span> (((<span class="keywordtype">long</span>) stack &amp; (THREAD_SIZE-1)) != 0) {
00043                 addr = *stack++;
00044                 <span class="keywordflow">if</span> (_stp_kta(addr)) {
00045                         <span class="keywordflow">if</span> (verbose)
00046                                 _stp_symbol_sprint (str, addr);
00047                         else
00048                                 _stp_sprintf (str, "0x%lx ", addr);
00049                 }
00050         }
00051 }
00052 
00053 #else  <span class="comment">/* i386 */</span>
00054 
00055 static inline <span class="keywordtype">int</span> valid_stack_ptr (struct thread_info *tinfo, <span class="keywordtype">void</span> *p)
00056 {
00057         <span class="keywordflow">return</span>  p &gt; (<span class="keywordtype">void</span> *)tinfo &amp;&amp;
00058                 p &lt; (<span class="keywordtype">void</span> *)tinfo + THREAD_SIZE - 3;
00059 }
00060 
00061 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> _stp_print_context_stack (
00062         <span class="keyword">struct</span> thread_info *tinfo,
00063         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, 
00064         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp )
00065 {
00066         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr;
00067 
00068 <span class="preprocessor">#ifdef  CONFIG_FRAME_POINTER</span>
00069 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, (<span class="keywordtype">void</span> *)ebp)) {
00070                 addr = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)(ebp + 4);
00071                 <a class="code" href="group__sym.html#ga2">_stp_symbol_print</a> (addr);
00072                 <a class="code" href="group__print.html#ga5">_stp_print_cstr</a>(<span class="stringliteral">"\n"</span>);
00073                 ebp = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)ebp;
00074         }
00075 <span class="preprocessor">#else</span>
00076 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, stack)) {
00077                 addr = *stack++;
00078                 <span class="keywordflow">if</span> (_stp_kta (addr)) {
00079                         <a class="code" href="group__sym.html#ga2">_stp_symbol_print</a> (addr);
00080                         <a class="code" href="group__print.html#ga5">_stp_print_cstr</a> (<span class="stringliteral">"\n"</span>);
00081                 }
00082         }
00083 <span class="preprocessor">#endif</span>
00084 <span class="preprocessor"></span>        <a class="code" href="group__print.html#ga2">_stp_print_flush</a>();
00085         <span class="keywordflow">return</span> ebp;
00086 }
00087 
00088 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> _stp_sprint_context_stack (
00089         String str,
00090         <span class="keyword">struct</span> thread_info *tinfo,
00091         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, 
00092         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp )
00093 {
00094         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr;
00095 
00096 <span class="preprocessor">#ifdef  CONFIG_FRAME_POINTER</span>
00097 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, (<span class="keywordtype">void</span> *)ebp)) {
00098                 addr = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)(ebp + 4);
00099                 <a class="code" href="group__sym.html#ga1">_stp_symbol_sprint</a> (str, addr);
00100                 <a class="code" href="group__string.html#ga9">_stp_string_cat</a> (<span class="stringliteral">"\n"</span>);
00101                 ebp = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)ebp;
00102         }
00103 <span class="preprocessor">#else</span>
00104 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, stack)) {
00105                 addr = *stack++;
00106                 <span class="keywordflow">if</span> (_stp_kta (addr)) {
00107                         <a class="code" href="group__sym.html#ga1">_stp_symbol_sprint</a> (addr);
00108                         <a class="code" href="group__string.html#ga9">_stp_string_cat</a> (<span class="stringliteral">"\n"</span>);
00109                 }
00110         }
00111 <span class="preprocessor">#endif</span>
00112 <span class="preprocessor"></span>        <span class="keywordflow">return</span> ebp;
00113 }
00114 
00115 <span class="keyword">static</span> <span class="keywordtype">void</span> __stp_stack_print (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, <span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00116 {
00117         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp;
00118 
00119         <span class="comment">/* Grab ebp right from our regs */</span>
00120         <span class="keyword">asm</span> (<span class="stringliteral">"movl %%ebp, %0"</span> : <span class="stringliteral">"=r"</span> (ebp) : );
00121 
00122         <span class="keywordflow">while</span> (stack) {
00123                 <span class="keyword">struct </span>thread_info *context = (<span class="keyword">struct </span>thread_info *)
00124                         ((<span class="keywordtype">unsigned</span> long)stack &amp; (~(THREAD_SIZE - 1)));
00125                 ebp = _stp_print_context_stack (context, stack, ebp);
00126                 stack = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>*)context-&gt;previous_esp;
00127         }
00128 }
00129 
00130 <span class="keyword">static</span> <span class="keywordtype">void</span> __stp_stack_sprint (String str, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, <span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00131 {
00132         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp;
00133 
00134         <span class="comment">/* Grab ebp right from our regs */</span>
00135         <span class="keyword">asm</span> (<span class="stringliteral">"movl %%ebp, %0"</span> : <span class="stringliteral">"=r"</span> (ebp) : );
00136 
00137         <span class="keywordflow">while</span> (stack) {
00138                 <span class="keyword">struct </span>thread_info *context = (<span class="keyword">struct </span>thread_info *)
00139                         ((<span class="keywordtype">unsigned</span> long)stack &amp; (~(THREAD_SIZE - 1)));
00140                 ebp = _stp_sprint_context_stack (str, context, stack, ebp);
00141                 stack = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>*)context-&gt;previous_esp;
00142         }
00143 }
00144 
00145 <span class="preprocessor">#endif </span><span class="comment">/* i386 */</span>
00146 <span class="comment"></span>
00147 <span class="comment">/** Print stack dump.</span>
00148 <span class="comment"> * Prints a stack dump to the print buffer.</span>
00149 <span class="comment"> * @param verbose Verbosity</span>
00150 <span class="comment"> * @param levels Number of levels to trace.</span>
00151 <span class="comment"> * @todo Implement verbosity and levels parameters.</span>
00152 <span class="comment"> * @bug levels parameter is not functional</span>
00153 <span class="comment"> */</span>
00154 
<a name="l00155"></a><a class="code" href="group__stack.html#ga6">00155</a> <span class="keywordtype">void</span> <a class="code" href="group__stack.html#ga6">_stp_stack_print</a> (<span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00156 {
00157   <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> stack;
00158   __stp_stack_print (&amp;stack, verbose, levels);
00159 }
00160 <span class="comment"></span>
00161 <span class="comment">/** Writes stack dump to a String</span>
00162 <span class="comment"> *</span>
00163 <span class="comment"> * @param str String</span>
00164 <span class="comment"> * @param verbose Verbosity</span>
00165 <span class="comment"> * @param levels Number of levels to trace.</span>
00166 <span class="comment"> * @returns Same String as was input.</span>
00167 <span class="comment"> * @todo Implement verbosity and levels parameters.</span>
00168 <span class="comment"> * @bug levels parameter is not functional</span>
00169 <span class="comment"> */</span>
00170 
<a name="l00171"></a><a class="code" href="group__stack.html#ga7">00171</a> String <a class="code" href="group__stack.html#ga7">_stp_stack_sprint</a> (String str, <span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00172 {
00173   <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> stack;
00174   __stp_stack_sprint (str, &amp;stack, verbose, levels);
00175   <a class="code" href="group__io.html#ga2">_stp_log</a> (<span class="stringliteral">"sss: str=%s\n"</span>, str-&gt;buf);
00176   <span class="keywordflow">return</span> str;
00177 }
00178 <span class="comment"></span>
00179 <span class="comment">/** @} */</span>
00180 <span class="preprocessor">#endif </span><span class="comment">/* _STACK_C_ */</span>
</pre></div></body></html>