note
	description: "Execution recorder"
	status: "See notice at end of class."
	legal: "See notice at end of class."
	date: "$Date: 2017-04-12 13:15:47 +0000 (Wed, 12 Apr 2017) $"
	revision: "$Revision: 100150 $"

class 
	RT_DBG_EXECUTION_RECORDER

create {RT_EXTENSION}
	make

feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	make (p: separate RT_DBG_EXECUTION_PARAMETERS)
			-- Creation of Current object
		require
			p_attached: p /= Void
		do
			update_parameters (p)
		end
	
feature -- Access

	callstack_record (dep: INTEGER_32): detachable RT_DBG_CALL_RECORD
			-- Call stack record with depth dep
		local
			i: INTEGER_32
		do
			Result := top_callstack_record
			if dep < 0 then
				from
					i := dep
				until
					Result = Void or i = -1
				loop
					Result := Result.parent
					i := i + 1
				end
			else
				from
				until
					Result = Void or else Result.depth = dep
				loop
					Result := Result.parent
				end
				if Result /= Void and then Result.depth /= dep then
					Result := Void
				end
			end
			debug ("rt_dbg_replay")
				if Result /= Void then
					print ("callstack_record (" + dep.out + ") -> Result=" + Result.to_string (0) + "%N")
				end
			end
		end

	callstack_record_by_id (a_id: STRING_8): like callstack_record
			-- Call record for a_id
		require
			a_id_attached: a_id /= Void
		local
			p: INTEGER_32
			i: INTEGER_32
			r: like callstack_record
			sub_id: detachable STRING_8
		do
			debug ("rt_dbg_replay")
				print ("callstack_record_by_id (" + a_id + ") -start-%N")
			end
			p := a_id.index_of ('.', 1)
			if p > 0 then
				sub_id := a_id.substring (p + 1, a_id.count)
				i := a_id.substring (1, p - 1).to_integer_32
			else
				i := a_id.to_integer_32
			end
			r := callstack_record (i)
			if sub_id = Void then
				Result := r
			elseif r /= Void then
				Result := r.call_by_id (sub_id)
			end
			debug ("rt_dbg_replay")
				print ("callstack_record_by_id (" + a_id + ") -end-%N")
			end
		end

	generating_type: TYPE [detachable RT_DBG_EXECUTION_RECORDER]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end
	
feature {NONE} -- Access

	Bit_type: INTEGER_32 = 8
			-- This type is obsolete and is not used anymore.
			-- (from REFLECTOR_CONSTANTS)

	Boolean_type: INTEGER_32 = 3
			-- Abstract type ID for predefined type BOOLEAN.
			-- (from REFLECTOR_CONSTANTS)

	Character_32_type: INTEGER_32 = 12
			-- Abstract type ID for predefined type CHARACTER_32.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Wide_character_type.
			-- (from REFLECTOR_CONSTANTS)

	Character_8_type: INTEGER_32 = 2
			-- Abstract type ID for predefined type CHARACTER_8.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Character_type.
			-- (from REFLECTOR_CONSTANTS)

	Character_type: INTEGER_32 = 2
			-- Abstract type ID for predefined type CHARACTER_8.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Character_8_type.
			-- (from REFLECTOR_CONSTANTS)

	Double_type: INTEGER_32 = 6
			-- Abstract type ID for predefined type REAL_64.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Real_64_type.
			-- (from REFLECTOR_CONSTANTS)

	Expanded_type: INTEGER_32 = 7
			-- Abstract type ID for a non-predefined expanded type.
			-- (from REFLECTOR_CONSTANTS)

	Integer_16_type: INTEGER_32 = 10
			-- Abstract type ID for predefined type INTEGER_16.
			-- (from REFLECTOR_CONSTANTS)

	Integer_32_type: INTEGER_32 = 4
			-- Abstract type ID for predefined type INTEGER_32.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Integer_type.
			-- (from REFLECTOR_CONSTANTS)

	Integer_64_type: INTEGER_32 = 11
			-- Abstract type ID for predefined type INTEGER_64.
			-- (from REFLECTOR_CONSTANTS)

	Integer_8_type: INTEGER_32 = 9
			-- Abstract type ID for predefined type INTEGER_8.
			-- (from REFLECTOR_CONSTANTS)

	Integer_type: INTEGER_32 = 4
			-- Abstract type ID for predefined type INTEGER_32.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Integer_32_type.
			-- (from REFLECTOR_CONSTANTS)

	Max_predefined_type: INTEGER_32 = 16
			-- (from REFLECTOR_CONSTANTS)

	Min_predefined_type: INTEGER_32 = -2
			-- (from REFLECTOR_CONSTANTS)

	Natural_16_type: INTEGER_32 = 14
			-- Abstract type ID for predefined type NATURAL_16.
			-- (from REFLECTOR_CONSTANTS)

	Natural_32_type: INTEGER_32 = 15
			-- Abstract type ID for predefined type NATURAL_32.
			-- (from REFLECTOR_CONSTANTS)

	Natural_64_type: INTEGER_32 = 16
			-- Abstract type ID for predefined type NATURAL_64.
			-- (from REFLECTOR_CONSTANTS)

	Natural_8_type: INTEGER_32 = 13
			-- Abstract type ID for predefined type NATURAL_8.
			-- (from REFLECTOR_CONSTANTS)

	None_type: INTEGER_32 = -2
			-- Type ID representation for NONE.
			-- (from REFLECTOR_CONSTANTS)

	Pointer_type: INTEGER_32 = 0
			-- Abstract type ID for predefined type POINTER.
			-- (from REFLECTOR_CONSTANTS)

	Real_32_type: INTEGER_32 = 5
			-- Abstract type ID for predefined type REAL_32.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Real_type.
			-- (from REFLECTOR_CONSTANTS)

	Real_64_type: INTEGER_32 = 6
			-- Abstract type ID for predefined type REAL_64.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Double_type.
			-- (from REFLECTOR_CONSTANTS)

	Real_type: INTEGER_32 = 5
			-- Abstract type ID for predefined type REAL_32.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Real_32_type.
			-- (from REFLECTOR_CONSTANTS)

	Reference_type: INTEGER_32 = 1
			-- Abstract type ID for a reference type.
			-- (from REFLECTOR_CONSTANTS)

	Wide_character_type: INTEGER_32 = 12
			-- Abstract type ID for predefined type CHARACTER_32.
			-- Was declared in REFLECTOR_CONSTANTS as synonym of Character_32_type.
			-- (from REFLECTOR_CONSTANTS)
	
feature -- Measurement

	is_call_at_depth (a_call: like replayed_call; d: INTEGER_32): BOOLEAN
			-- Call a_call has depth d ?
		do
			Result := attached {like replayed_call} a_call as c and then c.depth = d
		end
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	frozen is_deep_equal (other: RT_DBG_EXECUTION_RECORDER): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: RT_DBG_EXECUTION_RECORDER): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal (other: RT_DBG_EXECUTION_RECORDER): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature -- Status report

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- equal to other
			--
			-- For non-void other, clone calls copy;
			-- to change copying/cloning semantics, redefine copy.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: RT_DBG_EXECUTION_RECORDER)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_equal: Current ~ other
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: RT_DBG_EXECUTION_RECORDER)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: RT_DBG_EXECUTION_RECORDER
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: RT_DBG_EXECUTION_RECORDER)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: RT_DBG_EXECUTION_RECORDER
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	frozen twin: RT_DBG_EXECUTION_RECORDER
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached RT_DBG_EXECUTION_RECORDER
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen default: detachable RT_DBG_EXECUTION_RECORDER
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature {NONE} -- Implementation

	Reflected_object: REFLECTED_REFERENCE_OBJECT
			-- To enable object introspection.
			-- (from RT_DBG_INTERNAL)
		once
			create Result.make (Current)
		end

	Reflector: REFLECTOR
			-- To enable type discovery
			-- (from RT_DBG_INTERNAL)
		once
			create Result
		end
	
feature {NONE} -- Access local

	frozen c_stack_value_at (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_rt_type: NATURAL_32): detachable ANY
			-- Object value referenced at off offset of object
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					return (EIF_REFERENCE) rt_dbg_stack_value((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (uint32)$a_rt_type);
				#else
					return NULL;
				#endif
			]"
		end
	
