Is there a straight forward way to mark a memory region temporarily as "Read Only" in valgrind, similar to VALGRIND_MAKE_MEM_NOACCESS?
As an Example:
==942339== Memcheck, a memory error detector
==942339== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==942339== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==942339== Command: ./a.out
==942339==
==942339== Invalid read of size 4
==942339== at 0x40085C: main (example.c:10)
==942339== Address 0x1ffeffe724 is 0 bytes inside a READING IS ALLOWED IN THIS BLOCK of size 4 client-defined
==942339== at 0x4007E0: main (example.c:7)
==942339==
==942339== Invalid read of size 4
==942339== at 0x400862: main (example.c:11)
==942339== Address 0x1ffeffe724 is 0 bytes inside a READING IS ALLOWED IN THIS BLOCK of size 4 client-defined
==942339== at 0x4007E0: main (example.c:7)
==942339==
==942339== Invalid write of size 4
==942339== at 0x400868: main (example.c:11)
==942339== Address 0x1ffeffe724 is 0 bytes inside a READING IS ALLOWED IN THIS BLOCK of size 4 client-defined
==942339== at 0x4007E0: main (example.c:7)
==942339==
==942339== Invalid read of size 4
==942339== at 0x400A31: main (example.c:18)
==942339== Address 0x1ffeffe724 is 0 bytes inside a READING AND WRITING IS FORBIDDEN IN THIS BLOCK of size 4 client-defined
==942339== at 0x4009B5: main (example.c:15)
==942339==
==942339== Invalid read of size 4
==942339== at 0x400A37: main (example.c:19)
==942339== Address 0x1ffeffe724 is 0 bytes inside a READING AND WRITING IS FORBIDDEN IN THIS BLOCK of size 4 client-defined
==942339== at 0x4009B5: main (example.c:15)
==942339==
==942339== Invalid write of size 4
==942339== at 0x400A3D: main (example.c:19)
==942339== Address 0x1ffeffe724 is 0 bytes inside a READING AND WRITING IS FORBIDDEN IN THIS BLOCK of size 4 client-defined
==942339== at 0x4009B5: main (example.c:15)
==942339==
==942339==
==942339== HEAP SUMMARY:
==942339== in use at exit: 0 bytes in 0 blocks
==942339== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==942339==
==942339== All heap blocks were freed -- no leaks are possible
==942339==
==942339== For lists of detected and suppressed errors, rerun with: -s
==942339== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)
But don't want the first 2 errors of this report to be considered errors. The example code:
#include "memcheck.h"
int main(int argc, char **argv) {
int a = 10;
int b =0;
int valgrind_handle = VALGRIND_CREATE_BLOCK(&a, sizeof(a),
"READING IS ALLOWED IN THIS BLOCK");
VALGRIND_MAKE_MEM_NOACCESS(&a, sizeof(a));
b=a;// allowed to read a
a++;// forbidden to write a
VALGRIND_MAKE_MEM_DEFINED(&a, sizeof(a));
a++;// allowed
VALGRIND_DISCARD(valgrind_handle);
valgrind_handle = VALGRIND_CREATE_BLOCK(&a, sizeof(a),
"READING AND WRITING IS FORBIDDEN IN THIS BLOCK");
VALGRIND_MAKE_MEM_NOACCESS(&a, sizeof(a));
b=a;// forbidden
a++;// forbidden
VALGRIND_MAKE_MEM_DEFINED(&a, sizeof(a));
VALGRIND_DISCARD(valgrind_handle);
return 0;
}
Is there a better way than manually post-process the output to filter the unwanted errors based on the given block-names?