[#22684] [Bug #1247] YAML::load converts some dates into strings — Matthew Wilson <redmine@...>

Bug #1247: YAML::load converts some dates into strings

10 messages 2009/03/05

[#22725] [Bug #1253] Fix MSVC Build Issues — Charlie Savage <redmine@...>

Bug #1253: Fix MSVC Build Issues

13 messages 2009/03/07

[#22727] Moving ruby 1.9.1 forward on windows — Charlie Savage <cfis@...>

Hi everyone,

14 messages 2009/03/08

[#22731] [Bug #1255] += for large strings egrigiously slow — James Lee <redmine@...>

Bug #1255: += for large strings egrigiously slow

11 messages 2009/03/08

[#22736] Ruby 1.9.1 and tail recursion optimization — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...>

Moin, moin!

13 messages 2009/03/08
[#22739] Re: Ruby 1.9.1 and tail recursion optimization — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...> 2009/03/08

Wolfgang N疆asi-Donner schrieb:

[#22748] [Feature #1256] Add constant TAILRECURSION to let a program recognize if tail recursion optimization is implemented — Wolfgang Nádasi-Donner <redmine@...>

Feature #1256: Add constant TAILRECURSION to let a program recognize if tail recursion optimization is implemented

7 messages 2009/03/08

[#22803] Relegate 1.8.6 to Engine Yard, part II — Urabe Shyouhei <shyouhei@...>

Hello and sorry for my being slow for this issue. It's OK now for me to pass

21 messages 2009/03/10

[#22812] [Bug #1261] cross-compiling Ruby extensions using mkmf doesn't fully respect DESTDIR — Daniel Golle <redmine@...>

Bug #1261: cross-compiling Ruby extensions using mkmf doesn't fully respect DESTDIR

8 messages 2009/03/10

[#22892] Ruby Time — valodzka <valodzka@...>

Got tired of current ruby Time limitation, I have written this -

24 messages 2009/03/14
[#22949] Re: Ruby Time — Tanaka Akira <akr@...> 2009/03/19

In article <9e19ed87-9d12-4f98-af3c-bd49a71b0bd4@p11g2000yqe.googlegroups.com>,

[#22974] Re: Ruby Time — valodzka <valodzka@...> 2009/03/20

[#22977] Re: Ruby Time — Urabe Shyouhei <shyouhei@...> 2009/03/20

valodzka wrote:

[#22981] Re: Ruby Time — valodzka <valodzka@...> 2009/03/21

> I bet you'll get tired of updating that database. There's a major difference

[#22893] [Feature #1291] O_CLOEXEC flag missing for Kernel::open — David Martin <redmine@...>

Feature #1291: O_CLOEXEC flag missing for Kernel::open

10 messages 2009/03/15

[#22939] [Bug #1303] A name considered a local variable on RHS of an assignment that defines it — Tomas Matousek <redmine@...>

Bug #1303: A name considered a local variable on RHS of an assignment that defines it

8 messages 2009/03/19

[#23063] [Bug #1332] Reading file on Windows is 500x slower then with previous Ruby version — Damjan Rems <redmine@...>

Bug #1332: Reading file on Windows is 500x slower then with previous Ruby version

11 messages 2009/03/30

[#23075] [Bug #1336] Change in string representation of Floats — Brian Ford <redmine@...>

Bug #1336: Change in string representation of Floats

37 messages 2009/03/31
[#23179] [Bug #1336] Change in string representation of Floats — Roger Pack <redmine@...> 2009/04/11

Issue #1336 has been updated by Roger Pack.

[#23181] Re: [Bug #1336] Change in string representation of Floats — Brent Roman <brent@...> 2009/04/11

[#23186] Re: [Bug #1336] Change in string representation of Floats — Yukihiro Matsumoto <matz@...> 2009/04/12

Hi,

[#23187] Re: [Bug #1336] Change in string representation of Floats — Brent Roman <brent@...> 2009/04/13

[#23188] Re: [Bug #1336] Change in string representation of Floats — Yukihiro Matsumoto <matz@...> 2009/04/13

Hi,

[ruby-core:23049] Extending binding and set_trace_func in 1.9

From: Rocky Bernstein <rockyb@...>
Date: 2009-03-29 03:14:41 UTC
List: ruby-core #23049
It's been quiet in ruby-core.

Recently I've looking at introspection, tracing and writing a new debugger
for Ruby 1.9.

Here are two little extensions to some existing functions that I think will
help in tracing and writing a debugger.

1. set_trace_func().

Right now  set_trace_func() takes a function name. Internally though the C
code sets a trace mask to an event type to trigger (TRACE_MASK_ALL).  It is
helpful sometimes to pass a more selective mask. One possible approach is to
add this as an optional parameter.

In the attached patch this is done. However in the patch the optional
parameter is a Fixnum. I realize it might be nicer if the mask could be
instead set or a list of string event names. Since the change is in C code,
and I prefer to write Ruby, the way I'd suggest doing this is some outside
Ruby code that accomplishes this. Perhaps it could be added to tracer.rb

Not in the patch but something one may want to do is have a routine to
change the mask.

2. binding()

One of the things one wants to do in a debugger is to change the frame in
which to evaluate expressions. For this, ruby-debug adds Kernel#binding_n.
However, wouldn't it be nicer to just extend binding to allow an optional
level parameter (defaulting to 0) that returns a binding for the context
frame of the nth caller? Again this seems pretty simple to do in the
existing C code.

Attachments (1)

trace-mask.patch (6.21 KB, text/x-diff)
---
 test/trace.rb |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
 create mode 100644 test/trace.rb

diff --git a/test/trace.rb b/test/trace.rb
new file mode 100644
index 0000000..4e5f558
--- /dev/null
+++ b/test/trace.rb
@@ -0,0 +1,49 @@
+require 'test/unit'
+
+def sqr(x)
+  return x*x
+end
+
+def something()
+  x=5
+  x=6.2 if x==6.1
+  x=7
+  sqr(5)
+end
+
+class TestTrace < Test::Unit::TestCase
+
+  @@msgs = []
+  def setup
+    @@msgs = []
+  end
+
+  def trace_func(event, file, line, id, binding, klass, *)
+    @@msgs << [event, file, line]
+  end
+
+  def test_trace_func_nil
+    assert_equal(nil, set_trace_func(nil), "set_trace_func(nil)")
+  end
+
+  def test_trace_mask_and_all
+    set_trace_func(method(:trace_func).to_proc, 0x0018)
+    something()
+    set_trace_func(nil)
+    assert_equal(true, 
+                 @@msgs.inject do |result, triple| 
+                   result && ['call', 'return'].member?(triple[0])
+                 end,
+                 "trace - only call/return events"
+                 )
+    call_return_event_count = @@msgs.size
+    set_trace_func(method(:trace_func).to_proc)
+    something()
+    set_trace_func(nil)
+    assert_equal(true, @@msgs.size > call_return_event_count,
+                 'trace - all events')
+
+  end
+end
+
+
-- 
1.5.6.3


From 9b81ad951abcd5f0c70ee1b018468dfa28477561 Mon Sep 17 00:00:00 2001
From: rocky <rocky@sanchez.(none)>
Date: Thu, 26 Mar 2009 00:11:49 -0400
Subject: [PATCH] Add optional trace-event bit mask to filter trace events

---
 thread.c |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/thread.c b/thread.c
index 3627811..aaad570 100644
--- a/thread.c
+++ b/thread.c
@@ -3502,8 +3502,9 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU
 
 /*
  *  call-seq:
- *     set_trace_func(proc)    => proc
- *     set_trace_func(nil)     => nil
+ *     set_trace_func(proc)        => proc
+ *     set_trace_func(proc, mask)  => proc
+ *     set_trace_func(nil)         => nil
  *
  *  Establishes _proc_ as the handler for tracing, or disables
  *  tracing if the parameter is +nil+. _proc_ takes up
@@ -3517,6 +3518,8 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU
  *  <code>line</code> (execute code on a new line), <code>raise</code>
  *  (raise an exception), and <code>return</code> (return from a Ruby
  *  method). Tracing is disabled within the context of _proc_.
+ *  _mask_ is an optional bitmask of events to trigger on, See ruby.h
+ *  for the integer values. If no mask is specified all events are triggered.
  *
  *      class Test
  *	def test
@@ -3541,11 +3544,28 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU
  *	  line prog.rb:3        test     Test
  *	  line prog.rb:4        test     Test
  *      return prog.rb:4        test     Test
+ *
+ *      set_trace_func(proc { |event, file, line, id, binding, classname|
+ *	   printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
+ *      }, 0x018) # 0x018 == calls and returns only
+ *      t = Test.new
+ *      t.test
+ *
+ *  	  call prog.rb:2        test     Test
+ *      return prog.rb:4        test     Test
+
  */
 
 static VALUE
-set_trace_func(VALUE obj, VALUE trace)
+set_trace_func(int argc, VALUE *argv)
 {
+    VALUE vmask;
+    VALUE trace;
+    int mask=RUBY_EVENT_ALL;
+    if (2 == rb_scan_args(argc, argv, "11", &trace, &vmask)) {
+        mask = NUM2INT(vmask);
+    }
+
     rb_remove_event_hook(call_trace_func);
 
     if (NIL_P(trace)) {
@@ -3556,7 +3576,7 @@ set_trace_func(VALUE obj, VALUE trace)
 	rb_raise(rb_eTypeError, "trace_func needs to be Proc");
     }
 
-    rb_add_event_hook(call_trace_func, RUBY_EVENT_ALL, trace);
+    rb_add_event_hook(call_trace_func, mask, trace);
     return trace;
 }
 
@@ -3801,7 +3821,7 @@ Init_Thread(void)
     rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
 
     /* trace */
-    rb_define_global_function("set_trace_func", set_trace_func, 1);
+    rb_define_global_function("set_trace_func", set_trace_func, -1);
     rb_define_method(rb_cThread, "set_trace_func", thread_set_trace_func_m, 1);
     rb_define_method(rb_cThread, "add_trace_func", thread_add_trace_func_m, 1);
 
-- 
1.5.6.3


From e5a23cf5d135abe8420dad7f066a7127e34f6707 Mon Sep 17 00:00:00 2001
From: rocky <rocky@sanchez.(none)>
Date: Thu, 26 Mar 2009 05:54:30 -0400
Subject: [PATCH] Make sure test includes a "raise" event

---
 test/trace.rb |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/test/trace.rb b/test/trace.rb
index 4e5f558..fda610d 100644
--- a/test/trace.rb
+++ b/test/trace.rb
@@ -1,14 +1,16 @@
 require 'test/unit'
 
-def sqr(x)
-  return x*x
+def buggy(x, y)
+  return x / y * y
 end
 
-def something()
-  x=5
-  x=6.2 if x==6.1
-  x=7
-  sqr(5)
+def something(c)
+  b=0 if c==6.1
+  begin
+    return buggy(5, b)
+  rescue
+  end
+  return 0
 end
 
 class TestTrace < Test::Unit::TestCase
@@ -19,6 +21,7 @@ class TestTrace < Test::Unit::TestCase
   end
 
   def trace_func(event, file, line, id, binding, klass, *)
+    puts "#{file}:#{line} - #{event}" if $DEBUG
     @@msgs << [event, file, line]
   end
 
@@ -27,8 +30,8 @@ class TestTrace < Test::Unit::TestCase
   end
 
   def test_trace_mask_and_all
-    set_trace_func(method(:trace_func).to_proc, 0x0018)
-    something()
+    set_trace_func(method(:trace_func).to_proc, 0x0018) # Calls/returns
+    something(6.1)
     set_trace_func(nil)
     assert_equal(true, 
                  @@msgs.inject do |result, triple| 
@@ -37,11 +40,15 @@ class TestTrace < Test::Unit::TestCase
                  "trace - only call/return events"
                  )
     call_return_event_count = @@msgs.size
+    @@msgs = []
+    puts '=' * 20 if $DEBUG
     set_trace_func(method(:trace_func).to_proc)
-    something()
+    something(6.1)
     set_trace_func(nil)
     assert_equal(true, @@msgs.size > call_return_event_count,
-                 'trace - all events')
+                 'trace - all events. Should record more events.')
+    assert_equal(1, @@msgs.select {|x| x[0] == 'raise'}.size,
+                 'trace - all events. Should get a raise event')
 
   end
 end
-- 
1.5.6.3

In This Thread

Prev Next