feature {RT_EXTENSION} -- Change

	clear_recording_data
			-- Clear recording data when stopping recording
			-- or when leaving the recorded area (on leave_feature)
		do
			top_callstack_record := Void
			bottom_callstack_record := Void
			record_count := 0
		end

	start_recording (ref: ANY; cid: INTEGER_32; fid: INTEGER_32; dep: INTEGER_32; a_break_index: INTEGER_32)
			-- Start recording and
			-- Initialize recording with effective information.
		require
			ref_attached: ref /= Void
			top_callstack_record_is_void: top_callstack_record = Void
			bottom_callstack_record_is_void: bottom_callstack_record = Void
		local
			r: like bottom_callstack_record
		do
			record_count := 0
			bottom_callstack_record := Void
			top_callstack_record := Void
			check
				callstack_records_are_void: top_callstack_record = Void and bottom_callstack_record = Void
			end
			debug ("rt_dbg_record")
				print ("Start_recording  (")
				Io.put_string ("ref=")
				Io.put_string (($ref).out)
				Io.put_string (",cid=")
				Io.put_integer (cid)
				Io.put_string (",fid=")
				Io.put_integer (fid)
				Io.put_string (",dep=")
				Io.put_integer (dep)
				Io.put_string (",break_index=")
				Io.put_integer (a_break_index)
				Io.put_string (")%N")
			end
			create r.make (Current, ref, cid, fid, dep)
			r.set_breakable_info ([a_break_index, 0])
			bottom_callstack_record := r
			top_callstack_record := r
		ensure
			bottom_callstack_record_is_not_void: bottom_callstack_record /= Void
			top_callstack_record_is_bottom: top_callstack_record = bottom_callstack_record
		end

	stop_recording
			-- Stop recording (and clean data)
		do
			clear_recording_data
			if attached replay_stack as r then
				r.wipe_out
				replay_stack := Void
			end
			last_replay_operation_failed := False
			debug ("rt_dbg_record")
				print ("Stop_recording  %N")
			end
		ensure
			no_callstack_record: top_callstack_record = Void and bottom_callstack_record = Void
		end

	update_parameters (p: separate RT_DBG_EXECUTION_PARAMETERS)
		require
			p_attached: p /= Void
		do
			maximum_record_count := p.maximum_record_count
			flatten_when_closing := p.flatten_when_closing
			keep_calls_records := p.keep_calls_records
			recording_values := p.recording_values
		end
	
feature -- Change

	increment_records_count (n: INTEGER_32)
			-- Incremente record_count by n
		do
			record_count := record_count + n
		ensure
			record_count_positive: record_count >= 0
		end
	
feature {NONE} -- Change field

	set_field_at (off: INTEGER_32; a_type: NATURAL_32; value: detachable ANY; object: ANY)
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			object_attached: object /= Void
		local
			a_eif_type: INTEGER_32
		do
			debug ("rt_dbg_internal")
				print ("set_field_at (" + off.out + ", " + a_type.out + ", value, " + object.generator + ") %N")
			end
			a_eif_type := eif_type (a_type)
			inspect a_eif_type
			when Boolean_type then
				if attached {BOOLEAN} value as bool then
					{ISE_RUNTIME}.set_boolean_field_at (off, $object.to_pointer, 0, bool)
				end
			when Character_8_type then
				if attached {CHARACTER_8} value as c8 then
					{ISE_RUNTIME}.set_character_8_field_at (off, $object.to_pointer, 0, c8)
				end
			when Character_32_type then
				if attached {CHARACTER_32} value as c32 then
					{ISE_RUNTIME}.set_character_32_field_at (off, $object.to_pointer, 0, c32)
				end
			when Natural_8_type then
				if attached {NATURAL_8} value as n8 then
					{ISE_RUNTIME}.set_natural_8_field_at (off, $object.to_pointer, 0, n8)
				end
			when Natural_16_type then
				if attached {NATURAL_16} value as n16 then
					{ISE_RUNTIME}.set_natural_16_field_at (off, $object.to_pointer, 0, n16)
				end
			when Natural_32_type then
				if attached {NATURAL_32} value as n32 then
					{ISE_RUNTIME}.set_natural_32_field_at (off, $object.to_pointer, 0, n32)
				end
			when Natural_64_type then
				if attached {NATURAL_64} value as n64 then
					{ISE_RUNTIME}.set_natural_64_field_at (off, $object.to_pointer, 0, n64)
				end
			when Integer_8_type then
				if attached {INTEGER_8} value as i8 then
					{ISE_RUNTIME}.set_integer_8_field_at (off, $object.to_pointer, 0, i8)
				end
			when Integer_16_type then
				if attached {INTEGER_16} value as i16 then
					{ISE_RUNTIME}.set_integer_16_field_at (off, $object.to_pointer, 0, i16)
				end
			when Integer_32_type then
				if attached {INTEGER_32} value as i32 then
					{ISE_RUNTIME}.set_integer_32_field_at (off, $object.to_pointer, 0, i32)
				end
			when Integer_64_type then
				if attached {INTEGER_64} value as i64 then
					{ISE_RUNTIME}.set_integer_64_field_at (off, $object.to_pointer, 0, i64)
				end
			when Real_32_type then
				if attached {REAL_32} value as r32 then
					{ISE_RUNTIME}.set_real_32_field_at (off, $object.to_pointer, 0, r32)
				end
			when Real_64_type then
				if attached {REAL_64} value as r64 then
					{ISE_RUNTIME}.set_real_64_field_at (off, $object.to_pointer, 0, r64)
				end
			when Pointer_type then
				if attached {POINTER} value as ptr then
					{ISE_RUNTIME}.set_pointer_field_at (off, $object.to_pointer, 0, ptr)
				end
			when Reference_type then
				{ISE_RUNTIME}.set_reference_field_at (off, $object.to_pointer, 0, value)
			else
			end
		end
	
