From: "kjtsanaktsidis (KJ Tsanaktsidis)" Date: 2022-11-12T02:08:21+00:00 Subject: [ruby-core:110717] [Ruby master Feature#19117] Include the method owner in backtraces, not just the method name Issue #19117 has been updated by kjtsanaktsidis (KJ Tsanaktsidis). OK, so if I understand correctly, the proposal in this ticket is to make `Thread::Backtrace::Location#inspect` and `Kernel#callers` print method names using the algorithm used in `rb_profile_frame_qualified_method_name`. Currently, they just print either `iseq->body->location.label` or `cme->def->original_id`. The algorithm used by `rb_profile_frame_qualified_method_name` is: * Look up the `defined_class` for the method entry * If it's a singleton class, and the thing it's a singleton class of is a Class/Module: print `rb_class_path(attached) + "."` * If it's a singleton class, and the thing it's a singleton class of is NOT a Class/Module: print `"#<" + rb_class2name(class of attached) + ":" + hex of the VALUE address + ">" + "."` * Otherwise, print: `rb_class_path(klass) + "#"` * Then print `cme->def->original_id` This ticket would handle making this change ONLY. The motivation for this change is purely to give better developer ergonomics. What _I_ wanted to do was change the output to not include any `%p` representations of VALUE's at all - neither the one directly in `rb_profile_frame_classpath`, nor the one in `make_temporary_path` in variable.c called via `rb_class_path`. It sounds like you're saying I should make a separate proposal for that? In fact - perhaps it might be best not to change the default output of anything at all for my proposal, and simply add a keyword argument `Thread::Backtrace::Location#inspect`, `Thread::Backtrace::Location#label` (and probably also `Module`, `Method`, etc) to print representations _without_ addresses in them, by simply making them all 0x0 or something. This would avoid us having divergent representations of how to print fully-qualified methods whilst also achieving some sensible way to get rid of addresses for backtrace aggregations. ---------------------------------------- Feature #19117: Include the method owner in backtraces, not just the method name https://bugs.ruby-lang.org/issues/19117#change-100055 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal ---------------------------------------- ``` module Foo class Bar def inspect 1 + '1' end end end p Foo::Bar.new ``` This code produce the following backtrace: ``` /tmp/foo.rb:4:in `+': String can't be coerced into Integer (TypeError) from /tmp/foo.rb:4:in `inspect' from /tmp/foo.rb:9:in `p' from /tmp/foo.rb:9:in `
' ``` This works, but on large codebases and large backtraces the method name isn't always all that revealing, most of the time you need to open many of the locations listed in the backtrace to really understand what is going on. I propose that we also include the owner name: ``` /tmp/foo.rb:4:in `Integer#+': String can't be coerced into Integer (TypeError) from /tmp/foo.rb:4:in `Foo::Bar#inspect' from /tmp/foo.rb:9:in `Kernel#p' from /tmp/foo.rb:9:in `
' ``` I believe that in many case it would allow to much better understand the backtrace without having to jump back and forth between it and the source code. This is inspired by @ivoanjo 's `backtracie` gem: https://github.com/ivoanjo/backtracie -- https://bugs.ruby-lang.org/ Unsubscribe: