From 7bad605f43a4645c47b284ca6ae5b2a275bd01ec Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Mon, 26 Oct 2020 10:48:50 -0300 Subject: [PATCH 1/3] Make load_dwarf public but :nodoc: and introduce load_dwarf_impl --- src/exception/call_stack/dwarf.cr | 10 ++++++++-- src/exception/call_stack/elf.cr | 3 +-- src/exception/call_stack/mach_o.cr | 3 +-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/exception/call_stack/dwarf.cr b/src/exception/call_stack/dwarf.cr index 8e2a95c7a2cb..8192e6859681 100644 --- a/src/exception/call_stack/dwarf.cr +++ b/src/exception/call_stack/dwarf.cr @@ -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}" @@ -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 diff --git a/src/exception/call_stack/elf.cr b/src/exception/call_stack/elf.cr index 865b70029540..6dd50401d972 100644 --- a/src/exception/call_stack/elf.cr +++ b/src/exception/call_stack/elf.cr @@ -2,7 +2,7 @@ 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) @@ -10,7 +10,6 @@ struct Exception::CallStack end LibC.dl_iterate_phdr(phdr_callback, nil) - @@dwarf_loaded = true end protected def self.read_dwarf_sections(base_address = 0) diff --git a/src/exception/call_stack/mach_o.cr b/src/exception/call_stack/mach_o.cr index b858fe9da691..275eb75314f5 100644 --- a/src/exception/call_stack/mach_o.cr +++ b/src/exception/call_stack/mach_o.cr @@ -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 From abc6903b0b97b878f8d4fed0330eae9a2c8741aa Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Mon, 26 Oct 2020 10:50:02 -0300 Subject: [PATCH 2/3] Move load_dwarf call to kernel On preview_mt the specs are hang unless the initialization is changed --- src/exception/call_stack.cr | 6 ------ src/kernel.cr | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/exception/call_stack.cr b/src/exception/call_stack.cr index 2d6d589faba8..3fd4a8916bd0 100644 --- a/src/exception/call_stack.cr +++ b/src/exception/call_stack.cr @@ -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 diff --git a/src/kernel.cr b/src/kernel.cr index b0d5cfc38eca..9f233ce4d8f9 100644 --- a/src/kernel.cr +++ b/src/kernel.cr @@ -527,6 +527,12 @@ end LibExt.setup_sigfault_handler {% 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 + Exception::CallStack.load_dwarf +{% end %} + {% if flag?(:preview_mt) %} Crystal::Scheduler.init_workers {% end %} From 9fbb5a74700822a0371b2b61822b510d7c4d38c0 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Mon, 26 Oct 2020 12:19:33 -0300 Subject: [PATCH 3/3] Do not load dwarf on windows --- src/kernel.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel.cr b/src/kernel.cr index 9f233ce4d8f9..879c80641955 100644 --- a/src/kernel.cr +++ b/src/kernel.cr @@ -527,7 +527,7 @@ end LibExt.setup_sigfault_handler {% end %} -{% if flag?(:debug) %} +{% 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