手动制造4) SIGILL非法指令问题

本文介绍如何在程序中故意触发SIGILL非法指令信号,用于测试调试方法的可行性。通过使用非法函数指针和尝试打印非字符串类型,可以制造程序崩溃,以便于验证调试流程。适用于不易复现的非法指令问题追查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在追查非法指令问题时(不易复现),需要验证自己的调试方式是否可行,就需要制造4) SIGILL非法指令问题进行测试和验证方法的可行性,然后添加到代码中当程序崩溃时打印出有用的信息,下面列出几种方法。

非法函数指针

typedef void(*FUNC)(void);

int main(void)
{    
	const static unsigned char insn[4] = { 0xff, 0xff, 0xff, 0xff };    
	FUNC function = (FUNC) insn;
    function();
}

提示:非法指令(吐核),Signal Error! Signal is 4

打印非法string

#include <iostream>
#include <stdio.h>
using namespace std;
 
int main()
{
	string s = "123";
	printf("xxxx is %s\n", s);
}

我的gcc版本是:gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC),报编译错误。

main.c: 在函数‘int main()’中:
main.c:10:26: 错误:不能通过‘...’传递有不能平凡复制的类型‘std::string {aka class std::basic_string<char>}’
  printf("xxxx is %s\n", s);
                          ^

如果你的编译器编译通过且只报警告的话就能出发程序崩溃。

 warning: cannot pass objects of non-POD type ‘struct std::string’ through ‘...’; call will abort at runtime

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值