19 static VALUE rb_cBacktrace;
20 static VALUE rb_cBacktraceLocation;
26 if (!str)
return Qnil;
29 #define rb_id2str(id) id2str(id) 40 if (VM_FRAME_RUBYFRAME_P(cfp) && cfp->
iseq) {
41 return calc_lineno(cfp->
iseq, cfp->
pc);
77 location_mark(
void *ptr)
99 location_memsize(
const void *ptr)
112 location_ptr(
VALUE locobj)
127 return loc->
body.
iseq.lineno.lineno;
130 return location_lineno(loc->
body.
cfunc.prev_loc);
134 rb_bug(
"location_lineno: unreachable");
148 location_lineno_m(
VALUE self)
150 return INT2FIX(location_lineno(location_ptr(
self)));
164 rb_bug(
"location_label: unreachable");
197 location_label_m(
VALUE self)
199 return location_label(location_ptr(
self));
213 rb_bug(
"location_base_label: unreachable");
224 location_base_label_m(
VALUE self)
226 return location_base_label(location_ptr(
self));
238 return location_path(loc->
body.
cfunc.prev_loc);
243 rb_bug(
"location_path: unreachable");
257 location_path_m(
VALUE self)
259 return location_path(location_ptr(
self));
271 return location_realpath(loc->
body.
cfunc.prev_loc);
276 rb_bug(
"location_realpath: unreachable");
287 location_absolute_path_m(
VALUE self)
289 return location_realpath(location_ptr(
self));
325 lineno = loc->
body.
iseq.lineno.lineno;
331 lineno = location_lineno(loc->
body.
cfunc.prev_loc);
342 rb_bug(
"location_to_str: unreachable");
345 return location_format(file, lineno, name);
352 location_to_str_m(
VALUE self)
354 return location_to_str(location_ptr(
self));
362 location_inspect_m(
VALUE self)
376 backtrace_mark(
void *ptr)
381 for (i=0; i<s; i++) {
389 backtrace_free(
void *ptr)
397 backtrace_memsize(
const void *ptr)
405 {backtrace_mark, backtrace_free, backtrace_memsize,},
406 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
416 backtrace_alloc(
VALUE klass)
425 void (*init)(
void *arg,
size_t size),
449 if (start_cfp < last_cfp) {
453 size = start_cfp - last_cfp + 1;
468 ID mid = me->
def->original_id;
470 iter_cfunc(arg, cfp, mid);
482 bt_init(
void *ptr,
size_t size)
485 arg->
btobj = backtrace_alloc(rb_cBacktrace);
536 rb_bug(
"backtrace_collect: unreachable");
552 return location_to_str(loc);
556 backtrace_to_str_ary(
VALUE self,
long lev,
long n)
572 r = backtrace_collect(bt, lev, n, location_to_str_dmyarg, 0);
603 backtrace_to_location_ary(
VALUE self,
long lev,
long n)
619 r = backtrace_collect(bt, lev, n, location_create, (
void *)
self);
631 bt->
locary = backtrace_to_location_ary(
self, 0, 0);
637 backtrace_dump_data(
VALUE self)
674 oldbt_init(
void *ptr,
size_t dmy)
691 int lineno = arg->
lineno = calc_lineno(iseq, pc);
693 (arg->
func)(arg->
data, file, lineno, name);
704 (arg->
func)(arg->
data, file, lineno, name);
713 fprintf(fp,
"\tfrom %s:%d:in unknown method\n",
717 fprintf(fp,
"\tfrom %s:%d:in `%s'\n",
723 vm_backtrace_print(
FILE *fp)
727 arg.
func = oldbt_print;
728 arg.
data = (
void *)fp;
737 oldbt_bugreport(
void *arg,
VALUE file,
int line,
VALUE method)
741 fprintf(stderr,
"-- Ruby level backtrace information " 742 "----------------------------------------\n");
746 fprintf(stderr,
"%s:%d:in unknown method\n", filename, line);
749 fprintf(stderr,
"%s:%d:in `%s'\n", filename, line,
RSTRING_PTR(method));
759 arg.
func = oldbt_bugreport;
760 arg.
data = (
int *)&i;
772 vm_backtrace_print(stderr);
781 oldbt_print_to(
void *data,
VALUE file,
int lineno,
VALUE name)
803 arg.
func = oldbt_print_to;
831 if (argc == 2 &&
NIL_P(vn)) argc--;
835 lev = lev_default + lev_plus;
853 lev = beg + lev_plus;
880 r = backtrace_to_str_ary(btval, lev, n);
883 r = backtrace_to_location_ary(btval, lev, n);
890 thread_backtrace_to_ary(
int argc,
const VALUE *argv,
VALUE thval,
int to_str)
897 return threadptr_backtrace_to_ary(target_th, argc, argv, 0, 0, to_str);
903 return thread_backtrace_to_ary(argc, argv, thval, 1);
909 return thread_backtrace_to_ary(argc, argv, thval, 0);
951 rb_f_caller(
int argc,
VALUE *argv)
953 return threadptr_backtrace_to_ary(
GET_THREAD(), argc, argv, 1, 1, 1);
979 rb_f_caller_locations(
int argc,
VALUE *argv)
981 return threadptr_backtrace_to_ary(
GET_THREAD(), argc, argv, 1, 1, 0);
1046 rb_define_method(rb_cBacktraceLocation,
"base_label", location_base_label_m, 0);
1048 rb_define_method(rb_cBacktraceLocation,
"absolute_path", location_absolute_path_m, 0);
1083 collect_caller_bindings_init(
void *arg,
size_t size)
1094 return RBASIC(klass)->klass;
1145 collect_caller_bindings_init,
1146 collect_caller_bindings_iseq,
1147 collect_caller_bindings_cfunc,
1157 if (!
NIL_P(cfp_val)) {
1179 dbg_context.
th = th;
1183 dbg_context.
contexts = collect_caller_bindings(th);
1187 result = (*func)(&dbg_context, data);
1212 VALUE frame = frame_get(dc, index);
1219 VALUE frame = frame_get(dc, index);
1226 VALUE frame = frame_get(dc, index);
1233 VALUE frame = frame_get(dc, index);
1253 for (i=0; i<limit && cfp != end_cfp;) {
1254 if (cfp->
iseq && cfp->
pc) {
1263 buff[i] = (
VALUE)cme;
1269 if (lines) lines[i] = calc_lineno(cfp->
iseq, cfp->
pc);
1280 frame2iseq(
VALUE frame)
1291 switch (cme->
def->type) {
1293 return cme->
def->body.iseq.iseqptr;
1302 rb_bug(
"frame2iseq: unreachable");
1341 frame2klass(
VALUE frame)
1358 VALUE klass = frame2klass(frame);
1360 if (klass && !
NIL_P(klass)) {
1362 klass =
RBASIC(klass)->klass;
1379 VALUE klass = frame2klass(frame);
1401 if (method_name !=
Qnil) {
1405 if (classpath !=
Qnil) {
1407 classpath, singleton_p ==
Qtrue ?
"." :
"#", method_name);
1425 if (
NIL_P(qualified_method_name) || base_label == qualified_method_name) {
1431 int prefix_len =
rb_long2int(label_length - base_label_length);
struct rb_backtrace_location_struct::@126::@128 cfunc
VALUE rb_threadptr_backtrace_location_ary(rb_thread_t *th, long lev, long n)
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
void rb_bug(const char *fmt,...)
VALUE rb_ary_entry(VALUE ary, long offset)
VALUE rb_threadptr_backtrace_str_ary(rb_thread_t *th, long lev, long n)
#define RUBY_TYPED_FREE_IMMEDIATELY
VALUE rb_threadptr_backtrace_object(rb_thread_t *th)
int rb_vm_get_sourceline(const rb_control_frame_t *cfp)
int rb_backtrace_p(VALUE obj)
VALUE rb_profile_frame_classpath(VALUE frame)
VALUE rb_iseq_method_name(const rb_iseq_t *iseq)
void rb_undef_alloc_func(VALUE)
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
void rb_backtrace_each(VALUE(*iter)(VALUE recv, VALUE str), VALUE output)
void rb_raise(VALUE exc, const char *fmt,...)
struct rb_method_definition_struct *const def
const rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
VALUE rb_make_backtrace(void)
#define TH_JUMP_TAG(th, st)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_profile_frame_first_lineno(VALUE frame)
VALUE rb_profile_frame_method_name(VALUE frame)
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
struct rb_iseq_constant_body * body
VALUE rb_backtrace_to_location_ary(VALUE self)
VALUE rb_iseq_label(const rb_iseq_t *iseq)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_ivar_get(VALUE, ID)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
void rb_gc_mark(VALUE ptr)
VALUE rb_range_beg_len(VALUE, long *, long *, long, int)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
VALUE rb_profile_frame_singleton_method_p(VALUE frame)
void rb_undef_method(VALUE klass, const char *name)
VALUE rb_debug_inspector_frame_self_get(const rb_debug_inspector_t *dc, long index)
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_debug_inspector_frame_class_get(const rb_debug_inspector_t *dc, long index)
VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, long index)
const VALUE * iseq_encoded
VALUE rb_iseqw_new(const rb_iseq_t *)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
#define RB_TYPE_P(obj, type)
VALUE(* iter)(VALUE recv, VALUE str)
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, ID *called_idp, VALUE *klassp)
VALUE rb_profile_frame_absolute_path(VALUE frame)
VALUE rb_debug_inspector_backtrace_locations(const rb_debug_inspector_t *dc)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_profile_frame_full_label(VALUE frame)
rb_backtrace_location_t * loc
VALUE(* rb_debug_inspector_func_t)(const rb_debug_inspector_t *, void *)
VALUE rb_iseq_first_lineno(const rb_iseq_t *iseq)
void rb_ary_store(VALUE ary, long idx, VALUE val)
#define GetCoreDataFromValue(obj, type, ptr)
const VALUE defined_class
VALUE rb_profile_frame_path(VALUE frame)
VALUE rb_debug_inspector_frame_binding_get(const rb_debug_inspector_t *dc, long index)
VALUE rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data)
#define GC_GUARDED_PTR(p)
rb_backtrace_location_t * backtrace
VALUE rb_sprintf(const char *format,...)
VALUE rb_class_path(VALUE)
#define RUBY_SYMBOL_EXPORT_END
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void(* func)(void *data, VALUE file, int lineno, VALUE name)
#define RUBY_VM_NEXT_CONTROL_FRAME(cfp)
struct rb_backtrace_location_struct rb_backtrace_location_t
#define RUBYVM_CFUNC_FRAME_P(cfp)
VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp)
RUBY_EXTERN VALUE rb_cThread
void rb_backtrace_print_as_bugreport(void)
int rb_profile_frames(int start, int limit, VALUE *buff, int *lines)
const char * rb_class2name(VALUE)
#define RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_VM_END_CONTROL_FRAME(th)
register unsigned int len
VALUE rb_vm_thread_backtrace(int argc, const VALUE *argv, VALUE thval)
enum rb_thread_status status
void * ruby_xmalloc(size_t size)
VALUE rb_iseq_realpath(const rb_iseq_t *iseq)
VALUE rb_profile_frame_qualified_method_name(VALUE frame)
VALUE rb_backtrace_to_str_ary(VALUE self)
struct rb_backtrace_location_struct * prev_loc
VALUE rb_str_catf(VALUE str, const char *format,...)
void Init_vm_backtrace(void)
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
union rb_backtrace_location_struct::@126 body
VALUE rb_str_cat_cstr(VALUE, const char *)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_str_inspect(VALUE)
VALUE rb_iseq_path(const rb_iseq_t *iseq)
VALUE rb_iseq_base_label(const rb_iseq_t *iseq)
rb_execution_context_t ec
enum rb_backtrace_location_struct::LOCATION_TYPE type
struct rb_backtrace_struct rb_backtrace_t
VALUE rb_ary_reverse(VALUE ary)
#define GC_GUARDED_PTR_REF(p)
#define RUBY_TYPED_DEFAULT_FREE
VALUE rb_vm_thread_backtrace_locations(int argc, const VALUE *argv, VALUE thval)
rb_backtrace_location_t * backtrace_base
rb_backtrace_location_t * prev_loc
VALUE rb_profile_frame_base_label(VALUE frame)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_profile_frame_label(VALUE frame)
rb_iseq_location_t location