Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
692
|
第
19
章
19.7 调试
使用
-g
选项,可以允许
GCC
在对象文件和执行文件中包含符号表和源代码行号信息。
在调试程序时可以使用这些信息,当程序单步执行时将显示寄存器和内存中变量的内容
(第
21
章会进一步讨论与调试相关的内容)。符号信息有一些固定格式,在默认情况
下,
GCC
使用系统的原始格式。
也可以在
-g
后面附加后缀,构成新的命令行选项,该选项指示使用与系统原始格式不同的
格式来存储符号信息。这么做也可能是为了满足所使用的特定调试程序的需求。例如,
-ggdb
选
项指示选择系统可用的最佳格式,以使用
GNU
调试器
GDB
来进行调试。
因为符号信息会增加甚至成倍扩大可执行文件的空间大小,所以当调试和测试完成后,
应该不带
-g
选项再编译一次,并且使用
-s
选项进行链接。然而,某些软件包会在可执行
文件中附加有关调试信息,以便于诊断后续用户的问题。
19.8 剖析
使用
-p
选项会在程序中加入一些特殊的函数,以当执行程序时输出剖析信息(
profiling
information
)。剖析信息相当有用,可以辅助解决性能相关的问题,因为它可以帮助了
解程序中哪些函数正在耗费执行时间。剖析信息被存储到一个名为
mon.out
的文件中。然
后可以使用
prof
工具程序来以多种方式来分析剖析信息。关于
prof
的更多细节,请参考
prof
手册。
对于
GNU
剖析器(
profiler
)
gprof
,在编译程序时可以使用
-p g
选项启用它。剖析信息输
出的默认文件名是
gmon.out
。
gprof
结合
GCC
选项
-p g
使用,可以生成一张调用图,显示 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207