没有合适的资源?快使用搜索试试~ 我知道了~
首页linux下gcc编译器的使用
linux下gcc编译器的使用
4星 · 超过85%的资源 需积分: 11 7 下载量 57 浏览量
更新于2023-06-25
评论 4
收藏 2.12MB PDF 举报
在为Linux开发应用程序时,绝大多数情况下使用的都是C语言,因此几乎每一 位Linux程序员面临的首要问题都是如何灵活运用C编译器。目前Linux下最常用的C语言编译器是GCC(GNU Compiler Collection),它是GNU项目中符合ANSI C标准的编译系统,能够编译用C、C++和Object C等语言编写的程序。GCC不仅功能非常强大,结构也异常灵活。最值得称道的一点就是它可以通过不同的前端模块来支持各种语言,如Java、 Fortran、Pascal、Modula-3和Ada等。 开放、自由和灵活是Linux的魅力所在,而这一点在GCC上的体现就是程序员通过它能够更好地控制整个编译过程。在使用GCC编译程序时,编译过程可以被细分为四个阶段: ◆ 预处理(Pre-Processing) ◆ 编译(Compiling) ◆ 汇编(Assembling) ◆ 链接(Linking) Linux程序员可以根据自己的需要让GCC在编译的任何阶段结束,以便检查或使用编译器在该阶段的输出信息,或者对最后生成的二进制文件进行控 制,以便通过加入不同数量和种类的调试代码来为今后的调试做好准备。和其它常用的编译器一样,GCC也提供了灵活而强大的代码优化功能,利用它可以生成执 行效率更高的代码。 GCC提供了30多条警告信息和三个警告级别,使用它们有助于增强程序的稳定性和可移植性。此外,GCC还对标准的C和C++语言进行了大量的扩展,提高程序的执行效率,有助于编译器进行代码优化,能够减轻编程的工作量。 GCC起步
资源详情
资源评论
资源推荐
Debugging with gdb
The gnu Source-Level Debugger
Ninth Edition, for gdb version 6.8.50.20081014
(GDB)
Richard Stallman, Roland Pesch, Stan Shebs, et al.
(Send bugs and comments on gdb to http://www.gnu.org/software/gdb/bugs/.)
Debugging with gdb
T
E
Xinfo 2004-02-19.09
Copyright
c
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2006 Free Software Foundation, Inc.
Published by the Free Software Foundation
51 Franklin Street, Fifth Floor, B oston, MA 02110-1301, USA
ISBN 1-882114-77-9
Permission is granted to copy, distribute and/or modify this document under the terms
of the GNU Free Documentation License, Version 1.1 or any later version published by
the Free Software Foundation; with the Invariant Sections being “Free Software” and “Free
Software Needs Free Documentation”, with the Front-Cover Texts being “A GNU Manual,”
and w ith the Back-Cover Texts as in (a) below.
(a) The FSF’s Back-Cover Text is: “You are free to copy and modify this GNU Man-
ual. Buying copies from GNU Press supports the FSF in developing GNU and promoting
software freedom.”
This edition of the GDB manual is dedicated to the memory of Fred Fish. Fred was a
long-standing contributor to GDB and to Free software in general. We will miss him.
i
Table of Contents
Summary of gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free Software Needs Free Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Contributors to gdb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1 A Sample gdb Session . . . . . . . . . . . . . . . . . . . . . . 7
2 Getting In and Out of gdb . . . . . . . . . . . . . . . . 11
2.1 Invoking gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1.1 Choosing Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.2 Choosing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.3 What gd b Does During Startup . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2 Quitting gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3 Shell Com mands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Getting He lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4 Running Programs Under gdb . . . . . . . . . . . . . 25
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3 Your Program’s Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.4 Your Program’s Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.5 Your Program’s Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.6 Your Program’s Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . 31
4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.9 Debugging Multiple Inferiors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.10 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . 33
4.11 Debugging Programs with Multiple Processes. . . . . . . . . . . . . . . . 35
4.12 Setting a Bookmark to Re turn to Later . . . . . . . . . . . . . . . . . . . . . 37
4.12.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . 38
ii Debugging with gdb
5 Stopping and Continuing . . . . . . . . . . . . . . . . . . 41
5.1 Breakpoints, Watchpoints, and Catchpoints . . . . . . . . . . . . . . . . . . 41
5.1.1 Setting Bre akpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5.1.2 Setting Watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.1.3 Setting Catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.1.6 Break Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.1.7 Breakpoint Command Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.1.8 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.1.9 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . . 56
5.2 Continuing and Stepping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.4 Stopping and Starting Multi-thread Programs . . . . . . . . . . . . . . . . 61
5.4.1 All-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.4.2 Non-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.4.3 Background Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.4.4 Thread-Specific Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.4.5 Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 67
6.1 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
6.3 Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.4 Information About a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7 Examining Source Files . . . . . . . . . . . . . . . . . . . 73
7.1 Printing Source Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.2 Specifying a Location. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
7.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.6 Source and Machine Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.2 Ambiguous Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
8.3 Program Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.4 Artificial Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.5 Output Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.6 Examining Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
8.7 Automatic Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
8.8 Print Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8.9 Value History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
8.10 Convenience Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
8.11 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
剩余452页未读,继续阅读
xiaxiaoli_2013
- 粉丝: 23
- 资源: 82
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2