Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add MethodContext::line and update VM ruby backtrace to use it

  • Loading branch information...
commit 5c9c7f584e80768d27dc974e31f181511f574766 1 parent a64c449
Eric Hodel drbrain authored
22 vm/builtin/contexts.cpp
View
@@ -1,9 +1,10 @@
#include "builtin/contexts.hpp"
#include "objectmemory.hpp"
#include "builtin/block_environment.hpp"
+#include "builtin/class.hpp"
#include "builtin/compiledmethod.hpp"
#include "builtin/fixnum.hpp"
-#include "builtin/class.hpp"
+#include "builtin/tuple.hpp"
#include "context_cache.hpp"
@@ -64,6 +65,25 @@ namespace rubinius {
return ctx;
}
+ int MethodContext::line() {
+ if(this->cm->nil_p()) return -2; // trampoline context
+ if(this->cm->lines->nil_p()) return -3;
+
+ for(size_t i = 0; i < this->cm->lines->field_count; i++) {
+ Tuple* entry = as<Tuple>(this->cm->lines->at(i));
+
+ FIXNUM start_ip = as<Fixnum>(entry->at(0));
+ FIXNUM end_ip = as<Fixnum>(entry->at(1));
+ FIXNUM line = as<Fixnum>(entry->at(2));
+
+ if(start_ip->to_native() <= this->ip &&
+ end_ip->to_native() >= this->ip)
+ return line->to_native();
+ }
+
+ return -1;
+ }
+
/* Attempt to recycle +this+ context into the context cache, based
* on it's size. Returns true if the context was recycled, otherwise
* false. */
2  vm/builtin/contexts.hpp
View
@@ -43,6 +43,8 @@ namespace rubinius {
static MethodContext* create(STATE, OBJECT recv, CompiledMethod* meth);
static void initialize_cache(STATE);
static void reset_cache(STATE);
+
+ int line();
bool recycle(STATE);
void reference(STATE);
14 vm/test/test_contexts.hpp
View
@@ -29,6 +29,20 @@ class TestContexts : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(ctx->ip, 0);
}
+ void test_line() {
+ MethodContext* ctx = MethodContext::create(state, 10);
+ ctx->ip = 0;
+ ctx->cm = CompiledMethod::create(state);
+
+ ctx->cm->lines = Tuple::from(state, 1,
+ Tuple::from(state, 3,
+ Fixnum::from(0),
+ Fixnum::from(20),
+ Fixnum::from(10)));
+
+ TS_ASSERT_EQUALS(10, ctx->line());
+ }
+
void test_recycle() {
MethodContext* ctx = MethodContext::create(state, 10);
state->context_cache->reclaim = 1;
3  vm/vm.cpp
View
@@ -171,6 +171,7 @@ namespace rubinius {
while(!ctx->nil_p()) {
std::cout << (void*)ctx << ": ";
+ // HACK reports Object#[] instead of Hash::[], etc
std::cout << *ctx->module->name->to_str(this) << "#";
SYMBOL name = try_as<Symbol>(ctx->name);
@@ -180,7 +181,7 @@ namespace rubinius {
std::cout << *ctx->cm->name->to_str(this);
}
- std::cout << "+" << ctx->ip << " in " << *ctx->cm->file->to_str(this);
+ std::cout << ":" << ctx->line() << " in " << *ctx->cm->file->to_str(this);
std::cout << "\n";
ctx = ctx->sender;
Please sign in to comment.
Something went wrong with that request. Please try again.