Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/mod_init_exit_hooks_2.stp

raw
1 %{
2 #define STAP_MODULE_INIT_HOOK my_init
3 #define STAP_MODULE_EXIT_HOOK my_fini
4
5 long *my_global_ptr = NULL;
6
7 static int my_init(void) {
8 my_global_ptr = _stp_vzalloc(sizeof(long));
9 if (my_global_ptr == NULL) {
10 return ENOMEM;
11 }
12 *my_global_ptr = 17;
13 return 0;
14 }
15
16 static void my_fini(void) {
17 _stp_vfree(my_global_ptr);
18 }
19 %}
20
21 function get_val:long() %{
22 if (my_global_ptr == NULL) {
23 STAP_ERROR ("cannot resolve id in namespace");
24 } else {
25 STAP_RETURN(*my_global_ptr);
26 }
27 %}
28
29 probe oneshot {
30 println("res: ", get_val());
31 }