Exemplo n.º 1
0
static VALUE load_ustack_helper(VALUE klass, VALUE path) {
  dtrace_hdl_t *dtp;
  dtrace_prog_t *helper;

  int err;
  void *dof;
  int argc = 1;
  char *argv[1] = { "ruby" };

  printf("c land: I am trying to load %s", RSTRING_PTR(path));
  puts("");

  FILE *fp = fopen(RSTRING_PTR(path), "r");
  if (fp == NULL) {
		rb_raise(rb_eFatal, "failed to open '%s', errno %d: %s", path, errno, strerror(errno));
  }

  dtp = dtrace_open(DTRACE_VERSION, DTRACE_O_NODEV, &err);
  if (dtp == NULL) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "dtrace_open failed: %s", dtrace_errmsg(dtp, err));
  }

  (void) dtrace_setopt(dtp, "linkmode", "dynamic");
  (void) dtrace_setopt(dtp, "unodefs", NULL);

  if ((helper = dtrace_program_fcompile(dtp, fp,
          DTRACE_C_ZDEFS,
          argc, argv)) == NULL) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "compile failed: errno %d: %s", dtrace_errno(dtp), dtrace_errmsg(dtp, dtrace_errno(dtp)));
  }

  (void) fclose(fp);

  if ((dof = dtrace_dof_create(dtp, helper, 0)) == NULL) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "DOF create failed: %s", dtrace_errmsg(dtp, dtrace_errno(dtp)));
  }

  if (load_dof(dof) != 0) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "DOF load failed: %s", strerror(err));
  }

  dtrace_close(dtp);

  return Qnil;
}
Exemplo n.º 2
0
static void
compile_file(dtrace_cmd_t *dcp)
{
	char *arg0;
	FILE *fp;

	if ((fp = fopen(dcp->dc_arg, "r")) == NULL)
		fatal("failed to open %s", dcp->dc_arg);

	arg0 = g_argv[0];
	g_argv[0] = dcp->dc_arg;

	if ((dcp->dc_prog = dtrace_program_fcompile(g_dtp, fp,
	    g_cflags, g_argc, g_argv)) == NULL)
		dfatal("failed to compile script %s", dcp->dc_arg);

	g_argv[0] = arg0;
	(void) fclose(fp);

	dcp->dc_desc = "script";
	dcp->dc_name = dcp->dc_arg;
}