Skip to content

Commit

Permalink
Remove class info from backtrace lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed May 23, 2017
1 parent 497b19c commit d2458e6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 58 deletions.
2 changes: 0 additions & 2 deletions include/mruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ struct mrb_jmpbuf;
typedef struct {
const char *filename;
int lineno;
struct RClass *klass;
char sep;
mrb_sym method_id;
} mrb_backtrace_entry;

Expand Down
14 changes: 7 additions & 7 deletions mrbgems/mruby-kernel-ext/test/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def baz(*args)
bar(*args)
end
end
assert_equal "kernel.rb:#{caller_lineno}:in Object#foo", c.new.baz(0)[0][-26..-1]
assert_equal "#bar", c.new.baz[0][-4..-1]
assert_equal "#foo", c.new.baz(0)[0][-4..-1]
assert_equal "#bar", c.new.baz(1)[0][-4..-1]
assert_equal "#baz", c.new.baz(2)[0][-4..-1]
assert_equal ["#foo", "#bar"], c.new.baz(0, 2).map { |i| i[-4..-1] }
assert_equal ["#bar", "#baz"], c.new.baz(1..2).map { |i| i[-4..-1] }
assert_equal "kernel.rb:#{caller_lineno}:in foo", c.new.baz(0)[0][-19..-1]
assert_equal "bar", c.new.baz[0][-3..-1]
assert_equal "foo", c.new.baz(0)[0][-3..-1]
assert_equal "bar", c.new.baz(1)[0][-3..-1]
assert_equal "baz", c.new.baz(2)[0][-3..-1]
assert_equal ["foo", "bar"], c.new.baz(0, 2).map { |i| i[-3..-1] }
assert_equal ["bar", "baz"], c.new.baz(1..2).map { |i| i[-3..-1] }
assert_nil c.new.baz(10..20)
assert_raise(ArgumentError) { c.new.baz(-1) }
assert_raise(ArgumentError) { c.new.baz(-1, 1) }
Expand Down
45 changes: 2 additions & 43 deletions src/backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ struct backtrace_location_raw {
int lineno;
const char *filename;
mrb_sym method_id;
char sep;
struct RClass *klass;
};

struct backtrace_location {
int i;
int lineno;
const char *filename;
const char *method;
char sep;
const char *class_name;
};

typedef void (*each_backtrace_func)(mrb_state*, struct backtrace_location_raw*, void*);
Expand Down Expand Up @@ -57,12 +53,7 @@ print_backtrace_i(mrb_state *mrb, struct backtrace_location *loc, void *data)
fprintf(args->stream, "\t[%d] %s:%d", loc->i, loc->filename, loc->lineno);

if (loc->method) {
if (loc->class_name) {
fprintf(args->stream, ":in %s%c%s", loc->class_name, loc->sep, loc->method);
}
else {
fprintf(args->stream, ":in %s", loc->method);
}
fprintf(args->stream, ":in %s", loc->method);
}

fprintf(args->stream, "\n");
Expand All @@ -83,12 +74,6 @@ get_backtrace_i(mrb_state *mrb, struct backtrace_location *loc, void *data)

if (loc->method) {
mrb_str_cat_lit(mrb, str, ":in ");

if (loc->class_name) {
mrb_str_cat_cstr(mrb, str, loc->class_name);
mrb_str_cat(mrb, str, &loc->sep, 1);
}

mrb_str_cat_cstr(mrb, str, loc->method);
}

Expand Down Expand Up @@ -132,19 +117,11 @@ each_backtrace(mrb_state *mrb, mrb_int ciidx, mrb_code *pc0, each_backtrace_func

if (loc.lineno == -1) continue;

if (ci->target_class == ci->proc->target_class) {
loc.sep = '.';
}
else {
loc.sep = '#';
}

if (!loc.filename) {
loc.filename = "(unknown)";
}

loc.method_id = ci->mid;
loc.klass = ci->proc->target_class;
loc.i = i;
func(mrb, &loc, data);
}
Expand All @@ -165,8 +142,6 @@ output_backtrace_i(mrb_state *mrb, struct backtrace_location_raw *loc_raw, void
loc.lineno = loc_raw->lineno;
loc.filename = loc_raw->filename;
loc.method = mrb_sym2name(mrb, loc_raw->method_id);
loc.sep = loc_raw->sep;
loc.class_name = mrb_class_name(mrb, loc_raw->klass);

args->func(mrb, &loc, args->data);
}
Expand Down Expand Up @@ -244,15 +219,7 @@ print_backtrace_saved(mrb_state *mrb)
const char *method_name;

method_name = mrb_sym2name(mrb, entry->method_id);
if (entry->klass) {
fprintf(stream, ":in %s%c%s",
mrb_class_name(mrb, entry->klass),
entry->sep,
method_name);
}
else {
fprintf(stream, ":in %s", method_name);
}
fprintf(stream, ":in %s", method_name);
mrb_gc_arena_restore(mrb, ai);
}

Expand Down Expand Up @@ -353,8 +320,6 @@ save_backtrace_i(mrb_state *mrb,
entry = &mrb->backtrace.entries[mrb->backtrace.n];
entry->filename = loc_raw->filename;
entry->lineno = loc_raw->lineno;
entry->klass = loc_raw->klass;
entry->sep = loc_raw->sep;
entry->method_id = loc_raw->method_id;

mrb->backtrace.n++;
Expand Down Expand Up @@ -408,12 +373,6 @@ mrb_restore_backtrace(mrb_state *mrb)
mrb_fixnum_value(entry->lineno));
if (entry->method_id != 0) {
mrb_str_cat_lit(mrb, mrb_entry, ":in ");

if (entry->klass) {
mrb_str_cat_cstr(mrb, mrb_entry, mrb_class_name(mrb, entry->klass));
mrb_str_cat(mrb, mrb_entry, &entry->sep, 1);
}

mrb_str_cat_cstr(mrb, mrb_entry, mrb_sym2name(mrb, entry->method_id));
}

Expand Down
4 changes: 0 additions & 4 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,6 @@ root_scan_phase(mrb_state *mrb, mrb_gc *gc)
mrb_gc_mark(mrb, (struct RBasic*)mrb->exc);
/* mark backtrace */
mrb_gc_mark(mrb, (struct RBasic*)mrb->backtrace.exc);
e = (size_t)mrb->backtrace.n;
for (i=0; i<e; i++) {
mrb_gc_mark(mrb, (struct RBasic*)mrb->backtrace.entries[i].klass);
}
/* mark pre-allocated exception */
mrb_gc_mark(mrb, (struct RBasic*)mrb->nomem_err);
mrb_gc_mark(mrb, (struct RBasic*)mrb->stack_err);
Expand Down
4 changes: 2 additions & 2 deletions test/t/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def backtrace_available?
end
rescue => exception
GC.start
assert_equal("#{__FILE__}:#{line}:in Object.call",
assert_equal("#{__FILE__}:#{line}:in call",
exception.backtrace.first)
end
end
Expand All @@ -416,7 +416,7 @@ def backtrace_available?
rescue => exception
[3].each do
end
assert_equal("#{__FILE__}:#{line}:in Object.call",
assert_equal("#{__FILE__}:#{line}:in call",
exception.backtrace.first)
end
end

0 comments on commit d2458e6

Please sign in to comment.