Skip to content

Commit 421fb00

Browse files
viuginick1valich
authored andcommitted
new hash item presentation, lets add objectId of a hash key to the xml
so we can inspect it later
1 parent 91ff6d7 commit 421fb00

File tree

6 files changed

+96
-26
lines changed

6 files changed

+96
-26
lines changed

bin/rdebug-ide

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ options = OpenStruct.new(
2727
'catchpoint_deleted_event' => false,
2828
'value_as_nested_element' => false,
2929
'attach_mode' => false,
30-
'cli_debug' => false
30+
'cli_debug' => false,
31+
'key_value_mode' => false
3132
)
3233

3334
opts = OptionParser.new do |opts|
@@ -80,6 +81,9 @@ EOB
8081
opts.on("--attach-mode", "Tells that rdebug-ide is working in attach mode") do
8182
options.attach_mode = true
8283
end
84+
opts.on("--key-value", "Key/Value presentation of hash items") do
85+
options.key_value_mode = true
86+
end
8387
opts.on("--ignore-port", "Generate another port") do
8488
options.ignore_port = true
8589
end
@@ -166,6 +170,7 @@ Debugger.debugger_memory_limit = options.debugger_memory_limit
166170
Debugger.inspect_time_limit = options.inspect_time_limit
167171
Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions
168172
Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions
173+
Debugger.key_value_mode = options.key_value_mode
169174

170175
if options.attach_mode
171176
if Debugger::FRONT_END == "debase"

lib/ruby-debug-ide.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def cleanup_backtrace(backtrace)
5151
end
5252

5353
attr_accessor :attached
54+
attr_accessor :key_value_mode
5455
attr_accessor :cli_debug, :xml_debug, :evaluation_timeout
5556
attr_accessor :trace_to_s, :debugger_memory_limit, :inspect_time_limit
5657
attr_accessor :control_thread

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,36 @@ def print_array(array)
144144
end
145145
end
146146

147-
def print_hash(hash)
147+
def do_print_hash_key_value(hash)
148+
print_element("variables", {:type => 'hashItem'}) do
149+
hash.each {|(k, v)|
150+
print_variable('key', k, 'instance')
151+
print_variable('value', v, 'instance')
152+
}
153+
end
154+
end
155+
156+
def do_print_hash(hash)
148157
print_element("variables") do
149-
hash.keys.each {|k|
158+
hash.each {|(k, v)|
150159
if k.class.name == "String"
151160
name = '\'' + k + '\''
152161
else
153162
name = exec_with_allocation_control(k, :to_s, OverflowMessageType::EXCEPTION_MESSAGE)
154163
end
155-
print_variable(name, hash[k], 'instance')
164+
print_variable(name, v, 'instance')
156165
}
157166
end
158167
end
159168

169+
def print_hash(hash)
170+
if Debugger.key_value_mode
171+
do_print_hash_key_value(hash)
172+
else
173+
do_print_hash(hash)
174+
end
175+
end
176+
160177
def print_string(string)
161178
print_element("variables") do
162179
if string.respond_to?('bytes')
@@ -243,6 +260,7 @@ def exec_with_allocation_control(value, exec_method, overflow_message_type)
243260

244261
def print_variable(name, value, kind)
245262
name = name.to_s
263+
246264
if value.nil?
247265
print("<variable name=\"%s\" kind=\"%s\"/>", CGI.escapeHTML(name), kind)
248266
return
@@ -280,6 +298,7 @@ def print_variable(name, value, kind)
280298
CGI.escapeHTML(name), build_compact_value_attr(value, value_str), kind,
281299
build_value_attr(escaped_value_str), value.class,
282300
has_children, value.object_id)
301+
283302
print("<value><![CDATA[%s]]></value>", escaped_value_str) if Debugger.value_as_nested_element
284303
print('</variable>')
285304
rescue StandardError => e
@@ -439,8 +458,11 @@ def print_load_result(file, exception = nil)
439458
end
440459
end
441460

442-
def print_element(name)
443-
print("<#{name}>")
461+
def print_element(name, additional_tags = nil)
462+
additional_tags_presentation = additional_tags.nil? ? ''
463+
: additional_tags.map {|tag, value| " #{tag}=\"#{value}\""}.reduce(:+)
464+
465+
print("<#{name}#{additional_tags_presentation}>")
444466
begin
445467
yield if block_given?
446468
ensure

