ruby-dtrace 0.0.6 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/History.txt +21 -0
  2. data/Manifest.txt +86 -19
  3. data/README.txt +48 -6
  4. data/Rakefile +61 -20
  5. data/examples/scsi.rb +1 -1
  6. data/ext/dof/Makefile +154 -0
  7. data/ext/dof/constants.c +57 -0
  8. data/ext/dof/dof.h +56 -0
  9. data/ext/dof/dof_api.c +58 -0
  10. data/ext/dof/dof_helper.c +82 -0
  11. data/ext/dof/extconf.rb +4 -0
  12. data/ext/dof/file.c +90 -0
  13. data/ext/dof/generator.c +9 -0
  14. data/ext/dof/header.c +79 -0
  15. data/ext/dof/mkmf.log +10 -0
  16. data/ext/dof/parser.c +415 -0
  17. data/ext/dof/parser.h +10 -0
  18. data/ext/dof/section.c +312 -0
  19. data/ext/dtrace_aggdata.c +2 -2
  20. data/ext/dtrace_api.c +46 -34
  21. data/ext/dtrace_api.h +31 -7
  22. data/ext/dtrace_bufdata.c +3 -3
  23. data/ext/dtrace_hdl.c +66 -3
  24. data/ext/dtrace_probedata.c +4 -4
  25. data/ext/{dtrace_probe.c → dtrace_probedesc.c} +7 -7
  26. data/ext/extconf.rb +25 -0
  27. data/ext/i386-darwin/dtrace_probe.c +278 -0
  28. data/ext/i386-solaris/dtrace_probe.c +225 -0
  29. data/ext/stubs.txt +78 -0
  30. data/lib/dtrace.rb +34 -13
  31. data/lib/dtrace/aggregate.rb +40 -0
  32. data/lib/dtrace/aggregateset.rb +19 -0
  33. data/lib/dtrace/consumer.rb +174 -0
  34. data/lib/dtrace/data.rb +82 -0
  35. data/lib/dtrace/dof.rb +8 -0
  36. data/lib/dtrace/dof/file.rb +64 -0
  37. data/lib/dtrace/dof/section.rb +75 -0
  38. data/lib/dtrace/dof/section/strtab.rb +28 -0
  39. data/lib/{dtraceprintfrecord.rb → dtrace/printfrecord.rb} +4 -2
  40. data/lib/dtrace/probe.rb +3 -6
  41. data/lib/dtrace/probedata.rb +23 -0
  42. data/lib/dtrace/probedesc.rb +15 -0
  43. data/lib/dtrace/provider.rb +190 -169
  44. data/lib/dtrace/provider/klass.rb +33 -0
  45. data/lib/dtrace/provider/probedef.rb +24 -0
  46. data/lib/{dtracerecord.rb → dtrace/record.rb} +4 -2
  47. data/lib/{dtracestackrecord.rb → dtrace/stackrecord.rb} +10 -8
  48. data/lib/dtrace/version.rb +9 -0
  49. data/lib/dtraceconsumer.rb +3 -167
  50. data/plugin/dtrace/lib/dtracer.rb +4 -4
  51. data/test/apple-dof +0 -0
  52. data/test/disabled_probe_effect.txt +19 -0
  53. data/test/dof +0 -0
  54. data/test/dof2 +0 -0
  55. data/test/test_disabled_probe_effect.rb +56 -0
  56. data/test/test_dof_generator.rb +142 -0
  57. data/test/test_dof_helper.rb +106 -0
  58. data/test/test_dof_parser.rb +27 -0
  59. data/test/test_dof_providers.rb +278 -0
  60. data/test/test_dof_strtabs.rb +98 -0
  61. data/test/test_dtrace.rb +67 -1
  62. data/test/test_dtrace_aggregates.rb +5 -5
  63. data/test/test_dtrace_drops_errors.rb +5 -5
  64. data/test/test_dtrace_probe.rb +385 -0
  65. data/test/test_dtrace_probes.rb +414 -0
  66. data/test/test_dtrace_processes.rb +2 -2
  67. data/test/test_dtrace_profile.rb +12 -12
  68. data/test/test_dtrace_provider.rb +138 -0
  69. data/test/test_dtrace_repeat.rb +1 -1
  70. data/test/test_dtrace_rubyprobe.rb +3 -1
  71. data/test/test_dtrace_typefilter.rb +9 -9
  72. data/test/test_legacy_consumer.rb +56 -0
  73. metadata +112 -71
  74. data/lib/dtrace/provider/osx.rb +0 -25
  75. data/lib/dtrace/provider/solaris.rb +0 -29
  76. data/lib/dtraceaggregate.rb +0 -37
  77. data/lib/dtraceaggregateset.rb +0 -17
  78. data/lib/dtracedata.rb +0 -80
  79. data/lib/dtraceprobe.rb +0 -13
  80. data/lib/dtraceprobedata.rb +0 -21
  81. data/test/test_dynusdt.rb +0 -135
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Ruby-Dtrace
3
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ */
5
+
6
+ #include "dof.h"
7
+
8
+ void
9
+ _init_constants(VALUE dtrace_dof)
10
+ {
11
+ VALUE c = rb_define_module_under(dtrace_dof, "Constants");
12
+
13
+ rb_define_const(c, "DOF_DOFHDR_SIZE", INT2FIX(sizeof(dof_hdr_t)));
14
+ rb_define_const(c, "DOF_SECHDR_SIZE", INT2FIX(sizeof(dof_sec_t)));
15
+ rb_define_const(c, "DOF_PROBE_SIZE", INT2FIX(sizeof(dof_probe_t)));
16
+ rb_define_const(c, "DOF_PRARGS_SIZE", INT2FIX(sizeof(uint8_t)));
17
+ rb_define_const(c, "DOF_PROFFS_SIZE", INT2FIX(sizeof(uint32_t)));
18
+ rb_define_const(c, "DOF_PRENOFFS_SIZE", INT2FIX(sizeof(uint32_t)));
19
+ rb_define_const(c, "DOF_PROVIDER_SIZE", INT2FIX(sizeof(dof_provider_t)));
20
+
21
+ rb_define_const(c, "DOF_SECT_NONE", INT2FIX(DOF_SECT_NONE));
22
+ rb_define_const(c, "DOF_SECT_COMMENTS", INT2FIX(DOF_SECT_COMMENTS));
23
+ rb_define_const(c, "DOF_SECT_SOURCE", INT2FIX(DOF_SECT_SOURCE));
24
+ rb_define_const(c, "DOF_SECT_ECBDESC", INT2FIX(DOF_SECT_ECBDESC));
25
+ rb_define_const(c, "DOF_SECT_PROBEDESC", INT2FIX(DOF_SECT_PROBEDESC));
26
+ rb_define_const(c, "DOF_SECT_ACTDESC", INT2FIX(DOF_SECT_ACTDESC));
27
+ rb_define_const(c, "DOF_SECT_DIFOHDR", INT2FIX(DOF_SECT_DIFOHDR));
28
+ rb_define_const(c, "DOF_SECT_DIF", INT2FIX(DOF_SECT_DIF));
29
+ rb_define_const(c, "DOF_SECT_STRTAB", INT2FIX(DOF_SECT_STRTAB));
30
+ rb_define_const(c, "DOF_SECT_VARTAB", INT2FIX(DOF_SECT_VARTAB));
31
+ rb_define_const(c, "DOF_SECT_RELTAB", INT2FIX(DOF_SECT_RELTAB));
32
+ rb_define_const(c, "DOF_SECT_TYPTAB", INT2FIX(DOF_SECT_TYPTAB));
33
+ rb_define_const(c, "DOF_SECT_URELHDR", INT2FIX(DOF_SECT_URELHDR));
34
+ rb_define_const(c, "DOF_SECT_KRELHDR", INT2FIX(DOF_SECT_KRELHDR));
35
+ rb_define_const(c, "DOF_SECT_OPTDESC", INT2FIX(DOF_SECT_OPTDESC));
36
+ rb_define_const(c, "DOF_SECT_PROVIDER", INT2FIX(DOF_SECT_PROVIDER));
37
+ rb_define_const(c, "DOF_SECT_PROBES", INT2FIX(DOF_SECT_PROBES));
38
+ rb_define_const(c, "DOF_SECT_PRARGS", INT2FIX(DOF_SECT_PRARGS));
39
+ rb_define_const(c, "DOF_SECT_PROFFS", INT2FIX(DOF_SECT_PROFFS));
40
+ rb_define_const(c, "DOF_SECT_INTTAB", INT2FIX(DOF_SECT_INTTAB));
41
+ rb_define_const(c, "DOF_SECT_UTSNAME", INT2FIX(DOF_SECT_UTSNAME));
42
+ rb_define_const(c, "DOF_SECT_XLTAB", INT2FIX(DOF_SECT_XLTAB));
43
+ rb_define_const(c, "DOF_SECT_XLMEMBERS", INT2FIX(DOF_SECT_XLMEMBERS));
44
+ rb_define_const(c, "DOF_SECT_XLIMPORT", INT2FIX(DOF_SECT_XLIMPORT));
45
+ rb_define_const(c, "DOF_SECT_XLEXPORT", INT2FIX(DOF_SECT_XLEXPORT));
46
+ rb_define_const(c, "DOF_SECT_PREXPORT", INT2FIX(DOF_SECT_PREXPORT));
47
+ rb_define_const(c, "DOF_SECT_PRENOFFS", INT2FIX(DOF_SECT_PRENOFFS));
48
+
49
+ rb_define_const(c, "DTRACE_STABILITY_INTERNAL", INT2FIX(DTRACE_STABILITY_INTERNAL));
50
+ rb_define_const(c, "DTRACE_STABILITY_PRIVATE", INT2FIX(DTRACE_STABILITY_PRIVATE));
51
+ rb_define_const(c, "DTRACE_STABILITY_OBSOLETE", INT2FIX(DTRACE_STABILITY_OBSOLETE));
52
+ rb_define_const(c, "DTRACE_STABILITY_EXTERNAL", INT2FIX(DTRACE_STABILITY_EXTERNAL));
53
+ rb_define_const(c, "DTRACE_STABILITY_UNSTABLE", INT2FIX(DTRACE_STABILITY_UNSTABLE));
54
+ rb_define_const(c, "DTRACE_STABILITY_EVOLVING", INT2FIX(DTRACE_STABILITY_EVOLVING));
55
+ rb_define_const(c, "DTRACE_STABILITY_STABLE", INT2FIX(DTRACE_STABILITY_STABLE));
56
+ rb_define_const(c, "DTRACE_STABILITY_STANDARD", INT2FIX(DTRACE_STABILITY_STANDARD));
57
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Ruby-Dtrace
3
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ */
5
+
6
+ #include <ruby.h>
7
+ #include <sys/utsname.h>
8
+ #include <sys/dtrace.h>
9
+
10
+ /* Handle missing RARRAY_LEN etc */
11
+ #ifdef RARRAY_LEN
12
+ static inline long rb_str_len(VALUE s) {return RSTRING_LEN(s);}
13
+ static inline char *rb_str_ptr(VALUE s) {return RSTRING_PTR(s);}
14
+ static inline long rb_ary_len(VALUE s) {return RARRAY_LEN(s);}
15
+ static inline VALUE *rb_ary_ptr(VALUE s) {return RARRAY_PTR(s);}
16
+ #else
17
+ static inline long rb_str_len(VALUE s) {return RSTRING(s)->len;}
18
+ static inline char *rb_str_ptr(VALUE s) {return RSTRING(s)->ptr;}
19
+ static inline long rb_ary_len(VALUE s) {return RARRAY(s)->len;}
20
+ static inline VALUE *rb_ary_ptr(VALUE s) {return RARRAY(s)->ptr;}
21
+ #endif // RARRAY_LEN
22
+
23
+ /* Struct to contain Dof::File allocated memory */
24
+ typedef struct dof_file {
25
+ char *dof;
26
+ uint32_t len;
27
+ uint32_t offset;
28
+ } dof_file_t;
29
+
30
+ VALUE dof_parse(VALUE self, VALUE dof);
31
+
32
+ /* Section generate methods */
33
+ VALUE dof_generate_comments(VALUE self);
34
+ VALUE dof_generate_probes(VALUE self);
35
+ VALUE dof_generate_strtab(VALUE self);
36
+ VALUE dof_generate_utsname(VALUE self);
37
+ VALUE dof_generate_prargs(VALUE self);
38
+ VALUE dof_generate_proffs(VALUE self);
39
+ VALUE dof_generate_prenoffs(VALUE self);
40
+ VALUE dof_generate_provider(VALUE self);
41
+ VALUE dof_generate_reltab(VALUE self);
42
+ VALUE dof_generate_relhdr(VALUE self);
43
+
44
+ VALUE dof_generate_section_header(VALUE self);
45
+
46
+ VALUE dof_generate_header(VALUE self);
47
+ VALUE dof_header_len(VALUE self);
48
+
49
+ VALUE dof_file_alloc(VALUE klass);
50
+ VALUE dof_file_allocate_dof(VALUE self, VALUE size);
51
+ VALUE dof_file_append(VALUE self, VALUE data);
52
+ VALUE dof_file_addr(VALUE self);
53
+ VALUE dof_file_data(VALUE self);
54
+
55
+ VALUE dof_loaddof(VALUE self, VALUE dof, VALUE module_name);
56
+
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Ruby-Dtrace
3
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ */
5
+
6
+ #include "dof.h"
7
+
8
+ VALUE cDtraceDofParser;
9
+ VALUE cDtraceDofGenerator;
10
+ VALUE cDtraceDofSection;
11
+ VALUE cDtraceDofHeader;
12
+ VALUE cDtraceDofFile;
13
+ VALUE eDtraceDofException;
14
+
15
+ void Init_dof_api() {
16
+ VALUE dtrace = rb_define_class("Dtrace", rb_cObject);
17
+ VALUE dof = rb_define_class_under(dtrace, "Dof", rb_cObject);
18
+
19
+ rb_define_singleton_method(dof, "loaddof", dof_loaddof, 2); // in dof_helper.c
20
+
21
+ eDtraceDofException = rb_define_class_under(dof, "Exception", rb_eStandardError);
22
+
23
+ cDtraceDofParser = rb_define_class_under(dof, "Parser", rb_cObject);
24
+ cDtraceDofGenerator = rb_define_class_under(dof, "Generator", rb_cObject);
25
+
26
+ rb_define_singleton_method(cDtraceDofParser, "parse", dof_parse, 1); // in parser.c
27
+
28
+ cDtraceDofSection = rb_define_class_under(dof, "Section", rb_cObject);
29
+ rb_define_method(cDtraceDofSection, "dof_generate_comments", dof_generate_comments, 0); // in section.c
30
+ rb_define_method(cDtraceDofSection, "dof_generate_probes", dof_generate_probes, 0); // in section.c
31
+ rb_define_method(cDtraceDofSection, "dof_generate_strtab", dof_generate_strtab, 0); // in section.c
32
+ rb_define_method(cDtraceDofSection, "dof_generate_utsname", dof_generate_utsname, 0); // in section.c
33
+ rb_define_method(cDtraceDofSection, "dof_generate_prargs", dof_generate_prargs, 0); // in section.c
34
+ rb_define_method(cDtraceDofSection, "dof_generate_proffs", dof_generate_proffs, 0); // in section.c
35
+ rb_define_method(cDtraceDofSection, "dof_generate_prenoffs", dof_generate_prenoffs, 0); // in section.c
36
+ rb_define_method(cDtraceDofSection, "dof_generate_provider", dof_generate_provider, 0); // in section.c
37
+ rb_define_method(cDtraceDofSection, "dof_generate_reltab", dof_generate_reltab, 0); // in section.c
38
+ rb_define_method(cDtraceDofSection, "dof_generate_relhdr", dof_generate_relhdr, 0); // in section.c
39
+ rb_define_method(cDtraceDofSection, "generate_header", dof_generate_section_header, 0); // in section.c
40
+
41
+ cDtraceDofHeader = rb_define_class_under(dof, "Header", rb_cObject);
42
+ rb_define_attr(cDtraceDofHeader, "loadsz", 1, 1);
43
+ rb_define_attr(cDtraceDofHeader, "filesz", 1, 1);
44
+ rb_define_attr(cDtraceDofHeader, "secnum", 1, 1);
45
+ rb_define_attr(cDtraceDofHeader, "hdrlen", 1, 0);
46
+ rb_define_attr(cDtraceDofHeader, "dof_version", 0, 1);
47
+ rb_define_method(cDtraceDofHeader, "generate", dof_generate_header, 0); // in header.c
48
+ rb_define_method(cDtraceDofHeader, "hdrlen", dof_header_len, 0); // in header.c
49
+
50
+ cDtraceDofFile = rb_define_class_under(dof, "File", rb_cObject);
51
+ rb_define_alloc_func(cDtraceDofFile, dof_file_alloc); // in file.c
52
+ rb_define_method(cDtraceDofFile, "allocate", dof_file_allocate_dof, 1); // in file.c
53
+ rb_define_method(cDtraceDofFile, "<<", dof_file_append, 1); // in file.c
54
+ rb_define_method(cDtraceDofFile, "addr", dof_file_addr, 0); // in file.c
55
+ rb_define_method(cDtraceDofFile, "data", dof_file_data, 0); // in file.c
56
+
57
+ _init_constants(dof);
58
+ }
@@ -0,0 +1,82 @@
1
+ /* Ruby-Dtrace
2
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
3
+ */
4
+
5
+ #include "dof.h"
6
+
7
+ #include <errno.h>
8
+ #include <string.h>
9
+ #include <fcntl.h>
10
+
11
+ RUBY_EXTERN VALUE eDtraceDofException;
12
+
13
+ #ifdef __APPLE__
14
+ static const char *helper = "/dev/dtracehelper";
15
+
16
+ int _loaddof(int fd, dof_helper_t *dh)
17
+ {
18
+ int ret;
19
+ uint8_t buffer[sizeof(dof_ioctl_data_t) + sizeof(dof_helper_t)];
20
+ dof_ioctl_data_t* ioctlData = (dof_ioctl_data_t*)buffer;
21
+
22
+ ioctlData->dofiod_count = 1LL;
23
+ memcpy(&ioctlData->dofiod_helpers[0], dh, sizeof(dof_helper_t));
24
+
25
+ user_addr_t val = (user_addr_t)(unsigned long)ioctlData;
26
+ ret = ioctl(fd, DTRACEHIOC_ADDDOF, &val);
27
+
28
+ return ret;
29
+ }
30
+
31
+ #else /* Solaris */
32
+
33
+ /* ignore Sol10 GA ... */
34
+ static const char *helper = "/dev/dtrace/helper";
35
+
36
+ int _loaddof(int fd, dof_helper_t *dh)
37
+ {
38
+ return ioctl(fd, DTRACEHIOC_ADDDOF, dh);
39
+ }
40
+
41
+ #endif
42
+
43
+ /* Load the given Dtrace::Dof::File into the kernel, against the given
44
+ module name. */
45
+ VALUE dof_loaddof(VALUE self, VALUE dof_file, VALUE module_name)
46
+ {
47
+ dof_helper_t dh;
48
+ int fd;
49
+ int gen;
50
+ dof_file_t *file;
51
+ dof_hdr_t *dof;
52
+
53
+ Data_Get_Struct(dof_file, dof_file_t, file);
54
+ dof = (dof_hdr_t *)file->dof;
55
+
56
+ if (dof->dofh_ident[DOF_ID_MAG0] != DOF_MAG_MAG0 ||
57
+ dof->dofh_ident[DOF_ID_MAG1] != DOF_MAG_MAG1 ||
58
+ dof->dofh_ident[DOF_ID_MAG2] != DOF_MAG_MAG2 ||
59
+ dof->dofh_ident[DOF_ID_MAG3] != DOF_MAG_MAG3) {
60
+ rb_raise(eDtraceDofException, "DOF corrupt: bad magic");
61
+ return Qnil;
62
+ }
63
+
64
+ dh.dofhp_dof = (uintptr_t)dof;
65
+ dh.dofhp_addr = (uintptr_t)dof;
66
+ (void) snprintf(dh.dofhp_mod, sizeof (dh.dofhp_mod), RSTRING(module_name)->ptr);
67
+
68
+ if ((fd = open(helper, O_RDWR)) < 0) {
69
+ rb_raise(eDtraceDofException, "failed to open helper device %s: %s",
70
+ helper, strerror(errno));
71
+ return Qnil;
72
+ }
73
+ else {
74
+ if ((gen = _loaddof(fd, &dh)) < 0)
75
+ rb_raise(eDtraceDofException, "DTrace ioctl failed: %s", strerror(errno));
76
+
77
+ (void) close(fd);
78
+ }
79
+
80
+ return Qnil;
81
+ }
82
+
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+ $CFLAGS += " -D_LONGLONG_TYPE -g"
3
+ have_header("sys/dtrace.h")
4
+ create_makefile("dof_api")
@@ -0,0 +1,90 @@
1
+ /*
2
+ * Ruby-Dtrace
3
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ */
5
+
6
+ #include "dof.h"
7
+
8
+ RUBY_EXTERN eDtraceDofException;
9
+
10
+ static VALUE dof_file_free(void *arg)
11
+ {
12
+ dof_file_t *file = (dof_file_t *)arg;
13
+
14
+ if (file) {
15
+ free(file->dof);
16
+ free(file);
17
+ }
18
+ }
19
+
20
+ /* :nodoc: */
21
+ VALUE dof_file_alloc(VALUE klass)
22
+ {
23
+ VALUE obj;
24
+ dof_file_t *file;
25
+
26
+ file = (dof_file_t *)ALLOC(dof_file_t);
27
+ if (file == NULL) {
28
+ rb_raise(eDtraceDofException, "failed to allocate dof_file_t");
29
+ return Qnil;
30
+ }
31
+ file->dof = NULL;
32
+ file->len = 0;
33
+ file->offset = 0;
34
+
35
+ obj = Data_Wrap_Struct(klass, NULL, dof_file_free, file);
36
+ return obj;
37
+ }
38
+
39
+ /* :nodoc: */
40
+ VALUE dof_file_allocate_dof(VALUE self, VALUE size)
41
+ {
42
+ dof_file_t *file;
43
+ Data_Get_Struct(self, dof_file_t, file);
44
+
45
+ file->len = FIX2INT(size);
46
+ file->dof = (char *)ALLOC_N(char, file->len);
47
+ if (file->dof == NULL) {
48
+ rb_raise(eDtraceDofException, "failed to allocate %d bytes for DOF", file->len);
49
+ return Qnil;
50
+ }
51
+
52
+ return Qnil;
53
+ }
54
+
55
+ /* Appends the given string to the DOF file. */
56
+ VALUE dof_file_append(VALUE self, VALUE data)
57
+ {
58
+ dof_file_t *file;
59
+ Data_Get_Struct(self, dof_file_t, file);
60
+
61
+ if ((file->offset + RSTRING(data)->len) > file->len) {
62
+ rb_raise(eDtraceDofException, "DOF allocation insufficient: %d > %d",
63
+ (file->offset + RSTRING(data)->len), file->len);
64
+ return Qnil;
65
+ }
66
+
67
+ memcpy((file->dof + file->offset), RSTRING(data)->ptr, RSTRING(data)->len);
68
+ file->offset += RSTRING(data)->len;
69
+ }
70
+
71
+ /* Returns the memory address of the DOF file. */
72
+ VALUE dof_file_addr(VALUE self)
73
+ {
74
+ dof_file_t *file;
75
+ Data_Get_Struct(self, dof_file_t, file);
76
+ if (file->dof == NULL) {
77
+ rb_raise(eDtraceDofException, "must allocate DOF buffer before calling addr");
78
+ return Qnil;
79
+ }
80
+ return INT2FIX(file->dof);
81
+ }
82
+
83
+ /* Returns the DOF itself. */
84
+ VALUE dof_file_data(VALUE self)
85
+ {
86
+ dof_file_t *file;
87
+ Data_Get_Struct(self, dof_file_t, file);
88
+ return rb_str_new(file->dof, file->offset);
89
+ }
90
+
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Ruby-Dtrace
3
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ */
5
+
6
+ #include "dof.h"
7
+
8
+ RUBY_EXTERN eDtraceDofException;
9
+
@@ -0,0 +1,79 @@
1
+ /*
2
+ * Ruby-Dtrace
3
+ * (c) 2008 Chris Andrews <chris@nodnol.org>
4
+ */
5
+
6
+ #include "dof.h"
7
+ #include <errno.h>
8
+ #include <string.h>
9
+
10
+ RUBY_EXTERN eDtraceDofException;
11
+
12
+ /* :nodoc: */
13
+ VALUE dof_generate_header(VALUE self) {
14
+ dof_hdr_t hdr;
15
+ uint32_t secnum;
16
+ uint64_t loadsz;
17
+ uint64_t filesz;
18
+ uint64_t hdrlen;
19
+ VALUE hdr_data;
20
+ uint8_t dof_version;
21
+
22
+ /* DOF versioning: Apple always needs version 3, but Solaris can use
23
+ 1 or 2 depending on whether is-enabled probes are needed. */
24
+ #ifdef __APPLE__
25
+ dof_version = DOF_VERSION_3;
26
+ #else
27
+ switch(FIX2INT(rb_iv_get(self, "@dof_version"))) {
28
+ case 1:
29
+ dof_version = DOF_VERSION_1;
30
+ break;
31
+ case 2:
32
+ dof_version = DOF_VERSION_2;
33
+ break;
34
+ default:
35
+ dof_version = DOF_VERSION;
36
+ }
37
+ #endif
38
+
39
+ memset(&hdr, 0, sizeof(hdr));
40
+
41
+ hdr.dofh_ident[DOF_ID_MAG0] = DOF_MAG_MAG0;
42
+ hdr.dofh_ident[DOF_ID_MAG1] = DOF_MAG_MAG1;
43
+ hdr.dofh_ident[DOF_ID_MAG2] = DOF_MAG_MAG2;
44
+ hdr.dofh_ident[DOF_ID_MAG3] = DOF_MAG_MAG3;
45
+
46
+ hdr.dofh_ident[DOF_ID_MODEL] = DOF_MODEL_NATIVE;
47
+ hdr.dofh_ident[DOF_ID_ENCODING] = DOF_ENCODE_NATIVE;
48
+ hdr.dofh_ident[DOF_ID_VERSION] = dof_version;
49
+ hdr.dofh_ident[DOF_ID_DIFVERS] = DIF_VERSION;
50
+ hdr.dofh_ident[DOF_ID_DIFIREG] = DIF_DIR_NREGS;
51
+ hdr.dofh_ident[DOF_ID_DIFTREG] = DIF_DTR_NREGS;
52
+
53
+ hdr.dofh_hdrsize = sizeof(dof_hdr_t);
54
+ hdr.dofh_secsize = sizeof(dof_sec_t);
55
+
56
+ secnum = FIX2INT(rb_iv_get(self, "@secnum"));
57
+ hdr.dofh_secnum = secnum;
58
+
59
+ hdr.dofh_loadsz = FIX2INT(rb_iv_get(self, "@loadsz"));
60
+ hdr.dofh_filesz = FIX2INT(rb_iv_get(self, "@filesz"));
61
+
62
+ hdrlen = (sizeof(dof_hdr_t) + secnum * sizeof(dof_sec_t));
63
+ rb_iv_set(self, "@hdrlen", INT2FIX(hdrlen));
64
+ hdr.dofh_secoff = sizeof(dof_hdr_t);
65
+
66
+ hdr_data = rb_str_new((const char *)&hdr, sizeof(hdr));
67
+ return hdr_data;
68
+ }
69
+
70
+ /* :nodoc: */
71
+ VALUE dof_header_len(VALUE self) {
72
+ uint64_t hdrlen;
73
+ uint32_t secnum;
74
+
75
+ secnum = FIX2INT(rb_iv_get(self, "@secnum"));
76
+ hdrlen = (sizeof(dof_hdr_t) + secnum * sizeof(dof_sec_t));
77
+
78
+ return INT2FIX(hdrlen);
79
+ }
@@ -0,0 +1,10 @@
1
+ have_header: checking for sys/dtrace.h... -------------------- yes
2
+
3
+ "/usr/bin/cpp-4.0 -I. -I/opt/local/lib/ruby/1.8/i686-darwin9.7.0 -I. -I/opt/local/include -O2 -fno-common -pipe -fno-common -D_LONGLONG_TYPE -g conftest.c -o conftest.i"
4
+ checked program was:
5
+ /* begin */
6
+ 1: #include <sys/dtrace.h>
7
+ /* end */
8
+
9
+ --------------------
10
+