Skip to content

Commit

Permalink
Emit debug information for toplevel variables
Browse files Browse the repository at this point in the history
ggiraldez authored and Ary Borenszweig committed Oct 26, 2016

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent 8b7283b commit 61a3b69
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
@@ -202,6 +202,8 @@ module Crystal
initialize_simple_class_vars_and_constants

alloca_vars @program.vars, @program

emit_vars_debug_info(@program.vars) if @debug
end

# Here we only initialize simple constants and class variables, those
@@ -344,6 +346,8 @@ module Crystal
file_module = @program.file_module(node.filename)
if vars = file_module.vars?
alloca_vars vars, file_module

emit_vars_debug_info(vars) if @debug
end
node.node.accept self
end
13 changes: 13 additions & 0 deletions src/compiler/crystal/codegen/debug.cr
Original file line number Diff line number Diff line change
@@ -149,6 +149,19 @@ module Crystal
di_builder.insert_declare_at_end(alloca, var, expr, builder.current_debug_location, alloca_block)
end

# Emit debug info for toplevel variables. Used for the main module and all
# required files.
def emit_vars_debug_info(vars)
in_alloca_block do
vars.each do |name, var|
llvm_var = context.vars[name]
set_current_debug_location var.location
declare_variable name, var.type, llvm_var.pointer, var.location
end
clear_current_debug_location
end
end

def file_and_dir(file)
# @file_and_dir ||= {} of String | VirtualFile => {String, String}
realfile = case file
3 changes: 3 additions & 0 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
@@ -668,6 +668,9 @@ module Crystal

meta_var = (@meta_vars[var_name] ||= new_meta_var(var_name))

# Save variable assignment location for debugging output
meta_var.location ||= target.location

begin
meta_var.bind_to value
rescue ex : FrozenTypeException

0 comments on commit 61a3b69

Please sign in to comment.