@@ -19,7 +19,7 @@ def hook_builtins?
19
19
Mutex . new . synchronize do
20
20
@hook_builtins = true if @hook_builtins . nil?
21
21
22
- return false unless @hook_builtins
22
+ next false unless @hook_builtins
23
23
24
24
@hook_builtins = false
25
25
true
@@ -101,48 +101,52 @@ def hook_builtins
101
101
hook_loaded_code = lambda do |hooks_by_class , builtin |
102
102
hooks_by_class . each do |class_name , hooks |
103
103
Array ( hooks ) . each do |hook |
104
- if builtin && hook . package . require_name && hook . package . require_name != 'ruby'
105
- require hook . package . require_name
106
- end
107
-
108
- Array ( hook . method_names ) . each do |method_name |
109
- method_name = method_name . to_sym
110
-
104
+ HookLog . builtin class_name do
105
+ if builtin && hook . package . require_name && hook . package . require_name != 'ruby'
106
+ begin
107
+ require hook . package . require_name
108
+ rescue
109
+ HookLog . load_error hook . package . require_name , "Unable to require #{ hook . package . require_name } : #{ $!} " if HookLog . enabled?
110
+ next
111
+ end
112
+ end
113
+
111
114
begin
112
115
base_cls = Object . const_get class_name
113
116
rescue NameError
117
+ HookLog . load_error class_name , "Class #{ class_name } not found in global scope" if HookLog . enabled?
114
118
next
115
119
end
116
-
117
- HookLog . builtin_begin class_name , method_name if HookLog . enabled?
118
-
119
- hook_method = lambda do |entry |
120
- cls , method = entry
121
- next if config . never_hook? ( cls , method )
122
-
123
- hook . package . handler_class . new ( hook . package , cls , method ) . activate
124
- end
125
-
126
- methods = [ ]
127
- # irb(main):001:0> Kernel.public_instance_method(:system)
128
- # (irb):1:in `public_instance_method': method `system' for module `Kernel' is private (NameError)
129
- if base_cls == Kernel
130
- methods << [ base_cls , base_cls . instance_method ( method_name ) ] rescue nil
131
- end
132
- methods << [ base_cls , base_cls . public_instance_method ( method_name ) ] rescue nil
133
- methods << [ base_cls , base_cls . protected_instance_method ( method_name ) ] rescue nil
134
- if base_cls . respond_to? ( :singleton_class )
135
- methods << [ base_cls . singleton_class , base_cls . singleton_class . public_instance_method ( method_name ) ] rescue nil
136
- methods << [ base_cls . singleton_class , base_cls . singleton_class . protected_instance_method ( method_name ) ] rescue nil
137
- end
138
- methods . compact!
139
- if methods . empty?
140
- HookLog . log "Method #{ method_name } not found on #{ base_cls . name } " if HookLog . enabled?
141
- else
142
- methods . each ( &hook_method )
120
+
121
+ Array ( hook . method_names ) . each do |method_name |
122
+ method_name = method_name . to_sym
123
+
124
+ hook_method = lambda do |entry |
125
+ cls , method = entry
126
+ next if config . never_hook? ( cls , method )
127
+
128
+ hook . package . handler_class . new ( hook . package , cls , method ) . activate
129
+ end
130
+
131
+ methods = [ ]
132
+ # irb(main):001:0> Kernel.public_instance_method(:system)
133
+ # (irb):1:in `public_instance_method': method `system' for module `Kernel' is private (NameError)
134
+ if base_cls == Kernel
135
+ methods << [ base_cls , base_cls . instance_method ( method_name ) ] rescue nil
136
+ end
137
+ methods << [ base_cls , base_cls . public_instance_method ( method_name ) ] rescue nil
138
+ methods << [ base_cls , base_cls . protected_instance_method ( method_name ) ] rescue nil
139
+ if base_cls . respond_to? ( :singleton_class )
140
+ methods << [ base_cls . singleton_class , base_cls . singleton_class . public_instance_method ( method_name ) ] rescue nil
141
+ methods << [ base_cls . singleton_class , base_cls . singleton_class . protected_instance_method ( method_name ) ] rescue nil
142
+ end
143
+ methods . compact!
144
+ if methods . empty?
145
+ HookLog . load_error [ base_cls . name , method_name ] . join ( '[#.]' ) , "Method #{ method_name } not found on #{ base_cls . name } " if HookLog . enabled?
146
+ else
147
+ methods . each ( &hook_method )
148
+ end
143
149
end
144
-
145
- HookLog . builtin_end class_name , method_name if HookLog . enabled?
146
150
end
147
151
end
148
152
end
@@ -159,17 +163,14 @@ def trace_location(trace_point)
159
163
160
164
def trace_end ( trace_point )
161
165
location = trace_location ( trace_point )
162
- begin
163
- HookLog . usercode_begin location if HookLog . enabled?
164
-
165
- return unless @trace_locations . add? ( location )
166
-
166
+ return unless @trace_locations . add? ( location )
167
+ HookLog . on_load location do
167
168
path = trace_point . path
168
169
enabled = !@notrace_paths . member? ( path ) && config . path_enabled? ( path )
169
170
unless enabled
170
171
HookLog . log 'Not hooking - path is not enabled' if HookLog . enabled?
171
172
@notrace_paths << path
172
- return
173
+ next
173
174
end
174
175
175
176
cls = trace_point . self
@@ -191,7 +192,7 @@ def trace_end(trace_point)
191
192
method = begin
192
193
hook_cls . instance_method ( method_id )
193
194
rescue NameError
194
- HookLog . log "Method #{ hook_cls } #{ fn } is not accessible: #{ $!} " if HookLog . enabled?
195
+ HookLog . load_error [ hook_cls , method_id ] . join ( '[#.]' ) , "Method #{ hook_cls } #{ method_id } is not accessible: #{ $!} " if HookLog . enabled?
195
196
next
196
197
end
197
198
@@ -239,8 +240,6 @@ def trace_end(trace_point)
239
240
@module_load_times [ location ] += elapsed
240
241
end
241
242
end
242
- ensure
243
- HookLog . usercode_end ( location ) if HookLog . enabled?
244
243
end
245
244
end
246
245
end
0 commit comments