When I'm trying to debug a C program written on Linux machine (right now, I'm using Visual C++ Express), I first get a stack overflow error. So when I clicked continue, I got another error message,
Access violation reading location 0x00030000
So I decide to debug step by step. So when I try it, it shows me the error
There is no source code available for the current location.
What is the reason for this error?
The Code
#if 1
while(1)
#endif
{
fillList();
#if 1
{
op_ds_bulk(ops, &total, 1);
temp = res("Bulk Write:", total, fp);
index = 0;
}
#endif
void op_ds_bulk(u_int ops, u_int * totalp, int update)
{
char encode_db[] = "encode";
if(update)
{
database_insert_bluk(list, ops);
database_sync();
*totalp = ops;
}
else
{
CHUNK prefetch[4096];
int random = rand() % (h-ops+1);
__os_clock(NULL, &start_time.secs, &start_time.usecs);
database_select_e开发者_如何学Pythonnd(65546, random, prefetch, ops);
__os_clock(NULL, &end_time.secs, &end_time.usecs);
*totalp = ops;
}
}
}
The invalid access might occur somewhere in the standard library code. The source for that is not available in the Express edition.
You might check the call stack for the part of your code that calls a library function, and work it from there.
Some time ago I had a similar problem, maybe it is related to yours?
I had an array on the stack (you have one too - prefetch
) and I accidently cleared it too far (out of bounds of the array), removing whatever information was beyond the array.
When you call a function, the return address is also stored on the stack (computer must know where to return from a function). Since I have cleared that, the program jumped under address 0x0 and SegFault-ed. When debugging, I also got a message "there is no source code at current location", because "current location" was 0x0 and of course there was no code there.
So I suspect that you go out-of-bounds on some array which is on the stack.
By looking at your code, I see two suspicious things:
The size of your prefetch array is 4096, but you call
database_select_end
with parameter 65546. Maybe it is ok (no idea what that function does) but maybe it is not ;)65546 is not a power of 2. 2^16=65536
I solved the problem by writing the same code with a different function name. It's so weird for me because it solved my problem. I don't know why.
精彩评论