feature {NONE} -- Change local

	frozen c_set_boolean_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_bool: BOOLEAN): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_BOOL; a_val.it_bool = (EIF_BOOLEAN) $a_bool;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_character_32_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_ch32: CHARACTER_32): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_WCHAR; a_val.it_c4 = (EIF_WIDE_CHAR) $a_ch32;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_character_8_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_ch8: CHARACTER_8): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_CHAR; a_val.it_c1 = (EIF_CHARACTER) $a_ch8;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_integer_16_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_i16: INTEGER_16): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_INT16; a_val.it_i2 = (EIF_INTEGER_16) $a_i16;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_integer_32_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_i32: INTEGER_32): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_INT32; a_val.it_i4 = (EIF_INTEGER_32) $a_i32;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_integer_64_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_i64: INTEGER_64): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_INT64; a_val.it_i8 = (EIF_INTEGER_64) $a_i64;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_integer_8_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_i8: INTEGER_8): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_INT8; a_val.it_i1 = (EIF_INTEGER_8) $a_i8;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_natural_16_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_n16: NATURAL_16): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_UINT16; a_val.it_n2 = (EIF_NATURAL_16) $a_n16;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_natural_32_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_n32: NATURAL_32): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_UINT32; a_val.it_n4 = (EIF_NATURAL_32) $a_n32;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_natural_64_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_n64: NATURAL_64): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_UINT64; a_val.it_n8 = (EIF_NATURAL_64) $a_n64;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_natural_8_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_n8: NATURAL_8): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_UINT8; a_val.it_n1 = (EIF_NATURAL_8) $a_n8;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_pointer_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_p: POINTER): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_POINTER; a_val.it_p = (EIF_POINTER) $a_p;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_real_32_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_i32: REAL_32): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_REAL32; a_val.it_r4 = (EIF_REAL_32) $a_i32;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_real_64_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_i64: REAL_64): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; a_val.type = SK_REAL64; a_val.it_r8 = (EIF_REAL_64) $a_i64;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_reference_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_ref: POINTER): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			a_ref_not_null: a_ref /= default_pointer
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; 
					a_val.type = SK_REF; 
					a_val.it_ref = (EIF_REFERENCE) &($a_ref);
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	frozen c_set_void_stack_value (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32): INTEGER_32
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_TYPED_VALUE a_val; 
					a_val.type = SK_VOID; 
					a_val.it_ref = (char*) 0;
					return rt_dbg_set_stack_value ((uint32)$dep, (uint32)$a_loc_type, (uint32)$pos, (EIF_TYPED_VALUE*) &a_val);
				#else
					return 0;
				#endif
			]"
		end

	Rt_dlt_argument: INTEGER_32 = 0
			-- DLT=DebugLocalType, the type is an argument of a function
			-- (from RT_DBG_INTERNAL)

	Rt_dlt_localvar: INTEGER_32 = 1
			-- DLT=DebugLocalType, the type is a local variable inside a function
			-- (from RT_DBG_INTERNAL)

	Rt_dlt_result: INTEGER_32 = 2
			-- DLT=DebugLocalType, the type is the Result of the current feature
			-- (from RT_DBG_INTERNAL)

	set_stack_value_at (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_rt_type: NATURAL_32; value: detachable ANY): INTEGER_32
			-- Set stack value at position pos on stack of depth dep with value
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			a_loc_type_valid: a_loc_type = Rt_dlt_localvar or a_loc_type = Rt_dlt_argument or a_loc_type = Rt_dlt_result
		local
			a_eif_type: INTEGER_32
		do
			debug ("rt_dbg_internal")
				print ("set_stack_value_at (dep=" + dep.out + ", loc_type=" + a_loc_type.out + ", pos=" + pos.out + ", type=0x" + a_rt_type.to_hex_string + ", value=")
				if value = Void then
					print ("Void) %N")
				else
					print (value.generating_type.name + ": " + value.out + ") %N")
				end
			end
			a_eif_type := eif_type (a_rt_type)
			inspect a_eif_type
			when Boolean_type then
				if attached {BOOLEAN} value as bool then
					Result := c_set_boolean_stack_value (dep, a_loc_type, pos, bool)
				end
			when Character_8_type then
				if attached {CHARACTER_8} value as c8 then
					Result := c_set_character_8_stack_value (dep, a_loc_type, pos, c8)
				end
			when Character_32_type then
				if attached {CHARACTER_32} value as c32 then
					Result := c_set_character_32_stack_value (dep, a_loc_type, pos, c32)
				end
			when Natural_8_type then
				if attached {NATURAL_8} value as n8 then
					Result := c_set_natural_8_stack_value (dep, a_loc_type, pos, n8)
				end
			when Natural_16_type then
				if attached {NATURAL_16} value as n16 then
					Result := c_set_natural_16_stack_value (dep, a_loc_type, pos, n16)
				end
			when Natural_32_type then
				if attached {NATURAL_32} value as n32 then
					Result := c_set_natural_32_stack_value (dep, a_loc_type, pos, n32)
				end
			when Natural_64_type then
				if attached {NATURAL_64} value as n64 then
					Result := c_set_natural_64_stack_value (dep, a_loc_type, pos, n64)
				end
			when Integer_8_type then
				if attached {INTEGER_8} value as i8 then
					Result := c_set_integer_8_stack_value (dep, a_loc_type, pos, i8)
				end
			when Integer_16_type then
				if attached {INTEGER_16} value as i16 then
					Result := c_set_integer_16_stack_value (dep, a_loc_type, pos, i16)
				end
			when Integer_32_type then
				if attached {INTEGER_32} value as i32 then
					Result := c_set_integer_32_stack_value (dep, a_loc_type, pos, i32)
				end
			when Integer_64_type then
				if attached {INTEGER_64} value as i64 then
					Result := c_set_integer_64_stack_value (dep, a_loc_type, pos, i64)
				end
			when Real_32_type then
				if attached {REAL_32} value as r32 then
					Result := c_set_real_32_stack_value (dep, a_loc_type, pos, r32)
				end
			when Real_64_type then
				if attached {REAL_64} value as r64 then
					Result := c_set_real_64_stack_value (dep, a_loc_type, pos, r64)
				end
			when Pointer_type then
				if attached {POINTER} value as ptr then
					Result := c_set_pointer_stack_value (dep, a_loc_type, pos, ptr)
				end
			when Reference_type then
				if value /= Void then
					Result := c_set_reference_stack_value (dep, a_loc_type, pos, $value.to_pointer)
				else
					Result := c_set_void_stack_value (dep, a_loc_type, pos)
				end
			else
				Result := 2
			end
			debug ("rt_dbg_internal")
				print ("set_stack_value_at (dep=" + dep.out + ", loc_type=" + a_loc_type.out + ", pos=" + pos.out + ", ...) -> " + Result.out + " %N")
				print ("set_stack_value_at: check modification -> ")
				if attached stack_value_at (dep, a_loc_type, pos, a_rt_type) as a then
					print (a.generating_type.name + ": " + a.out + "%N")
				else
					print (" Void %N")
				end
			end
		end
	
feature -- Constants from eif_debug.h

	Direction_back: INTEGER_32 = 1
			-- previous call

	Direction_forth: INTEGER_32 = 2
			-- next call

	Direction_left: INTEGER_32 = 3
			-- previous instruction

	Direction_right: INTEGER_32 = 4
			-- next intruction
	
