tracepoint 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY ADDED
@@ -0,0 +1,12 @@
1
+ = HISTORY
2
+
3
+ == 1.0.0 / 2009-07-10
4
+
5
+ Tracepoint is a spin-off of Ruby Facets. This is it's first release as
6
+ a stand alone project. Tracepoint is a Binding with event information that
7
+ can be used to trace execution, akin to #set_trace_func.
8
+
9
+ * 1 major enhancement
10
+
11
+ * Birthday!
12
+
data/LICENSE ADDED
@@ -0,0 +1,167 @@
1
+
2
+ = GNU LESSER GENERAL PUBLIC LICENSE
3
+
4
+ Version 3, 29 June 2007
5
+
6
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+ This version of the GNU Lesser General Public License incorporates
11
+ the terms and conditions of version 3 of the GNU General Public
12
+ License, supplemented by the additional permissions listed below.
13
+
14
+ == 0. Additional Definitions.
15
+
16
+ As used herein, "this License" refers to version 3 of the GNU Lesser
17
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
18
+ General Public License.
19
+
20
+ "The Library" refers to a covered work governed by this License,
21
+ other than an Application or a Combined Work as defined below.
22
+
23
+ An "Application" is any work that makes use of an interface provided
24
+ by the Library, but which is not otherwise based on the Library.
25
+ Defining a subclass of a class defined by the Library is deemed a mode
26
+ of using an interface provided by the Library.
27
+
28
+ A "Combined Work" is a work produced by combining or linking an
29
+ Application with the Library. The particular version of the Library
30
+ with which the Combined Work was made is also called the "Linked
31
+ Version".
32
+
33
+ The "Minimal Corresponding Source" for a Combined Work means the
34
+ Corresponding Source for the Combined Work, excluding any source code
35
+ for portions of the Combined Work that, considered in isolation, are
36
+ based on the Application, and not on the Linked Version.
37
+
38
+ The "Corresponding Application Code" for a Combined Work means the
39
+ object code and/or source code for the Application, including any data
40
+ and utility programs needed for reproducing the Combined Work from the
41
+ Application, but excluding the System Libraries of the Combined Work.
42
+
43
+ == 1. Exception to Section 3 of the GNU GPL.
44
+
45
+ You may convey a covered work under sections 3 and 4 of this License
46
+ without being bound by section 3 of the GNU GPL.
47
+
48
+ == 2. Conveying Modified Versions.
49
+
50
+ If you modify a copy of the Library, and, in your modifications, a
51
+ facility refers to a function or data to be supplied by an Application
52
+ that uses the facility (other than as an argument passed when the
53
+ facility is invoked), then you may convey a copy of the modified
54
+ version:
55
+
56
+ a) under this License, provided that you make a good faith effort to
57
+ ensure that, in the event an Application does not supply the
58
+ function or data, the facility still operates, and performs
59
+ whatever part of its purpose remains meaningful, or
60
+
61
+ b) under the GNU GPL, with none of the additional permissions of
62
+ this License applicable to that copy.
63
+
64
+ == 3. Object Code Incorporating Material from Library Header Files.
65
+
66
+ The object code form of an Application may incorporate material from
67
+ a header file that is part of the Library. You may convey such object
68
+ code under terms of your choice, provided that, if the incorporated
69
+ material is not limited to numerical parameters, data structure
70
+ layouts and accessors, or small macros, inline functions and templates
71
+ (ten or fewer lines in length), you do both of the following:
72
+
73
+ a) Give prominent notice with each copy of the object code that the
74
+ Library is used in it and that the Library and its use are
75
+ covered by this License.
76
+
77
+ b) Accompany the object code with a copy of the GNU GPL and this license
78
+ document.
79
+
80
+ == 4. Combined Works.
81
+
82
+ You may convey a Combined Work under terms of your choice that,
83
+ taken together, effectively do not restrict modification of the
84
+ portions of the Library contained in the Combined Work and reverse
85
+ engineering for debugging such modifications, if you also do each of
86
+ the following:
87
+
88
+ a) Give prominent notice with each copy of the Combined Work that
89
+ the Library is used in it and that the Library and its use are
90
+ covered by this License.
91
+
92
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
93
+ document.
94
+
95
+ c) For a Combined Work that displays copyright notices during
96
+ execution, include the copyright notice for the Library among
97
+ these notices, as well as a reference directing the user to the
98
+ copies of the GNU GPL and this license document.
99
+
100
+ d) Do one of the following:
101
+
102
+ d.0) Convey the Minimal Corresponding Source under the terms of this
103
+ License, and the Corresponding Application Code in a form
104
+ suitable for, and under terms that permit, the user to
105
+ recombine or relink the Application with a modified version of
106
+ the Linked Version to produce a modified Combined Work, in the
107
+ manner specified by section 6 of the GNU GPL for conveying
108
+ Corresponding Source.
109
+
110
+ d.1) Use a suitable shared library mechanism for linking with the
111
+ Library. A suitable mechanism is one that (a) uses at run time
112
+ a copy of the Library already present on the user's computer
113
+ system, and (b) will operate properly with a modified version
114
+ of the Library that is interface-compatible with the Linked
115
+ Version.
116
+
117
+ e) Provide Installation Information, but only if you would otherwise
118
+ be required to provide such information under section 6 of the
119
+ GNU GPL, and only to the extent that such information is
120
+ necessary to install and execute a modified version of the
121
+ Combined Work produced by recombining or relinking the
122
+ Application with a modified version of the Linked Version. (If
123
+ you use option 4d0, the Installation Information must accompany
124
+ the Minimal Corresponding Source and Corresponding Application
125
+ Code. If you use option 4d1, you must provide the Installation
126
+ Information in the manner specified by section 6 of the GNU GPL
127
+ for conveying Corresponding Source.)
128
+
129
+ == 5. Combined Libraries.
130
+
131
+ You may place library facilities that are a work based on the
132
+ Library side by side in a single library together with other library
133
+ facilities that are not Applications and are not covered by this
134
+ License, and convey such a combined library under terms of your
135
+ choice, if you do both of the following:
136
+
137
+ a) Accompany the combined library with a copy of the same work based
138
+ on the Library, uncombined with any other library facilities,
139
+ conveyed under the terms of this License.
140
+
141
+ b) Give prominent notice with the combined library that part of it
142
+ is a work based on the Library, and explaining where to find the
143
+ accompanying uncombined form of the same work.
144
+
145
+ == 6. Revised Versions of the GNU Lesser General Public License.
146
+
147
+ The Free Software Foundation may publish revised and/or new versions
148
+ of the GNU Lesser General Public License from time to time. Such new
149
+ versions will be similar in spirit to the present version, but may
150
+ differ in detail to address new problems or concerns.
151
+
152
+ Each version is given a distinguishing version number. If the
153
+ Library as you received it specifies that a certain numbered version
154
+ of the GNU Lesser General Public License "or any later version"
155
+ applies to it, you have the option of following the terms and
156
+ conditions either of that published version or of any later version
157
+ published by the Free Software Foundation. If the Library as you
158
+ received it does not specify a version number of the GNU Lesser
159
+ General Public License, you may choose any version of the GNU Lesser
160
+ General Public License ever published by the Free Software Foundation.
161
+
162
+ If the Library as you received it specifies that a proxy can decide
163
+ whether future versions of the GNU Lesser General Public License shall
164
+ apply, that proxy's public statement of acceptance of any version is
165
+ permanent authorization for you to choose that version for the
166
+ Library.
167
+
@@ -0,0 +1,19 @@
1
+ test
2
+ RELEASE
3
+ LICENSE
4
+ README
5
+ HISTORY
6
+ meta
7
+ meta/created
8
+ meta/repository
9
+ meta/homepage
10
+ meta/summary
11
+ meta/abstract
12
+ meta/package
13
+ meta/released
14
+ meta/version
15
+ meta/license
16
+ meta/authors
17
+ meta/project
18
+ lib
19
+ lib/tracepoint.rb
data/README ADDED
@@ -0,0 +1,62 @@
1
+ = Tracepoint
2
+
3
+ * http://death.rubyforge.org
4
+ * http://death.rubyforge.org/tracepoint
5
+
6
+ == DESCRIPTION:
7
+
8
+ A TracePoint is a Binding with the addition of event information.
9
+ Among other things, it functions very well as the join-point for AOP.
10
+ In practice it provides a better means than #set_trace_func.
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ * Easier and more versitle than #set_trace_func.
15
+ * Set mutliple traces easily.
16
+
17
+ == RELEASE/NOTES:
18
+
19
+ Please see RELEASE file.
20
+
21
+ == SYNOPSIS:
22
+
23
+ Let's watch everything that happens:
24
+
25
+ TracePoint.trace { |tp|
26
+ puts "#{tp.self.class}\t#{tp.called}\t#{tp.event}\t#{tp.return?}\t#{tp.back == tp.bind}"
27
+ }
28
+
29
+ 1 + 1
30
+
31
+ produces
32
+
33
+ Class trace return true false
34
+ Object line false false
35
+ Fixnum + c-call false false
36
+ Fixnum + c-return false false
37
+
38
+ See RDocs for more information.
39
+
40
+ == INSTALL:
41
+
42
+ * sudo gem install tracepoint
43
+
44
+ == LICENSE:
45
+
46
+ (LGPL v3 License)
47
+
48
+ Copyright (c) 2005,2009 The Coding Dead <death.rubyforge.org>
49
+
50
+ This program is free software: you can redistribute it and/or modify
51
+ it under the terms of the GNU Lesser General Public License as published
52
+ by the Free Software Foundation, either version 3 of the License, or
53
+ (at your option) any later version.
54
+
55
+ This program is distributed in the hope that it will be useful,
56
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
57
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58
+ GNU General Public License for more details.
59
+
60
+ You should have received a copy of the GNU Lesser General Public License
61
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
62
+
data/RELEASE ADDED
@@ -0,0 +1,12 @@
1
+ = RELEASE NOTES
2
+
3
+ Tracepoint is a spin-off of Ruby Facets. This is it's first release as
4
+ a stand alone project. Tracepoint is a Binding with event information that
5
+ can be used to trace execution, akin to #set_trace_func.
6
+
7
+ ### 1.0.0 / 2009-07-10
8
+
9
+ * 1 major enhancement
10
+
11
+ * Birthday!
12
+
@@ -0,0 +1,209 @@
1
+ # = TracePoint
2
+ #
3
+ # A TracePoint is a Binding with the addition event information.
4
+ # And it's a better way to use set_trace_func.
5
+ #
6
+ # A TracePoint is a Binding with the addition of event information.
7
+ # Among other things, it functions very well as the join-point for
8
+ # Event-based AOP.
9
+ #
10
+ # == Usage
11
+ #
12
+ # TracePoint.trace { |tp|
13
+ # puts "#{tp.self.class}\t#{tp.called}\t#{tp.event}\t#{tp.return?}\t#{tp.back == tp.bind}"
14
+ # }
15
+ #
16
+ # 1 + 1
17
+ #
18
+ # produces
19
+ #
20
+ # Class trace return true false
21
+ # Object line false false
22
+ # Fixnum + c-call false false
23
+ # Fixnum + c-return false false
24
+ #
25
+ # == Notes
26
+ #
27
+ # You can't subclass Binding, so we delegate (which is better anyway).
28
+ #
29
+ # == Authors
30
+ #
31
+ # * Thomas Sawyer
32
+ #
33
+ # == Copying
34
+ #
35
+ # Copyright (c) 2005 Thomas Sawyer
36
+ #
37
+ # Ruby License
38
+ #
39
+ # This module is free software. You may use, modify, and/or redistribute this
40
+ # software under the same terms as Ruby.
41
+ #
42
+ # This program is distributed in the hope that it will be useful, but WITHOUT
43
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
44
+ # FOR A PARTICULAR PURPOSE.
45
+
46
+ require 'facets/binding'
47
+
48
+ # = CodePoint
49
+ #
50
+ # This is the same as a Binding. Not really needed, but I like consistency :)
51
+
52
+ CodePoint = Binding
53
+
54
+ # = TracePoint
55
+ #
56
+ # A TracePoint is a Binding with the addition of event information.
57
+ # Among other things, it functions very well as the join-point for
58
+ # Event-based AOP.
59
+ #
60
+ # == Usage
61
+ #
62
+ # TracePoint.trace { |tp|
63
+ # puts "#{tp.self.class}\t#{tp.called}\t#{tp.event}\t#{tp.return?}\t#{tp.back == tp.bind}"
64
+ # }
65
+ #
66
+ # 1 + 1
67
+ #
68
+ # produces
69
+ #
70
+ # Class trace return true false
71
+ # Object line false false
72
+ # Fixnum + c-call false false
73
+ # Fixnum + c-return false false
74
+ #
75
+ # == Notes
76
+ #
77
+ # You can't subclass Binding, so we delegate (which is better anyway).
78
+
79
+ class TracePoint #< Codepoint
80
+
81
+ # -- class ---------------------
82
+ class << self
83
+
84
+ @@active = false
85
+
86
+ def active ; @@active ; end
87
+
88
+ def active=(x)
89
+ @@active = x ? true : false
90
+ unless @@active
91
+ set_trace_func nil
92
+ end
93
+ end
94
+
95
+ # Trace execution using a TracePoint.
96
+ def trace # :yield:
97
+ if active
98
+ bb_stack = []
99
+ set_trace_func proc{ |e, f, l, m, b, k|
100
+ #(p e, f, l, m, b, k, @@bb_stack; puts "---") if $DEBUG
101
+ if ['call','c-call','class'].include?(e)
102
+ bb_stack << b
103
+ elsif ['return','c-return','end'].include?(e)
104
+ bb = bb_stack.pop
105
+ end
106
+ b = bb if ! b # this sucks!
107
+ tp = TracePoint.new(e,m,b,bb)
108
+ yield(tp)
109
+ }
110
+ end
111
+ end
112
+
113
+ end #class
114
+
115
+ # -- instance -------------------
116
+
117
+ attr_accessor :event, :binding, :back_binding
118
+
119
+ # Until Ruby has a built-in way to get the name of the calling method
120
+ # that information must be passed into the TracePoint.
121
+ def initialize( event, method, bind, back_binding=bind )
122
+ @event = event
123
+ @method = method
124
+ @binding = bind
125
+ @back_binding = back_binding
126
+ end
127
+
128
+ # shorthand for binding
129
+ def bind ; @binding ; end
130
+
131
+ # shorthand for back_binding
132
+ def back ; @back_binding ; end
133
+
134
+ # Delegates "self" to the binding which
135
+ # in turn delegates the binding object.
136
+ def self ; @binding.self ; end
137
+
138
+ # Returns the name of the event's method.
139
+ # This could delegate to the binding if Ruby had
140
+ # an internal way to retrieve the current method name.
141
+ def callee ; @method ; end
142
+ #def method ; @method ; end # TODO Conflict with Kernel#method?
143
+ alias_method( :called, :callee ) # TODO deprecate
144
+ alias_method( :method_name, :called ) # TODO deprecate
145
+
146
+ # delegate to binding
147
+ #def method_missing(meth, *args, &blk)
148
+ # @binding.send(meth, *args, &blk)
149
+ #end
150
+
151
+ ### methods for working with events
152
+
153
+ EVENT_MAP = {
154
+ :all => ['call', 'c-call', 'return', 'c-return', 'line', 'class', 'end', 'raise'],
155
+ :before => ['call', 'c-call'],
156
+ :after => ['return', 'c-return'],
157
+ :call => ['call'],
158
+ :return => ['return'],
159
+ :ccall => ['c-call'],
160
+ :creturn => ['c-return'],
161
+ :line => ['line'],
162
+ :class => ['class'],
163
+ :end => ['end'],
164
+ :raise => ['raise']
165
+ }
166
+ def event_map(e) ; EVENT_MAP[e] ; end
167
+
168
+ # Is the trace point defined or undefined?
169
+ def event? ; !! @event ; end
170
+ def eventless? ; ! @event ; end
171
+
172
+ # For use in case conditions
173
+ def ===(e)
174
+ EVENT_MAP[e].include?(@event)
175
+ end
176
+
177
+ # Creates an <event>? method for each of the above event mappings.
178
+ EVENT_MAP.each_pair { |m,v|
179
+ define_method( "#{m}?" ){ v.include?(@event) }
180
+ }
181
+
182
+ end
183
+
184
+
185
+
186
+ # _____ _
187
+ # |_ _|__ ___| |_
188
+ # | |/ _ \/ __| __|
189
+ # | | __/\__ \ |_
190
+ # |_|\___||___/\__|
191
+ #
192
+
193
+ # TODO
194
+
195
+ =begin #test
196
+
197
+ # Note: TracePoint will probably prove tricky to test, since
198
+ # manipulating set_trace_func tends to wreak havoc on errors,
199
+ # the call stack, and so on.
200
+
201
+ TracePoint.active = true
202
+
203
+ TracePoint.trace { |tp|
204
+ puts "#{tp.self.class}\t#{tp.called}\t#{tp.event}\t#{tp.return?}\t#{tp.back == tp.bind}"
205
+ }
206
+
207
+ 1 + 1
208
+
209
+ =end
@@ -0,0 +1,3 @@
1
+ A TracePoint is a Binding with the addition of event information.
2
+ Among other things, it functions very well as the join-point for AOP.
3
+ In practice it provides a better alternative to using #set_trace_func.
@@ -0,0 +1 @@
1
+ Trans <transfire@gmail.com>
@@ -0,0 +1 @@
1
+ 2008-08-08 23:09:48 -0400
@@ -0,0 +1 @@
1
+ http://death.rubyforge.org/tracepoint
@@ -0,0 +1 @@
1
+ LGPL v3
@@ -0,0 +1 @@
1
+ tracepoint
@@ -0,0 +1 @@
1
+ death
@@ -0,0 +1 @@
1
+ 2009-07-11
@@ -0,0 +1 @@
1
+ svn://rubyforge.org/var/svn/death/tracepoint
@@ -0,0 +1 @@
1
+ An alternate to #set_trace_func.
@@ -0,0 +1 @@
1
+ 1.0.0
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tracepoint
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Trans <transfire@gmail.com>
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-11 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |-
17
+ A TracePoint is a Binding with the addition of event information.
18
+ Among other things, it functions very well as the join-point for AOP.
19
+ In practice it provides a better alternative to using #set_trace_func.
20
+ email: transfire@gmail.com
21
+ executables: []
22
+
23
+ extensions: []
24
+
25
+ extra_rdoc_files:
26
+ - README
27
+ - MANIFEST
28
+ - RELEASE
29
+ - LICENSE
30
+ - HISTORY
31
+ files:
32
+ - RELEASE
33
+ - LICENSE
34
+ - README
35
+ - HISTORY
36
+ - meta/created
37
+ - meta/repository
38
+ - meta/homepage
39
+ - meta/summary
40
+ - meta/abstract
41
+ - meta/package
42
+ - meta/released
43
+ - meta/version
44
+ - meta/license
45
+ - meta/authors
46
+ - meta/project
47
+ - lib/tracepoint.rb
48
+ - MANIFEST
49
+ has_rdoc: true
50
+ homepage: http://death.rubyforge.org/tracepoint
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --inline-source
56
+ - --title
57
+ - tracepoint api
58
+ - --main
59
+ - README
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: death
77
+ rubygems_version: 1.3.4
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: A TracePoint is a Binding with the addition of event information.
81
+ test_files: []
82
+