This commit is contained in:
fofolee
2019-04-21 11:50:48 +08:00
parent 359d29ee0b
commit 38dcd51d8a
6901 changed files with 258583 additions and 2326828 deletions

View File

@@ -1,61 +1,61 @@
<h1 id="ltrace">ltrace</h1>
<p>用来跟踪进程调用库函数的情况</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>ltrace命令</strong> 是用来跟踪进程调用库函数的情况。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">ltrace [option ...] [command [arg ...]]</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-a 对齐具体某个列的返回值。
-c 计算时间和调用,并在程序退出时打印摘要。
-C 解码低级别名称(内核级)为用户级名称。
-d 打印调试信息。
-e 改变跟踪的事件。
-f 跟踪子进程。
-h 打印帮助信息。
-i 打印指令指针,当库调用时。
-l 只打印某个库中的调用。
-L 不打印库调用。
-n, --indent=NR 对每个调用级别嵌套以NR个空格进行缩进输出。
-o, --output=file 把输出定向到文件。
-p PID 附着在值为PID的进程号上进行ltrace。
-r 打印相对时间戳。
-s STRLEN 设置打印的字符串最大长度。
-S 显示系统调用。
-t, -tt, -ttt 打印绝对时间戳。
-T 输出每个调用过程的时间开销。
-u USERNAME 使用某个用户id或组ID来运行命令。
-V, --version 打印版本信息,然后退出。
-x NAME treat the global NAME like a library subroutine.(求翻译)</code></pre>
<h3 id="实例">实例</h3>
<p>最基本应用,不带任何参数:</p>
<pre><code class="language-bash">[guest@localhost tmp]$ ltrace ./a.out
__libc_start_main(0x80484aa, 1, 0xbfc07744, 0x8048550, 0x8048540 &lt;unfinished ...&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 10, 6, 4no1:10 no2:6 diff:4 ) = 24
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 9, 7, 2no1:9 no2:7 diff:2 ) = 23
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 8, 8, 0no1:8 no2:8 diff:0 ) = 23
--- SIGFPE (Floating point exception) ---
+++ killed by SIGFPE +++</code></pre>
<p>输出调用时间开销:</p>
<pre><code class="language-bash">[guest@localhost tmp]$ ltrace -T ./a.out
__libc_start_main(0x80484aa, 1, 0xbf81d394, 0x8048550, 0x8048540 &lt;unfinished ...&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 10, 6, 4no1:10 no2:6 diff:4 ) = 24 &lt;0.000972&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 9, 7, 2no1:9 no2:7 diff:2 ) = 23 &lt;0.000155&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 8, 8, 0no1:8 no2:8 diff:0 ) = 23 &lt;0.000153&gt;
--- SIGFPE (Floating point exception) ---
+++ killed by SIGFPE +++</code></pre>
<p>显示系统调用:</p>
<pre><code class="language-bash">[guest@localhost tmp]$ ltrace -S ./a.out
SYS_brk(NULL) = 0x9e20000
SYS_access(0xa4710f, 4, 0xa4afc0, 0, 0xa4b644) = 0
SYS_open(&quot;/etc/ld.so.preload&quot;, 0, 02) = 3
SYS_fstat64(3, 0xbfbd7a94, 0xa4afc0, -1, 3) = 0
SYS_mmap2(0, 17, 3, 2, 3) = 0xb7f2a000
SYS_close(3) = 0
SYS_open(&quot;/lib/libcwait.so&quot;, 0, 00) = 3
SYS_read(3, &quot;\177ELF\001\001\001&quot;, 512) = 512
SYS_fstat64(3, 0xbfbd76fc, 0xa4afc0, 4, 0xa4b658) = 0
SYS_mmap2(0, 4096, 3, 34, -1) = 0xb7f29000
SYS_mmap2(0, 5544, 5, 2050, 3) = 0x423000
SYS_mmap2(0x424000, 4096, 3, 2066, 3) = 0x424000
.............省去若干行</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->
<h1 id="ltrace">ltrace</h1>
<p>用来跟踪进程调用库函数的情况</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>ltrace命令</strong> 是用来跟踪进程调用库函数的情况。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">ltrace [option ...] [command [arg ...]]</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-a 对齐具体某个列的返回值。
-c 计算时间和调用,并在程序退出时打印摘要。
-C 解码低级别名称(内核级)为用户级名称。
-d 打印调试信息。
-e 改变跟踪的事件。
-f 跟踪子进程。
-h 打印帮助信息。
-i 打印指令指针,当库调用时。
-l 只打印某个库中的调用。
-L 不打印库调用。
-n, --indent=NR 对每个调用级别嵌套以NR个空格进行缩进输出。
-o, --output=file 把输出定向到文件。
-p PID 附着在值为PID的进程号上进行ltrace。
-r 打印相对时间戳。
-s STRLEN 设置打印的字符串最大长度。
-S 显示系统调用。
-t, -tt, -ttt 打印绝对时间戳。
-T 输出每个调用过程的时间开销。
-u USERNAME 使用某个用户id或组ID来运行命令。
-V, --version 打印版本信息,然后退出。
-x NAME treat the global NAME like a library subroutine.(求翻译)</code></pre>
<h3 id="实例">实例</h3>
<p>最基本应用,不带任何参数:</p>
<pre><code class="language-bash">[guest@localhost tmp]$ ltrace ./a.out
__libc_start_main(0x80484aa, 1, 0xbfc07744, 0x8048550, 0x8048540 &lt;unfinished ...&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 10, 6, 4no1:10 no2:6 diff:4 ) = 24
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 9, 7, 2no1:9 no2:7 diff:2 ) = 23
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 8, 8, 0no1:8 no2:8 diff:0 ) = 23
--- SIGFPE (Floating point exception) ---
+++ killed by SIGFPE +++</code></pre>
<p>输出调用时间开销:</p>
<pre><code class="language-bash">[guest@localhost tmp]$ ltrace -T ./a.out
__libc_start_main(0x80484aa, 1, 0xbf81d394, 0x8048550, 0x8048540 &lt;unfinished ...&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 10, 6, 4no1:10 no2:6 diff:4 ) = 24 &lt;0.000972&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 9, 7, 2no1:9 no2:7 diff:2 ) = 23 &lt;0.000155&gt;
printf(&quot;no1:%d \t no2:%d \t diff:%d\n&quot;, 8, 8, 0no1:8 no2:8 diff:0 ) = 23 &lt;0.000153&gt;
--- SIGFPE (Floating point exception) ---
+++ killed by SIGFPE +++</code></pre>
<p>显示系统调用:</p>
<pre><code class="language-bash">[guest@localhost tmp]$ ltrace -S ./a.out
SYS_brk(NULL) = 0x9e20000
SYS_access(0xa4710f, 4, 0xa4afc0, 0, 0xa4b644) = 0
SYS_open(&quot;/etc/ld.so.preload&quot;, 0, 02) = 3
SYS_fstat64(3, 0xbfbd7a94, 0xa4afc0, -1, 3) = 0
SYS_mmap2(0, 17, 3, 2, 3) = 0xb7f2a000
SYS_close(3) = 0
SYS_open(&quot;/lib/libcwait.so&quot;, 0, 00) = 3
SYS_read(3, &quot;\177ELF\001\001\001&quot;, 512) = 512
SYS_fstat64(3, 0xbfbd76fc, 0xa4afc0, 4, 0xa4b658) = 0
SYS_mmap2(0, 4096, 3, 34, -1) = 0xb7f29000
SYS_mmap2(0, 5544, 5, 2050, 3) = 0x423000
SYS_mmap2(0x424000, 4096, 3, 2066, 3) = 0x424000
.............省去若干行</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->