https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-06-27T17:23:49ZRuby Issue Tracking SystemRuby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=401732013-06-27T17:23:49Zdeivid (David Rodríguez)
<ul></ul><p>"no replies after 10 days" reminder. This is affecting <a href="https://github.com/deivid-rodriguez/byebug" class="external">https://github.com/deivid-rodriguez/byebug</a>, I can easily make it crash by doing:</p>
<pre><code>davidr@pantani:~/Proyectos/byebug$ ruby -Ilib -rbyebug -e 'byebug; fail "Bang!"'
-e @ 1
(byebug) catch Exception
Catch exception Exception.
(byebug) c
Catchpoint at -e:1: `Bang!' (RuntimeError)
from /home/davidr/Proyectos/byebug/lib/byebug/context.rb:44:in `at_catchpoint'
from -e:1:in `<main>'
-e @ 1
(byebug) bt
--> #0 <main> at -e:1
INTERNAL ERROR!!! That frame doesn't exist!
/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:90:in `frame_file'
/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:90:in `print_frame'
/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:85:in `block in print_backtrace'
/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:84:in `each'
/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:84:in `print_backtrace'
/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:127:in `execute'
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:260:in `one_cmd'
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:244:in `block (2 levels) in process_commands'
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:243:in `each'
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:243:in `block in process_commands'
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:236:in `catch'
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:236:in `process_commands'
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:158:in `at_line'
(eval):5:in `block in at_line'
(eval):3:in `synchronize'
(eval):3:in `at_line'
/home/davidr/Proyectos/byebug/lib/byebug/context.rb:52:in `at_line'
-e:1:in `<main>'-e:1:in `<main>': Bang! (RuntimeError)
</code></pre>
<p>When the raise event comes, byebug thinks the stack size is 2 but there's only one element. I think this is caused by the inconsistent behaviour explained above.</p>
<p>Thanks a lot guys!</p> Ruby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=401752013-06-27T18:23:16Zjudofyr (Magnus Holm)judofyr@gmail.com
<ul></ul><p>It seems like #initialize is never pushed to the stack:</p>
<p>class Foo<br>
def initialize<br>
puts caller<br>
end<br>
end</p>
<p>Foo.new</p>
<p>Result:</p>
<p>f.rb:8:in <code>new' f.rb:8:in </code>'</p>
<p>// Magnus Holm</p>
<p>On Thu, Jun 27, 2013 at 10:23 AM, deivid (David Rodríguez) <<br>
<a href="mailto:deivid.rodriguez@gmail.com" class="email">deivid.rodriguez@gmail.com</a>> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: c method not pushed into the callstack when called, but popped when returned (Closed)" href="https://bugs.ruby-lang.org/issues/8538">#8538</a> has been updated by deivid (David Rodríguez).</p>
<p>"no replies after 10 days" reminder. This is affecting<br>
<a href="https://github.com/deivid-rodriguez/byebug" class="external">https://github.com/deivid-rodriguez/byebug</a>, I can easily make it crash by<br>
doing:</p>
<pre><code>davidr@pantani:~/Proyectos/byebug$ ruby -Ilib -rbyebug -e 'byebug;
</code></pre>
<p>fail "Bang!"'<br>
-e @ 1<br>
(byebug) catch Exception<br>
Catch exception Exception.<br>
(byebug) c<br>
Catchpoint at -e:1: <code>Bang!' (RuntimeError) from /home/davidr/Proyectos/byebug/lib/byebug/context.rb:44:in </code>at_catchpoint'<br>
from -e:1:in `'<br>
-e @ 1<br>
(byebug) bt<br>
--> #0 at -e:1<br>
INTERNAL ERROR!!! That frame doesn't exist!</p>
<p>/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:90:in<br>
`frame_file'</p>
<p>/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:90:in<br>
`print_frame'</p>
<p>/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:85:in `block in<br>
print_backtrace'</p>
<p>/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:84:in `each'</p>
<p>/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:84:in<br>
`print_backtrace'</p>
<p>/home/davidr/Proyectos/byebug/lib/byebug/commands/frame.rb:127:in <code>execute' /home/davidr/Proyectos/byebug/lib/byebug/processor.rb:260:in </code>one_cmd'<br>
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:244:in<br>
<code>block (2 levels) in process_commands' /home/davidr/Proyectos/byebug/lib/byebug/processor.rb:243:in </code>each'<br>
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:243:in<br>
<code>block in process_commands' /home/davidr/Proyectos/byebug/lib/byebug/processor.rb:236:in </code>catch'<br>
/home/davidr/Proyectos/byebug/lib/byebug/processor.rb:236:in<br>
<code>process_commands' /home/davidr/Proyectos/byebug/lib/byebug/processor.rb:158:in </code>at_line'<br>
(eval):5:in <code>block in at_line' (eval):3:in </code>synchronize'<br>
(eval):3:in <code>at_line' /home/davidr/Proyectos/byebug/lib/byebug/context.rb:52:in </code>at_line'<br>
-e:1:in <code><main>'-e:1:in </code>': Bang! (RuntimeError)</p>
<p>When the raise event comes, byebug thinks the stack size is 2 but there's<br>
only one element. I think this is caused by the inconsistent behaviour<br>
explained above.</p>
<a name="Thanks-a-lot-guys"></a>
<h2 >Thanks a lot guys!<a href="#Thanks-a-lot-guys" class="wiki-anchor">¶</a></h2>
<p>Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: c method not pushed into the callstack when called, but popped when returned (Closed)" href="https://bugs.ruby-lang.org/issues/8538">#8538</a>: c method not pushed into the callstack when called, but popped<br>
when returned<br>
<a href="https://bugs.ruby-lang.org/issues/8538#change-40173" class="external">https://bugs.ruby-lang.org/issues/8538#change-40173</a></p>
<p>Author: deivid (David Rodríguez)<br>
Status: Open<br>
Priority: Normal<br>
Assignee:<br>
Category:<br>
Target version:<br>
ruby -v: ruby 2.0.0p195 (2013-05-14) [i686-linux]<br>
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN</p>
<p>See the following example:</p>
<pre><code>trace = TracePoint.new do |tp|
puts "Event: #{tp.event}, Method: #{tp.method_id}\n"
puts "Stack: #{caller}\n\n"
end
trace.enable
fail "bang!"
</code></pre>
<p>The output shows:</p>
<pre><code>Event: c_return, Method: enable
Stack: ["trace.rb:6:in `<main>'"]
Event: line, Method:
Stack: ["trace.rb:8:in `<main>'"]
Event: c_call, Method: fail
Stack: ["trace.rb:8:in `<main>'"]
Event: c_call, Method: new
Stack: ["trace.rb:8:in `fail'", "trace.rb:8:in `<main>'"]
Event: c_call, Method: initialize
Stack: ["trace.rb:8:in `new'", "trace.rb:8:in `fail'", "trace.rb:8:in
</code></pre>
<p>`'"]</p>
<pre><code>Event: c_return, Method: initialize
Stack: ["trace.rb:8:in `new'", "trace.rb:8:in `fail'", "trace.rb:8:in
</code></pre>
<p>`'"]</p>
<pre><code>Event: c_return, Method: new
Stack: ["trace.rb:8:in `fail'", "trace.rb:8:in `<main>'"]
Event: c_call, Method: backtrace
Stack: ["trace.rb:8:in `<main>'"]
Event: c_return, Method: backtrace
Stack: ["trace.rb:8:in `<main>'"]
Event: raise, Method:
Stack: ["trace.rb:8:in `<main>'"]
Event: c_return, Method: fail
Stack: ["trace.rb:8:in `<main>'"]
trace.rb:8:in `<main>': bang! (RuntimeError)
</code></pre>
<p>It looks like the method "initialize" is not pushed into the stack when<br>
called, but something (the previous method call) is popped when returning<br>
from it.</p>
<p>Thanks a lot.</p>
<p>--<br>
<a href="http://bugs.ruby-lang.org/" class="external">http://bugs.ruby-lang.org/</a></p>
</blockquote> Ruby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=401762013-06-27T19:06:06Zdeivid (David Rodríguez)
<ul></ul><p>judofyr (Magnus Holm) wrote:</p>
<blockquote>
<p>It seems like #initialize is never pushed to the stack:</p>
<p>class Foo<br>
def initialize<br>
puts caller<br>
end<br>
end</p>
<p>Foo.new</p>
<p>Result:</p>
<p>f.rb:8:in <code>new' f.rb:8:in </code>'</p>
<p>// Magnus Holm</p>
</blockquote>
<p>In your example, it is, you're just not printing the current frame</p>
<pre><code>class Foo
def initialize
puts caller(0)
end
end
Foo.new
</code></pre>
<p>Result:</p>
<pre><code>f.rb:4 in `initialize'
f.rb:8:in `new'
f.rb:8:in `<main>'
</code></pre> Ruby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=401982013-06-29T23:04:10Zko1 (Koichi Sasada)
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li><li><strong>Target version</strong> set to <i>2.1.0</i></li></ul><p>Is it similar problem of the following?<br>
<a href="/issues/7976">[ruby-core:52971]</a> [ruby-trunk - Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: TracePoint call is at call point, not call site (Closed)" href="https://bugs.ruby-lang.org/issues/7976">#7976</a>][Open] TracePoint call is at call point, not call site</p>
<a name="I-will-back-from-Euruko-mode-in-a-few-days"></a>
<h1 >I will back from Euruko-mode in a few days.<a href="#I-will-back-from-Euruko-mode-in-a-few-days" class="wiki-anchor">¶</a></h1> Ruby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=402072013-06-30T22:18:08Zdeivid (David Rodríguez)
<ul></ul><p>=begin<br>
Thanks, <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/17">@ko1 (Koichi Sasada)</a>. I commented the other issue, I think it's not the same thing.</p>
<p>I'm adding the actual output versus the expected output to try make this more clear.</p>
<pre><code>tp = TracePoint.new do |tp|
warn "%-8s %-11p %s" % [tp.event, tp.method_id, caller]
end
tp.enable
raise "bang!"
</code></pre>
<p>Actual output:</p>
<pre><code>c_return :enable ["bt_test.rb:4:in `<main>'"]
line nil ["bt_test.rb:6:in `<main>'"]
c_call :raise ["bt_test.rb:6:in `<main>'"]
c_call :new ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_call :initialize ["bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :initialize ["bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :new ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_call :backtrace ["bt_test.rb:6:in `<main>'"]
c_return :backtrace ["bt_test.rb:6:in `<main>'"]
raise nil ["bt_test.rb:6:in `<main>'"]
c_return :raise ["bt_test.rb:6:in `<main>'"]
bt_test.rb:6:in `<main>': bang! (RuntimeError)
</code></pre>
<p>Expected output:</p>
<pre><code>c_return :enable ["bt_test.rb:4:in `enable'", bt_test.rb:4:in `<main>'"]
line nil ["bt_test.rb:6:in `<main>'"]
c_call :raise ["bt_test.rb:6:in `<main>'"]
c_call :new ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_call :initialize ["bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :initialize ["bt_test.rb:6:in `initialize'", "bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :new ["bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_call :backtrace ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :backtrace ["bt_test.rb:6:in `backtrace'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
raise nil ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :raise ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
bt_test.rb:6:in `<main>': bang! (RuntimeError)
</code></pre>
<p>=end</p> Ruby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=402902013-07-04T23:33:14Zdeivid (David Rodríguez)
<ul></ul><p>=begin<br>
Maybe the granularity requested in my previous message implies more work. I would be fine with just correcting the inconsistent behaviour by not popping from the stack when returning from <code>initialize</code>. The expected output in this case would be</p>
<pre><code>c_return :enable ["bt_test.rb:4:in `<main>'"]
line nil ["bt_test.rb:6:in `<main>'"]
c_call :raise ["bt_test.rb:6:in `<main>'"]
c_call :new ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_call :initialize ["bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :initialize ["bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :new ["bt_test.rb:6:in `new'", "bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_call :backtrace ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :backtrace ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
raise nil ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
c_return :raise ["bt_test.rb:6:in `raise'", "bt_test.rb:6:in `<main>'"]
bt_test.rb:6:in `<main>': bang! (RuntimeError)
</code></pre>
<p>=end</p>
<p>Salute.</p> Ruby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=417172013-09-10T19:19:59Zdeivid (David Rodríguez)
<ul></ul><p>=begin<br>
Hi, I've been investigating this issue and I was misunderstanding it. The order of events is</p>
<pre><code>1. Trigger C_CALL_EVENT
2. Push frame into the stack
3. Pop frame from the stack
4. Trigger C_RETURN_EVENT
</code></pre>
<p>That's why I thought <code>initialize</code> was never pushed into the stack. It is, of course, but it is popped before the TracePoint API can see it.</p>
<p>The issue can be closed. Thanks!<br>
=end</p> Ruby master - Bug #8538: c method not pushed into the callstack when called, but popped when returnedhttps://bugs.ruby-lang.org/issues/8538?journal_id=417182013-09-10T19:32:35ZAnonymous
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul>