|
From: juris <ju...@mt...> - 2015-04-08 05:45:13
|
Hello, I was wondering if it is possible to partially mark a memory location as undefined when running under valgrind. I am using a custom allocator, that allocates a some bits in a bitmap for each memory allocation. I would like to catch access to these bits before they are initialized. Is there some way to do it? Thank you for the help. |
|
From: Azat K. <a3a...@gm...> - 2015-04-08 06:00:54
|
On Wed, Apr 08, 2015 at 08:43:27AM +0300, juris wrote: > Hello, I was wondering if it is possible to partially mark > a memory location as undefined when running under valgrind. > > I am using a custom allocator, that allocates a some bits > in a bitmap for each memory allocation. I would like to catch > access to these bits before they are initialized. Is there some > way to do it? > > Thank you for the help. You could look at VALGRIND_SET_VBITS here: http://valgrind.org/docs/manual/mc-manual.html Example here: http://repo.or.cz/w/valgrind.git/blob/HEAD:/memcheck/tests/metadata.c |
|
From: juris <ju...@mt...> - 2015-04-08 09:37:53
|
On Wed, 8 Apr 2015 09:00:43 +0300 Azat Khuzhin <a3a...@gm...> wrote: > You could look at VALGRIND_SET_VBITS here: > http://valgrind.org/docs/manual/mc-manual.html > > Example here: > http://repo.or.cz/w/valgrind.git/blob/HEAD:/memcheck/tests/metadata.c Thank you very much! The example is helpful. (But the documentation isn't :-( This looks sufficient to implement the marking of separate bits. Am I safe to assume that V bit value '0' will always mean 'defined' and '1' will mean 'undefined'? Or at least that this meaning will not be different for different address ranges? I cannot find this mentioned in manual... |
|
From: Florian K. <fl...@ei...> - 2015-04-08 09:48:50
|
On 08.04.2015 11:37, juris wrote: > Thank you very much! The example is helpful. (But the documentation isn't :-( You know how it is with documentation... Patches welcome. :) > This looks sufficient to implement the marking of separate bits. > Am I safe to assume that V bit value '0' will always mean 'defined' and > '1' will mean 'undefined'? Yes. memcheck/mc_include.h:#define V_BIT_DEFINED 0 memcheck/mc_include.h:#define V_BIT_UNDEFINED 1 Florian |
|
From: John R. <jr...@bi...> - 2015-04-08 06:09:46
|
> Hello, I was wondering if it is possible to partially mark > a memory location as undefined when running under valgrind. Quoting the documentation http://valgrind.org/info/tools.html : > Memcheck tracks addressability at the byte-level, and initialisation of values at the bit-level. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations Therefore: Run memcheck under a debugger, and watch while memcheck checks this program: ----- #include <stdlib.h> int *p; int main() { p = (int *)malloc(100); p[5] &= 0xec6da539; /* clear some bits, leave the rest uninit */ return p[0xff & p[5]]; /* indexing by uninit is an immediate error */ } ----- |