我需要了解汇编来调试用 C 编写的程序吗?
我正在通过《C 编程语言》第二版学习 C,并做每个练习。
我是否需要了解汇编才能调试我为书籍练习的解决方案编写的 C 程序?
另外,您推荐哪种调试器?
I am learning C with "The C Programming Language", 2nd edition, and also doing each exercise.
Do I need to know assembly in order to debug C programs that I wrote as solutions to the books exercises?
Also, which debugger do you recommend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您不需要了解汇编语言即可用C 进行编程,包括调试。然而,如果您了解汇编,C 就开始变得很有意义;掌握一些汇编概念(最好是关于几种不同体系结构的一些概念,例如 x86 和 ARM)确实很有帮助,而不仅仅是为了调试。
You do not need to know assembly to program in C, including debugging. However, if you know assembly, C begins to make a lot of sense; it really helps to have some notions of assembly (preferably, some notions on several distinct architectures, such as x86 and ARM), and not only for debugging.
这不是必需的,但有时非常有帮助。如果你使用的是MSVC++,只需使用IDE中的那个,它也可以显示反汇编。
It is not required but sometimes is extremely helpful. If you're using MSVC++, just use the one in the IDE, it can show disassembly too.
不,您不需要了解汇编来学习 C。
就调试器而言,也许最简单的选择是使用您正在使用的 IDE 中内置的调试器。在 Windows 上,Microsoft Visual Studio 很流行(有一个 免费版本)。 Eclipse 是另一个流行的选择,可在许多平台上使用。
还有命令行调试器,例如 gdb,但它们会更难获得首先是基于 GUI 的。
No, you don't need to know assembly in order to learn C.
As far as debuggers go, perhaps the easiest choice is to use the debugger that's built into the IDE that you're using. On Windows, Microsoft Visual Studio is popular (there's a free version). Eclipse is another popular choice that's available on a number of platforms.
There are also command-line debuggers, such as gdb, but they'll be harder to get started with than a GUI-based one.
为了逐步调试,了解汇编可能会有所帮助,但不是必需的。是否真的有必要还取决于调试器。
但还有其他方法可以调试程序,例如将
printf()
调用放在重要位置。In order to debug step by step, it might be helpful, but not necessary, to know assembly. It also depends on the debugger if it is really necessary.
But there are other ways to debug a program, e.g. put
printf()
calls at strategic places.不,asm 不是必需的,但很有帮助,就像其他人所说的那样,使用调试器...其他人没有说的是,您甚至可以使用 GDB,但请确保禁用编译器优化,否则调试可能会很困难。
No, asm is not required but helpful, like others have said, use a debugger... What others have not said, is that you could even use GDB, but be sure you disable compiler optimisations or debugging might be hard.
当您使用 GCC
-g2
或-g3
标志进行编译时,您可以使用 GDB 调试程序。在这里您可以找到如何使用 GDB http://cs.baylor 的简短教程。 edu/~donahoo/tools/gdb/tutorial.html 在这里您可以找到更广泛的教程http://www.delorie.com/gnu/docs/gdb/gdb_toc.htmlWhen you compile with the GCC
-g2
or-g3
flag you can debug you program with GDB. Here you can find a short tutorial howto use GDB http://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html and here you can find a somewhat more extensive tutorial http://www.delorie.com/gnu/docs/gdb/gdb_toc.html如果您要调试自己的程序,则不需要学习汇编。编译器可以将源代码信息嵌入到可执行文件(GCC 的
-g
标志)或辅助文件(MSVC 的/Z
标志系列)中。调试器入门并不难(即使您使用命令行),而且互联网上到处都有大量资源。这是会给您带来最大回报的投资。
尽管如此,掌握一些汇编语言有时还是有用的。当您想要检查某些优化是如何完成时,有时(很少)需要查看编译器生成的程序集。但这是你不应该担心的事情,除非你有一份非常具体的工作。
You don't need to learn assembly if you are going to debug your own programs. Compilers can embed source code information into the executable (
-g
flag with GCC) or into a side file (/Z
family of flags with MSVC).Getting started with a debugger is not hard (even if you use a command line one), and there are plenty of resources everywhere on the internet. It is the investment which will give you the most return.
Nevertheless, having some grasp of the assembly language can prove useful at times. Looking at the assembly generated by the compiler is sometimes (rarely) needed when you want to check how some optimizations are done. But this is something you shouldn't worry about unless you have a very specific job.
不,你不知道。 Microsoft Visual Studio 有一个很好的调试器。其他选项是 Code::Blocks 或 Eclipse。
No, you don't. Microsoft Visual Studio has a nice debugger. Other options are Code::Blocks or Eclipse.