From cf94227b2c6da45cb093511c79d657c3fd961b4e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 9 Jun 2018 09:16:23 +0300 Subject: [PATCH] fix code init bug where initial pos wasnt propagated --- lib/risc/position/code_listener.rb | 7 +++++++ lib/risc/position/position.rb | 6 +++++- test/risc/position/test_code_listener1.rb | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/risc/position/code_listener.rb b/lib/risc/position/code_listener.rb index 54f4f73f..60c6381b 100644 --- a/lib/risc/position/code_listener.rb +++ b/lib/risc/position/code_listener.rb @@ -18,6 +18,13 @@ module Risc end def position_changed(position) + nekst = position.object.next + if( nekst ) + nekst_pos = Position.get(nekst) + unless(nekst_pos.valid?) + nekst_pos.set(position + position.object.padded_length) + end + end set_jump_for(position) end diff --git a/lib/risc/position/position.rb b/lib/risc/position/position.rb index 44bf55ac..50c15edb 100644 --- a/lib/risc/position/position.rb +++ b/lib/risc/position/position.rb @@ -178,7 +178,11 @@ module Risc end self.positions[position.object] = position @reverse_cache[to] = position unless position.object.is_a?(Label) - log.debug "Set #{position} to 0x#{to.to_s(16)} for #{position.object.class} #{position.object.object_id.to_s(16)}" + if to == -1 + log.debug "Initialize for #{position.object.class} #{position.object.object_id.to_s(16)}" + else + log.debug "Set #{position} to 0x#{to.to_s(16)} for #{position.object.class} #{position.object.object_id.to_s(16)}" + end position end end diff --git a/test/risc/position/test_code_listener1.rb b/test/risc/position/test_code_listener1.rb index ff335586..19986a2b 100644 --- a/test/risc/position/test_code_listener1.rb +++ b/test/risc/position/test_code_listener1.rb @@ -17,10 +17,15 @@ module Risc pos = Position.get(@binary.next) assert_equal CodeListener , pos.event_table[:position_changed].first.class end + def test_valid_pos_for_extended + @binary.extend_one + CodeListener.init(@binary).set(10) + assert Position.get(@binary.next).valid? + end def test_extend_sets_next_pos CodeListener.init(@binary).set(10) @binary.extend_one - assert Position.get(@binary.next) + assert Position.get(@binary.next).valid? end def test_extends_creates_jump CodeListener.init(@binary).set(10)