Skip to content

Instantly share code, notes, and snippets.

@XrXr

XrXr/crasher.rb Secret

Created March 11, 2020 00:34
Show Gist options
  • Save XrXr/b3e2d57101248eaf286eed193ccbba54 to your computer and use it in GitHub Desktop.
Save XrXr/b3e2d57101248eaf286eed193ccbba54 to your computer and use it in GitHub Desktop.
require_relative 'tracepoint_crash'
RubyTracePointCrash.enable
require 'mkmf'
$CFLAGS = "-Wall"
create_makefile('tracepoint_crash/tracepoint_crash')
#!/bin/bash
# To run, put all the files in this gist in a empty directory then run this script
ruby extconf.rb && make clean && make && ruby -v crasher.rb
#include <ruby.h>
#include <ruby/debug.h>
static VALUE tracepoint = Qnil;
static void
gctracker_hook(VALUE tpval, void *data)
{
fprintf(stderr, "hook is called\n");
}
static VALUE
tracepoint_enable(VALUE klass)
{
rb_event_flag_t events;
events = RUBY_INTERNAL_EVENT_GC_EXIT;
tracepoint = rb_tracepoint_new(Qnil, events, gctracker_hook, NULL);
rb_global_variable(&tracepoint);
rb_tracepoint_enable(tracepoint);
fprintf(stderr, "tp is %ld and it is now enabled\n", tracepoint);
return Qtrue;
}
void
Init_tracepoint_crash()
{
VALUE cRubyTracePointCrash = rb_define_class("RubyTracePointCrash", rb_cObject);
rb_define_module_function(cRubyTracePointCrash, "enable", tracepoint_enable, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment