1
2/* Check of variable location identification when using .debug_types.  */
3
4/* Relevant compile flags are:
5
6   -Wall -g -I$prefix/include/valgrind -gdwarf-4 -fdebug-types-section
7
8   eg -Wall -g -I`pwd`/Inst/include/valgrind -gdwarf-4 -fdebug-types-section
9*/
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <assert.h>
14#include "memcheck/memcheck.h"
15
16/* Cause memcheck to complain about the address "a" and so to print
17   its best guess as to what "a" actually is.  a must be
18   addressible. */
19
20void croak ( void* aV )
21{
22  char* a = (char*)aV;
23  char* undefp = malloc(1);
24  char saved = *a;
25  assert(undefp);
26  *a = *undefp;
27  VALGRIND_CHECK_MEM_IS_DEFINED(a, 1);
28  *a = saved;
29  free(undefp);
30}
31
32struct s1
33{
34  char c;
35  short s;
36  int i;
37  long l;
38  float f;
39  double d;
40};
41
42struct s1 S2[30];
43
44int main ( void )
45{
46  struct s1 local;
47  struct s1* onheap = malloc(sizeof (struct s1));
48  assert(onheap);
49  croak(&onheap->i);
50
51  croak( &S2[0].i );
52  croak( &local.i );
53  return 0;
54}
55