-
捕获
C++
异常-
格式
catch throw [regexp] | catch rethrow [regexp] | catch catch [regexp]
-
说明
- 以正则表达式的方式指定感兴趣的异常.
- 在
throw
阶段捕获. $_exception
获取抛出的什么异常.- 无参表示捕获所有.
-
局限
- 系统依赖.遵循
gnu-v3
标准的c++ ABI
支持这种断点.
- 系统依赖.遵循
-
案例
-
代码
#include<stdio.h> int main(){ try{ throw 2;}catch(int a){ printf("%d\n",a);} }
- 文件名
test.cpp
.
- 文件名
-
编译执行
g++ -g test.cpp -o a.out gdb -q -ex 'catch throw int' -ex 'r' -ex 'bt' ./a.out
-
查看
catch
异常的位置g++ -g test.cpp -o a.out gdb -q -ex 'catch catch int' -ex 'r' -ex 'bt' ./a.out
-
-
二次抛出
-
代码
#include<stdio.h> int main(){ try{ throw 2;}catch(int a){ printf("%d\n",a);throw a;} }
-
编译执行指令
g++ -g test.cpp -o a.out gdb -q -ex 'catch rethrow int' -ex 'r' -ex 'bt' ./a.out
-
-
-
捕获系统调用
-
格式
catch syscall | catch syscall [name | number | group:groupname | g:groupname] ...
-
说明
- 无参表示捕获所有系统调用.
- 有参则捕获指定.
- 按名字,按系统调用编号,按分组.都可.
-
案例
-
代码
#include<stdio.h> int main(){ try{ throw 2;}catch(int a){ printf("%d\n",a);} }
- 文件名
test.cpp
.
- 文件名
-
编译执行
g++ -g test.cpp -o a.out gdb -q -ex 'catch syscall' -ex 'r' -ex 'bt' ./a.out
- 这里捕获到的是内存分配
brk
.
- 这里捕获到的是内存分配
-
捕获
printf
gdb -q -ex 'catch syscall write' -ex 'r' -ex 'bt' ./a.out
-
-
-
捕获库的装载卸载
-
格式
catch load [regexp] | catch unload [regexp]
-
说明
- 无参表示所有.
- 以正则的方式匹配库名.
-
案例
-
代码
#include<stdio.h> int main(){ try{ throw 2;}catch(int a){ printf("%d\n",a);} }
- 文件名
test.cpp
.
- 文件名
-
编译执行
g++ -g test.cpp -o a.out gdb -q -ex 'catch load libc' -ex 'r' -ex 'bt' ./a.out
- 这里捕获
libc
.可能会有多个匹配.
- 这里捕获
-
-
使用场景
- 观察某个库的加载卸载,比如
dlopen,dlclose
之类.
- 观察某个库的加载卸载,比如
-
-
捕获信号
-
格式
catch signal [signal... | ‘all’]
-
说明
- 无参所有信号,
gdb
默认捕获一些信号. SIG
然后tab
补全.
- 无参所有信号,
-
常见
- 捕获因为非法指针访问出问题的位置.
-
-
信号与异常
-
说明
C++
的捕获机制,linux
下并不是所有的都会被捕获到.- 比如:空指针异常和算术异常和指令异常.
- 或者说信号都不能被异常捕获机制捕获.
-
信号处理
- 信号默认处理方式,和信号自定义处理方式.
- 信号处理进程共享,不会存在线程特有处理方式.
-
信号分发
- 信号分发会发给合适的线程.
- 没有阻塞,在执行的,循环搜索.
- 分发给指定线程的信号:空指针异常和算术异常和指令异常.
-
信号处理周期
- 每次从内核出来会检查进程状态,是否有信号需要处理.
SIGPENDING
.
- 每次从内核出来会检查进程状态,是否有信号需要处理.
-
信号信息
- 一般通过
siginfo_t
打包信号信息,没有内存保存则仅仅是信号值.
- 一般通过
-
信号区分
- 普通信号
0-32
.实时信号33-64
. - 普通信号用
set
存储(uint位运算)
,实时信号用队列存储. - 普通信号不存在重复的,实时信号可重复.
- 普通信号
-
信号处理函数
- 一般有默认,但是
SIGKILL == 9
不能被自定义,也无法捕获,这种是为了防止牛皮癣,存在干不掉的进程.1
号进程就是牛皮癣.
- 一般有默认,但是
-
详细解决方案
gdb调试c++异常,系统调用,库的load,unload,信号异常等.
热度:81 发布时间:2023-12-22 02:50:58.0
相关解决方案
- <load-on-startup>的有关问题
- Servlet配备太神奇鸟:(load-on-startup设置为负数肿么还是加载
- Unable to load class for JSP,该如何处理
- struts2.3.4.1启动抛错误 Unable to load configuration
- Could not load JDBC driver class 咋回事
- jquery.load(*json) 解析不已。求帮忙
- Cannot load JDBC driver class 'com.microsoft.jdbc.sqlserver.SQLServerDriver'解决方法
- 答案 jquery load()
- SonyEricsson_W800 Couldn't load zayitlib.dll library?解决思路
- 求教高手:Unable to load configuration.该如何处理
- org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryV
- websphere5.12 Error 503: Failed to load target servlet [action],该如何处理
- CImage:Load(IStream* pStream)失败
- obj.Load(""),水晶报表在服务器地址10.132.22.22上,在服务器c:\下,这个?要如何改
- c#中,运作程序时,提示mysql.data load failed
- jquery .load() 的有关问题
- DataTable.Load(SqlDataReader)和SqlDataAdapter.Fill()的区别,该怎么处理
- jquery load 在google上报错
- 自定义控件,提示"在 DataBind、Init、Load、PreRender 或 Unload 阶段,不能修改该控件集合。"待。
- Exception Details: System.IO.FileLoadException: Could not load file or assembly 'FreeTextBox' or one of its dependencies. 磁盘空间不足,该如何解决
- 请问一个 JQuery Load 方法有关问题
- .net Unable to load DLL 'libmySQL.dll': 拒绝访问。该怎么处理
- 请教在asp.net mvc下怎么使用Assembly.Load
- Could not load the assembly 'App_Web_dmb5jsqc'?解决办法
- Could not load file or assembly 'Interop.ADODB, Version=6.0.0.0, Culture=neutral解决办法
- 关于Could not load file or assembly 异常的有关问题
- 对于这个有关问题,小弟我真心跪了. Could not load file or assembly 'System.Drawing
- Could not load file or assembly 'Meta.Web' or one of its dependencies. 磁盘空间不足解决思路
- Could not load file or assembly 'Microsoft.Office.Interop.Owc11, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e94,该怎么处理
- 请问:Could not load type… 这个有关问题怎么解决