feature -- Event

	enter_feature (ref: ANY; cid, fid: INTEGER_32; dep: INTEGER_32)
			-- Enter feature {cid}.fid on object ref, depth is dep
		require
			ref_attached: ref /= Void
			is_not_replaying: not is_replaying
			cid_positive: cid >= 0
		local
			r: RT_DBG_CALL_RECORD
		do
			debug ("rt_dbg_record")
				dtrace_indent (dep)
				dtrace ("enter_feature (")
				dtrace (ref.generating_type.name.as_string_8)
				dtrace (", " + cid.out + ", " + fid.out + ", " + dep.out + ")")
				dtrace (" [[" + record_count.out + "]]%N")
			end
			monitor_record_count
			create r.make (Current, ref, cid, fid, dep)
			increment_records_count (1)
			if attached top_callstack_record as topr then
				if topr.depth = 0 or else topr.depth = r.depth - 1 then
					r.attach_to (topr)
				else
					debug ("rt_dbg_warning")
						print ("Warning: enter mismatch !!!%N")
						print (" top: depth=" + r.depth.out + " ->" + r.debug_output + "%N")
						print (" now: depth=" + dep.out)
						print (" obj=" + ref.generating_type.name)
						print (" cid=" + cid.out)
						print (" fid=" + fid.out)
						print ("%N")
						print ("%N")
					end
					if topr.depth = r.depth then
						topr.deep_close
					end
					if attached {like callstack_record} callstack_record (r.depth - 1) as depr then
						r.attach_to (depr)
					else
						check
							should_not_occur: False
						end
					end
				end
			end
			top_callstack_record := r
			check
					top_callstack_record /= Void
			end
			if bottom_callstack_record = Void then
				bottom_callstack_record := top_callstack_record
			end
		end

	enter_rescue (ref: ANY; cid, fid: INTEGER_32; dep: INTEGER_32)
			-- Enter rescue on object ref, depth is dep
		require
			ref_attached: ref /= Void
			is_not_replaying: not is_replaying
		local
			r: detachable RT_DBG_CALL_RECORD
		do
			debug ("rt_dbg_record")
				dtrace_indent (dep)
				dtrace ("enter_rescue (")
				dtrace (ref.generating_type.name.as_string_8)
				dtrace (", " + dep.out + ")")
				dtrace (" [[" + record_count.out + "]]%N")
			end
			from
				r := top_callstack_record
			until
				r = Void or else r.depth = dep
			loop
				r := r.parent
			end
			if r = Void then
				debug ("rt_dbg_record")
					dtrace ("Error: enter_rescue -> No record !!%N")
				end
				stop_recording
				start_recording (ref, cid, fid, dep, 0)
			else
				check
					same_depth: r.depth = dep
				end
				top_callstack_record := r
				r.close_call_records
				top_callstack_record := r
			end
		end

	leave_feature (ref: ANY; cid, fid: INTEGER_32; dep: INTEGER_32)
			-- Leave feature {cid}.fid on object ref, depth is dep
		require
			ref_attached: ref /= Void
			is_not_replaying: not is_replaying
		local
			n: like callstack_record
		do
			debug ("rt_dbg_record")
				dtrace_indent (dep)
				dtrace ("leave_feature (")
				dtrace (ref.generating_type.name + " <" + ($ref).out + ">".as_string_8)
				dtrace (", " + cid.out + ", " + fid.out + ", " + dep.out + "). %N")
			end
			if not attached {like callstack_record} top_callstack_record as r then
			else
				if r = bottom_callstack_record then
					check
						parent_is_void: r.parent = Void
					end
					clear_recording_data
				else
					n := r
					if r.depth > dep then
						debug ("rt_dbg_warning")
							print ("Warning: leave mismatch !!!%N")
							print (" top: depth=" + r.depth.out + " ->" + r.debug_output + "%N")
							print (" now: depth=" + dep.out)
							print (" obj=" + ref.generating_type.name)
							print (" cid=" + cid.out)
							print (" fid=" + fid.out)
							print ("%N")
							print ("%N")
						end
						from
						until
							n = Void or else n.depth = dep
						loop
							n := n.parent
						end
						if n /= Void then
							r.deep_close_until (n)
							n.close_call_records
						end
					end
					if n = Void then
						debug ("rt_dbg_record")
							dtrace ("Error: leave_feature -> No associated record !!%N")
						end
						check
							should_not_occur: False
						end
						clear_recording_data
					else
						check
							same_dep: n.depth = dep
							same_object_type: n.same_object_type (ref)
							same_reference: not n.is_expanded implies n.object = ref
							same_cid: n.class_type_id = cid
							same_fid: n.feature_rout_id = fid
						end
						n.close
						top_callstack_record := n.parent
					end
				end
			end
		end

	notify_rt_assign_attribute (a_dep: INTEGER_32; ref: ANY; a_offset: INTEGER_32; a_type: NATURAL_32; a_xpm: INTEGER_32)
			-- Notify variable assignment
			-- a_xpm contains information about expanded, precompiled, melted
		require
			ref_attached: ref /= Void
			is_not_replaying: not is_replaying
			top_call_stack_record_not_void: top_callstack_record /= Void
			valid_xpm_value: valid_xpm_value (a_xpm)
		do
			if attached top_callstack_record as t then
				check
					same_associated_depth: a_dep = t.depth
				end
				if attached {RT_DBG_VALUE_RECORD} object_attribute_record (a_offset, a_type, ref) as l_record then
					debug ("rt_dbg_record")
						print ("Att Assign=> " + l_record.debug_output + "%N")
					end
					t.add_value_record (l_record)
				end
			else
				debug ("rt_dbg_record")
					print ("Att Assign=> ERROR, no top_callstack_record !%N")
				end
				check
					should_not_occur: False
				end
			end
		end

	notify_rt_assign_local (a_dep: INTEGER_32; a_position: INTEGER_32; a_type: NATURAL_32; a_xpm: INTEGER_32)
			-- Notify variable assignment
			-- a_xpm contains information about expanded, precompiled, melted
		require
			is_not_replaying: not is_replaying
			top_call_stack_record_not_void: top_callstack_record /= Void
			valid_xpm_value: valid_xpm_value (a_xpm)
		do
			if attached top_callstack_record as t then
				debug ("rt_dbg_warning")
					if a_dep /= t.depth and t.depth /= 0 then
						print ("Loc Assign: dep=" + a_dep.out + "; pos=" + a_position.out + " -> depth mismatch %N")
					end
				end
				check
					same_associated_depth: a_dep = t.depth
				end
				if attached {RT_DBG_VALUE_RECORD} object_local_record (a_dep, a_position, a_type) as l_record then
					debug ("rt_dbg_record")
						print ("Loc Assign=> " + l_record.debug_output + "%N")
					end
					t.add_value_record (l_record)
				end
			else
				debug ("rt_dbg_record")
					print ("Loc Assign=> ERROR, no top_callstack_record !%N")
				end
				check
					should_not_occur: False
				end
			end
		end

	notify_rt_hook (dep: INTEGER_32; bp_i, bp_ni: INTEGER_32)
			-- Notify RT_HOOK (bp_i) or RTNHOOK (bp_i, bp_ni)
		require
			is_not_replaying: not is_replaying
		do
			if attached {like callstack_record} top_callstack_record as r then
				if r.depth = dep then
					r.register_position (bp_i, bp_ni)
				else
					debug ("rt_dbg_warning")
						print ("Warning: hook mismatch on depth now=" + dep.out + " top.depth=" + r.depth.out + "%N")
					end
				end
			end
		end
	
feature {NONE} -- External implementation

	frozen c_eif_type (a_field_type: NATURAL_32): INTEGER_32
			-- EIF_ type related to a_field_type
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_internal.h%""
		alias
			"ei_eif_type((uint32) $a_field_type)"
		end

	frozen c_object_is_expanded (object: POINTER): BOOLEAN
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_eiffel.h%""
		alias
			"eif_is_expanded(HEADER($object)->ov_flags)"
		end

	frozen c_rt_dynamic_type (object: POINTER): INTEGER_32
			-- Dynamic type of object.
			-- (from RT_DBG_INTERNAL)
		external
			"C macro signature (EIF_REFERENCE): EIF_INTEGER use %"eif_macros.h%""
		alias
			"Dtype"
		end

	frozen c_rt_field_type (i: INTEGER_32; a_type_id: INTEGER_32): NATURAL_32
			-- RT field type related to i on a_type_id
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_internal.h%""
		alias
			"System(To_dtype($a_type_id)).cn_types[$i]"
		end
	
