microprobe.code.context.Context

class Context(default_context: Context | None = None, code_segment: int | None = None, data_segment: int | None = None, symbolic: bool = True, absolute: bool = False)[source]

Bases: object

Class to represent the execution context (e.g. register values, etc … on each benchmark building block)

__init__(default_context: Context | None = None, code_segment: int | None = None, data_segment: int | None = None, symbolic: bool = True, absolute: bool = False)[source]
Parameters:
  • default_context – (Default value = None)

  • code_segment – (Default value = None)

  • data_segment – (Default value = None)

  • symbolic – (Default value = True)

Methods

__init__([default_context, code_segment, ...])

param default_context:

(Default value = None)

add_reserved_registers(rregs)

Add the provided registers into the reserved register list.

copy()

Returns a copy of the current context.

dump()

Return a dump of the current context status.

get_closest_address_value(address)

Returns the closest address to the given address.

get_closest_value(value)

Returns the closest value to the given value.

get_memory_value(address)

Gets a memory value.

get_register_closest_value(value)

Returns the register with the closest value to the given value.

get_register_value(register)

Returns the register value.

get_registername_value(register_name)

Returns the register value.

register_has_value(value)

Returns if a value is in a register.

registers_get_value(value)

Gets a list of registers containing the specified value.

remove_reserved_registers(rregs)

Remove the provided registers from the reserved register list.

set_absolute(value)

Sets the force_absolute property.

set_code_segment(value)

Sets the code segment start address.

set_dat(dat)

Sets the dynamic address translation object.

set_data_segment(value)

Sets the data segment start address.

set_memory_value(mem_value)

Sets a memory value.

set_register_value(register, value)

Set the provided register to the specified value.

set_symbolic(value)

Sets the symbolic property.

unset_memory(address, length)

Unsets a memory region.

unset_register(register)

Remove the value from a register.

unset_registers(registers)

Removes the values from registers.

Attributes

code_segment

Address starting the code segment (:int)

dat

DAT object (DynamicAddressTranslation

data_segment

Address starting the data segment (:int)

force_absolute

Boolean indicating if absolute addresses are needed.

register_values

Dictionary of register, value pairs (dict)

reserved_registers

List of reserved registers (list)

symbolic

Boolean indicating if the context allows symbol labels




copy()[source]

Returns a copy of the current context.

add_reserved_registers(rregs: List[Register])[source]

Add the provided registers into the reserved register list.

Parameters:

rregs (list of Register) – Registers to reserve

remove_reserved_registers(rregs: List[Register])[source]

Remove the provided registers from the reserved register list.

Parameters:

rregs (list of Register) – Registers to un-reserve

set_register_value(register: Register, value: int | float | Address | str)[source]

Set the provided register to the specified value.

Parameters:
get_closest_value(value)[source]

Returns the closest value to the given value.

Returns the closest value to the given value. If there are not values registered, None is returned.

Parameters:

value (int, float, long, Address or str) – value to look for

get_closest_address_value(address: Address)[source]

Returns the closest address to the given address.

Returns the closest address to the given address. If there are not addresses registered, None is returned.

Parameters:

address (Address) – Address to look for

get_register_closest_value(value)[source]

Returns the register with the closest value to the given value.

Returns the register with the closest value to the given value. If there are not values registered, None is returned. Address values are ignored.

Parameters:

value (int, float, long, Address or str) – Value to look for

get_register_value(register: Register)[source]

Returns the register value. None if not found.

Parameters:

register (Register) – Register to get its value

get_registername_value(register_name: str)[source]

Returns the register value. None if not found.

Parameters:
  • register (str) – Register name to get its value

  • register_name

unset_registers(registers: List[Register])[source]

Removes the values from registers.

Parameters:

registers (list of Register) – List of registers

unset_register(register)[source]

Remove the value from a register.

Parameters:

register (Register) – Registers

set_memory_value(mem_value: MemoryValue)[source]

Sets a memory value.

Parameters:

mem_value (MemoryValue) – Memory value to set.

get_memory_value(address: Address)[source]

Gets a memory value.

Parameters:

address (Address) – Address to look for

unset_memory(address: Address, length: int)[source]

Unsets a memory region.

Parameters:
  • address (Address) – Start address of the region

  • length (int) – Length in bytes of the region

register_has_value(value: int | float | Address | str)[source]

Returns if a value is in a register.

Parameters:

value (bool) – Value to look for

registers_get_value(value: int | float | Address | str)[source]

Gets a list of registers containing the specified value.

Parameters:

value (int or float or Address) – Value to look for

property register_values

Dictionary of register, value pairs (dict)

property reserved_registers

List of reserved registers (list)

property data_segment

Address starting the data segment (:int)

set_data_segment(value: int | None)[source]

Sets the data segment start address.

Parameters:

value (:int) – Start address.

property dat

DAT object (DynamicAddressTranslation

set_dat(dat: DynamicAddressTranslation)[source]

Sets the dynamic address translation object.

Parameters:

dat (DynamicAddressTranslation) – DAT object.

property code_segment

Address starting the code segment (:int)

set_code_segment(value: int | None)[source]

Sets the code segment start address.

Parameters:

value (int) – Start address.

property symbolic

Boolean indicating if the context allows symbol labels

Boolean indicating if the context allows symbol labels (bool)

set_symbolic(value: bool)[source]

Sets the symbolic property.

Parameters:

value (bool) – Boolean indicating if the context allows symbol labels

property force_absolute

Boolean indicating if absolute addresses are needed.

Boolean indicating if absolute addresses are needed (bool)

set_absolute(value: bool)[source]

Sets the force_absolute property.

Parameters:

value (bool) – Boolean indicating if absolute addresses are needed

dump()[source]

Return a dump of the current context status.

Return a dump of the current context status. Very useful for pass debugging purposes.