ruby-usdt 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +52 -34
- data/ext/usdt/test.rb +20 -3
- data/ext/usdt/usdt.c +46 -0
- data/lib/usdt/version.rb +1 -1
- metadata +8 -26
- data/ext/libusdt/LICENCE +0 -21
- data/ext/libusdt/Makefile +0 -148
- data/ext/libusdt/README.md +0 -81
- data/ext/libusdt/test.pl +0 -112
- data/ext/libusdt/test_mem_usage.c +0 -77
- data/ext/libusdt/test_usdt.c +0 -87
- data/ext/libusdt/usdt.c +0 -296
- data/ext/libusdt/usdt.h +0 -66
- data/ext/libusdt/usdt_dof.c +0 -128
- data/ext/libusdt/usdt_dof_file.c +0 -277
- data/ext/libusdt/usdt_dof_sections.c +0 -190
- data/ext/libusdt/usdt_internal.h +0 -95
- data/ext/libusdt/usdt_probe.c +0 -74
- data/ext/libusdt/usdt_tracepoints_i386.s +0 -69
- data/ext/libusdt/usdt_tracepoints_x86_64.s +0 -123
- data/ext/usdt/Makefile +0 -213
- data/ext/usdt/usdt.h +0 -57
data/ext/libusdt/usdt_dof_file.c
DELETED
@@ -1,277 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2012, Chris Andrews. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
#include "usdt_internal.h"
|
6
|
-
|
7
|
-
#include <stdio.h>
|
8
|
-
#include <stdlib.h>
|
9
|
-
|
10
|
-
static uint8_t
|
11
|
-
dof_version(uint8_t header_version)
|
12
|
-
{
|
13
|
-
uint8_t dof_version;
|
14
|
-
/* DOF versioning: Apple always needs version 3, but Solaris can use
|
15
|
-
1 or 2 depending on whether is-enabled probes are needed. */
|
16
|
-
#ifdef __APPLE__
|
17
|
-
dof_version = DOF_VERSION_3;
|
18
|
-
#else
|
19
|
-
switch(header_version) {
|
20
|
-
case 1:
|
21
|
-
dof_version = DOF_VERSION_1;
|
22
|
-
break;
|
23
|
-
case 2:
|
24
|
-
dof_version = DOF_VERSION_2;
|
25
|
-
break;
|
26
|
-
default:
|
27
|
-
dof_version = DOF_VERSION;
|
28
|
-
}
|
29
|
-
#endif
|
30
|
-
return dof_version;
|
31
|
-
}
|
32
|
-
|
33
|
-
#ifdef __APPLE__
|
34
|
-
static const char *helper = "/dev/dtracehelper";
|
35
|
-
|
36
|
-
static int
|
37
|
-
load_dof(int fd, dof_helper_t *dh)
|
38
|
-
{
|
39
|
-
int ret;
|
40
|
-
uint8_t buffer[sizeof(dof_ioctl_data_t) + sizeof(dof_helper_t)];
|
41
|
-
dof_ioctl_data_t* ioctlData = (dof_ioctl_data_t*)buffer;
|
42
|
-
user_addr_t val;
|
43
|
-
|
44
|
-
ioctlData->dofiod_count = 1;
|
45
|
-
memcpy(&ioctlData->dofiod_helpers[0], dh, sizeof(dof_helper_t));
|
46
|
-
|
47
|
-
val = (user_addr_t)(unsigned long)ioctlData;
|
48
|
-
ret = ioctl(fd, DTRACEHIOC_ADDDOF, &val);
|
49
|
-
|
50
|
-
if (ret < 0)
|
51
|
-
return ret;
|
52
|
-
|
53
|
-
return (int)(ioctlData->dofiod_helpers[0].dofhp_dof);
|
54
|
-
}
|
55
|
-
|
56
|
-
#else /* Solaris */
|
57
|
-
|
58
|
-
/* ignore Sol10 GA ... */
|
59
|
-
static const char *helper = "/dev/dtrace/helper";
|
60
|
-
|
61
|
-
static int
|
62
|
-
load_dof(int fd, dof_helper_t *dh)
|
63
|
-
{
|
64
|
-
return ioctl(fd, DTRACEHIOC_ADDDOF, dh);
|
65
|
-
}
|
66
|
-
|
67
|
-
#endif
|
68
|
-
|
69
|
-
static void
|
70
|
-
pad_section(usdt_dof_section_t *sec)
|
71
|
-
{
|
72
|
-
size_t i, pad;
|
73
|
-
|
74
|
-
if (sec->align > 1) {
|
75
|
-
i = sec->offset % sec->align;
|
76
|
-
if (i > 0) {
|
77
|
-
pad = sec->align - i;
|
78
|
-
sec->offset = (pad + sec->offset);
|
79
|
-
sec->pad = pad;
|
80
|
-
}
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
static void
|
85
|
-
dof_header(dof_hdr_t *header)
|
86
|
-
{
|
87
|
-
int i;
|
88
|
-
|
89
|
-
header->dofh_ident[DOF_ID_MAG0] = DOF_MAG_MAG0;
|
90
|
-
header->dofh_ident[DOF_ID_MAG1] = DOF_MAG_MAG1;
|
91
|
-
header->dofh_ident[DOF_ID_MAG2] = DOF_MAG_MAG2;
|
92
|
-
header->dofh_ident[DOF_ID_MAG3] = DOF_MAG_MAG3;
|
93
|
-
|
94
|
-
header->dofh_ident[DOF_ID_MODEL] = DOF_MODEL_NATIVE;
|
95
|
-
header->dofh_ident[DOF_ID_ENCODING] = DOF_ENCODE_NATIVE;
|
96
|
-
header->dofh_ident[DOF_ID_VERSION] = dof_version(2);
|
97
|
-
header->dofh_ident[DOF_ID_DIFVERS] = DIF_VERSION;
|
98
|
-
header->dofh_ident[DOF_ID_DIFIREG] = DIF_DIR_NREGS;
|
99
|
-
header->dofh_ident[DOF_ID_DIFTREG] = DIF_DTR_NREGS;
|
100
|
-
|
101
|
-
for (i = DOF_ID_PAD; i < DOF_ID_SIZE; i++)
|
102
|
-
header->dofh_ident[i] = 0;
|
103
|
-
|
104
|
-
header->dofh_flags = 0;
|
105
|
-
|
106
|
-
header->dofh_hdrsize = sizeof(dof_hdr_t);
|
107
|
-
header->dofh_secsize = sizeof(dof_sec_t);
|
108
|
-
header->dofh_secoff = sizeof(dof_hdr_t);
|
109
|
-
|
110
|
-
header->dofh_loadsz = 0;
|
111
|
-
header->dofh_filesz = 0;
|
112
|
-
header->dofh_pad = 0;
|
113
|
-
}
|
114
|
-
|
115
|
-
static size_t
|
116
|
-
add_header(usdt_dof_file_t *file, size_t offset, usdt_dof_section_t *section)
|
117
|
-
{
|
118
|
-
dof_sec_t header;
|
119
|
-
|
120
|
-
header.dofs_flags = section->flags;
|
121
|
-
header.dofs_type = section->type;
|
122
|
-
header.dofs_offset = section->offset;
|
123
|
-
header.dofs_size = section->size;
|
124
|
-
header.dofs_entsize = section->entsize;
|
125
|
-
header.dofs_align = section->align;
|
126
|
-
|
127
|
-
memcpy((file->dof + offset), &header, sizeof(dof_sec_t));
|
128
|
-
return (offset + sizeof(dof_sec_t));
|
129
|
-
}
|
130
|
-
|
131
|
-
static size_t
|
132
|
-
add_section(usdt_dof_file_t *file, size_t offset, usdt_dof_section_t *section)
|
133
|
-
{
|
134
|
-
if (section->pad > 0) {
|
135
|
-
/* maximum padding required is 7 */
|
136
|
-
memcpy((file->dof + offset), "\0\0\0\0\0\0\0", section->pad);
|
137
|
-
offset += section->pad;
|
138
|
-
}
|
139
|
-
|
140
|
-
memcpy((file->dof + offset), section->data, section->size);
|
141
|
-
return (offset + section->size);
|
142
|
-
}
|
143
|
-
|
144
|
-
int
|
145
|
-
usdt_dof_file_unload(usdt_dof_file_t *file)
|
146
|
-
{
|
147
|
-
int fd, ret;
|
148
|
-
|
149
|
-
if ((fd = open(helper, O_RDWR)) < 0)
|
150
|
-
return (-1);
|
151
|
-
|
152
|
-
ret = ioctl(fd, DTRACEHIOC_REMOVE, file->gen);
|
153
|
-
|
154
|
-
if (ret < 0)
|
155
|
-
return (-1);
|
156
|
-
|
157
|
-
if ((close(fd)) < 0)
|
158
|
-
return (-1);
|
159
|
-
|
160
|
-
return (0);
|
161
|
-
}
|
162
|
-
|
163
|
-
int
|
164
|
-
usdt_dof_file_load(usdt_dof_file_t *file, const char *module)
|
165
|
-
{
|
166
|
-
dof_helper_t dh;
|
167
|
-
dof_hdr_t *dof;
|
168
|
-
int fd;
|
169
|
-
|
170
|
-
dof = (dof_hdr_t *) file->dof;
|
171
|
-
|
172
|
-
dh.dofhp_dof = (uintptr_t)dof;
|
173
|
-
dh.dofhp_addr = (uintptr_t)dof;
|
174
|
-
(void) strncpy(dh.dofhp_mod, module, sizeof (dh.dofhp_mod));
|
175
|
-
|
176
|
-
if ((fd = open(helper, O_RDWR)) < 0)
|
177
|
-
return (-1);
|
178
|
-
|
179
|
-
file->gen = load_dof(fd, &dh);
|
180
|
-
|
181
|
-
if ((close(fd)) < 0)
|
182
|
-
return (-1);
|
183
|
-
|
184
|
-
if (file->gen < 0)
|
185
|
-
return (-1);
|
186
|
-
|
187
|
-
return (0);
|
188
|
-
}
|
189
|
-
|
190
|
-
void
|
191
|
-
usdt_dof_file_append_section(usdt_dof_file_t *file, usdt_dof_section_t *section)
|
192
|
-
{
|
193
|
-
usdt_dof_section_t *s;
|
194
|
-
|
195
|
-
if (file->sections == NULL) {
|
196
|
-
file->sections = section;
|
197
|
-
}
|
198
|
-
else {
|
199
|
-
for (s = file->sections; (s->next != NULL); s = s->next) ;
|
200
|
-
s->next = section;
|
201
|
-
}
|
202
|
-
}
|
203
|
-
|
204
|
-
void
|
205
|
-
usdt_dof_file_generate(usdt_dof_file_t *file, usdt_strtab_t *strtab)
|
206
|
-
{
|
207
|
-
dof_hdr_t header;
|
208
|
-
uint64_t filesz;
|
209
|
-
uint64_t loadsz;
|
210
|
-
usdt_dof_section_t *sec;
|
211
|
-
size_t offset;
|
212
|
-
|
213
|
-
dof_header(&header);
|
214
|
-
header.dofh_secnum = 6;
|
215
|
-
|
216
|
-
filesz = sizeof(dof_hdr_t) + (sizeof(dof_sec_t) * header.dofh_secnum);
|
217
|
-
loadsz = filesz;
|
218
|
-
|
219
|
-
strtab->offset = filesz;
|
220
|
-
pad_section((usdt_dof_section_t *)strtab);
|
221
|
-
filesz += strtab->size + strtab->pad;
|
222
|
-
|
223
|
-
if (strtab->flags & 1)
|
224
|
-
loadsz += strtab->size + strtab->pad;
|
225
|
-
|
226
|
-
for (sec = file->sections; sec != NULL; sec = sec->next) {
|
227
|
-
sec->offset = filesz;
|
228
|
-
pad_section(sec);
|
229
|
-
filesz += sec->size + sec->pad;
|
230
|
-
if (sec->flags & 1)
|
231
|
-
loadsz += sec->size + sec->pad;
|
232
|
-
}
|
233
|
-
|
234
|
-
header.dofh_loadsz = loadsz;
|
235
|
-
header.dofh_filesz = filesz;
|
236
|
-
memcpy(file->dof, &header, sizeof(dof_hdr_t));
|
237
|
-
|
238
|
-
offset = sizeof(dof_hdr_t);
|
239
|
-
|
240
|
-
offset = add_header(file, offset, (usdt_dof_section_t *)strtab);
|
241
|
-
|
242
|
-
for (sec = file->sections; sec != NULL; sec = sec->next)
|
243
|
-
offset = add_header(file, offset, sec);
|
244
|
-
|
245
|
-
offset = add_section(file, offset, (usdt_dof_section_t *)strtab);
|
246
|
-
|
247
|
-
for (sec = file->sections; sec != NULL; sec = sec->next)
|
248
|
-
offset = add_section(file, offset, sec);
|
249
|
-
}
|
250
|
-
|
251
|
-
usdt_dof_file_t *
|
252
|
-
usdt_dof_file_init(usdt_provider_t *provider, size_t size)
|
253
|
-
{
|
254
|
-
usdt_dof_file_t *file;
|
255
|
-
|
256
|
-
if ((file = malloc(sizeof(*file))) == NULL) {
|
257
|
-
usdt_error(provider, USDT_ERROR_MALLOC);
|
258
|
-
return (NULL);
|
259
|
-
}
|
260
|
-
|
261
|
-
if ((file->dof = valloc(size)) == NULL) {
|
262
|
-
usdt_error(provider, USDT_ERROR_VALLOC);
|
263
|
-
return (NULL);
|
264
|
-
}
|
265
|
-
|
266
|
-
file->sections = NULL;
|
267
|
-
file->size = size;
|
268
|
-
|
269
|
-
return (file);
|
270
|
-
}
|
271
|
-
|
272
|
-
void
|
273
|
-
usdt_dof_file_free(usdt_dof_file_t *file)
|
274
|
-
{
|
275
|
-
free(file->dof);
|
276
|
-
free(file);
|
277
|
-
}
|
@@ -1,190 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2012, Chris Andrews. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
#include "usdt_internal.h"
|
6
|
-
|
7
|
-
int
|
8
|
-
usdt_dof_probes_sect(usdt_dof_section_t *probes,
|
9
|
-
usdt_provider_t *provider, usdt_strtab_t *strtab)
|
10
|
-
{
|
11
|
-
usdt_probedef_t *pd;
|
12
|
-
dof_probe_t p;
|
13
|
-
dof_stridx_t type, argv;
|
14
|
-
uint8_t argc, i;
|
15
|
-
uint32_t argidx = 0;
|
16
|
-
uint32_t offidx = 0;
|
17
|
-
|
18
|
-
usdt_dof_section_init(probes, DOF_SECT_PROBES, 1);
|
19
|
-
|
20
|
-
for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
|
21
|
-
argc = 0;
|
22
|
-
argv = 0;
|
23
|
-
type = 0;
|
24
|
-
|
25
|
-
for (i = 0; i < pd->argc; i++) {
|
26
|
-
switch(pd->types[i]) {
|
27
|
-
case USDT_ARGTYPE_INTEGER:
|
28
|
-
type = usdt_strtab_add(strtab, "int");
|
29
|
-
break;
|
30
|
-
case USDT_ARGTYPE_STRING:
|
31
|
-
type = usdt_strtab_add(strtab, "char *");
|
32
|
-
break;
|
33
|
-
default:
|
34
|
-
break;
|
35
|
-
}
|
36
|
-
|
37
|
-
argc++;
|
38
|
-
if (argv == 0)
|
39
|
-
argv = type;
|
40
|
-
}
|
41
|
-
|
42
|
-
if (usdt_create_tracepoints(pd->probe) < 0) {
|
43
|
-
usdt_error(provider, USDT_ERROR_VALLOC);
|
44
|
-
return (-1);
|
45
|
-
}
|
46
|
-
|
47
|
-
#ifdef __x86_64__
|
48
|
-
p.dofpr_addr = (uint64_t) pd->probe->isenabled_addr;
|
49
|
-
#elif __i386__ || __i386
|
50
|
-
p.dofpr_addr = (uint32_t) pd->probe->isenabled_addr;
|
51
|
-
#else
|
52
|
-
#error "only x86_64 and i386 supported"
|
53
|
-
#endif
|
54
|
-
p.dofpr_func = usdt_strtab_add(strtab, pd->function);
|
55
|
-
p.dofpr_name = usdt_strtab_add(strtab, pd->name);
|
56
|
-
p.dofpr_nargv = argv;
|
57
|
-
p.dofpr_xargv = argv;
|
58
|
-
p.dofpr_argidx = argidx;
|
59
|
-
p.dofpr_offidx = offidx;
|
60
|
-
p.dofpr_nargc = argc;
|
61
|
-
p.dofpr_xargc = argc;
|
62
|
-
p.dofpr_noffs = 1;
|
63
|
-
p.dofpr_enoffidx = offidx;
|
64
|
-
p.dofpr_nenoffs = 1;
|
65
|
-
p.dofpr_pad1 = 0;
|
66
|
-
p.dofpr_pad2 = 0;
|
67
|
-
|
68
|
-
usdt_dof_section_add_data(probes, &p, sizeof(dof_probe_t));
|
69
|
-
probes->entsize = sizeof(dof_probe_t);
|
70
|
-
|
71
|
-
argidx += argc;
|
72
|
-
offidx++;
|
73
|
-
}
|
74
|
-
|
75
|
-
return (0);
|
76
|
-
}
|
77
|
-
|
78
|
-
int
|
79
|
-
usdt_dof_prargs_sect(usdt_dof_section_t *prargs, usdt_provider_t *provider)
|
80
|
-
{
|
81
|
-
usdt_probedef_t *pd;
|
82
|
-
uint8_t i;
|
83
|
-
|
84
|
-
usdt_dof_section_init(prargs, DOF_SECT_PRARGS, 2);
|
85
|
-
prargs->entsize = 1;
|
86
|
-
|
87
|
-
for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
|
88
|
-
for (i = 0; i < pd->argc; i++)
|
89
|
-
usdt_dof_section_add_data(prargs, &i, 1);
|
90
|
-
}
|
91
|
-
if (prargs->size == 0) {
|
92
|
-
i = 0;
|
93
|
-
if (usdt_dof_section_add_data(prargs, &i, 1) < 0) {
|
94
|
-
usdt_error(provider, USDT_ERROR_MALLOC);
|
95
|
-
return (-1);
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
return (0);
|
100
|
-
}
|
101
|
-
|
102
|
-
int
|
103
|
-
usdt_dof_proffs_sect(usdt_dof_section_t *proffs,
|
104
|
-
usdt_provider_t *provider, char *dof)
|
105
|
-
{
|
106
|
-
usdt_probedef_t *pd;
|
107
|
-
uint32_t off;
|
108
|
-
|
109
|
-
usdt_dof_section_init(proffs, DOF_SECT_PROFFS, 3);
|
110
|
-
proffs->entsize = 4;
|
111
|
-
|
112
|
-
for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
|
113
|
-
off = usdt_probe_offset(pd->probe, dof, pd->argc);
|
114
|
-
if (usdt_dof_section_add_data(proffs, &off, 4) < 0) {
|
115
|
-
usdt_error(provider, USDT_ERROR_MALLOC);
|
116
|
-
return (-1);
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
return (0);
|
121
|
-
}
|
122
|
-
|
123
|
-
int
|
124
|
-
usdt_dof_prenoffs_sect(usdt_dof_section_t *prenoffs,
|
125
|
-
usdt_provider_t *provider, char *dof)
|
126
|
-
{
|
127
|
-
usdt_probedef_t *pd;
|
128
|
-
uint32_t off;
|
129
|
-
|
130
|
-
usdt_dof_section_init(prenoffs, DOF_SECT_PRENOFFS, 4);
|
131
|
-
prenoffs->entsize = 4;
|
132
|
-
|
133
|
-
for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
|
134
|
-
off = usdt_is_enabled_offset(pd->probe, dof);
|
135
|
-
if (usdt_dof_section_add_data(prenoffs, &off, 4) < 0) {
|
136
|
-
usdt_error(provider, USDT_ERROR_MALLOC);
|
137
|
-
return (-1);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
return (0);
|
142
|
-
}
|
143
|
-
|
144
|
-
int
|
145
|
-
usdt_dof_provider_sect(usdt_dof_section_t *provider_s, usdt_provider_t *provider)
|
146
|
-
{
|
147
|
-
dof_provider_t p;
|
148
|
-
|
149
|
-
usdt_dof_section_init(provider_s, DOF_SECT_PROVIDER, 5);
|
150
|
-
|
151
|
-
p.dofpv_strtab = 0;
|
152
|
-
p.dofpv_probes = 1;
|
153
|
-
p.dofpv_prargs = 2;
|
154
|
-
p.dofpv_proffs = 3;
|
155
|
-
p.dofpv_prenoffs = 4;
|
156
|
-
p.dofpv_name = 1; /* provider name always first strtab entry. */
|
157
|
-
|
158
|
-
/*
|
159
|
-
* Stability is something of a hack. Everything is marked *
|
160
|
-
* "stable" here to permit use of the "args" array, which is *
|
161
|
-
* needed to access arguments past "arg9".
|
162
|
-
*
|
163
|
-
* It should be up to the creator of the provider to decide
|
164
|
-
* this, though, and it should be possible to set the
|
165
|
-
* appropriate stability at creation time.
|
166
|
-
*/
|
167
|
-
|
168
|
-
p.dofpv_provattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
|
169
|
-
DTRACE_STABILITY_STABLE,
|
170
|
-
DTRACE_STABILITY_STABLE);
|
171
|
-
p.dofpv_modattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
|
172
|
-
DTRACE_STABILITY_STABLE,
|
173
|
-
DTRACE_STABILITY_STABLE);
|
174
|
-
p.dofpv_funcattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
|
175
|
-
DTRACE_STABILITY_STABLE,
|
176
|
-
DTRACE_STABILITY_STABLE);
|
177
|
-
p.dofpv_nameattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
|
178
|
-
DTRACE_STABILITY_STABLE,
|
179
|
-
DTRACE_STABILITY_STABLE);
|
180
|
-
p.dofpv_argsattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
|
181
|
-
DTRACE_STABILITY_STABLE,
|
182
|
-
DTRACE_STABILITY_STABLE);
|
183
|
-
|
184
|
-
if ((usdt_dof_section_add_data(provider_s, &p, sizeof(p))) < 0) {
|
185
|
-
usdt_error(provider, USDT_ERROR_MALLOC);
|
186
|
-
return (-1);
|
187
|
-
}
|
188
|
-
|
189
|
-
return (0);
|
190
|
-
}
|
data/ext/libusdt/usdt_internal.h
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2012, Chris Andrews. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
#include <sys/dtrace.h>
|
6
|
-
#include <sys/types.h>
|
7
|
-
#include <sys/mman.h>
|
8
|
-
|
9
|
-
#include <errno.h>
|
10
|
-
#include <string.h>
|
11
|
-
#include <fcntl.h>
|
12
|
-
#include <unistd.h>
|
13
|
-
#include <stdint.h>
|
14
|
-
#include <assert.h>
|
15
|
-
|
16
|
-
#ifndef __APPLE__
|
17
|
-
/* solaris and freebsd */
|
18
|
-
#include <stdlib.h>
|
19
|
-
#endif
|
20
|
-
|
21
|
-
#define FUNC_SIZE 32
|
22
|
-
|
23
|
-
#include "usdt.h"
|
24
|
-
|
25
|
-
extern void usdt_tracepoint_isenabled(void);
|
26
|
-
extern void usdt_tracepoint_probe(void);
|
27
|
-
extern void usdt_tracepoint_end(void);
|
28
|
-
extern void usdt_probe_args(void *, int, void**);
|
29
|
-
|
30
|
-
uint32_t usdt_probe_offset(usdt_probe_t *probe, char *dof, uint8_t argc);
|
31
|
-
uint32_t usdt_is_enabled_offset(usdt_probe_t *probe, char *dof);
|
32
|
-
int usdt_create_tracepoints(usdt_probe_t *probe);
|
33
|
-
|
34
|
-
typedef struct usdt_dof_section {
|
35
|
-
dof_secidx_t index;
|
36
|
-
uint32_t type;
|
37
|
-
uint32_t flags;
|
38
|
-
uint32_t align;
|
39
|
-
uint64_t offset;
|
40
|
-
uint64_t size;
|
41
|
-
uint32_t entsize;
|
42
|
-
size_t pad;
|
43
|
-
struct usdt_dof_section *next;
|
44
|
-
char *data;
|
45
|
-
} usdt_dof_section_t;
|
46
|
-
|
47
|
-
int usdt_dof_section_init(usdt_dof_section_t *section,
|
48
|
-
uint32_t type, dof_secidx_t index);
|
49
|
-
int usdt_dof_section_add_data(usdt_dof_section_t *section,
|
50
|
-
void *data, size_t length);
|
51
|
-
|
52
|
-
typedef struct usdt_strtab {
|
53
|
-
dof_secidx_t index;
|
54
|
-
uint32_t type;
|
55
|
-
uint32_t flags;
|
56
|
-
uint32_t align;
|
57
|
-
uint64_t offset;
|
58
|
-
uint64_t size;
|
59
|
-
uint32_t entsize;
|
60
|
-
size_t pad;
|
61
|
-
int strindex;
|
62
|
-
char *data;
|
63
|
-
} usdt_strtab_t;
|
64
|
-
|
65
|
-
int usdt_strtab_init(usdt_strtab_t *strtab, dof_secidx_t index);
|
66
|
-
dof_stridx_t usdt_strtab_add(usdt_strtab_t *strtab, const char *string);
|
67
|
-
char *usdt_strtab_header(usdt_strtab_t *strtab);
|
68
|
-
size_t usdt_strtab_size(usdt_strtab_t *strtab);
|
69
|
-
|
70
|
-
size_t usdt_provider_dof_size(usdt_provider_t *provider, usdt_strtab_t *strtab);
|
71
|
-
|
72
|
-
typedef struct usdt_dof_file {
|
73
|
-
char *dof;
|
74
|
-
int gen;
|
75
|
-
size_t size;
|
76
|
-
usdt_dof_section_t *sections;
|
77
|
-
} usdt_dof_file_t;
|
78
|
-
|
79
|
-
usdt_dof_file_t *usdt_dof_file_init(usdt_provider_t *provider, size_t size);
|
80
|
-
void usdt_dof_file_append_section(usdt_dof_file_t *file, usdt_dof_section_t *section);
|
81
|
-
void usdt_dof_file_generate(usdt_dof_file_t *file, usdt_strtab_t *strtab);
|
82
|
-
int usdt_dof_file_load(usdt_dof_file_t *file, const char *module);
|
83
|
-
int usdt_dof_file_unload(usdt_dof_file_t *file);
|
84
|
-
|
85
|
-
int usdt_dof_probes_sect(usdt_dof_section_t *probes,
|
86
|
-
usdt_provider_t *provider, usdt_strtab_t *strtab);
|
87
|
-
int usdt_dof_prargs_sect(usdt_dof_section_t *prargs,
|
88
|
-
usdt_provider_t *provider);
|
89
|
-
int usdt_dof_proffs_sect(usdt_dof_section_t *proffs,
|
90
|
-
usdt_provider_t *provider, char *dof);
|
91
|
-
int usdt_dof_prenoffs_sect(usdt_dof_section_t *prenoffs,
|
92
|
-
usdt_provider_t *provider, char *dof);
|
93
|
-
int usdt_dof_provider_sect(usdt_dof_section_t *provider_s,
|
94
|
-
usdt_provider_t *provider);
|
95
|
-
|
data/ext/libusdt/usdt_probe.c
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2012, Chris Andrews. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
#include "usdt_internal.h"
|
6
|
-
|
7
|
-
#ifdef __APPLE__
|
8
|
-
|
9
|
-
uint32_t
|
10
|
-
usdt_probe_offset(usdt_probe_t *probe, char *dof, uint8_t argc)
|
11
|
-
{
|
12
|
-
uint32_t offset;
|
13
|
-
#ifdef __x86_64__
|
14
|
-
offset = ((uint64_t) probe->probe_addr - (uint64_t) dof + 2);
|
15
|
-
#elif __i386__
|
16
|
-
offset = ((uint32_t) probe->probe_addr - (uint32_t) dof + 2);
|
17
|
-
#else
|
18
|
-
#error "only x86_64 and i386 supported"
|
19
|
-
#endif
|
20
|
-
return (offset);
|
21
|
-
}
|
22
|
-
|
23
|
-
uint32_t
|
24
|
-
usdt_is_enabled_offset(usdt_probe_t *probe, char *dof)
|
25
|
-
{
|
26
|
-
uint32_t offset;
|
27
|
-
#ifdef __x86_64__
|
28
|
-
offset = ((uint64_t) probe->isenabled_addr - (uint64_t) dof + 6);
|
29
|
-
#elif __i386__
|
30
|
-
offset = ((uint32_t) probe->isenabled_addr - (uint32_t) dof + 6);
|
31
|
-
#else
|
32
|
-
#error "only x86_64 and i386 supported"
|
33
|
-
#endif
|
34
|
-
return (offset);
|
35
|
-
}
|
36
|
-
|
37
|
-
#else /* solaris and freebsd */
|
38
|
-
|
39
|
-
uint32_t
|
40
|
-
usdt_probe_offset(usdt_probe_t *probe, char *dof, uint8_t argc)
|
41
|
-
{
|
42
|
-
return (16);
|
43
|
-
}
|
44
|
-
|
45
|
-
uint32_t
|
46
|
-
usdt_is_enabled_offset(usdt_probe_t *probe, char *dof)
|
47
|
-
{
|
48
|
-
return (8);
|
49
|
-
}
|
50
|
-
|
51
|
-
#endif
|
52
|
-
|
53
|
-
int
|
54
|
-
usdt_create_tracepoints(usdt_probe_t *probe)
|
55
|
-
{
|
56
|
-
size_t size;
|
57
|
-
|
58
|
-
/* ensure that the tracepoints will fit the heap we're allocating */
|
59
|
-
size = ((char *)usdt_tracepoint_end - (char *)usdt_tracepoint_isenabled);
|
60
|
-
assert(size < FUNC_SIZE);
|
61
|
-
|
62
|
-
if ((probe->isenabled_addr = (int (*)())valloc(FUNC_SIZE)) == NULL)
|
63
|
-
return (-1);
|
64
|
-
|
65
|
-
size = ((char *)usdt_tracepoint_probe - (char *)usdt_tracepoint_isenabled);
|
66
|
-
probe->probe_addr = (char *)probe->isenabled_addr + size;
|
67
|
-
|
68
|
-
memcpy((void *)probe->isenabled_addr,
|
69
|
-
(const void *)usdt_tracepoint_isenabled, FUNC_SIZE);
|
70
|
-
mprotect((void *)probe->isenabled_addr, FUNC_SIZE,
|
71
|
-
PROT_READ | PROT_WRITE | PROT_EXEC);
|
72
|
-
|
73
|
-
return (0);
|
74
|
-
}
|
@@ -1,69 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (c) 2012, Chris Andrews. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
/*
|
6
|
-
* Stub functions containing DTrace tracepoints for probes and
|
7
|
-
* is-enabled probes. These functions are copied for each probe
|
8
|
-
* dynamically created.
|
9
|
-
*
|
10
|
-
*/
|
11
|
-
.text
|
12
|
-
|
13
|
-
.align 4, 0x90
|
14
|
-
.globl usdt_tracepoint_isenabled
|
15
|
-
.globl _usdt_tracepoint_isenabled
|
16
|
-
.globl usdt_tracepoint_probe
|
17
|
-
.globl _usdt_tracepoint_probe
|
18
|
-
.globl usdt_tracepoint_end
|
19
|
-
.globl _usdt_tracepoint_end
|
20
|
-
.globl usdt_probe_args
|
21
|
-
.globl _usdt_probe_args
|
22
|
-
|
23
|
-
usdt_tracepoint_isenabled:
|
24
|
-
_usdt_tracepoint_isenabled:
|
25
|
-
pushl %ebp
|
26
|
-
movl %esp, %ebp
|
27
|
-
subl $8, %esp
|
28
|
-
xorl %eax, %eax
|
29
|
-
nop
|
30
|
-
nop
|
31
|
-
leave
|
32
|
-
ret
|
33
|
-
usdt_tracepoint_probe:
|
34
|
-
_usdt_tracepoint_probe:
|
35
|
-
nop
|
36
|
-
nop
|
37
|
-
nop
|
38
|
-
nop
|
39
|
-
nop
|
40
|
-
addl $0x20,%esp
|
41
|
-
leave
|
42
|
-
usdt_tracepoint_end:
|
43
|
-
_usdt_tracepoint_end:
|
44
|
-
ret
|
45
|
-
|
46
|
-
/*
|
47
|
-
* Probe argument marshalling, i386 style
|
48
|
-
*
|
49
|
-
*/
|
50
|
-
|
51
|
-
usdt_probe_args:
|
52
|
-
_usdt_probe_args:
|
53
|
-
pushl %ebp
|
54
|
-
movl %esp,%ebp
|
55
|
-
subl $8,%esp
|
56
|
-
subl $8,%esp
|
57
|
-
movl 8(%ebp),%ebx
|
58
|
-
movl 0xc(%ebp),%ecx
|
59
|
-
test %ecx,%ecx
|
60
|
-
je fire
|
61
|
-
args: movl %ecx,%eax
|
62
|
-
sal $2,%eax
|
63
|
-
subl $4,%eax
|
64
|
-
addl 0x10(%ebp),%eax
|
65
|
-
pushl (%eax)
|
66
|
-
dec %ecx
|
67
|
-
jne args
|
68
|
-
fire: jmp *%ebx
|
69
|
-
|