summaryrefslogtreecommitdiffstats
path: root/runtime/docs/html/io_8c-source.html
blob: 246f36d899460ed8529b4c4c204264fc29bfd691 (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
<!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: io.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="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>io.c</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/** Logs data.</span>
00002 <span class="comment"> * This function is compatible with printk.  In fact it currently</span>
00003 <span class="comment"> * sends all output to vprintk, after sending "STP: ". This allows</span>
00004 <span class="comment"> * us to easily detect SystemTap output in the log file.</span>
00005 <span class="comment"> *</span>
00006 <span class="comment"> * @param fmt A variable number of args.</span>
00007 <span class="comment"> * @bug Lines are limited in length by printk buffer.</span>
00008 <span class="comment"> * @todo Needs replaced with something much faster that does not</span>
00009 <span class="comment"> * use the system log.</span>
00010 <span class="comment"> */</span>
00011 <span class="keywordtype">void</span> dlog (<span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...)
00012 {
00013   va_list args;
00014   printk(<span class="stringliteral">"STP: "</span>);
00015   va_start(args, fmt);
00016   vprintk(fmt, args);
00017   va_end(args);
00018 }
00019 
00020 
00021 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * (*_stp_kallsyms_lookup)(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> addr,
00022                             <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *symbolsize,
00023                             <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *offset,
00024                             <span class="keywordtype">char</span> **modname, <span class="keywordtype">char</span> *namebuf)=(<span class="keywordtype">void</span> *)KALLSYMS_LOOKUP;
00025 
00026 
00027 <span class="preprocessor">#define STP_BUF_LEN 8191</span>
00028 <span class="preprocessor"></span>
00029 <span class="comment">/* FIXME. These need to be per-cpu */</span>
00030 <span class="keyword">static</span> <span class="keywordtype">char</span> _stp_pbuf[STP_BUF_LEN+1];
00031 <span class="keyword">static</span> <span class="keywordtype">int</span> _stp_pbuf_len = STP_BUF_LEN;
00032 
00033 <span class="keywordtype">void</span> _stp_print_buf (<span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, ...)
00034 {
00035   <span class="keywordtype">int</span> num;
00036   va_list args;
00037   <span class="keywordtype">char</span> *buf = _stp_pbuf + STP_BUF_LEN - _stp_pbuf_len;
00038   va_start(args, fmt);
00039   num = vscnprintf(buf, _stp_pbuf_len, fmt, args);
00040   va_end(args);
00041   <span class="keywordflow">if</span> (num &gt; 0)
00042     _stp_pbuf_len -= num;
00043 }
00044 
00045 <span class="keywordtype">void</span> _stp_print_buf_init (<span class="keywordtype">void</span>)
00046 {
00047   _stp_pbuf_len = STP_BUF_LEN;
00048   _stp_pbuf[0] = 0;
00049 }
00050 
00051 <span class="keywordtype">void</span> _stp_print_symbol(<span class="keyword">const</span> <span class="keywordtype">char</span> *fmt, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address)
00052 {
00053         <span class="keywordtype">char</span> *modname;
00054         <span class="keyword">const</span> <span class="keywordtype">char</span> *name;
00055         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> offset, size;
00056         <span class="keywordtype">char</span> namebuf[KSYM_NAME_LEN+1];
00057 
00058         name = _stp_kallsyms_lookup(address, &amp;size, &amp;offset, &amp;modname, namebuf);
00059 
00060         <span class="keywordflow">if</span> (!name)
00061                 _stp_print_buf("0x%lx", address);
00062         else {
00063           <span class="keywordflow">if</span> (modname)
00064             _stp_print_buf("%s+%#lx/%#lx [%s]", name, offset,
00065                            size, modname);
00066           else
00067             _stp_print_buf("%s+%#lx/%#lx", name, offset, size);
00068         }
00069 }
00070 
00071  
00072 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> cur_ret_addr (struct pt_regs *regs)
00073 {
00074 <span class="preprocessor">#ifdef __x86_64__</span>
00075 <span class="preprocessor"></span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *ra = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)regs-&gt;rsp;
00076 <span class="preprocessor">#else</span>
00077 <span class="preprocessor"></span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *ra = (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *)regs-&gt;esp;
00078 <span class="preprocessor">#endif</span>
00079 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (ra)
00080     return *ra;
00081   else
00082     return 0;
00083 }
</pre></div><hr size="1"><address style="align: right;"><small>
Generated on Tue Mar 22 00:32:02 2005 for SystemTap.</small></body>
</html>