TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Strace – My Favourite Secret Weapon (2011)

311 点作者 zwischenzug超过 7 年前

14 条评论

orivej超过 7 年前
Re. <i>My Library Is Not Loading!</i>, a pretty useful trick to find what files are missing is to extend your path env var with an empty directory and then grep strace output for its occurrences, e.g.<p><pre><code> mkdir &#x2F;tmp&#x2F;empty LD_LIBRARY_PATH+=:&#x2F;tmp&#x2F;empty # or PATH, or PERL5LIB, etc. strace -f program |&amp; grep &#x2F;tmp&#x2F;empty </code></pre> I had a need to track what files are used by what processes spawned by a program (to infer dependencies between the processes), and it seemed (and probably was) simpler to use ptrace directly rather than to parse strace output, so I wrote <a href="https:&#x2F;&#x2F;github.com&#x2F;orivej&#x2F;fptrace&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;orivej&#x2F;fptrace&#x2F;</a> . Soon it turned out useful to dump its data into shell scripts that reflect the tree of spawned processes and let you rerun an arbitrary subtree. I mostly use it to debug build systems, for example to trace <i>configure</i> and examine what env var affected a certain check in a strange way, or to trace <i>make</i> and rerun the C compiler with <i>-dD -E</i> to inspect an unexpected interference between includes.
评论 #16354959 未加载
评论 #16354651 未加载
评论 #16354821 未加载
brendangregg超过 7 年前
No mention of overhead. strace can bring down your production environment -- it is not safe. This is why I wrote this: <a href="http:&#x2F;&#x2F;www.brendangregg.com&#x2F;blog&#x2F;2014-05-11&#x2F;strace-wow-much-syscall.html" rel="nofollow">http:&#x2F;&#x2F;www.brendangregg.com&#x2F;blog&#x2F;2014-05-11&#x2F;strace-wow-much-...</a><p>&quot;perf trace&quot; has improved since I wrote that, and may well be mostly strace-equivalent (but without crippling overhead) in the latest Linux.
评论 #16357110 未加载
评论 #16361986 未加载
评论 #16357843 未加载
评论 #16356978 未加载
评论 #16356474 未加载
zwischenzug超过 7 年前
Nice to see something I wrote 7 years ago hasn&#x27;t gone entirely to waste. Spot the &#x27;ancient&#x27; technologies like Solaris and perl mentioned there...
评论 #16354347 未加载
评论 #16358428 未加载
评论 #16354457 未加载
评论 #16354597 未加载
lucb1e超过 7 年前
Strace and Wireshark. If a program&#x27;s output doesn&#x27;t immediately tell me what the hell its issue is, I&#x27;ll just dive into this depending on the kind of trouble.<p>The only thing I&#x27;d still like to have is something like strace but for general function calls. Often, the issue is within the application and does not show in syscalls. I guess this should be possible with gdb, but I haven&#x27;t looked into it yet, also because any meaningful names are often stripped from the binaries.
评论 #16354587 未加载
amelius超过 7 年前
The secret weapon has a (serious) flaw on Linux though: you can&#x27;t run strace on programs that use strace. That&#x27;s because the Linux ptrace call is not re-entrant.
评论 #16355814 未加载
shinnok超过 7 年前
A good complement to strace is ltrace(1):<p><pre><code> ltrace is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls executed by the program. </code></pre> Also noteworthy is that you can simply press <i>s</i> key in <i>htop</i> to immediately attach a process and inspect it, which was handy many times for me.
thedatamonger超过 7 年前
I was in awe when I first used strace. The world of tracing is vast these days and filled with wonders. I can&#x27;t possibly say it better than this this guy so I&#x27;ll just include a link.<p><a href="http:&#x2F;&#x2F;www.brendangregg.com&#x2F;blog&#x2F;2016-03-05&#x2F;linux-bpf-superpowers.html" rel="nofollow">http:&#x2F;&#x2F;www.brendangregg.com&#x2F;blog&#x2F;2016-03-05&#x2F;linux-bpf-superp...</a>
snissn超过 7 年前
Is there a substitute for mac&#x2F;osx?
评论 #16356332 未加载
评论 #16355385 未加载
lamby超过 7 年前
Here&#x27;s my strace hack from 2008: <a href="https:&#x2F;&#x2F;chris-lamb.co.uk&#x2F;posts&#x2F;can-you-get-cp-to-give-a-progress-bar-like-wget" rel="nofollow">https:&#x2F;&#x2F;chris-lamb.co.uk&#x2F;posts&#x2F;can-you-get-cp-to-give-a-prog...</a>
adultSwim超过 7 年前
This is my favorite strace resource: <a href="https:&#x2F;&#x2F;jvns.ca&#x2F;strace-zine-v3.pdf" rel="nofollow">https:&#x2F;&#x2F;jvns.ca&#x2F;strace-zine-v3.pdf</a>
ggm超过 7 年前
strace is great. There are times this feels like the modern equivalent of printf() debugging, because working out why a syscall is failing involves a fair amount of back tracing to context sometimes. But, as a foot in the door? its ace.
partycoder超过 7 年前
If you want to listen on a port under 1024 you require superuser access or special privileges.<p><a href="https:&#x2F;&#x2F;www.w3.org&#x2F;Daemon&#x2F;User&#x2F;Installation&#x2F;PrivilegedPorts.html" rel="nofollow">https:&#x2F;&#x2F;www.w3.org&#x2F;Daemon&#x2F;User&#x2F;Installation&#x2F;PrivilegedPorts....</a>
posharma超过 7 年前
Is there a strace equivalent for windows?
vram22超过 7 年前
As I said in a comment on the OP, lsof (LiSt Open Files - it does more than its name suggests) is pretty useful too.<p>fuser is useful too, and available on many Unixen. I&#x27;ve used &quot;fuser -k&quot; many times to find and kill rogue processes.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Lsof" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Lsof</a><p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fuser_(Unix)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fuser_(Unix)</a><p>Edited for grammar.
评论 #16355147 未加载