feature {NONE} -- Factory

	frozen object_attribute_record (off: INTEGER_32; t: NATURAL_32; obj: ANY): detachable RT_DBG_VALUE_RECORD
			-- Record for attribute of type t at offset o on object obj
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			obj_attached: obj /= Void
		local
			ft: INTEGER_32
			l_reflected_object: REFLECTED_REFERENCE_OBJECT
		do
			ft := eif_type (t)
			inspect ft
			when Boolean_type then
				create {RT_DBG_ATTRIBUTE_RECORD [BOOLEAN]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.boolean_field_at (off, $obj.to_pointer, 0))
			when Character_8_type then
				create {RT_DBG_ATTRIBUTE_RECORD [CHARACTER_8]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.character_8_field_at (off, $obj.to_pointer, 0))
			when Character_32_type then
				create {RT_DBG_ATTRIBUTE_RECORD [CHARACTER_32]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.character_32_field_at (off, $obj.to_pointer, 0))
			when Integer_8_type then
				create {RT_DBG_ATTRIBUTE_RECORD [INTEGER_8]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.integer_8_field_at (off, $obj.to_pointer, 0))
			when Integer_16_type then
				create {RT_DBG_ATTRIBUTE_RECORD [INTEGER_16]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.integer_16_field_at (off, $obj.to_pointer, 0))
			when Integer_32_type then
				create {RT_DBG_ATTRIBUTE_RECORD [INTEGER_32]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.integer_32_field_at (off, $obj.to_pointer, 0))
			when Integer_64_type then
				create {RT_DBG_ATTRIBUTE_RECORD [INTEGER_64]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.integer_64_field_at (off, $obj.to_pointer, 0))
			when Natural_8_type then
				create {RT_DBG_ATTRIBUTE_RECORD [NATURAL_8]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.natural_8_field_at (off, $obj.to_pointer, 0))
			when Natural_16_type then
				create {RT_DBG_ATTRIBUTE_RECORD [NATURAL_16]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.natural_16_field_at (off, $obj.to_pointer, 0))
			when Natural_32_type then
				create {RT_DBG_ATTRIBUTE_RECORD [NATURAL_32]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.natural_8_field_at (off, $obj.to_pointer, 0).to_natural_32)
			when Natural_64_type then
				create {RT_DBG_ATTRIBUTE_RECORD [NATURAL_64]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.natural_8_field_at (off, $obj.to_pointer, 0).to_natural_64)
			when Real_32_type then
				create {RT_DBG_ATTRIBUTE_RECORD [REAL_32]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.real_32_field_at (off, $obj.to_pointer, 0))
			when Real_64_type then
				create {RT_DBG_ATTRIBUTE_RECORD [REAL_64]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.real_64_field_at (off, $obj.to_pointer, 0))
			when Pointer_type then
				create {RT_DBG_ATTRIBUTE_RECORD [POINTER]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.pointer_field_at (off, $obj.to_pointer, 0))
			when Reference_type then
				create {RT_DBG_ATTRIBUTE_RECORD [ANY]} Result.make (obj, off, ft, t, {ISE_RUNTIME}.reference_field_at (off, $obj.to_pointer, 0))
			when Expanded_type then
				create l_reflected_object.make_for_expanded_field_at (obj, off)
				create {RT_DBG_ATTRIBUTE_RECORD [ANY]} Result.make (obj, off, ft, t, l_reflected_object.object)
			else
			end
		end

	frozen object_local_record (dep: INTEGER_32; pos: INTEGER_32; t: NATURAL_32): detachable RT_DBG_VALUE_RECORD
			-- Local or Result value record.
			-- (from RT_DBG_INTERNAL)
		local
			ft: INTEGER_32
		do
			ft := eif_type (t)
			inspect ft
			when Boolean_type then
				create {RT_DBG_LOCAL_RECORD [BOOLEAN]} Result.make (dep, pos, ft, t)
			when Character_8_type then
				create {RT_DBG_LOCAL_RECORD [CHARACTER_8]} Result.make (dep, pos, ft, t)
			when Character_32_type then
				create {RT_DBG_LOCAL_RECORD [CHARACTER_32]} Result.make (dep, pos, ft, t)
			when Natural_8_type then
				create {RT_DBG_LOCAL_RECORD [NATURAL_8]} Result.make (dep, pos, ft, t)
			when Natural_16_type then
				create {RT_DBG_LOCAL_RECORD [NATURAL_16]} Result.make (dep, pos, ft, t)
			when Natural_32_type then
				create {RT_DBG_LOCAL_RECORD [NATURAL_32]} Result.make (dep, pos, ft, t)
			when Natural_64_type then
				create {RT_DBG_LOCAL_RECORD [NATURAL_64]} Result.make (dep, pos, ft, t)
			when Integer_8_type then
				create {RT_DBG_LOCAL_RECORD [INTEGER_8]} Result.make (dep, pos, ft, t)
			when Integer_16_type then
				create {RT_DBG_LOCAL_RECORD [INTEGER_16]} Result.make (dep, pos, ft, t)
			when Integer_32_type then
				create {RT_DBG_LOCAL_RECORD [INTEGER_32]} Result.make (dep, pos, ft, t)
			when Integer_64_type then
				create {RT_DBG_LOCAL_RECORD [INTEGER_64]} Result.make (dep, pos, ft, t)
			when Real_32_type then
				create {RT_DBG_LOCAL_RECORD [REAL_32]} Result.make (dep, pos, ft, t)
			when Real_64_type then
				create {RT_DBG_LOCAL_RECORD [REAL_64]} Result.make (dep, pos, ft, t)
			when Pointer_type then
				create {RT_DBG_LOCAL_RECORD [POINTER]} Result.make (dep, pos, ft, t)
			when Reference_type then
				create {RT_DBG_LOCAL_RECORD [ANY]} Result.make (dep, pos, ft, t)
			when Expanded_type then
				create {RT_DBG_LOCAL_RECORD [ANY]} Result.make (dep, pos, ft, t)
			when None_type then
			else
			end
			if Result /= Void then
				Result.get_value
			end
		end

	frozen object_record (i: INTEGER_32; obj: ANY): detachable RT_DBG_VALUE_RECORD
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			obj_attached: obj /= Void
		local
			ft: INTEGER_32
			l_reflected_object: like Reflected_object
		do
			l_reflected_object := Reflected_object
			l_reflected_object.set_object (obj)
			ft := l_reflected_object.field_type (i)
			Result := object_attribute_record (l_reflected_object.field_offset (i), c_rt_field_type (i, ft), obj)
			inspect ft
			when Integer_8_type then
				create {RT_DBG_FIELD_RECORD [INTEGER_8]} Result.make (obj, i, ft, l_reflected_object.integer_8_field (i))
			when Integer_16_type then
				create {RT_DBG_FIELD_RECORD [INTEGER_16]} Result.make (obj, i, ft, l_reflected_object.integer_16_field (i))
			when Integer_32_type then
				create {RT_DBG_FIELD_RECORD [INTEGER_32]} Result.make (obj, i, ft, l_reflected_object.integer_32_field (i))
			when Integer_64_type then
				create {RT_DBG_FIELD_RECORD [INTEGER_64]} Result.make (obj, i, ft, l_reflected_object.integer_64_field (i))
			when Natural_8_type then
				create {RT_DBG_FIELD_RECORD [NATURAL_8]} Result.make (obj, i, ft, l_reflected_object.natural_8_field (i))
			when Natural_16_type then
				create {RT_DBG_FIELD_RECORD [NATURAL_16]} Result.make (obj, i, ft, l_reflected_object.natural_16_field (i))
			when Natural_32_type then
				create {RT_DBG_FIELD_RECORD [NATURAL_32]} Result.make (obj, i, ft, l_reflected_object.natural_32_field (i))
			when Natural_64_type then
				create {RT_DBG_FIELD_RECORD [NATURAL_64]} Result.make (obj, i, ft, l_reflected_object.natural_64_field (i))
			when Pointer_type then
				create {RT_DBG_FIELD_RECORD [POINTER]} Result.make (obj, i, ft, l_reflected_object.pointer_field (i))
			when Reference_type then
				create {RT_DBG_FIELD_RECORD [detachable ANY]} Result.make (obj, i, ft, l_reflected_object.reference_field (i))
			when Expanded_type then
				create {RT_DBG_FIELD_RECORD [detachable ANY]} Result.make (obj, i, ft, l_reflected_object.field (i))
			when Boolean_type then
				create {RT_DBG_FIELD_RECORD [BOOLEAN]} Result.make (obj, i, ft, l_reflected_object.boolean_field (i))
			when Real_32_type then
				create {RT_DBG_FIELD_RECORD [REAL_32]} Result.make (obj, i, ft, l_reflected_object.real_32_field (i))
			when Real_64_type then
				create {RT_DBG_FIELD_RECORD [REAL_64]} Result.make (obj, i, ft, l_reflected_object.real_64_field (i))
			when Character_8_type then
				create {RT_DBG_FIELD_RECORD [CHARACTER_8]} Result.make (obj, i, ft, l_reflected_object.character_8_field (i))
			when Character_32_type then
				create {RT_DBG_FIELD_RECORD [CHARACTER_32]} Result.make (obj, i, ft, l_reflected_object.character_32_field (i))
			else
			end
		end
	
feature -- Helpers

	valid_xpm_value (a_xpm: INTEGER_32): BOOLEAN
			-- Is a_xpm a valid xpm value ?
		local
			x, p, m: BOOLEAN
		do
			x := xpm_to_is_expanded (a_xpm)
			p := xpm_to_is_precompiled (a_xpm)
			m := xpm_to_is_melted (a_xpm)
			Result := a_xpm = x.to_integer + (p.to_integer |<< 1) + (m.to_integer |<< 2)
		end

	xpm_to_is_expanded (a_xpm: INTEGER_32): BOOLEAN
			-- Does a_xpm say is expanded ?
		do
			Result := (a_xpm & 1).to_boolean
		end

	xpm_to_is_melted (a_xpm: INTEGER_32): BOOLEAN
			-- Does a_xpm say is melted ?
		do
			Result := ((a_xpm & 4) |>> 2).to_boolean
		end

	xpm_to_is_precompiled (a_xpm: INTEGER_32): BOOLEAN
			-- Does a_xpm say is precompiled ?
		do
			Result := ((a_xpm & 2) |>> 1).to_boolean
		end
	
