Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/externalvar.c

raw
1 /* externalvar test case
2 * Copyright (C) 2009, Red Hat Inc.
3 *
4 * This file is part of systemtap, and is free software. You can
5 * redistribute it and/or modify it under the terms of the GNU General
6 * Public License (GPL); either version 2, or (at your option) any
7 * later version.
8 *
9 * Tests that an external exported variable can be accessed.
10 */
11
12 #include <stdlib.h>
13
14 // function from our library
15 int lib_main (void);
16
17 struct exestruct
18 {
19 char c;
20 int i;
21 long l;
22 struct exestruct *s1;
23 struct exestruct *s2;
24 };
25
26 char exevar_c;
27 int exevar_i;
28 long exevar_l;
29 struct exestruct *exe_s;
30
31 static char stat_exevar_c;
32 static int stat_exevar_i;
33 static long stat_exevar_l;
34 static struct exestruct *stat_exe_s;
35
36 static void
37 main_call ()
38 {
39 asm (""); // dummy method, just to probe and extract and jump into lib.
40 lib_main ();
41 }
42
43 // We're using the asm() statement to make sure gcc doesn't optimize
44 // the variables away.
45
46 int
47 main ()
48 {
49 exevar_c = 42;
50 stat_exevar_c = exevar_c;
51 asm ("nop" : "=r"(stat_exevar_c) : "r"(stat_exevar_c));
52 exevar_i = 2;
53 stat_exevar_i = exevar_i;
54 asm ("nop" : "=r"(stat_exevar_i) : "r"(stat_exevar_i));
55 exevar_l = 21;
56 stat_exevar_l = exevar_l;
57 asm ("nop" : "=r"(stat_exevar_l) : "r"(stat_exevar_l));
58 exe_s = (struct exestruct *) malloc(sizeof(struct exestruct));
59 exe_s->i =1;
60 exe_s->l =2;
61 exe_s->c =3;
62 exe_s->s1 = NULL;
63 exe_s->s2 = exe_s;
64 stat_exe_s = exe_s;
65 asm ("nop" : "=r"(stat_exe_s) : "r"(stat_exe_s));
66 main_call ();
67 return 0;
68 }