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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How Does a C Debugger Work? (2014)

131 点作者 btashton超过 4 年前

7 条评论

userbinator超过 4 年前
<i>It writes an invalid instruction at this location. What ever this instruction, it just has to be invalid.</i><p>On x86 at least, it is a valid instruction. INT3, or CC in hex. There are also the debug registers which implement breakpoints without modifying any code, although it&#x27;s limited to a maximum of 4 at once.<p>Characterising gdb as a &quot;C debugger&quot; is quite appropriate --- try to debug the Asm directly with it is an excruciating experience.
评论 #24815696 未加载
评论 #24817275 未加载
评论 #24815710 未加载
评论 #24816735 未加载
评论 #24815658 未加载
elvis70超过 4 年前
See also the &quot;Writing a Linux Debugger&quot; series of posts in which a source-level debugger is implemented: <a href="https:&#x2F;&#x2F;blog.tartanllama.xyz&#x2F;writing-a-linux-debugger-setup&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.tartanllama.xyz&#x2F;writing-a-linux-debugger-setup&#x2F;</a>
woodruffw超过 4 年前
This is a fantastic summary of debugger implementation!<p>Another great one that actually walks through writing a basic debugger is Eli Bendersky&#x27;s series[1].<p>One nitpick:<p>&gt; It could, and that would work (that the way valgrind memory debugger works), but that would be too slow. Valgrind slows the application 1000x down, GDB doesn&#x27;t. That&#x27;s also the way virtual machines like Qemu work.<p>This is usecase-dependent: running a program until you hit a breakpoint will be significantly faster with `int 3`, but running a piece of instrumentation on every instruction (or branch, or basic block, or ...) will be significantly faster with Valgrind (or another dynamic binary instrumentation framework). This is because Valgrind and other DBI tools can rewrite the instruction stream to sidecar instrumentation into the same process, versus converting every instruction (or other program feature) into a sequence of expensive system calls.<p>[1]: <a href="https:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;tag&#x2F;debuggers" rel="nofollow">https:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;tag&#x2F;debuggers</a>
jbn超过 4 年前
One useful reference for this is <a href="https:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;~nr&#x2F;pubs&#x2F;retargetable-abstract.html" rel="nofollow">https:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;~nr&#x2F;pubs&#x2F;retargetable-abstract.html</a>
qlk1123超过 4 年前
It writes an invalid instruction at this location. What ever this instruction, it just has to be invalid.<p>RISC-V actually did this in a special instruction called ebreak. It can change the CPU privileged mode into Debug Mode.
评论 #24816740 未加载
Gunax超过 4 年前
What about optimizations?<p>Isn&#x27;t it possible the compiler will re-order or combine statements differently than how they are written in source?
评论 #24817118 未加载
评论 #24816547 未加载
jonny383超过 4 年前
And here I was thinking this would be an article on writing printf() statements.