Skip to content

Commit a18fa86

Browse files
committed
Change how to correct the first lineno in the backtrace on ArgumentError
Follow up to fix 3b7373f. In that commit, the line number in the first frame was overwritten after the whole backtrace was created. There was a problem that the line number was overwritten even if the location was backpatched. Instead, this commit uses first_lineno if the frame is VM_FRAME_MAGIC_DUMMY when generating the backtrace. Before the patch: ``` $ ./miniruby -e '[1, 2].inject(:tap)' -e:in '<main>': wrong number of arguments (given 1, expected 0) (ArgumentError) from -e:1:in 'Enumerable#inject' from -e:1:in '<main>' ``` After the patch: ``` $ ./miniruby -e '[1, 2].inject(:tap)' -e:1:in '<main>': wrong number of arguments (given 1, expected 0) (ArgumentError) from -e:1:in 'Enumerable#inject' from -e:1:in '<main>' ```
1 parent 74e6bdd commit a18fa86

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

internal/vm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ int rb_get_node_id_from_frame_info(VALUE obj);
121121
const struct rb_iseq_struct *rb_get_iseq_from_frame_info(VALUE obj);
122122

123123
VALUE rb_ec_backtrace_object(const struct rb_execution_context_struct *ec);
124-
void rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self);
125124

126125
#define RUBY_DTRACE_CREATE_HOOK(name, arg) \
127126
RUBY_DTRACE_HOOK(name##_CREATE, arg)

vm_args.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,6 @@ raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VA
985985
ISEQ_BODY(iseq)->iseq_encoded,
986986
ec->cfp->sp, 0, 0 /* stack_max */);
987987
at = rb_ec_backtrace_object(ec);
988-
rb_backtrace_use_iseq_first_lineno_for_last_location(at);
989988
rb_vm_pop_frame(ec);
990989
}
991990
else {

vm_backtrace.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,12 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
715715
}
716716
else {
717717
RB_OBJ_WRITE(btobj, &loc->iseq, iseq);
718-
loc->pc = pc;
718+
if ((VM_FRAME_TYPE(cfp) & VM_FRAME_MAGIC_MASK) == VM_FRAME_MAGIC_DUMMY) {
719+
loc->pc = NULL; // means location.first_lineno
720+
}
721+
else {
722+
loc->pc = pc;
723+
}
719724
bt_backpatch_loc(backpatch_counter, loc-1, iseq, pc);
720725
if (do_yield) {
721726
bt_yield_loc(loc - backpatch_counter, backpatch_counter+1, btobj);
@@ -813,22 +818,6 @@ rb_backtrace_to_str_ary(VALUE self)
813818
return bt->strary;
814819
}
815820

816-
void
817-
rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self)
818-
{
819-
rb_backtrace_t *bt;
820-
rb_backtrace_location_t *loc;
821-
822-
TypedData_Get_Struct(self, rb_backtrace_t, &backtrace_data_type, bt);
823-
VM_ASSERT(bt->backtrace_size > 0);
824-
825-
loc = &bt->backtrace[0];
826-
827-
VM_ASSERT(!loc->cme || loc->cme->def->type == VM_METHOD_TYPE_ISEQ);
828-
829-
loc->pc = NULL; // means location.first_lineno
830-
}
831-
832821
static VALUE
833822
location_create(rb_backtrace_location_t *srcloc, void *btobj)
834823
{

0 commit comments

Comments
 (0)