]> sourceware.org Git - systemtap.git/blob - runtime/probes.c
19539044d1fc379b4f8a8ae2429616512906df11
[systemtap.git] / runtime / probes.c
1 /* -*- linux-c -*-
2 * Functions for Registering and Unregistering Probes
3 * Copyright (C) 2005 Red Hat Inc.
4 *
5 * This file is part of systemtap, and is free software. You can
6 * redistribute it and/or modify it under the terms of the GNU General
7 * Public License (GPL); either version 2, or (at your option) any
8 * later version.
9 */
10
11 #ifndef _PROBES_C_
12 #define _PROBES_C
13
14 /** @file probes.c
15 * @brief Functions to assist loading and unloading groups of probes.
16 */
17
18 /** Unregister a group of jprobes.
19 * @param probes Pointer to an array of struct jprobe.
20 * @param num_probes Number of probes in the array.
21 */
22
23 void _stp_unregister_jprobes (struct jprobe *probes, int num_probes)
24 {
25 int i;
26 for (i = 0; i < num_probes; i++)
27 unregister_jprobe(&probes[i]);
28 dbug("All jprobes removed\n");
29 }
30
31 /** Register a group of jprobes.
32 * @param probes Pointer to an array of struct jprobe.
33 * @param num_probes Number of probes in the array.
34 * @return 0 on success.
35 */
36
37 int _stp_register_jprobes (struct jprobe *probes, int num_probes)
38 {
39 int i, ret ;
40 unsigned long addr;
41
42 for (i = 0; i < num_probes; i++) {
43 addr =kallsyms_lookup_name((char *)probes[i].kp.addr);
44 if (addr == 0) {
45 _stp_warn("function %s not found!\n", (char *)probes[i].kp.addr);
46 ret = -1; /* FIXME */
47 goto out;
48 }
49 dbug("inserting jprobe at %s (%p)\n", probes[i].kp.addr, addr);
50 probes[i].kp.addr = (kprobe_opcode_t *)addr;
51 ret = register_jprobe(&probes[i]);
52 if (ret)
53 goto out;
54 }
55 return 0;
56 out:
57 _stp_warn("probe module initialization failed. Exiting...\n");
58 _stp_unregister_jprobes(probes, i);
59 return ret;
60 }
61
62 /** Unregister a group of kprobes.
63 * @param probes Pointer to an array of struct kprobe.
64 * @param num_probes Number of probes in the array.
65 */
66
67 void _stp_unregister_kprobes (struct kprobe *probes, int num_probes)
68 {
69 int i;
70 for (i = 0; i < num_probes; i++)
71 unregister_kprobe(&probes[i]);
72 dbug("All kprobes removed\n");
73 }
74
75
76 #ifdef USE_RET_PROBES
77 /** Unregister a group of return probes.
78 * @param probes Pointer to an array of struct kretprobe.
79 * @param num_probes Number of probes in the array.
80 */
81 void _stp_unregister_kretprobes (struct kretprobe *probes, int num_probes)
82 {
83 int i;
84 for (i = 0; i < num_probes; i++)
85 unregister_kretprobe(&probes[i]);
86 dbug("All return probes removed\n");
87 }
88 #endif
89
90 /** Register a group of kprobes.
91 * @param probes Pointer to an array of struct kprobe.
92 * @param num_probes Number of probes in the array.
93 * @return 0 on success.
94 */
95 int _stp_register_kprobes (struct kprobe *probes, int num_probes)
96 {
97 int i, ret ;
98 unsigned long addr;
99
100 for (i = 0; i < num_probes; i++) {
101 addr = kallsyms_lookup_name((char *)probes[i].addr);
102 if (addr == 0) {
103 _stp_warn("function %s not found!\n", (char *)probes[i].addr);
104 ret = -1;
105 goto out;
106 }
107 dbug("inserting kprobe at %s (%p)\n", probes[i].addr, addr);
108 probes[i].addr = (kprobe_opcode_t *)addr;
109 ret = register_kprobe(&probes[i]);
110 if (ret)
111 goto out;
112 }
113 return 0;
114 out:
115 _stp_warn("probe module initialization failed. Exiting...\n");
116 _stp_unregister_kprobes(probes, i);
117 return ret;
118 }
119
120 #ifdef USE_RET_PROBES
121 /** Register a group of return probes.
122 * @param probes Pointer to an array of struct kretprobe.
123 * @param num_probes Number of probes in the array.
124 * @return 0 on success.
125 */
126 int _stp_register_kretprobes (struct kretprobe *probes, int num_probes)
127 {
128 int i, ret ;
129 unsigned long addr;
130
131 for (i = 0; i < num_probes; i++) {
132 addr = kallsyms_lookup_name((char *)probes[i].kp.addr);
133 if (addr == 0) {
134 _stp_warn("function %s not found!\n",
135 (char *)probes[i].kp.addr);
136 ret = -1; /* FIXME */
137 goto out;
138 }
139 dbug("inserting kretprobe at %s (%p)\n", probes[i].kp.addr, addr);
140 probes[i].kp.addr = (kprobe_opcode_t *)addr;
141 ret = register_kretprobe(&probes[i]);
142 if (ret)
143 goto out;
144 }
145 return 0;
146 out:
147 _stp_warn("probe module initialization failed. Exiting...\n");
148 _stp_unregister_kretprobes(probes, i);
149 return ret;
150 }
151 #endif
152 #endif /* _PROBES_C */
This page took 0.044701 seconds and 4 git commands to generate.