feature -- Monitoring

	monitor_record_count
			-- Monitor if record_count is not over max_record_count
			-- if max_record_count is 0, then no limit
		local
			bt: like bottom_callstack_record
			p: like bottom_callstack_record
			c, m, n: INTEGER_32
		do
			m := maximum_record_count
			if m > 0 then
				c := record_count
				if c.to_double > 1.1 * m.to_double then
					bt := bottom_callstack_record
					if top_callstack_record /= bt then
						debug ("rt_dbg_optimization")
							print ("monitor_record_count[" + ((m - c).abs // m).out + "%%] -> remove oldest: record_count=" + c.out + " (max=" + m.out + ")%N")
						end
						from
							p := top_callstack_record
						until
							p = Void or else p.parent = bt
						loop
							p := p.parent
						end
						check
							p_not_void_and_last_of_parent: p /= Void and then bt /= Void and then bt.is_last_call_record (p)
						then
							n := bt.record_count_but (p)
							p.remove_parent
						end
						bottom_callstack_record := p
						bt := p
						c := c - n
						record_count := c
						check
							same_record_count: bt /= Void and then record_count = bt.record_count_but (Void)
						end
						if c.to_double <= 0.9 * m.to_double then
							monitor_record_count
						end
						debug ("rt_dbg_optimization")
							print ("monitor_record_count -> count=" + c.out + "%N")
						end
					end
				end
			end
		end
	
feature {NONE} -- Object access

	frozen eif_type (a_field_type: NATURAL_32): INTEGER_32
			-- EIF_ type from field type a_field_type
			-- (from RT_DBG_INTERNAL)
		do
			Result := c_eif_type (a_field_type)
		end

	frozen field_at (off: INTEGER_32; a_field_type: NATURAL_32; object: ANY): detachable ANY
			-- Object attached at offset off field of object
			-- (directly or through a reference)
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			object_not_void: object /= Void
			index_large_enough: off >= 1
		local
			t: INTEGER_32
		do
			t := eif_type (a_field_type)
			inspect t
			when Boolean_type then
				Result := {ISE_RUNTIME}.boolean_field_at (off, $object.to_pointer, 0)
			when Character_8_type then
				Result := {ISE_RUNTIME}.character_8_field_at (off, $object.to_pointer, 0)
			when Character_32_type then
				Result := {ISE_RUNTIME}.character_32_field_at (off, $object.to_pointer, 0)
			when Natural_8_type then
				Result := {ISE_RUNTIME}.natural_8_field_at (off, $object.to_pointer, 0)
			when Natural_16_type then
				Result := {ISE_RUNTIME}.natural_16_field_at (off, $object.to_pointer, 0)
			when Natural_32_type then
				Result := {ISE_RUNTIME}.natural_32_field_at (off, $object.to_pointer, 0)
			when Natural_64_type then
				Result := {ISE_RUNTIME}.natural_64_field_at (off, $object.to_pointer, 0)
			when Integer_8_type then
				Result := {ISE_RUNTIME}.integer_8_field_at (off, $object.to_pointer, 0)
			when Integer_16_type then
				Result := {ISE_RUNTIME}.integer_16_field_at (off, $object.to_pointer, 0)
			when Integer_32_type then
				Result := {ISE_RUNTIME}.integer_32_field_at (off, $object.to_pointer, 0)
			when Integer_64_type then
				Result := {ISE_RUNTIME}.integer_64_field_at (off, $object.to_pointer, 0)
			when Real_32_type then
				Result := {ISE_RUNTIME}.real_32_field_at (off, $object.to_pointer, 0)
			when Real_64_type then
				Result := {ISE_RUNTIME}.real_64_field_at (off, $object.to_pointer, 0)
			when Pointer_type then
				Result := {ISE_RUNTIME}.pointer_field_at (off, $object.to_pointer, 0)
			when Reference_type then
				Result := {ISE_RUNTIME}.reference_field_at (off, $object.to_pointer, 0)
			else
			end
		end

	frozen field_index_at (off: INTEGER_32; obj: ANY): INTEGER_32
			-- Field name at offset off on obj
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
				obj /= Void
		local
			n: INTEGER_32
			l_reflected_object: like Reflected_object
		do
			from
				l_reflected_object := Reflected_object
				l_reflected_object.set_object (obj)
				n := l_reflected_object.field_count
			until
				n = 0 or Result > 0
			loop
				if off = l_reflected_object.field_offset (n) then
					Result := n
				end
				n := n - 1
			end
		end

	frozen field_name_at (off: INTEGER_32; obj: ANY): detachable STRING_8
			-- Field name at offset off on obj
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
				obj /= Void
		local
			i: INTEGER_32
		do
			i := field_index_at (off, obj)
			if i > 0 then
				Reflected_object.set_object (obj)
				Result := Reflected_object.field_name (i)
			end
		end

	frozen object_field_count (obj: ANY): INTEGER_32
			-- Field_count on obj
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			obj_attached: obj /= Void
		do
			Reflected_object.set_object (obj)
			Result := Reflected_object.field_count
		end

	frozen object_is_expanded (object: ANY): BOOLEAN
			-- Is object an expanded value ?
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			object_not_void: object /= Void
		do
			Result := c_object_is_expanded ($object.to_pointer)
		end

	frozen object_records (obj: ANY): detachable ARRAYED_LIST [RT_DBG_VALUE_RECORD]
			-- List of field records on obj
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			obj_attached: obj /= Void
		local
			i, cnb: INTEGER_32
			l_records: like object_records
		do
			cnb := object_field_count (obj)
			if cnb > 0 then
				create l_records.make (cnb)
				from
					i := 1
				until
					i > cnb
				loop
					if attached {like object_record} object_record (i, obj) as r then
						l_records.extend (r)
					end
					i := i + 1
				end
				Result := l_records
			end
		end

	frozen rt_dynamic_type (object: ANY): INTEGER_32
			-- Dynamic type of object
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			object_not_void: object /= Void
		do
			Result := c_rt_dynamic_type ($object.to_pointer)
		ensure -- from RT_DBG_INTERNAL
			rt_dynamic_type_nonnegative: Result >= 0
		end

	frozen stack_value_at (dep: INTEGER_32; a_loc_type: INTEGER_32; pos: INTEGER_32; a_rt_type: NATURAL_32): detachable ANY
			-- Object attached at offset off field of object
			-- (directly or through a reference)
			-- (from RT_DBG_INTERNAL)
		require -- from RT_DBG_INTERNAL
			index_large_enough: pos >= 1
		do
			debug ("rt_dbg_internal")
				print ("%Nstack_value_at (" + dep.out + ", " + pos.out + ", 0x" + a_rt_type.to_hex_string + ")%N")
			end
			Result := c_stack_value_at (dep, a_loc_type, pos, a_rt_type)
			debug ("rt_dbg_internal")
				print ("stack_value_at -> ")
				if Result /= Void then
					print (Result.generating_type.name + " = " + Result.out)
				else
					print ("Void Result")
				end
				print ("%N")
			end
		end
	
feature -- Optimization properties

	flatten_when_closing: BOOLEAN
			-- Option: flatten record when closing

	keep_calls_records: BOOLEAN
			-- Option: keep calls record even when flattening calls

	maximum_record_count: INTEGER_32
			-- Maximum number of records.
			-- 0 stands for no limit.

	record_count: INTEGER_32
			-- Number of field records.

	recording_values: BOOLEAN
			-- Option: record values ?
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		do
			Result := tagged_out
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		do
			if o /= Void then
				Io.put_string (o.out)
			end
		ensure -- from ANY
			instance_free: class
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature -- Properties

	bottom_callstack_record: detachable like callstack_record
			-- Bottom (or root) callstack record.

	top_callstack_record: detachable like callstack_record
			-- Current top callstack record.
	
feature -- Query

	changes_between (csr1: RT_DBG_CALL_RECORD; csr2: detachable RT_DBG_CALL_RECORD): ARRAYED_LIST [RT_DBG_VALUE_RECORD]
			-- Return records from r1 to -beginning-of- r2.
			-- (from RT_DBG_COMMON)
		require -- from RT_DBG_COMMON
			csr1_not_void: csr1 /= Void
		local
			chgs: like changes_between
			c, v: CURSOR
			r: detachable like changes_between
		do
			if csr1.is_flat then
				r := csr1.value_records
			end
			if r /= Void then
				Result := r
			else
				create Result.make (30)
				if attached csr1.value_records as vrecs then
					v := vrecs.cursor
					Result.append (vrecs)
					vrecs.go_to (v)
				end
				if attached csr1.call_records as crecs then
					c := crecs.cursor
					from
						crecs.start
					until
						crecs.after or crecs.item_for_iteration = csr2
					loop
						chgs := changes_between (crecs.item_for_iteration, csr2)
						if chgs /= Void then
							Result.append (chgs)
						end
						crecs.forth
					end
					crecs.go_to (c)
				end
			end
		ensure -- from RT_DBG_COMMON
			result_not_void: Result /= Void
		end
	
feature -- Replay

	activate_replay (b: BOOLEAN)
			-- Activate or deactive replay mode according to b
		do
			if b then
				if is_replaying then
				else
					replayed_call := top_callstack_record
					is_replaying := True
				end
			else
				if is_replaying then
					revert_replay_stack
					check
							replay_stack = Void
					end
					is_replaying := False
					replayed_call := Void
				end
			end
		ensure
			b_set: b and is_replaying
		end

	callstack_record_details (a_id: STRING_8; nb: INTEGER_32): detachable STRING_8
			-- Details for callstack identified by a_id
			-- get information for nb levels.
		require
			a_id_attached: a_id /= Void
			is_replaying: is_replaying
		do
			debug ("rt_dbg_replay")
				print ("callstack_record_details (" + a_id + "," + nb.out + ") -start- %N")
			end
			if attached {like callstack_record_by_id} callstack_record_by_id (a_id) as r then
				Result := r.to_string (nb)
			end
			debug ("rt_dbg_replay")
				print ("callstack_record_details (" + a_id + "," + nb.out + ") -end- %N")
				if Result = Void then
					print ("%T -> Not Found")
				else
					print ("%T -> Result=" + Result)
				end
				print ("%N")
			end
		end

	replay (dir: INTEGER_32; nb: INTEGER_32)
			-- Replay execution nb steps in direction dir
		do
			inspect dir
			when Direction_back then
				replay_back
			when Direction_forth then
				replay_forth
			when Direction_left then
				replay_left
			when Direction_right then
				replay_right
			else
			end
		end

	replay_query (dir: INTEGER_32): INTEGER_32
			-- Replay execution nb steps in direction dir
		do
			inspect dir
			when Direction_back then
				if bottom_callstack_record /= Void and attached replayed_call as rc then
					Result := rc.available_calls_to_bottom
				end
			when Direction_forth then
				if attached replay_stack as rs then
					Result := rs.count
				end
			when Direction_left then
			when Direction_right then
			else
			end
		end

	replay_to_point (a_id: STRING_8): BOOLEAN
			-- Replay execution to point identified by a_id
		require
			a_id_attached: a_id /= Void
		local
			d1, d2: INTEGER_32
		do
			debug ("rt_dbg_replay")
				print ("replay_to_point (" + a_id + ") -start-%N")
			end
			if attached replayed_call as l_curr and then attached {like callstack_record_by_id} callstack_record_by_id (a_id) as l_req and then attached {like callstack_record} l_req.associated_replayable_call as l_next then
				d1 := l_curr.depth
				d2 := l_next.depth
				if d2 > d1 then
					from
					until
						d1 >= d2
					loop
						replay_forth
						d1 := d1 + 1
						check
							valid_replayed_depth: is_call_at_depth (replayed_call, d1)
						end
					end
					check
						valid_replayed_depth: is_call_at_depth (replayed_call, d2)
					end
				elseif d2 < d1 then
					from
					until
						d1 <= d2
					loop
						replay_back
						d1 := d1 - 1
						check
							valid_replayed_depth: is_call_at_depth (replayed_call, d1)
						end
					end
					check
						valid_replayed_depth: is_call_at_depth (replayed_call, d2)
					end
				end
				Result := True
			end
			debug ("rt_dbg_replay")
				print ("replay_to_point (" + a_id + ") -end- => " + Result.out + "%N")
			end
		end

	replayed_call_details: detachable STRING_8
			-- Details for replayed_call
		require
			is_replaying: is_replaying
		do
			if attached replayed_call as r then
				debug ("rt_dbg_replay")
					print ("replayed_call_details -> " + r.to_string (0) + "%N")
				end
				Result := r.to_string (0)
			else
				debug ("rt_dbg_replay")
					print ("replayed_call_details -> None !%N")
				end
			end
		end
	
feature -- Replay operation

	is_replaying: BOOLEAN
			-- Is replaying

	last_replay_operation_failed: BOOLEAN
			-- Does last replay operation failed ?

	replay_back
			-- Replay execution back
		require
			is_replaying: is_replaying
			replayed_call_attached: replayed_call /= Void
		local
			rs: like replay_stack
			n: detachable RT_DBG_CALL_RECORD
			l_records: like changes_between
			chgs: detachable ARRAYED_LIST [TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]]
		do
			debug ("rt_dbg_replay")
				print ("replay_back -start- %N")
			end
			if attached {RT_DBG_CALL_RECORD} replayed_call as r then
				if attached {RT_DBG_CALL_RECORD} r.parent as p then
					last_replay_operation_failed := False
					if attached replay_stack as ot_rs then
						rs := ot_rs
						check
							replay_stack_not_empty: rs.count > 0
						end
						n := rs.last.call_record
					else
						create rs.make
						replay_stack := rs
						n := Void
					end
					l_records := changes_between (r, n)
					if not last_replay_operation_failed then
						create chgs.make (l_records.count)
						from
							l_records.finish
						until
							l_records.before
						loop
							debug ("rt_dbg_replay")
								print ("replay_back -> " + l_records.item_for_iteration.debug_output + " %N")
							end
							if attached l_records.item_for_iteration as ot_rec then
								if attached ot_rec.current_value_record as val then
									chgs.extend ([ot_rec, val])
									ot_rec.restore (val)
								else
									check
										should_not_occur: False
									end
								end
							end
							l_records.back
						end
						rs.extend ([r, chgs])
						replayed_call := p
					end
				else
					last_replay_operation_failed := True
				end
			else
				last_replay_operation_failed := True
			end
			debug ("rt_dbg_replay")
				print ("replay_back -end- %N")
			end
		ensure
			replayed_call_attached: replayed_call /= Void
		end

	replay_forth
			-- Replay execution forth
		require
			is_replaying: is_replaying
			replayed_call_not_void: replayed_call /= Void
			replay_stack_not_empty: replay_stack_not_empty
		local
			n: RT_DBG_CALL_RECORD
			t: TUPLE [call_record: RT_DBG_CALL_RECORD; chgs: detachable ARRAYED_LIST [TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]]]
			done: BOOLEAN
		do
			debug ("rt_dbg_replay")
				print ("replay_forth -start-%N")
			end
			if attached replay_stack as rs then
				check
						attached replayed_call as r
				then
					from
					until
						done
					loop
						check
								rs.count > 0
						end
						rs.finish
						t := rs.item_for_iteration
						rs.remove
						if rs.is_empty then
							replay_stack := Void
						end
						n := t.call_record
						if attached t.chgs as ot_chgs then
							from
								ot_chgs.finish
							until
								ot_chgs.before
							loop
								debug ("rt_dbg_replay")
									print ("replay_forth -> " + ot_chgs.item_for_iteration.record.debug_output + " %N")
								end
								if attached {TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]} ot_chgs.item_for_iteration as ch then
									ch.record.revert (ch.backup)
								end
								ot_chgs.back
							end
						end
						if n = r then
							r.revert_left_step
							done := replay_stack = Void
						else
							check
									r = n.parent
							end
							replayed_call := n
							done := True
						end
					end
				end
			else
				last_replay_operation_failed := True
			end
			debug ("rt_dbg_replay")
				print ("replay_forth -end-%N")
			end
		ensure
			replayed_call_attached: replayed_call /= Void
		end

	replay_left
			-- Replay left (up in the current call stack element)
		require
			is_replaying: is_replaying
			replayed_call_attached: replayed_call /= Void
		local
			n: like replayed_call
			chgs: detachable ARRAYED_LIST [TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]]
			r_pos_line: INTEGER_32
			done: BOOLEAN
			rs: like replay_stack
		do
			debug ("rt_dbg_replay")
				print ("replay_left -start- %N")
			end
			if attached replayed_call as r then
				from
					r_pos_line := r.replayed_position.line
					if attached replay_stack as ot_rs then
						rs := ot_rs
					else
						create rs.make
						replay_stack := rs
					end
				until
					done
				loop
					if attached r.left_step as ot_records then
						last_replay_operation_failed := False
						create chgs.make (ot_records.count)
						from
							ot_records.finish
						until
							ot_records.before
						loop
							debug ("rt_dbg_replay")
								print ("replay_left -> " + ot_records.item_for_iteration.debug_output + " %N")
							end
							if attached ot_records.item_for_iteration as ot_rec then
								if attached ot_rec.current_value_record as val then
									chgs.extend ([ot_rec, val])
									ot_rec.restore (val)
								else
									check
										should_not_occur: False
									end
								end
							end
							ot_records.back
						end
						rs.extend ([r, chgs])
					else
						if r.parent = Void then
							r.revert_left_step
						else
							replay_back
						end
						done := True
					end
					n := replayed_call
					check
						n_attached: n /= Void
					end
					if not done then
						done := n /= r or else n = Void or else (n.replayed_position.line /= r_pos_line)
					end
				end
			end
			debug ("rt_dbg_replay")
				print ("replay_left -end- %N")
			end
		ensure
			replayed_call_attached: replayed_call /= Void
		end

	replay_left_to_first
			-- Replay execution left as many times as needed to be at the entry of the feature
		local
			r, prev: like replayed_call
		do
			from
				r := replayed_call
			until
				r = Void or else r.replayed_position_is_first or else prev = r
			loop
				prev := r
				replay_left
				r := replayed_call
			end
		end

	replay_right
			-- Replay right (down in the current call stack element)
		require
			is_replaying: is_replaying
			replayed_call_not_void: replayed_call /= Void
			replay_stack_not_empty: replay_stack_not_empty
		local
			n: RT_DBG_CALL_RECORD
			t: TUPLE [call_record: RT_DBG_CALL_RECORD; chgs: detachable ARRAYED_LIST [TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]]]
			r_pos_line: INTEGER_32
			done: BOOLEAN
		do
			debug ("rt_dbg_replay")
				print ("replay_right -start-%N")
			end
			if attached replay_stack as rs then
				check
						attached replayed_call as r
				then
					from
						r_pos_line := r.replayed_position.line
					until
						done
					loop
						check
							replay_stack_not_empty: replay_stack_not_empty
						end
						rs.finish
						t := rs.item_for_iteration
						rs.remove
						if rs.is_empty then
							replay_stack := Void
						end
						if attached t.chgs as ot_chgs then
							from
								ot_chgs.finish
							until
								ot_chgs.before
							loop
								debug ("rt_dbg_replay")
									print ("replay_right -> " + ot_chgs.index.out + ") " + ot_chgs.item_for_iteration.record.debug_output + " %N")
								end
								if attached {TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]} ot_chgs.item_for_iteration as ch then
									ch.record.revert (ch.backup)
								end
								ot_chgs.back
							end
						end
						n := t.call_record
						if n = r then
							n.revert_left_step
							done := n.replayed_position.line /= r_pos_line
						else
							check
									r = n.parent
							end
							if n.replayed_position.line = 0 then
								n.revert_left_step
							end
							replayed_call := n
							replay_left_to_first
							replayed_call := n
							done := True
						end
					end
				end
			else
				last_replay_operation_failed := True
			end
			debug ("rt_dbg_replay")
				print ("replay_right -end-%N")
			end
		ensure
			replayed_call_attached: replayed_call /= Void
		end

	replay_stack: detachable LINKED_LIST [TUPLE [call_record: RT_DBG_CALL_RECORD; chgs: detachable ARRAYED_LIST [TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]]]]
			-- Replay operation stacks.
			-- useful to "revert" the replay steps.

	replay_stack_not_empty: BOOLEAN
			-- Is replay_stack non empty?
		do
			Result := attached replay_stack as rs and then not rs.is_empty
		end

	replayed_call: detachable RT_DBG_CALL_RECORD
			-- Current replayed call stack record

	revert_replay_stack
			-- Revert remaining replay stack
		require
			is_replaying: is_replaying
		local
			r: like replayed_call
			n: like callstack_record
			t: TUPLE [call_record: RT_DBG_CALL_RECORD; chgs: detachable ARRAYED_LIST [TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]]]
		do
			debug ("rt_dbg_replay")
				print ("revert_replay_stack -start-%N")
			end
			if attached replay_stack as rs then
				from
					r := replayed_call
				until
					rs.is_empty
				loop
					rs.finish
					t := rs.item_for_iteration
					rs.remove
					n := t.call_record
					if attached t.chgs as ot_chgs then
						from
							ot_chgs.finish
						until
							ot_chgs.before
						loop
							debug ("rt_dbg_replay")
								print ("revert_replay_stack -> " + ot_chgs.item_for_iteration.record.debug_output + " %N")
							end
							if attached {TUPLE [record: RT_DBG_VALUE_RECORD; backup: RT_DBG_VALUE_RECORD]} ot_chgs.item_for_iteration as ch then
								ch.record.revert (ch.backup)
							end
							ot_chgs.back
						end
					end
					if n = r then
						if r /= Void then
							r.revert_left_step
						end
					else
						check
								r = n.parent
						end
						replayed_call := n
					end
				end
				check
					empty_replay_stack: rs.is_empty
				end
			end
			replay_stack := Void
			debug ("rt_dbg_replay")
				print ("revert_replay_stack -end-%N")
			end
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_8
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ")
				create l_exc
				l_msg.append (generating_type.name)
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
feature {NONE} -- Testing

	c_rt_set_is_inside_rt_eiffel_code (v: INTEGER_32)
			-- (from RT_DBG_INTERNAL)
		external
			"C inline use %"eif_debug.h%""
		alias
			"[
				#ifdef WORKBENCH
					EIF_GET_CONTEXT; is_inside_rt_eiffel_code = $v;
				#endif
			]"
		end

	test_locals (dep: INTEGER_32; loc_pos: INTEGER_32; val: ANY; a_rt_type: NATURAL_32)
			-- (from RT_DBG_INTERNAL)
		local
			s: STRING_8
			retried: BOOLEAN
		do
			if not retried then
				c_rt_set_is_inside_rt_eiffel_code (1)
				s := "----------------------------------%N"
				s.append ("Loc #" + loc_pos.out + "(stack depth=" + dep.out + ")")
				if val /= Void then
					s.append (": should be " + val.generating_type.name)
				end
				s.append ("%N")
				print (s)
				s.append (" -> ")
				if attached stack_value_at (dep, Rt_dlt_localvar, loc_pos, a_rt_type) as a then
					s.append (a.generating_type.name + "=" + a.out)
				else
					s.append ("Void object")
				end
				s.append ("%N")
				print (s)
				c_rt_set_is_inside_rt_eiffel_code (0)
			else
				print ("Rescued%N")
				c_rt_set_is_inside_rt_eiffel_code (0)
			end
		rescue
			retried := True
			retry
		end

	test_set_local (dep: INTEGER_32; loc_pos: INTEGER_32; val: ANY; a_rt_type: NATURAL_32)
			-- (from RT_DBG_INTERNAL)
		local
			s: STRING_8
			r: INTEGER_32
			retried: BOOLEAN
		do
			if not retried then
				c_rt_set_is_inside_rt_eiffel_code (1)
				s := "----------------------------------%N"
				s.append ("SetLoc #" + loc_pos.out + "(stack depth=" + dep.out + ")")
				if val /= Void then
					s.append (": value " + val.generating_type.name)
				else
					s.append (": value Void")
				end
				s.append ("%N")
				print (s)
				r := set_stack_value_at (dep, Rt_dlt_localvar, loc_pos, a_rt_type, val)
				s.append (" -> ")
				s.append ("Result = " + r.out)
				s.append ("%N")
				print (s)
				c_rt_set_is_inside_rt_eiffel_code (0)
			else
				print ("Rescued%N")
				c_rt_set_is_inside_rt_eiffel_code (0)
			end
		rescue
			retried := True
			retry
		end
	
feature -- Trace

	dtrace (m: STRING_8)
			-- note: might be be removed with 6.2	
			-- (from RT_EXTENSION_COMMON)
		require -- from RT_EXTENSION_COMMON
			m_attached: m /= Void
		do
			Io.Error.put_string (m)
		end

	dtrace_indent (n: INTEGER_32)
			-- note: might be removed with 6.2
			-- (from RT_EXTENSION_COMMON)
		do
			Io.Error.put_string (create {STRING_8}.make_filled (' ', 2 * n))
		end
	
invariant
		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

note
	library: "EiffelBase: Library of reusable components for Eiffel."
	copyright: "Copyright (c) 1984-2017, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class RT_DBG_EXECUTION_RECORDER

Generated by ISE EiffelStudio