Skip to content

Commit

Permalink
Use Dwarf information on Exception::CallStack.print_frame (crystal-la…
Browse files Browse the repository at this point in the history
…ng#9792)

* Use dwarf if available on Exception::CallStack.print_frame

Calling callee at the beginning of the program will load dwarf

* Load dwarf on start up and look for it only if compiled with --debug
  • Loading branch information
Brian J. Cardiff committed Oct 7, 2020
1 parent 5251f2a commit a3f9182
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/exception/call_stack.cr
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ struct Exception::CallStack
end

private def self.print_frame(repeated_frame)
{% if flag?(:debug) %}
if @@dwarf_loaded &&
(name = decode_function_name(repeated_frame.ip.address))
file, line, column = Exception::CallStack.decode_line_number(repeated_frame.ip.address)
if file && file != "??"
if repeated_frame.count == 0
Crystal::System.print_error "[0x%lx] %s at %s:%ld:%i\n", repeated_frame.ip, name, file, line, column
else
Crystal::System.print_error "[0x%lx] %s at %s:%ld:%i (%ld times)\n", repeated_frame.ip, name, file, line, column, repeated_frame.count + 1
end
return
end
end
{% end %}

frame = decode_frame(repeated_frame.ip)
if frame
offset, sname = frame
Expand Down Expand Up @@ -202,4 +217,10 @@ struct Exception::CallStack
end
end
end

{% if flag?(:debug) %}
# load dwarf on start up of the program when compiled with --debug
# this will make dwarf available on print_frame that is used on __crystal_sigfault_handler
load_dwarf
{% end %}
end

0 comments on commit a3f9182

Please sign in to comment.