Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework dwarf eager loading (follow up to #9792) #9852

Merged
merged 3 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/exception/call_stack.cr
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,4 @@ 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
10 changes: 8 additions & 2 deletions src/exception/call_stack/dwarf.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ struct Exception::CallStack
@@dwarf_line_numbers : Crystal::DWARF::LineNumbers?
@@dwarf_function_names : Array(Tuple(LibC::SizeT, LibC::SizeT, String))?

# :nodoc:
def self.load_dwarf
load_dwarf_impl unless @@dwarf_loaded
@@dwarf_loaded = true
end

protected def self.decode_line_number(pc)
load_dwarf unless @@dwarf_loaded
load_dwarf
if ln = @@dwarf_line_numbers
if row = ln.find(pc)
path = "#{row.directory}/#{row.file}"
Expand All @@ -22,7 +28,7 @@ struct Exception::CallStack
end

protected def self.decode_function_name(pc)
load_dwarf unless @@dwarf_loaded
load_dwarf
if fn = @@dwarf_function_names
fn.each do |(low_pc, high_pc, function_name)|
return function_name if low_pc <= pc <= high_pc
Expand Down
3 changes: 1 addition & 2 deletions src/exception/call_stack/elf.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ require "crystal/elf"
require "c/link"

struct Exception::CallStack
protected def self.load_dwarf
protected def self.load_dwarf_impl
phdr_callback = LibC::DlPhdrCallback.new do |info, size, data|
# The first entry is the header for the current program
read_dwarf_sections(info.value.addr)
1
end

LibC.dl_iterate_phdr(phdr_callback, nil)
@@dwarf_loaded = true
end

protected def self.read_dwarf_sections(base_address = 0)
Expand Down
3 changes: 1 addition & 2 deletions src/exception/call_stack/mach_o.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ end
struct Exception::CallStack
@@image_slide : LibC::Long?

protected def self.load_dwarf
protected def self.load_dwarf_impl
read_dwarf_sections
@@dwarf_loaded = true
end

protected def self.read_dwarf_sections
Expand Down
6 changes: 6 additions & 0 deletions src/kernel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ end
LibExt.setup_sigfault_handler
{% end %}

{% if flag?(:debug) && !flag?(:win32) %}
# 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
Exception::CallStack.load_dwarf
{% end %}

{% if flag?(:preview_mt) %}
Crystal::Scheduler.init_workers
{% end %}