Permalink
Browse files

emit dwarf metadata at compilation time and use it to establish backt…

…racing later at runtime

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3117 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 09efc03 commit 0f14388c1c21f02a780e3c4c1c1e3bff096cffc4 @lrz lrz committed Dec 15, 2009
Showing with 124 additions and 102 deletions.
  1. +1 −0 bridgesupport.cpp
  2. +34 −10 compiler.cpp
  3. +5 −32 compiler.h
  4. +1 −0 llvm.h
  5. +83 −60 vm.cpp
View
@@ -13,6 +13,7 @@
#include <llvm/Instructions.h>
#include <llvm/ModuleProvider.h>
#include <llvm/Intrinsics.h>
+#include <llvm/Analysis/DebugInfo.h>
#include <llvm/ExecutionEngine/JIT.h>
#include <llvm/PassManager.h>
#include <llvm/Target/TargetData.h>
View
@@ -8,6 +8,10 @@
#define ROXOR_COMPILER_DEBUG 0
+#if !defined(DW_LANG_Ruby)
+# define DW_LANG_Ruby 0x15 // TODO: Python is 0x14, request a real number
+#endif
+
#include "llvm.h"
#include "ruby/ruby.h"
#include "ruby/encoding.h"
@@ -17,6 +21,7 @@
#include "vm.h"
#include "compiler.h"
#include "objc.h"
+#include "version.h"
extern "C" const char *ruby_node_name(int node);
@@ -26,6 +31,9 @@ RoxorCompiler *RoxorCompiler::shared = NULL;
RoxorCompiler::RoxorCompiler(void)
{
+ assert(RoxorCompiler::module != NULL);
+ debug_info = new DIFactory(*RoxorCompiler::module);
+
fname = "";
inside_eval = false;
@@ -58,7 +66,6 @@ RoxorCompiler::RoxorCompiler(void)
return_from_block = -1;
return_from_block_ids = 0;
ensure_pn = NULL;
- current_scope = NULL;
dispatcherFunc = NULL;
fastPlusFunc = NULL;
@@ -737,10 +744,11 @@ RoxorCompiler::compile_dispatch_call(std::vector<Value *> &params)
(module->getOrInsertFunction("rb_vm_dispatch", ft));
}
- assert(current_scope != NULL);
- current_scope->dispatch_lines.push_back(current_line);
-
- return compile_protected_call(dispatcherFunc, params);
+ Instruction *insn = compile_protected_call(dispatcherFunc, params);
+ if (fname != NULL) {
+ debug_info->InsertStopPoint(debug_compile_unit, current_line, 0, bb);
+ }
+ return insn;
}
Value *
@@ -3096,10 +3104,6 @@ RoxorCompiler::compile_node(NODE *node)
Function *f = Function::Create(ft, GlobalValue::ExternalLinkage,
function_name, module);
- RoxorScope *old_current_scope = current_scope;
- current_scope = new RoxorScope(fname);
- scopes[f] = current_scope;
-
BasicBlock *old_rescue_invoke_bb = rescue_invoke_bb;
BasicBlock *old_rescue_rethrow_bb = rescue_rethrow_bb;
BasicBlock *old_entry_bb = entry_bb;
@@ -3110,6 +3114,13 @@ RoxorCompiler::compile_node(NODE *node)
rescue_rethrow_bb = NULL;
bb = BasicBlock::Create(context, "MainBlock", f);
+ DISubprogram old_debug_subprogram = debug_subprogram;
+ debug_subprogram = debug_info->CreateSubprogram(
+ debug_compile_unit, f->getName(), f->getName(),
+ f->getName(), debug_compile_unit, nd_line(node),
+ DIType(), f->hasInternalLinkage(), true);
+ debug_info->InsertSubprogramStart(debug_subprogram, bb);
+
std::map<ID, Value *> old_lvars = lvars;
lvars.clear();
Value *old_self = current_self;
@@ -3360,7 +3371,7 @@ RoxorCompiler::compile_node(NODE *node)
current_self = old_self;
current_var_uses = old_current_var_uses;
running_block = old_running_block;
- current_scope = old_current_scope;
+ debug_subprogram = old_debug_subprogram;
return cast<Value>(f);
}
@@ -5300,6 +5311,19 @@ RoxorCompiler::compile_node(NODE *node)
return NULL;
}
+void
+RoxorCompiler::set_fname(const char *_fname)
+{
+ if (fname != _fname) {
+ fname = _fname;
+
+ if (fname != NULL) {
+ debug_compile_unit = debug_info->CreateCompileUnit(DW_LANG_Ruby,
+ fname, "", RUBY_DESCRIPTION, false, false, "");
+ }
+ }
+}
+
Function *
RoxorCompiler::compile_main_function(NODE *node)
{
View
@@ -27,14 +27,6 @@
#define DEFINED_SUPER 6
#define DEFINED_METHOD 7
-class RoxorScope {
- public:
- std::string path;
- std::vector<unsigned int> dispatch_lines;
-
- RoxorScope(const char *fname) : path(fname) {}
-};
-
class RoxorCompiler {
public:
static llvm::Module *module;
@@ -43,9 +35,7 @@ class RoxorCompiler {
RoxorCompiler(void);
virtual ~RoxorCompiler(void) { }
- void set_fname(const char *_fname) {
- fname = _fname;
- }
+ void set_fname(const char *_fname);
Value *compile_node(NODE *node);
@@ -71,26 +61,11 @@ class RoxorCompiler {
bool is_dynamic_class(void) { return dynamic_class; }
void set_dynamic_class(bool flag) { dynamic_class = flag; }
- RoxorScope *scope_for_function(Function *f) {
- std::map<Function *, RoxorScope *>::iterator i = scopes.find(f);
- return i == scopes.end() ? NULL : i->second;
- }
-
- bool delete_scope(Function *f) {
- std::map<Function *, RoxorScope *>::iterator i = scopes.find(f);
- if (i != scopes.end()) {
- scopes.erase(i);
- delete i->second;
- return true;
- }
- return false;
- }
-
- void clear_scopes(void) {
- scopes.clear();
- }
-
protected:
+ DIFactory *debug_info;
+ DICompileUnit debug_compile_unit;
+ DISubprogram debug_subprogram;
+
const char *fname;
bool inside_eval;
@@ -99,7 +74,6 @@ class RoxorCompiler {
std::map<ID, Value *> ivar_slots_cache;
std::map<std::string, GlobalVariable *> static_strings;
std::map<CFHashCode, GlobalVariable *> static_ustrings;
- std::map<Function *, RoxorScope *> scopes;
#if ROXOR_COMPILER_DEBUG
int level;
@@ -142,7 +116,6 @@ class RoxorCompiler {
int return_from_block;
int return_from_block_ids;
PHINode *ensure_pn;
- RoxorScope *current_scope;
bool class_declaration;
Function *dispatcherFunc;
View
@@ -11,6 +11,7 @@
#include <llvm/Instructions.h>
#include <llvm/ModuleProvider.h>
#include <llvm/Intrinsics.h>
+#include <llvm/Analysis/DebugInfo.h>
#include <llvm/ExecutionEngine/JIT.h>
#include <llvm/PassManager.h>
#include <llvm/Target/TargetData.h>
Oops, something went wrong. Retry.

0 comments on commit 0f14388

Please sign in to comment.