Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: debug.rb
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
[0] Fix | Delete
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
[1] Fix | Delete
# Copyright (C) 2000-2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
[2] Fix | Delete
[3] Fix | Delete
if $SAFE > 0
[4] Fix | Delete
STDERR.print "-r debug.rb is not available in safe mode\n"
[5] Fix | Delete
exit 1
[6] Fix | Delete
end
[7] Fix | Delete
[8] Fix | Delete
require 'tracer'
[9] Fix | Delete
require 'pp'
[10] Fix | Delete
[11] Fix | Delete
class Tracer
[12] Fix | Delete
def Tracer.trace_func(*vars)
[13] Fix | Delete
Single.trace_func(*vars)
[14] Fix | Delete
end
[15] Fix | Delete
end
[16] Fix | Delete
[17] Fix | Delete
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
[18] Fix | Delete
[19] Fix | Delete
class DEBUGGER__
[20] Fix | Delete
class Mutex
[21] Fix | Delete
def initialize
[22] Fix | Delete
@locker = nil
[23] Fix | Delete
@waiting = []
[24] Fix | Delete
@locked = false;
[25] Fix | Delete
end
[26] Fix | Delete
[27] Fix | Delete
def locked?
[28] Fix | Delete
@locked
[29] Fix | Delete
end
[30] Fix | Delete
[31] Fix | Delete
def lock
[32] Fix | Delete
return if Thread.critical
[33] Fix | Delete
return if @locker == Thread.current
[34] Fix | Delete
while (Thread.critical = true; @locked)
[35] Fix | Delete
@waiting.push Thread.current
[36] Fix | Delete
Thread.stop
[37] Fix | Delete
end
[38] Fix | Delete
@locked = true
[39] Fix | Delete
@locker = Thread.current
[40] Fix | Delete
Thread.critical = false
[41] Fix | Delete
self
[42] Fix | Delete
end
[43] Fix | Delete
[44] Fix | Delete
def unlock
[45] Fix | Delete
return if Thread.critical
[46] Fix | Delete
return unless @locked
[47] Fix | Delete
unless @locker == Thread.current
[48] Fix | Delete
raise RuntimeError, "unlocked by other"
[49] Fix | Delete
end
[50] Fix | Delete
Thread.critical = true
[51] Fix | Delete
t = @waiting.shift
[52] Fix | Delete
@locked = false
[53] Fix | Delete
@locker = nil
[54] Fix | Delete
Thread.critical = false
[55] Fix | Delete
t.run if t
[56] Fix | Delete
self
[57] Fix | Delete
end
[58] Fix | Delete
end
[59] Fix | Delete
MUTEX = Mutex.new
[60] Fix | Delete
[61] Fix | Delete
class Context
[62] Fix | Delete
DEBUG_LAST_CMD = []
[63] Fix | Delete
[64] Fix | Delete
begin
[65] Fix | Delete
require 'readline'
[66] Fix | Delete
def readline(prompt, hist)
[67] Fix | Delete
Readline::readline(prompt, hist)
[68] Fix | Delete
end
[69] Fix | Delete
rescue LoadError
[70] Fix | Delete
def readline(prompt, hist)
[71] Fix | Delete
STDOUT.print prompt
[72] Fix | Delete
STDOUT.flush
[73] Fix | Delete
line = STDIN.gets
[74] Fix | Delete
exit unless line
[75] Fix | Delete
line.chomp!
[76] Fix | Delete
line
[77] Fix | Delete
end
[78] Fix | Delete
USE_READLINE = false
[79] Fix | Delete
end
[80] Fix | Delete
[81] Fix | Delete
def initialize
[82] Fix | Delete
if Thread.current == Thread.main
[83] Fix | Delete
@stop_next = 1
[84] Fix | Delete
else
[85] Fix | Delete
@stop_next = 0
[86] Fix | Delete
end
[87] Fix | Delete
@last_file = nil
[88] Fix | Delete
@file = nil
[89] Fix | Delete
@line = nil
[90] Fix | Delete
@no_step = nil
[91] Fix | Delete
@frames = []
[92] Fix | Delete
@finish_pos = 0
[93] Fix | Delete
@trace = false
[94] Fix | Delete
@catch = "StandardError"
[95] Fix | Delete
@suspend_next = false
[96] Fix | Delete
end
[97] Fix | Delete
[98] Fix | Delete
def stop_next(n=1)
[99] Fix | Delete
@stop_next = n
[100] Fix | Delete
end
[101] Fix | Delete
[102] Fix | Delete
def set_suspend
[103] Fix | Delete
@suspend_next = true
[104] Fix | Delete
end
[105] Fix | Delete
[106] Fix | Delete
def clear_suspend
[107] Fix | Delete
@suspend_next = false
[108] Fix | Delete
end
[109] Fix | Delete
[110] Fix | Delete
def suspend_all
[111] Fix | Delete
DEBUGGER__.suspend
[112] Fix | Delete
end
[113] Fix | Delete
[114] Fix | Delete
def resume_all
[115] Fix | Delete
DEBUGGER__.resume
[116] Fix | Delete
end
[117] Fix | Delete
[118] Fix | Delete
def check_suspend
[119] Fix | Delete
return if Thread.critical
[120] Fix | Delete
while (Thread.critical = true; @suspend_next)
[121] Fix | Delete
DEBUGGER__.waiting.push Thread.current
[122] Fix | Delete
@suspend_next = false
[123] Fix | Delete
Thread.stop
[124] Fix | Delete
end
[125] Fix | Delete
Thread.critical = false
[126] Fix | Delete
end
[127] Fix | Delete
[128] Fix | Delete
def trace?
[129] Fix | Delete
@trace
[130] Fix | Delete
end
[131] Fix | Delete
[132] Fix | Delete
def set_trace(arg)
[133] Fix | Delete
@trace = arg
[134] Fix | Delete
end
[135] Fix | Delete
[136] Fix | Delete
def stdout
[137] Fix | Delete
DEBUGGER__.stdout
[138] Fix | Delete
end
[139] Fix | Delete
[140] Fix | Delete
def break_points
[141] Fix | Delete
DEBUGGER__.break_points
[142] Fix | Delete
end
[143] Fix | Delete
[144] Fix | Delete
def display
[145] Fix | Delete
DEBUGGER__.display
[146] Fix | Delete
end
[147] Fix | Delete
[148] Fix | Delete
def context(th)
[149] Fix | Delete
DEBUGGER__.context(th)
[150] Fix | Delete
end
[151] Fix | Delete
[152] Fix | Delete
def set_trace_all(arg)
[153] Fix | Delete
DEBUGGER__.set_trace(arg)
[154] Fix | Delete
end
[155] Fix | Delete
[156] Fix | Delete
def set_last_thread(th)
[157] Fix | Delete
DEBUGGER__.set_last_thread(th)
[158] Fix | Delete
end
[159] Fix | Delete
[160] Fix | Delete
def debug_eval(str, binding)
[161] Fix | Delete
begin
[162] Fix | Delete
val = eval(str, binding)
[163] Fix | Delete
rescue StandardError, ScriptError => e
[164] Fix | Delete
at = eval("caller(1)", binding)
[165] Fix | Delete
stdout.printf "%s:%s\n", at.shift, e.to_s.sub(/\(eval\):1:(in `.*?':)?/, '')
[166] Fix | Delete
for i in at
[167] Fix | Delete
stdout.printf "\tfrom %s\n", i
[168] Fix | Delete
end
[169] Fix | Delete
throw :debug_error
[170] Fix | Delete
end
[171] Fix | Delete
end
[172] Fix | Delete
[173] Fix | Delete
def debug_silent_eval(str, binding)
[174] Fix | Delete
begin
[175] Fix | Delete
eval(str, binding)
[176] Fix | Delete
rescue StandardError, ScriptError
[177] Fix | Delete
nil
[178] Fix | Delete
end
[179] Fix | Delete
end
[180] Fix | Delete
[181] Fix | Delete
def var_list(ary, binding)
[182] Fix | Delete
ary.sort!
[183] Fix | Delete
for v in ary
[184] Fix | Delete
stdout.printf " %s => %s\n", v, eval(v, binding).inspect
[185] Fix | Delete
end
[186] Fix | Delete
end
[187] Fix | Delete
[188] Fix | Delete
def debug_variable_info(input, binding)
[189] Fix | Delete
case input
[190] Fix | Delete
when /^\s*g(?:lobal)?\s*$/
[191] Fix | Delete
var_list(global_variables, binding)
[192] Fix | Delete
[193] Fix | Delete
when /^\s*l(?:ocal)?\s*$/
[194] Fix | Delete
var_list(eval("local_variables", binding), binding)
[195] Fix | Delete
[196] Fix | Delete
when /^\s*i(?:nstance)?\s+/
[197] Fix | Delete
obj = debug_eval($', binding)
[198] Fix | Delete
var_list(obj.instance_variables, obj.instance_eval{binding()})
[199] Fix | Delete
[200] Fix | Delete
when /^\s*c(?:onst(?:ant)?)?\s+/
[201] Fix | Delete
obj = debug_eval($', binding)
[202] Fix | Delete
unless obj.kind_of? Module
[203] Fix | Delete
stdout.print "Should be Class/Module: ", $', "\n"
[204] Fix | Delete
else
[205] Fix | Delete
var_list(obj.constants, obj.module_eval{binding()})
[206] Fix | Delete
end
[207] Fix | Delete
end
[208] Fix | Delete
end
[209] Fix | Delete
[210] Fix | Delete
def debug_method_info(input, binding)
[211] Fix | Delete
case input
[212] Fix | Delete
when /^i(:?nstance)?\s+/
[213] Fix | Delete
obj = debug_eval($', binding)
[214] Fix | Delete
[215] Fix | Delete
len = 0
[216] Fix | Delete
for v in obj.methods.sort
[217] Fix | Delete
len += v.size + 1
[218] Fix | Delete
if len > 70
[219] Fix | Delete
len = v.size + 1
[220] Fix | Delete
stdout.print "\n"
[221] Fix | Delete
end
[222] Fix | Delete
stdout.print v, " "
[223] Fix | Delete
end
[224] Fix | Delete
stdout.print "\n"
[225] Fix | Delete
[226] Fix | Delete
else
[227] Fix | Delete
obj = debug_eval(input, binding)
[228] Fix | Delete
unless obj.kind_of? Module
[229] Fix | Delete
stdout.print "Should be Class/Module: ", input, "\n"
[230] Fix | Delete
else
[231] Fix | Delete
len = 0
[232] Fix | Delete
for v in obj.instance_methods(false).sort
[233] Fix | Delete
len += v.size + 1
[234] Fix | Delete
if len > 70
[235] Fix | Delete
len = v.size + 1
[236] Fix | Delete
stdout.print "\n"
[237] Fix | Delete
end
[238] Fix | Delete
stdout.print v, " "
[239] Fix | Delete
end
[240] Fix | Delete
stdout.print "\n"
[241] Fix | Delete
end
[242] Fix | Delete
end
[243] Fix | Delete
end
[244] Fix | Delete
[245] Fix | Delete
def thnum
[246] Fix | Delete
num = DEBUGGER__.instance_eval{@thread_list[Thread.current]}
[247] Fix | Delete
unless num
[248] Fix | Delete
DEBUGGER__.make_thread_list
[249] Fix | Delete
num = DEBUGGER__.instance_eval{@thread_list[Thread.current]}
[250] Fix | Delete
end
[251] Fix | Delete
num
[252] Fix | Delete
end
[253] Fix | Delete
[254] Fix | Delete
def debug_command(file, line, id, binding)
[255] Fix | Delete
MUTEX.lock
[256] Fix | Delete
unless defined?($debugger_restart) and $debugger_restart
[257] Fix | Delete
callcc{|c| $debugger_restart = c}
[258] Fix | Delete
end
[259] Fix | Delete
set_last_thread(Thread.current)
[260] Fix | Delete
frame_pos = 0
[261] Fix | Delete
binding_file = file
[262] Fix | Delete
binding_line = line
[263] Fix | Delete
previous_line = nil
[264] Fix | Delete
if ENV['EMACS']
[265] Fix | Delete
stdout.printf "\032\032%s:%d:\n", binding_file, binding_line
[266] Fix | Delete
else
[267] Fix | Delete
stdout.printf "%s:%d:%s", binding_file, binding_line,
[268] Fix | Delete
line_at(binding_file, binding_line)
[269] Fix | Delete
end
[270] Fix | Delete
@frames[0] = [binding, file, line, id]
[271] Fix | Delete
display_expressions(binding)
[272] Fix | Delete
prompt = true
[273] Fix | Delete
while prompt and input = readline("(rdb:%d) "%thnum(), true)
[274] Fix | Delete
catch(:debug_error) do
[275] Fix | Delete
if input == ""
[276] Fix | Delete
next unless DEBUG_LAST_CMD[0]
[277] Fix | Delete
input = DEBUG_LAST_CMD[0]
[278] Fix | Delete
stdout.print input, "\n"
[279] Fix | Delete
else
[280] Fix | Delete
DEBUG_LAST_CMD[0] = input
[281] Fix | Delete
end
[282] Fix | Delete
[283] Fix | Delete
case input
[284] Fix | Delete
when /^\s*tr(?:ace)?(?:\s+(on|off))?(?:\s+(all))?$/
[285] Fix | Delete
if defined?( $2 )
[286] Fix | Delete
if $1 == 'on'
[287] Fix | Delete
set_trace_all true
[288] Fix | Delete
else
[289] Fix | Delete
set_trace_all false
[290] Fix | Delete
end
[291] Fix | Delete
elsif defined?( $1 )
[292] Fix | Delete
if $1 == 'on'
[293] Fix | Delete
set_trace true
[294] Fix | Delete
else
[295] Fix | Delete
set_trace false
[296] Fix | Delete
end
[297] Fix | Delete
end
[298] Fix | Delete
if trace?
[299] Fix | Delete
stdout.print "Trace on.\n"
[300] Fix | Delete
else
[301] Fix | Delete
stdout.print "Trace off.\n"
[302] Fix | Delete
end
[303] Fix | Delete
[304] Fix | Delete
when /^\s*b(?:reak)?\s+(?:(.+):)?([^.:]+)$/
[305] Fix | Delete
pos = $2
[306] Fix | Delete
if $1
[307] Fix | Delete
klass = debug_silent_eval($1, binding)
[308] Fix | Delete
file = $1
[309] Fix | Delete
end
[310] Fix | Delete
if pos =~ /^\d+$/
[311] Fix | Delete
pname = pos
[312] Fix | Delete
pos = pos.to_i
[313] Fix | Delete
else
[314] Fix | Delete
pname = pos = pos.intern.id2name
[315] Fix | Delete
end
[316] Fix | Delete
break_points.push [true, 0, klass || file, pos]
[317] Fix | Delete
stdout.printf "Set breakpoint %d at %s:%s\n", break_points.size, klass || file, pname
[318] Fix | Delete
[319] Fix | Delete
when /^\s*b(?:reak)?\s+(.+)[#.]([^.:]+)$/
[320] Fix | Delete
pos = $2.intern.id2name
[321] Fix | Delete
klass = debug_eval($1, binding)
[322] Fix | Delete
break_points.push [true, 0, klass, pos]
[323] Fix | Delete
stdout.printf "Set breakpoint %d at %s.%s\n", break_points.size, klass, pos
[324] Fix | Delete
[325] Fix | Delete
when /^\s*wat(?:ch)?\s+(.+)$/
[326] Fix | Delete
exp = $1
[327] Fix | Delete
break_points.push [true, 1, exp]
[328] Fix | Delete
stdout.printf "Set watchpoint %d:%s\n", break_points.size, exp
[329] Fix | Delete
[330] Fix | Delete
when /^\s*b(?:reak)?$/
[331] Fix | Delete
if break_points.find{|b| b[1] == 0}
[332] Fix | Delete
n = 1
[333] Fix | Delete
stdout.print "Breakpoints:\n"
[334] Fix | Delete
for b in break_points
[335] Fix | Delete
if b[0] and b[1] == 0
[336] Fix | Delete
stdout.printf " %d %s:%s\n", n, b[2], b[3]
[337] Fix | Delete
end
[338] Fix | Delete
n += 1
[339] Fix | Delete
end
[340] Fix | Delete
end
[341] Fix | Delete
if break_points.find{|b| b[1] == 1}
[342] Fix | Delete
n = 1
[343] Fix | Delete
stdout.print "\n"
[344] Fix | Delete
stdout.print "Watchpoints:\n"
[345] Fix | Delete
for b in break_points
[346] Fix | Delete
if b[0] and b[1] == 1
[347] Fix | Delete
stdout.printf " %d %s\n", n, b[2]
[348] Fix | Delete
end
[349] Fix | Delete
n += 1
[350] Fix | Delete
end
[351] Fix | Delete
end
[352] Fix | Delete
if break_points.size == 0
[353] Fix | Delete
stdout.print "No breakpoints\n"
[354] Fix | Delete
else
[355] Fix | Delete
stdout.print "\n"
[356] Fix | Delete
end
[357] Fix | Delete
[358] Fix | Delete
when /^\s*del(?:ete)?(?:\s+(\d+))?$/
[359] Fix | Delete
pos = $1
[360] Fix | Delete
unless pos
[361] Fix | Delete
input = readline("Clear all breakpoints? (y/n) ", false)
[362] Fix | Delete
if input == "y"
[363] Fix | Delete
for b in break_points
[364] Fix | Delete
b[0] = false
[365] Fix | Delete
end
[366] Fix | Delete
end
[367] Fix | Delete
else
[368] Fix | Delete
pos = pos.to_i
[369] Fix | Delete
if break_points[pos-1]
[370] Fix | Delete
break_points[pos-1][0] = false
[371] Fix | Delete
else
[372] Fix | Delete
stdout.printf "Breakpoint %d is not defined\n", pos
[373] Fix | Delete
end
[374] Fix | Delete
end
[375] Fix | Delete
[376] Fix | Delete
when /^\s*disp(?:lay)?\s+(.+)$/
[377] Fix | Delete
exp = $1
[378] Fix | Delete
display.push [true, exp]
[379] Fix | Delete
stdout.printf "%d: ", display.size
[380] Fix | Delete
display_expression(exp, binding)
[381] Fix | Delete
[382] Fix | Delete
when /^\s*disp(?:lay)?$/
[383] Fix | Delete
display_expressions(binding)
[384] Fix | Delete
[385] Fix | Delete
when /^\s*undisp(?:lay)?(?:\s+(\d+))?$/
[386] Fix | Delete
pos = $1
[387] Fix | Delete
unless pos
[388] Fix | Delete
input = readline("Clear all expressions? (y/n) ", false)
[389] Fix | Delete
if input == "y"
[390] Fix | Delete
for d in display
[391] Fix | Delete
d[0] = false
[392] Fix | Delete
end
[393] Fix | Delete
end
[394] Fix | Delete
else
[395] Fix | Delete
pos = pos.to_i
[396] Fix | Delete
if display[pos-1]
[397] Fix | Delete
display[pos-1][0] = false
[398] Fix | Delete
else
[399] Fix | Delete
stdout.printf "Display expression %d is not defined\n", pos
[400] Fix | Delete
end
[401] Fix | Delete
end
[402] Fix | Delete
[403] Fix | Delete
when /^\s*c(?:ont)?$/
[404] Fix | Delete
prompt = false
[405] Fix | Delete
[406] Fix | Delete
when /^\s*s(?:tep)?(?:\s+(\d+))?$/
[407] Fix | Delete
if $1
[408] Fix | Delete
lev = $1.to_i
[409] Fix | Delete
else
[410] Fix | Delete
lev = 1
[411] Fix | Delete
end
[412] Fix | Delete
@stop_next = lev
[413] Fix | Delete
prompt = false
[414] Fix | Delete
[415] Fix | Delete
when /^\s*n(?:ext)?(?:\s+(\d+))?$/
[416] Fix | Delete
if $1
[417] Fix | Delete
lev = $1.to_i
[418] Fix | Delete
else
[419] Fix | Delete
lev = 1
[420] Fix | Delete
end
[421] Fix | Delete
@stop_next = lev
[422] Fix | Delete
@no_step = @frames.size - frame_pos
[423] Fix | Delete
prompt = false
[424] Fix | Delete
[425] Fix | Delete
when /^\s*w(?:here)?$/, /^\s*f(?:rame)?$/
[426] Fix | Delete
display_frames(frame_pos)
[427] Fix | Delete
[428] Fix | Delete
when /^\s*l(?:ist)?(?:\s+(.+))?$/
[429] Fix | Delete
if not $1
[430] Fix | Delete
b = previous_line ? previous_line + 10 : binding_line - 5
[431] Fix | Delete
e = b + 9
[432] Fix | Delete
elsif $1 == '-'
[433] Fix | Delete
b = previous_line ? previous_line - 10 : binding_line - 5
[434] Fix | Delete
e = b + 9
[435] Fix | Delete
else
[436] Fix | Delete
b, e = $1.split(/[-,]/)
[437] Fix | Delete
if e
[438] Fix | Delete
b = b.to_i
[439] Fix | Delete
e = e.to_i
[440] Fix | Delete
else
[441] Fix | Delete
b = b.to_i - 5
[442] Fix | Delete
e = b + 9
[443] Fix | Delete
end
[444] Fix | Delete
end
[445] Fix | Delete
previous_line = b
[446] Fix | Delete
display_list(b, e, binding_file, binding_line)
[447] Fix | Delete
[448] Fix | Delete
when /^\s*up(?:\s+(\d+))?$/
[449] Fix | Delete
previous_line = nil
[450] Fix | Delete
if $1
[451] Fix | Delete
lev = $1.to_i
[452] Fix | Delete
else
[453] Fix | Delete
lev = 1
[454] Fix | Delete
end
[455] Fix | Delete
frame_pos += lev
[456] Fix | Delete
if frame_pos >= @frames.size
[457] Fix | Delete
frame_pos = @frames.size - 1
[458] Fix | Delete
stdout.print "At toplevel\n"
[459] Fix | Delete
end
[460] Fix | Delete
binding, binding_file, binding_line = @frames[frame_pos]
[461] Fix | Delete
stdout.print format_frame(frame_pos)
[462] Fix | Delete
[463] Fix | Delete
when /^\s*down(?:\s+(\d+))?$/
[464] Fix | Delete
previous_line = nil
[465] Fix | Delete
if $1
[466] Fix | Delete
lev = $1.to_i
[467] Fix | Delete
else
[468] Fix | Delete
lev = 1
[469] Fix | Delete
end
[470] Fix | Delete
frame_pos -= lev
[471] Fix | Delete
if frame_pos < 0
[472] Fix | Delete
frame_pos = 0
[473] Fix | Delete
stdout.print "At stack bottom\n"
[474] Fix | Delete
end
[475] Fix | Delete
binding, binding_file, binding_line = @frames[frame_pos]
[476] Fix | Delete
stdout.print format_frame(frame_pos)
[477] Fix | Delete
[478] Fix | Delete
when /^\s*fin(?:ish)?$/
[479] Fix | Delete
if frame_pos == @frames.size
[480] Fix | Delete
stdout.print "\"finish\" not meaningful in the outermost frame.\n"
[481] Fix | Delete
else
[482] Fix | Delete
@finish_pos = @frames.size - frame_pos
[483] Fix | Delete
frame_pos = 0
[484] Fix | Delete
prompt = false
[485] Fix | Delete
end
[486] Fix | Delete
[487] Fix | Delete
when /^\s*cat(?:ch)?(?:\s+(.+))?$/
[488] Fix | Delete
if $1
[489] Fix | Delete
excn = $1
[490] Fix | Delete
if excn == 'off'
[491] Fix | Delete
@catch = nil
[492] Fix | Delete
stdout.print "Clear catchpoint.\n"
[493] Fix | Delete
else
[494] Fix | Delete
@catch = excn
[495] Fix | Delete
stdout.printf "Set catchpoint %s.\n", @catch
[496] Fix | Delete
end
[497] Fix | Delete
else
[498] Fix | Delete
if @catch
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function