summaryrefslogtreecommitdiffstats
path: root/runtime/docs/html/stack_8c-source.html
blob: 552f51ccb43ce46f2005b8fdb90c6e7d73262bfb (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
<!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="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</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>
00002 <span class="preprocessor"></span><span class="preprocessor">#define _STACK_C_</span>
00003 <span class="preprocessor"></span><span class="comment">/* -*- linux-c -*- */</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_print ("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                                 _stp_symbol_print (addr);
00030                         else
00031                                 _stp_print ("0x%lx ", addr);
00032                 }
00033         }
00034         _stp_print_str ("\n");
00035 }
00036 
00037 
00038 static <span class="keywordtype">char</span> *__stp_stack_sprint (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, <span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00039 {
00040         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr;
00041         <span class="keywordtype">char</span> *ptr = _stp_scbuf_cur();
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 (addr);
00047                         else
00048                                 _stp_sprint ("0x%lx ", addr);
00049                 }
00050         }
00051         return ptr;
00052 }
00053 
00054 #else  <span class="comment">/* i386 */</span>
00055 
00056 static inline <span class="keywordtype">int</span> valid_stack_ptr (struct thread_info *tinfo, <span class="keywordtype">void</span> *p)
00057 {
00058         <span class="keywordflow">return</span>  p &gt; (<span class="keywordtype">void</span> *)tinfo &amp;&amp;
00059                 p &lt; (<span class="keywordtype">void</span> *)tinfo + THREAD_SIZE - 3;
00060 }
00061 
00062 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> _stp_print_context_stack (
00063         <span class="keyword">struct</span> thread_info *tinfo,
00064         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, 
00065         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp )
00066 {
00067         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr;
00068 
00069 <span class="preprocessor">#ifdef  CONFIG_FRAME_POINTER</span>
00070 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, (<span class="keywordtype">void</span> *)ebp)) {
00071                 addr = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)(ebp + 4);
00072                 <a class="code" href="group__sym.html#ga3">_stp_symbol_print</a> (addr);
00073                 <a class="code" href="group__io.html#ga2">_stp_print_str</a>(<span class="stringliteral">"\n"</span>);
00074                 ebp = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)ebp;
00075         }
00076 <span class="preprocessor">#else</span>
00077 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, stack)) {
00078                 addr = *stack++;
00079                 <span class="keywordflow">if</span> (_stp_kta (addr)) {
00080                         <a class="code" href="group__sym.html#ga3">_stp_symbol_print</a> (addr);
00081                         <a class="code" href="group__io.html#ga2">_stp_print_str</a> (<span class="stringliteral">"\n"</span>);
00082                 }
00083         }
00084 <span class="preprocessor">#endif</span>
00085 <span class="preprocessor"></span>        <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         <span class="keyword">struct</span> thread_info *tinfo,
00090         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, 
00091         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp )
00092 {
00093         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr;
00094 
00095 <span class="preprocessor">#ifdef  CONFIG_FRAME_POINTER</span>
00096 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, (<span class="keywordtype">void</span> *)ebp)) {
00097                 addr = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)(ebp + 4);
00098                 <a class="code" href="group__sym.html#ga2">_stp_symbol_sprint</a> (addr);
00099                 <a class="code" href="group__scbuf.html#ga3">_stp_sprint_str</a>(<span class="stringliteral">"\n"</span>);
00100                 ebp = *(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)ebp;
00101         }
00102 <span class="preprocessor">#else</span>
00103 <span class="preprocessor"></span>        <span class="keywordflow">while</span> (valid_stack_ptr(tinfo, stack)) {
00104                 addr = *stack++;
00105                 <span class="keywordflow">if</span> (_stp_kta (addr)) {
00106                         <a class="code" href="group__sym.html#ga2">_stp_symbol_sprint</a> (addr);
00107                         <a class="code" href="group__scbuf.html#ga3">_stp_sprint_str</a> (<span class="stringliteral">"\n"</span>);
00108                 }
00109         }
00110 <span class="preprocessor">#endif</span>
00111 <span class="preprocessor"></span>        <span class="keywordflow">return</span> ebp;
00112 }
00113 
00114 <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)
00115 {
00116         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp;
00117 
00118         <span class="comment">/* Grab ebp right from our regs */</span>
00119         <span class="keyword">asm</span> (<span class="stringliteral">"movl %%ebp, %0"</span> : <span class="stringliteral">"=r"</span> (ebp) : );
00120 
00121         <span class="keywordflow">while</span> (stack) {
00122                 <span class="keyword">struct </span>thread_info *context = (<span class="keyword">struct </span>thread_info *)
00123                         ((<span class="keywordtype">unsigned</span> long)stack &amp; (~(THREAD_SIZE - 1)));
00124                 ebp = _stp_print_context_stack (context, stack, ebp);
00125                 stack = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>*)context-&gt;previous_esp;
00126         }
00127 }
00128 
00129 <span class="keyword">static</span> <span class="keywordtype">void</span> __stp_stack_sprint (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *stack, <span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00130 {
00131         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ebp;
00132 
00133         <span class="comment">/* Grab ebp right from our regs */</span>
00134         <span class="keyword">asm</span> (<span class="stringliteral">"movl %%ebp, %0"</span> : <span class="stringliteral">"=r"</span> (ebp) : );
00135 
00136         <span class="keywordflow">while</span> (stack) {
00137                 <span class="keyword">struct </span>thread_info *context = (<span class="keyword">struct </span>thread_info *)
00138                         ((<span class="keywordtype">unsigned</span> long)stack &amp; (~(THREAD_SIZE - 1)));
00139                 ebp = _stp_sprint_context_stack (context, stack, ebp);
00140                 stack = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>*)context-&gt;previous_esp;
00141         }
00142 }
00143 
00144 <span class="preprocessor">#endif </span><span class="comment">/* i386 */</span>
00145 <span class="comment"></span>
00146 <span class="comment">/** Print stack dump.</span>
00147 <span class="comment"> * Prints a stack dump to the trace buffer.</span>
00148 <span class="comment"> * @param verbose Verbosity:</span>
00149 <span class="comment"> */</span>
00150 
<a name="l00151"></a><a class="code" href="group__stack.html#ga6">00151</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)
00152 {
00153   <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> stack;
00154   <span class="keywordflow">return</span> __stp_stack_print (&amp;stack, verbose, levels);
00155 }
00156 
00157 <span class="keywordtype">char</span> *_stp_stack_sprint (<span class="keywordtype">int</span> verbose, <span class="keywordtype">int</span> levels)
00158 {
00159   <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> stack;
00160   <span class="keywordtype">char</span> *ptr = _stp_scbuf_cur();
00161   __stp_stack_sprint (&amp;stack, verbose, levels);
00162   <span class="keywordflow">return</span> ptr;
00163 }
00164 <span class="comment"></span>
00165 <span class="comment">/** @} */</span>
00166 <span class="preprocessor">#endif </span><span class="comment">/* _STACK_C_ */</span>
</pre></div></body></html>