Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 69dd9ad2cf11
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6c8d58228b54
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Mar 13, 2016

  1. Copy the full SHA
    8c38256 View commit details
  2. Fixed generating backtraces.

    brixen committed Mar 13, 2016
    Copy the full SHA
    6c8d582 View commit details
2 changes: 1 addition & 1 deletion core/vm.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ class Rubinius::VM
# Rubinius::VariableScope object that can be used to access the frames
# running information like locals, self, etc.
#
def self.backtrace(frames_to_skip, include_vars=false)
def self.backtrace(frames_to_skip)
Rubinius.primitive :vm_backtrace

# Add the + 1 to skip this frame
86 changes: 50 additions & 36 deletions machine/builtin/location.cpp
Original file line number Diff line number Diff line change
@@ -86,71 +86,87 @@ namespace rubinius {
return loc;
}

Array* Location::from_call_stack(STATE, bool include_vars, bool on_ip, ssize_t up) {
CallFrame* frame = state->vm()->call_frame();

while(frame && up-- > 0) {
frame = frame->previous;
}

if(!frame) return nil<Array>();

Array* Location::debugging_call_stack(STATE) {
CallFrame* base = state->vm()->call_frame();
size_t count = 0;

CallFrame* base = frame;
while(base) {
count++;
base = base->previous;
}

if(!base) return nil<Array>();

Array* array = Array::create(state, count);
bool first = true;

while(frame) {
if(first) {
if(!frame->compiled_code) continue;

first = false;
if(Location* location = Location::create(state, frame, include_vars)) {
if(on_ip) location->set_ip_on_current(state);
for(CallFrame* frame = base; frame; frame = frame->previous) {
if(frame->compiled_code) {
if(Location* location = Location::create(state, frame, true)) {
if(first) {
location->set_ip_on_current(state);
first = false;
}
array->append(state, location);
}
} else {
if(frame->compiled_code) {
array->append(state, Location::create(state, frame, include_vars));
} else if(NativeMethodFrame* nmf = frame->native_method_frame()) {
if(Location* location = Location::create(state, nmf)) {
array->append(state, location);
}
} else if(NativeMethodFrame* nmf = frame->native_method_frame()) {
if(Location* location = Location::create(state, nmf)) {
array->append(state, location);
}
}

frame = frame->previous;
}

return array;
}

Array* Location::mri_backtrace(STATE, ssize_t up) {
CallFrame* frame = state->vm()->call_frame();
Array* Location::from_call_stack(STATE, ssize_t up) {
CallFrame* base = state->vm()->call_frame();
size_t count = 0;

while(frame && up-- > 0) {
frame = frame->previous;
while(base) {
if(up-- > 0) {
// ignore this frame
} else {
count++;
}
base = base->previous;
}

if(!frame) return nil<Array>();
if(!base) return nil<Array>();

Array* array = Array::create(state, count);

for(CallFrame* frame = base; frame; frame = frame->previous) {
if(frame->compiled_code) {
array->append(state, Location::create(state, frame));
} else if(NativeMethodFrame* nmf = frame->native_method_frame()) {
if(Location* location = Location::create(state, nmf)) {
array->append(state, location);
}
}
}

return array;
}

Array* Location::mri_backtrace(STATE, ssize_t up) {
CallFrame* base = state->vm()->call_frame();
size_t count = 0;

CallFrame* base = frame;
while(base) {
count++;
if(up-- > 0) {
// ignore this frame
} else {
count++;
}
base = base->previous;
}

if(!base) return nil<Array>();

Array* array = Array::create(state, count);

while(frame) {
for(CallFrame* frame = base; frame; frame = frame->previous) {
if(frame->compiled_code && !frame->compiled_code->core_method(state)) {
Symbol* name;
Object* block = cFalse;
@@ -177,8 +193,6 @@ namespace rubinius {
array->append(state,
Tuple::from(state, 4, frame->compiled_code, line, block, name));
}

frame = frame->previous;
}

return array;
4 changes: 2 additions & 2 deletions machine/builtin/location.hpp
Original file line number Diff line number Diff line change
@@ -71,8 +71,8 @@ namespace rubinius {
// Rubinius.primitive :location_of_closest_ruby_method
static Location* of_closest_ruby_method(STATE);

static Array* from_call_stack(STATE,
bool include_vars=false, bool on_ip=false, ssize_t up=1);
static Array* debugging_call_stack(STATE);
static Array* from_call_stack(STATE, ssize_t up=1);
static Array* mri_backtrace(STATE, ssize_t up=1);

class Info : public TypeInfo {
2 changes: 1 addition & 1 deletion machine/builtin/native_method.cpp
Original file line number Diff line number Diff line change
@@ -639,7 +639,7 @@ namespace rubinius {
if(arity >= 0 && (size_t)arity != args.total()) {
Exception* exc = Exception::make_argument_error(
state, arity, args.total(), args.name());
exc->locations(state, Location::from_call_stack(state, state->vm()->call_frame()));
exc->locations(state, Location::from_call_stack(state));
state->raise_exception(exc);

return NULL;
2 changes: 1 addition & 1 deletion machine/builtin/object.cpp
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ namespace rubinius {
class_object(state) != other->class_object(state)) {
Exception* exc =
Exception::make_type_error(state, type_id(), other);
exc->locations(state, Location::from_call_stack(state, state->vm()->call_frame()));
exc->locations(state, Location::from_call_stack(state));
state->raise_exception(exc);
return NULL;
}
9 changes: 2 additions & 7 deletions machine/builtin/system.cpp
Original file line number Diff line number Diff line change
@@ -941,16 +941,11 @@ namespace rubinius {
/* @todo Could possibly capture the system backtrace at this
* point. --rue
*/
Array* System::vm_backtrace(STATE, Fixnum* skip, Object* inc_vars) {
bool include_vars = CBOOL(inc_vars);

// TODO: CallFrame: fix this API
return Location::from_call_stack(state,
include_vars, false, skip->to_native());
Array* System::vm_backtrace(STATE, Fixnum* skip) {
return Location::from_call_stack(state, skip->to_native());
}

Array* System::vm_mri_backtrace(STATE, Fixnum* skip) {
// TODO: CallFrame: fix this API
return Location::mri_backtrace(state, skip->to_native());
}

2 changes: 1 addition & 1 deletion machine/builtin/system.hpp
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ namespace rubinius {
* Backtrace as an Array.
*/
// Rubinius.primitive :vm_backtrace
static Array* vm_backtrace(STATE, Fixnum* skip, Object* inc_vars);
static Array* vm_backtrace(STATE, Fixnum* skip);

// Rubinius.primitive :vm_mri_backtrace
static Array* vm_mri_backtrace(STATE, Fixnum* skip);
11 changes: 9 additions & 2 deletions machine/capi/capi.cpp
Original file line number Diff line number Diff line change
@@ -156,6 +156,8 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

@@ -201,6 +203,8 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

@@ -254,6 +258,8 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

@@ -300,6 +306,8 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

@@ -357,8 +365,7 @@ namespace rubinius {

void capi_raise_backend(Exception* exception) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
exception->locations(env->state(), Location::from_call_stack(env->state(),
env->current_call_frame()));
exception->locations(env->state(), Location::from_call_stack(env->state()));
env->state()->raise_exception(exception);

env->current_ep()->return_to(env);
2 changes: 1 addition & 1 deletion machine/helpers.cpp
Original file line number Diff line number Diff line change
@@ -309,7 +309,7 @@ namespace rubinius {
cur->control_channel(state, my_control);
}

Array* locs = Location::from_call_stack(state, true, true);
Array* locs = Location::debugging_call_stack(state);

OnStack<1> os(state, my_control);