Services - tools - models - for embedded software development
Embecosm divider strip
Prev  Next

4.7.15.  Matchpoint Handling

Matchpoint is the general term used for breakpoints (both memory and hardware) and watchpoints (write, read and access). Matchpoints are removed with zcommand> packets and set with Z packets. The functionality is provided respectively in resp_remove_matchpoint () and resp_insert_matchpoint ().

The current implementation only supports memory (soft) breakpoints controlled by Z0 and Z0 packets. However the OpenRISC 1000 architecture and Or1ksim have hardware breakpoint and watchpoint functionality within the debug unit, which will be supported in the future.

The target is responsible for keeping track of any memory breakpoints set. This is managed through the hash table pointed to by rsp.mp_hash. Each matchpoint is recorded in a matchpoint entry:

struct mp_entry
{
  enum mp_type       type;
  unsigned long int  addr;
  unsigned long int  instr;
  struct mp_entry   *next;
};
	

When an instruction is replaced by l.trap for a memory breakpoint, the replace instruction is recorded in the hash table as a struct mp_entry with type BP_MEMORY. This allows it to be replaced when the the breakpoint is cleared.

The hash table is accessed by the functions mp_hash_init (), mp_hash_add (), mp_hash_lookup () and mp_hash_delete (). These are described in more detail in Section 4.3.2.1

4.7.15.1.  Setting Matchpoints

Only memory (soft) breakpoints are supported. The instruction is read from memory at the location of the breakpoint and stored in the hash table (using mp_hash_add ()). A l.trap instruction (OR1K_TRAP_INSTR) is inserted in its place using set_program32 () and a reply of "OK" sent back.

      mp_hash_add (type, addr, eval_direct32 (addr, 0, 0));
      set_program32 (addr, OR1K_TRAP_INSTR);
      put_str_packet ("OK");
	  
[Caution]Caution

The use of eval_direct32 () with second and third arguments both zero and set_program32 () is not correct, since it ignores any caching or memory management. As a result the current implementation is only correct for configurations with no instruction MMU or instruction cache.

4.7.15.2.  Clearing Matchpoints

Only memory (soft) breakpoints are supported. The instruction that was substituted by l.trap is retrieved and deleted from the hash table using mp_hash_delete (). The instruction is then put back in its original location using set_program32 ().

mp_hash_delete () returns the struct mp_entry that was removed from the hash table. Once the instruction information has been retrieved, its memory must be returned by calling free ().

It is possible to receive multiple requests to delete a breakpoint if the serial connection is poor (due to retransmissions). By checking that the entry is in the hash table, actual deletion of the breakpoint and restoration of the instruction happens at most once.

      mpe = mp_hash_delete (type, addr);

      if (NULL != mpe)
        {
          set_program32 (addr, mpe->instr);
          free (mpe);
        }

      put_str_packet ("OK");
          
[Caution]Caution

The use of set_program32 () is not correct, since it ignores any caching or memory management. As a result the current implementation is only correct for configurations with no instruction MMU or instruction cache.

Embecosm divider strip