|
From: Nicholas N. <nj...@ca...> - 2003-08-05 10:02:07
|
On Tue, 5 Aug 2003 Bor...@pd... wrote:
> I've just started to use valgrind. But my philosophy on every program is,
> it's better to tell the user what's the problem if you can, then to let him
> guess where the problem lies.
> I think it would be a really usefull feature for a lot of users, if you
> could write a short message,
> When you know that the programm will write a core.
> By supervising the memory you should know when some program tries to
> dereference a NULL-Pointer.
As I said, Valgrind does tell you this:
==8495== Invalid read of size 4
==8495== at 0x804830E: main (core.c:5)
==8495== by 0x8048264: ??? (start.S:81)
==8495== Address 0x0 is not stack'd, malloc'd or free'd
Segmentation fault (core dumped)
I think your suggested message and prompt would get annoying quite
quickly; it's just repeating information. Also, Vincent made a good
point about programs for which an interactive prompt is unsuitable.
> Till now I'am only disappointed by one point about valgrind, and that is the
> lack of monitoring of local memory within function call. Especially detects
> it no under or over runs for arrays.
>
> For Example take the following program:
> #include <stdio.h>
>
> int main( int argc, char** argv )
> {
>
> int test[3];
> test[4] = 42; // out of bounds write
> printf("%d\n", test[4] );
Yes, this is an array overrun.
> char* x = "test";
> x[5] = 'x'; // the same as above
> printf("%s\n", x ); // causes memory dump
It's actually the assignment to x[5] that cause the seg fault. Run your
core file through gdb to see. The reason is that you're writing to
read-only memory. There was a thread on this mailing list about this just
the other day called "detect writing to TOC(?)". The (well, my)
conclusion was that, yes, writing to read-only memory can cause seg
faults, but they're rare and detecting them would have a big performance
cost, so it's not worth it. AFAIK, writing to read-only memory is the
only way a program can seg fault without Valgrind giving a warning first.
> return 0;
> }
>
>
> I think this are really common bugs, which would be really usefull to
> detect.
You're absolutely right, and if anyone knows how to do it without access
to the program's source code, with reasonable performance, and without
horrific complexity, we'd love to know :)
> Especially the second leads to a really bad behaviour by dumping your
> memory.
Well, the array overruns not detected by Valgrind will never cause a seg
fault. As I said, the dump for the program above is caused by writing to
read-only memory.
N
|