test-base/test_base.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def debug_jruby?
8282
config_load('debug_jruby')
8383
end
8484

85-
def start_ruby_process(script)
85+
def start_ruby_process(script, additional_opts = '')
8686
@port = TestBase.find_free_port
87-
cmd = debug_command(script, @port)
87+
cmd = debug_command(script, @port, additional_opts)
8888
debug "Starting: #{cmd}\n"
8989

9090
Thread.new do
@@ -147,10 +147,10 @@ def create_test2(lines)
147147

148148
# Creates test.rb with the given lines, set up @test_name and @test_path
149149
# variables and then start the process.
150-
def create_socket(lines)
150+
def create_socket(lines, additional_opts = '')
151151
@test_name = "test.rb"
152152
@test_path = create_file(@test_name, lines)
153-
start_ruby_process(@test_path)
153+
start_ruby_process(@test_path, additional_opts)
154154
end
155155

156156
def socket

test-base/variables_test.rb

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,64 @@ def test_to_s_raises_exception
199199
send_cont
200200
end
201201

202+
def test_new_hash_presentation
203+
create_socket ['class A',
204+
' def to_s',
205+
' "A instance"',
206+
' end',
207+
'end',
208+
209+
'class C',
210+
' def to_s',
211+
' "C instance"',
212+
' end',
213+
'end',
214+
215+
'b = Hash.new',
216+
'c = C.new',
217+
'a = A.new',
218+
'b[1] = a',
219+
'b[a] = "1"',
220+
'b[c] = a',
221+
'puts b #bp here'], '--key-value'
222+
run_to_line(17)
223+
send_ruby('v l')
224+
assert_variables(read_variables, 3,
225+
{:name => "a", :value => "A instance",:type => "A"},
226+
{:name => "b", :value => "Hash (3 elements)", :type => "Hash"},
227+
{:name => "c", :value => "C instance", :type => "C"})
228+
229+
send_ruby("v i b")
230+
231+
assert_variables(read_variables, 6,
232+
{:name => "key", :value => "1"},
233+
{:name => "value", :value => "A instance", :type => "A"},
234+
235+
{:name => "key", :value => "A instance", :type => "A"},
236+
{:name => "value", :value => "1", :type => "String"},
237+
238+
{:name => "key", :value => "C instance", :type => "C"},
239+
{:name => "value", :value => "A instance", :type => "A"})
240+
send_cont
241+
end
242+
202243
def test_to_s_timelimit
203244
create_socket ['class A',
204-
'def to_s',
205-
'a = 1',
206-
'loop do',
207-
'a = a + 1',
208-
'sleep 1',
209-
'break if (a > 2)',
210-
'end',
211-
'a.to_s',
212-
'end',
213-
'end',
214-
'b = Hash.new',
215-
'b[A.new] = A.new',
216-
'b[1] = A.new',
217-
'puts b #bp here']
245+
'def to_s',
246+
'a = 1',
247+
'loop do',
248+
'a = a + 1',
249+
'sleep 1',
250+
'break if (a > 2)',
251+
'end',
252+
'a.to_s',
253+
'end',
254+
'end',
255+
256+
'b = Hash.new',
257+
'b[A.new] = A.new',
258+
'b[1] = A.new',
259+
'puts b #bp here'], '--evaluation-control --time-limit 100 --memory-limit 0'
218260
run_to_line(15)
219261
send_ruby('v l')
220262
assert_variables(read_variables, 1,

test/rd_test_base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def setup
1818
end
1919
end
2020

21-
def debug_command(script, port)
21+
def debug_command(script, port, additional_opts='')
2222
cmd = "#{interpreter}"
2323
cmd << " --debug" if jruby?
2424
cmd << " -J-Xdebug -J-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" if jruby? and debug_jruby?
2525
cmd << " -I 'lib:#{File.dirname(script)}' #{@rdebug_ide}" +
2626
(@verbose_server ? " -d" : "") +
27-
" -p #{port} --evaluation-control --time-limit 100 --memory-limit 0 -- '#{script}'"
27+
" -p #{port} #{additional_opts} -- '#{script}'"
2828
end
2929

3030
def start_debugger

0 commit comments

Comments
 (0)