2 /* Check of variable location identification when using .debug_types. */
4 /* Relevant compile flags are:
6 -Wall -g -I$prefix/include/valgrind -gdwarf-4 -fdebug-types-section
8 eg -Wall -g -I`pwd`/Inst/include/valgrind -gdwarf-4 -fdebug-types-section
15 #include "tests/sys_mman.h"
16 #include <sys/types.h>
19 #include "memcheck/memcheck.h"
21 /* Cause memcheck to complain about the address "a" and so to print
22 its best guess as to what "a" actually is.*/
23 void croak ( void* aV
)
25 if(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(aV
,1) != 0)
28 char* undefp
= malloc(1);
32 (void) VALGRIND_CHECK_MEM_IS_DEFINED(a
, 1);
52 struct s1
* onheap
= malloc(sizeof (struct s1
));
64 /* Describe anonymous mmap-ed */
65 p
= mmap( 0, 16 * 1024, PROT_READ
|PROT_WRITE
,
66 MAP_PRIVATE
|MAP_ANONYMOUS
, -1, 0 );
67 assert(p
!= MAP_FAILED
);
70 /* Describe file mmap-ed */
71 snprintf(filename
, sizeof(filename
), "./valgrind-dw4-test.%ld",
76 fd
= open(filename
, O_RDWR
| O_CREAT
, S_IRUSR
| S_IWUSR
);
78 n
= write(fd
, filename
, strlen(filename
));
80 q
= mmap(NULL
, 100, PROT_READ
|PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
81 assert (q
!= MAP_FAILED
);
85 /* Describe memory in or past the heap end. */
87 croak(addr
); // in the first brk page, after brk_limit
88 sbrk(4 * 1024); // increase brk segment
89 croak(addr
); // Now, must be inside.
90 addr
= (void *) ((char*)addr
+ 2 * 1024);
91 croak(addr
); // Must still be inside.
93 croak(addr
); // Must now be after.