一个退出奇怪的coredump [英] A quit strange coredump

查看:74
本文介绍了一个退出奇怪的coredump的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:

在我的C代码中有一个惊人的coredump,我正在思考它并且

结束...

代码很简单如下:


// ***************************** ********

const unsigned long int len = 102400000;

int array [len];

unsigned long int i ;

for(i = 0; i< len; i ++)

{

array [i] = 0; // coredump线;

}

// ************************* ************


与gdb,当变量i变为0时,array [i] = 0,进程

收到分段错误并留下coredump。

那条线有什么不对吗?似乎没事,条件是i = 0.


--tomy

解决方案

< blockquote> tomy schrieb:

大家好:
在我的C代码中有一个惊人的coredump,我正在思考它并且
结束......
代码很简单如下:

// *********************************** **
const unsigned long int len = 102400000;
int array [len];
unsigned long int i;

for(i = 0; i< len ; i ++)
{
array [i] = 0; // coredump line;
}
// ********************************* ****

使用gdb,当变量i变为0时,array [i] = 0,过程接收到分段错误并留下coredump。这条线路有什么不对吗?似乎没问题,条件是i = 0.




请将您的代码分解为最小的编译示例

仍然展示问题。发布在这里,并说明你是否使用C99或C90
$ b $。


当你似乎在使用gcc时,请提高警告级别:

gcc -std = c99 -pedantic -W -O yourcode.c -c

注意:您的代码不能是C90代码(-std = c89或-ansi)作为len

不是C90中数组大小

所需的编译时常量。 (const不提供C中的编译时间常量。)

干杯

Michael

-

E-邮件:我的是/ at / gmx / dot / de地址。


tomy< to ****** @ gmail.com>写道:

大家好:
在我的C代码中有一个惊人的coredump,我正在思考它并且
结束......
代码很简单下面:

// *************************************
const unsigned long int len = 102400000;
int array [len];
unsigned long int i;

for(i = 0; i< len; i ++)
{
array [i] = 0; // coredump line;
}
// ********************************* ****

使用gdb,当变量i变为0时,array [i] = 0,过程接收到分段错误并留下coredump。这条线路有什么不对吗?似乎没问题,条件是i = 0.




请提供完整,独立,可编辑的示例,而不是

只是一个片段。如果array []是一个

自动变量,你的帖子就不清楚了;如果是这种情况,它的大小接近100 MB

可能在你的平台上太多了。

-

:wq

^ X ^ Cy ^ K ^ X ^ C ^ C ^ C ^ C


2006-06-11,tomy< ;到****** @ gmail.com>写道:

大家好:
在我的C代码中有一个惊人的coredump,我正在思考它并且
结束......
代码很简单下面:

// *************************************
const unsigned long int len = 102400000;
int array [len];
unsigned long int i;

for(i = 0; i< len; i ++)
{
array [i] = 0; // coredump line;
}
// ********************************* ****

使用gdb,当变量i变为0时,array [i] = 0,过程接收到分段错误并留下coredump。这条线路有什么不对吗?看起来没问题,条件是i = 0.




我认为这个程序应该没问题,假设它是C99并假设你的

机器的堆栈足够大。数组是一个很大的对象,可以将

放在堆栈上,而coredump可能是由堆栈间接引起的。

溢出。


Hi all:
There is an amazing coredump in my C code, I was thinking it over and
over...
The code is simple as below:

//*************************************
const unsigned long int len = 102400000;
int array[len];
unsigned long int i;
for(i=0; i<len; i++)
{
array[i] = 0; //The coredump line;
}
//*************************************

with gdb, when variable i came to 0, the "array[i]=0", the process
received segmentation fault and left coredump. Is there any wrong in
THAT line? It seems all right, with the condition i=0.

--tomy

解决方案

tomy schrieb:

Hi all:
There is an amazing coredump in my C code, I was thinking it over and
over...
The code is simple as below:

//*************************************
const unsigned long int len = 102400000;
int array[len];
unsigned long int i;
for(i=0; i<len; i++)
{
array[i] = 0; //The coredump line;
}
//*************************************

with gdb, when variable i came to 0, the "array[i]=0", the process
received segmentation fault and left coredump. Is there any wrong in
THAT line? It seems all right, with the condition i=0.



Please break your code down to a minimal compiling example that
still exhibits the problem. Post it here and state whether you
are using C99 or C90.

As you seem to be using gcc, turn the warning level up:
gcc -std=c99 -pedantic -W -O yourcode.c -c
Note: Your code cannot be C90 code (-std=c89 or -ansi) as len
is not a compile time constant which is required for array sizes
in C90. (const does not provide compile time constants in C.)
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


tomy <to******@gmail.com> wrote:

Hi all:
There is an amazing coredump in my C code, I was thinking it over and
over...
The code is simple as below:

//*************************************
const unsigned long int len = 102400000;
int array[len];
unsigned long int i;
for(i=0; i<len; i++)
{
array[i] = 0; //The coredump line;
}
//*************************************

with gdb, when variable i came to 0, the "array[i]=0", the process
received segmentation fault and left coredump. Is there any wrong in
THAT line? It seems all right, with the condition i=0.



Please provide a complete, standalone, compilable example, instead of
just a snippet. Your post does not make it clear if array[] is an
automatic variable; if this is the case, it''s size of nearly 100 MB
might just be too much on your platform.
--
:wq
^X^Cy^K^X^C^C^C^C


On 2006-06-11, tomy <to******@gmail.com> wrote:

Hi all:
There is an amazing coredump in my C code, I was thinking it over and
over...
The code is simple as below:

//*************************************
const unsigned long int len = 102400000;
int array[len];
unsigned long int i;
for(i=0; i<len; i++)
{
array[i] = 0; //The coredump line;
}
//*************************************

with gdb, when variable i came to 0, the "array[i]=0", the process
received segmentation fault and left coredump. Is there any wrong in
THAT line? It seems all right, with the condition i=0.



I think this program should be OK, assuming it''s C99 and assuming your
machine''s stack is big enough. The array is rather a big object to put
on the stack, and the coredump may well be caused indirectly by a stack
overflow.


这篇关于一个退出奇怪的coredump的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