Version | Date | Change |
---|---|---|
0.1 | 2008-01-10 | Initial contribution |
1.0 | 2008-05-06 | Approved |
1.1 | 2009-03-16 | Added context properties |
The service provides basic operations to read/write memory on a target. Command and event parameters are encoded as zero terminated JSON strings.
The service uses standard format for error reports, see Error Report Format.
A single memory access can succeed for some addresses and fail for others. In such situation result message can contain partially valid data. Array of error addresses, in addition to error report, describes data validity on per byte basis:
<array of error addresses> ⇒ null ⇒ [ <error address list> ] <error address list> ⇒ <error address> ⇒ <error address list> , <error address> <error address> ⇒ { "addr" : <int: range starting address> , "size" : <int: range length in bytes> , "stat" : <int: status code> , "msg" : <object: error description> }
If there is no entry in error addresses array for a data byte, then status of such byte is defined by main error report.
Status code is bitwise or of status flags:
BYTE_VALID = 0x00
BYTE_UNKNOWN = 0x01
BYTE_INVALID = 0x02
BYTE_CANNOT_READ = 0x04
BYTE_CANNOT_WRITE = 0x08
The memory access commands have <int: mode> argument. The mode is logical OR of any combination of:
C • <token> • Memory • getContext • <string: context ID> •
The command retrieves context info for given context ID. A context corresponds to an execution thread, process, address space, etc. Exact meaning of a context depends on the target. Target agent should define contexts hierarchy that is:
For traditional OS, like UNIX, memory access context can be one of:
Reply:
R • <token> • <error report> • <context data> • <context data> ⇒ null ⇒ <object>
Context data object should, at least, contain member "ID" : <string>. Context data is expected to be cached by clients. Service sends contextChanged event to notify changes in context data.
Predefined memory context properties are:
"ID" : <string>
- ID of the context, same as getContext command argument.
"ParentID" : <string>
- ID of a parent context.
"ProcessID" : <string>
- process ID.
"BigEndian" : <boolean>
- true if memory is big-endian.
"AddressSize" : <int>
- size of memory address in bytes.
"Name" : <string>
- name of the context, can be used for UI purposes.
"StartBound" : <int>
- lowest address (inclusive) which is valid for the context.
"EndBound" : <int>
- highest address (inclusive) which is valid for the context.
"AccessTypes" : <array of strings>
- Defines the access types allowed for this context.
Target system can support multiple different memory access types, like instruction and data access. Different access types can use different logic for address translation and memory mapping, so they can end up accessing different data bits, even if address is the same. Each distinct access type should be represented by separate memory context. A memory context can represent multiple access types if they are equivalent - all access same memory bits. Same data bits can be exposed through multiple memory contexts.
Predefined access types are:
"instruction"
- Context represent instructions fetch access.
"data"
- Context represents data access.
"io"
- Context represents IO peripherals.
"user"
- Context represents a user (e.g. application running in Linux) view to memory.
"supervisor"
- Context represents a supervisor (e.g. Linux kernel) view to memory.
"hypervisor"
- Context represents a hypervisor view to memory.
"virtual"
- Context uses virtual addresses.
"physical"
- Context uses physical addresses.
"cache"
- Context is a cache.
"tlb"
- Context is a TLB memory.
C • <token> • Memory • getChildren • <string: parent context ID> •
The command requests a list of contexts available for memory access commands.
Parent context ID can be null – to retrieve top level of the hierarchy, can be one of context IDs retrieved by previous getChildren commands, or it can be obtained from another service. Contexts hierarchy can be simple plain list or it can form a tree. It is up to target agent developers to choose layout that is most descriptive for a given target.
Reply:
R • <token> • <error report> • <array of context IDs> • <array of context IDs> ⇒ null ⇒ [ ] ⇒ [ <context ID list> ] <context ID list> ⇒ <string: context ID> ⇒ <context ID list> , <string: context ID>
C • <token> • Memory • set • <string: context ID> • <int: address> • <int: word size> • <int: byte count> • <int: mode> • <string: BASE64 encoded byte array> •
Writes data bytes at given address in memory, "word size" bytes at a time. Address should be aligned by "word size". Context ID must be one returned by getContexts. See Memory Access Mode for encoding of "mode".
Result message:
R • <token> • <error report> • <array of error addresses> •
Error report provides integer error code and a short, human readable explanation of error. Error addresses, when present, let client know which bytes of data failed to be written into memory.
C • <token> • Memory • get • <string: context ID> • <int: address> • <int: word size> • <int: byte count> • <int: mode> •
Reads data bytes at given address in memory, "word size" bytes at a time. Address should be aligned by "word size". Context ID must be one returned by getContexts. See Memory Access Mode for encoding of "mode".
Result message:
R • <token> • <string: BASE64 encoded byte array> • <error report> • <array of error addresses> •
Error report provides integer error code and a short, human readable explanation of error. Error addresses, when present, let client know which bytes of data failed to be retrieved from memory.
C • <token> • Memory • fill • <string: context ID> • <int: address> • <int: word size> • <int: byte count> • <int: mode> • <array: array of pattern bytes> •
Writes pattern bytes at given address in memory, "word size" bytes at a time. Address should be aligned by "word size". If "byte count" is bigger then pattern size, then pattern is repeated necessary number of times. Context ID must be one returned by getContexts. See Memory Access Mode for encoding of "mode".
Result message:
R • <token> • <error report> • <array of error addresses> •
Error report provides integer error code and a short, human readable explanation of error. Error addresses, when present, let client know which bytes of data failed to be written into memory.
Memory service broadcasts notification events when memory contexts are added, removed or changed, and when memory content is altered by "set" or "fill" commands.
E • Memory • contextAdded • <array of context data> • E • Memory • contextChanged • <array of context data> • E • Memory • contextRemoved • <array of context IDs> • E • Memory • memoryChanged • <string: context ID> • <array of address ranges> • <array of context data> - see Get Contexts command. <array of context IDs> ⇒ [ <context ID list> ] <context ID list> ⇒ <string: context ID> ⇒ <context ID list> , <string: context ID> <array of address ranges> ⇒ null ⇒ [ <address ranges list> ] <address ranges list> ⇒ <address range> ⇒ <address ranges list> , <address range> <address range> ⇒ { "addr" : <int: range starting address> , "size" : <int: range length in bytes> }
/** * IMemory service provides basic operations to read/write memory on a target. * * The service represents memory addresses in number of bytes, regardless of actual addressable unit size. * Clients can translate between byte and word addresses using value of "AddressableUnitSize". * Byte is 8 bits. * * @noimplement This interface is not intended to be implemented by clients. */ public interface IMemory extends IService { /** * This service name, as it appears on the wire - a TCF name of the service. */ static final String NAME = "Memory"; /** * Context property names. */ static final String PROP_ID = "ID", /** String, ID of the context, same as getContext command argument */ PROP_PARENT_ID = "ParentID", /** String, ID of a parent context */ PROP_PROCESS_ID = "ProcessID", /** String, process ID, see Processes service */ PROP_BIG_ENDIAN = "BigEndian", /** Boolean, true if memory is big-endian */ PROP_ADDRESS_SIZE = "AddressSize", /** Number, size of memory address in bytes */ PROP_NAME = "Name", /** String, name of the context, can be used for UI purposes */ PROP_START_BOUND = "StartBound", /** Number, lowest address (inclusive) which is valid for the context */ PROP_END_BOUND = "EndBound", /** Number, highest address (inclusive) which is valid for the context */ PROP_ACCESS_TYPES = "AccessTypes"; /** Array of String, the access types allowed for this context */ /** @since 1.3 */ static final String PROP_ADDRESSABLE_UNIT_SIZE = "AddressableUnitSize", /** Number, addressable unit size in number of bytes */ PROP_DEFAULT_WORD_SIZE = "DefaultWordSize"; /** Number, default word size in number of bytes */ /** * Values of "AccessTypes". * Target system can support multiple different memory access types, like instruction and data access. * Different access types can use different logic for address translation and memory mapping, so they can * end up accessing different data bits, even if address is the same. * Each distinct access type should be represented by separate memory context. * A memory context can represent multiple access types if they are equivalent - all access same memory bits. * Same data bits can be exposed through multiple memory contexts. */ static final String ACCESS_INSTRUCTION = "instruction", /** Context represent instructions fetch access */ ACCESS_DATA = "data", /** Context represents data access */ ACCESS_IO = "io", /** Context represents IO peripherals */ ACCESS_USER = "user", /** Context represents a user (e.g. application running in Linux) view to memory */ ACCESS_SUPERVISOR = "supervisor", /** Context represents a supervisor (e.g. Linux kernel) view to memory */ ACCESS_HYPERVISOR = "hypervisor", /** Context represents a hypervisor view to memory */ ACCESS_VIRTUAL = "virtual", /** Context uses virtual addresses */ ACCESS_PHYSICAL = "physical", /** Context uses physical addresses */ ACCESS_CACHE = "cache", /** Context is a cache */ ACCESS_TLB = "tlb"; /** Context is a TLB memory */ /** * Retrieve context info for given context ID. * * @param id - context ID. * @param done - call back interface called when operation is completed. * @return - pending command handle. */ IToken getContext(String id, DoneGetContext done); /** * Client call back interface for getContext(). */ interface DoneGetContext { /** * Called when context data retrieval is done. * @param error - error description if operation failed, null if succeeded. * @param context - context data. */ void doneGetContext(IToken token, Exception error, MemoryContext context); } /** * Retrieve contexts available for memory commands. * A context corresponds to an execution thread, process, address space, etc. * A context can belong to a parent context. Contexts hierarchy can be simple * plain list or it can form a tree. It is up to target agent developers to choose * layout that is most descriptive for a given target. Context IDs are valid across * all services. In other words, all services access same hierarchy of contexts, * with same IDs, however, each service accesses its own subset of context's * attributes and functionality, which is relevant to that service. * * @param parent_context_id - parent context ID. Can be null - * to retrieve top level of the hierarchy, or one of context IDs retrieved * by previous getChildren commands. * @param done - call back interface called when operation is completed. * @return - pending command handle. */ IToken getChildren(String parent_context_id, DoneGetChildren done); /** * Client call back interface for getChildren(). */ interface DoneGetChildren { /** * Called when context list retrieval is done. * @param error - error description if operation failed, null if succeeded. * @param context_ids - array of available context IDs. */ void doneGetChildren(IToken token, Exception error, String[] context_ids); } /** * Memory access mode: * Carry on when some of the memory cannot be accessed and * return MemoryError at the end if any of the bytes * were not processed correctly. */ static final int MODE_CONTINUEONERROR = 0x1; /** * Memory access mode: * Verify result of memory operations (by reading and comparing). */ static final int MODE_VERIFY = 0x2; /** * Memory access mode: * Don't block access when memory address is known to be invalid. * Note: can crash or hang target system. * @since 1.7 */ static final int MODE_BYPASS_ADDR_CHECK = 0x4; /** * Memory access mode: * Don't flush or invalidate caches. * Note: can compromise data coherence. * @since 1.7 */ static final int MODE_BYPASS_CACHE_SYNC = 0x8; /** * Memory access mode: * Don't stop contexts in the process group. * Note: can compromise data coherence. * @since 1.7 */ static final int MODE_DONT_STOP = 0x10; /** * Memory access mode: * Block access to memory mapped I/O. * @since 1.8 */ static final int MODE_MEMORY_ONLY = 0x20; /** * @noimplement This interface is not intended to be implemented by clients. */ interface MemoryContext { /** * Get context ID. * @return context ID. */ String getID(); /** * Get parent context ID. * @return parent ID. */ String getParentID(); /** * Get process ID, if applicable. * @return process ID. */ String getProcessID(); /** * Get memory endianness. * @return true if memory is big-endian. */ boolean isBigEndian(); /** * Get memory address size. * @return number of bytes used to store memory address value. */ int getAddressSize(); /** * Get memory context name. * The name can be used for UI purposes. * @return context name. */ String getName(); /** * Get lowest address (inclusive) which is valid for the context. * @return lowest address. */ Number getStartBound(); /** * Get highest address (inclusive) which is valid for the context. * @return highest address. */ Number getEndBound(); /** * Get the access types allowed for this context. * @return collection of access type names. */ Collection<String> getAccessTypes(); /** * Get this memory context's addressable unit size in number of bytes. * The addressable size indicates the minimum number of bytes that * can be retrieved as a single unit. * @return addressable unit size in bytes. * @since 1.3 */ int getAddressableUnitSize(); /** * Get default word size in number of bytes. * The size is supposed to be used as the default memory view word representation. * Returns zero is word size is unknown. * @return word size in bytes. * @since 1.3 */ int getDefaultWordSize(); /** * Get context properties. * @return all available context properties. */ Map<String,Object> getProperties(); /** * Set target memory. * If 'word_size' is 0 it means client does not care about word size. */ IToken set(Number addr, int word_size, byte[] buf, int offs, int size, int mode, DoneMemory done); /** * Read target memory. */ IToken get(Number addr, int word_size, byte[] buf, int offs, int size, int mode, DoneMemory done); /** * Fill target memory with given pattern. * 'size' is number of bytes to fill. */ IToken fill(Number addr, int word_size, byte[] value, int size, int mode, DoneMemory done); } /** * Client call back interface for set(), get() and fill() commands. */ interface DoneMemory { public void doneMemory(IToken token, MemoryError error); } class MemoryError extends Exception { private static final long serialVersionUID = 1L; public MemoryError(String msg) { super(msg); } } /** * ErrorOffset interface can be implemented by MemoryError object, * which is returned by get, set and fill commands. * * get/set/fill () returns this exception when reading failed * for some but not all bytes, and MODE_CONTINUEONERROR * has been set in mode. (For example, when only part of the request * translates to valid memory addresses.) * Exception.getMessage can be used for generalized message of the * possible reasons of partial memory operation. */ interface ErrorOffset { // Error may have per byte information static final int BYTE_VALID = 0x00, BYTE_UNKNOWN = 0x01, // e.g. out of range BYTE_INVALID = 0x02, BYTE_CANNOT_READ = 0x04, BYTE_CANNOT_WRITE = 0x08; static final String RANGE_KEY_ADDR = "addr", RANGE_KEY_SIZE = "size", RANGE_KEY_STAT = "stat", RANGE_KEY_MSG = "msg"; int getStatus(int offset); /** * Returns the detail message string about the * byte associated with specified location. * @return the detail error message string. */ String getMessage(int offset); } /** * Add memory service event listener. * @param listener - event listener implementation. */ void addListener(MemoryListener listener); /** * Remove memory service event listener. * @param listener - event listener implementation. */ void removeListener(MemoryListener listener); /** * Memory event listener is notified when memory context hierarchy * changes, and when memory is modified by memory service commands. */ interface MemoryListener { /** * Called when a new memory access context(s) is created. */ void contextAdded(MemoryContext[] contexts); /** * Called when a memory access context(s) properties changed. */ void contextChanged(MemoryContext[] contexts); /** * Called when memory access context(s) is removed. */ void contextRemoved(String[] context_ids); /** * Called when target memory content was changed and clients * need to update themselves. Clients, at least, should invalidate * corresponding cached memory data. * Not every change is notified - it is not possible, * only those, which are not caused by normal execution of the debuggee. * 'addr' and 'size' can be null if unknown. */ void memoryChanged(String context_id, Number[] addr, long[] size); } }