|
|
@@ -5,7 +5,11 @@
|
|
5
|
5
|
|
|
6
|
6
|
#include <linux/ptrace.h>
|
|
7
|
7
|
|
|
|
8
|
+#include "func.h"
|
|
|
9
|
+#include "node.h"
|
|
8
|
10
|
#include "ply.h"
|
|
|
11
|
+#include "sym.h"
|
|
|
12
|
+#include "type.h"
|
|
9
|
13
|
|
|
10
|
14
|
struct kprobe {
|
|
11
|
15
|
};
|
|
|
@@ -24,12 +28,12 @@ struct kprobe {
|
|
24
|
28
|
/* return 0; */
|
|
25
|
29
|
/* } */
|
|
26
|
30
|
|
|
27
|
|
-/* static inline int is_arg(const char *name) */
|
|
28
|
|
-/* { */
|
|
29
|
|
-/* return (strstr(name, "arg") == name) */
|
|
30
|
|
-/* && (strlen(name) == 4) */
|
|
31
|
|
-/* && (name[3] >= '0' && name[3] <= '9'); */
|
|
32
|
|
-/* } */
|
|
|
31
|
+static inline int is_arg(const char *name)
|
|
|
32
|
+{
|
|
|
33
|
+ return (strstr(name, "arg") == name)
|
|
|
34
|
+ && (strlen(name) == 4)
|
|
|
35
|
+ && (name[3] >= '0' && name[3] <= '9');
|
|
|
36
|
+}
|
|
33
|
37
|
|
|
34
|
38
|
/* static int kprobe_rewrite_arg(prog_t *prog, node_t *n) */
|
|
35
|
39
|
/* { */
|
|
|
@@ -89,9 +93,43 @@ struct kprobe {
|
|
89
|
93
|
/* return sym_add(prog->locals, n->ident, t, &n->sym); */
|
|
90
|
94
|
/* } */
|
|
91
|
95
|
|
|
|
96
|
+static const struct func kprobe_arg_func = {
|
|
|
97
|
+ .name = "argN",
|
|
|
98
|
+
|
|
|
99
|
+ /* for now, in the future we could read dwarf symbols to
|
|
|
100
|
+ * figure out the real type. */
|
|
|
101
|
+ .type = &t_ulong,
|
|
|
102
|
+ .static_ret = 1,
|
|
|
103
|
+};
|
|
|
104
|
+
|
|
92
|
105
|
static int kprobe_sym_alloc(struct prog *prog, struct node *n)
|
|
93
|
106
|
{
|
|
94
|
|
- return -ENOENT;
|
|
|
107
|
+ const struct func *func = NULL;
|
|
|
108
|
+ int err;
|
|
|
109
|
+
|
|
|
110
|
+ switch (n->ntype) {
|
|
|
111
|
+ case N_EXPR:
|
|
|
112
|
+ break;
|
|
|
113
|
+ case N_IDENT:
|
|
|
114
|
+ if (is_arg(n->ident.name))
|
|
|
115
|
+ func = &kprobe_arg_func;
|
|
|
116
|
+ break;
|
|
|
117
|
+ default:
|
|
|
118
|
+ break;
|
|
|
119
|
+ }
|
|
|
120
|
+
|
|
|
121
|
+ if (!func)
|
|
|
122
|
+ return -ENOENT;
|
|
|
123
|
+
|
|
|
124
|
+ err = func_static_validate(func, n);
|
|
|
125
|
+ if (err)
|
|
|
126
|
+ return err;
|
|
|
127
|
+
|
|
|
128
|
+ n->sym = sym_alloc(prog->locals, n, func);
|
|
|
129
|
+
|
|
|
130
|
+ if (func->static_ret)
|
|
|
131
|
+ n->sym->type = func_return_type(func);
|
|
|
132
|
+ return 0;
|
|
95
|
133
|
}
|
|
96
|
134
|
|
|
97
|
135
|
static int kprobe_probe(struct prog *prog)
|