-
Macro:
int
SIGILL
-
The name of this signal is derived from “illegal instruction”; itusually means your program is trying to execute garbage or a privilegedinstruction. Since the C compiler generates only valid instructions,
SIGILL
typically indicates that the executable file is corrupted,or that you are trying to execute data. Some common ways of gettinginto the latter situation are by passing an invalid object where apointer to a function was expected, or by writing past the end of anautomatic array (or similar problems with pointers to automaticvariables) and corrupting other data on the stack such as the returnaddress of a stack frame.SIGILL
can also be generated when the stack overflows, or whenthe system has trouble running the handler for a signal.
printf使用%s直接输出string类型,Program received signal SIGILL, Illegal instruction
分类: 学习心得 2008-04-14 22:26 1618人阅读 评论(1) 收藏 举报
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
string a;
a[0]='a';
a[1]='/0';
printf("%s/n",a);
system("pause");
}
出错: [Warning] cannot pass objects of non-POD type `struct std::string' through `...'; call will abort at runtime
printf只能输出C语言内置的数据,而string不是内置的,只是一个扩展的类,这样肯定是链接错误的。string不等于char*,&a代表的是这个字符串的存储地址,并不是指向字符串的首地址,aa 对象中包含一个指向"string"的指针, &aar得到的是这个对象的地址,不是"string"的地址。
printf输出string类型应如此操作!
#include<iostream>
#include<string>
using namespace std;
void main()
{
string aa="qqq";
printf("%s",aa.c_str()); //不推荐
//或者cout<<a;
}
由于string是C的一个 扩展类型,其数据赋值可以用其提供的方法:assign(const char *)或直接用其构造函数
string str( "Now is the time..." );
illegal instruction 信号sigill
2010-10-19 22:53
ctags :illegal instruction SIGILL linux
error "Illegal instruction" 是由信号:“SIGILL”产生。
WIKI SIGILL From Wikipedia
不放过任何一个警告。
“warning: cannot pass objects of non-POD type 'const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' through '...'; call will abort at runtime”
问题解决过程说明:
1. 首先确定:在同一台机器上编译执行,不存在任何的交叉编译错误。
2. 再次编译,查看解决告警信息,发现将一个 “string” 类型的变量按”%s”的格式进行输出,导致告警。
3. 告警没解决导致执行时发生“Illegal instruction”的错误。
告警解决后,问题解决。
other:
SIGILL 信号是cpu在发现非法指令之后发出一个异常,然后由负责处理该异常的内核的ISR对含有这个非法指令的进程发出的。程序收到这个信号,一般就是报 告 illegal instruction 错误信息。
可执行程序含有非法指令的原因,一般也就是cpu架构不对,编译时指定的march和实际执行的机器的march不同。这种情况,因为工具链一样,连接脚 本一样,所以可执行程序可以执行,不会发生exec format error。但是会包含一些不兼容的指令。还有另外一种可能,就是程序的执行权限不够,比如在目态下运行的程序只能执行非特权指令,一旦CPU遇到特权指 令,将产生illegal instruction错误。
在系统运行过程中,处理机状态是动态变化的。从目态转换为管态只能通过中断来实现。从管态到目态的转换可通过修改程序状态字PSW来实现。
SIGILL | |||||||||||||||||
Description | Illegal instruction | ||||||||||||||||
Default action | Abnormal termination of the process | ||||||||||||||||
SA_SIGINFO macros | |||||||||||||||||
|