subsys/debug/gdb_server.c
/**
 * @brief add a new breakpoint or watchpoint to breakpoint list
 *
 * This routine adds a new breakpoint or watchpoint to breakpoint list. For
 * watchpoints, this routine checks that the given type/length combination is
 * supported on current architecture, and that debug registers are not full.
 *
 * @param type GDB breakpoint type:
 *
 *        0 : software breakpoint    (GDB_SOFT_BP)
 *        1 : hardware breakpoint    (GDB_HW_INST_BP)
 *        2 : write watchpoint       (GDB_HW_DATA_WRITE_BP)
 *        3 : read watchpoint        (GDB_HW_DATA_READ_BP)
 *        4 : access watchpoint      (GDB_HW_DATA_ACCESS_BP)
 *
 * @param addr Breakpoint address
 * @param len For a software breakpoint, len specifies the size of the
 *            instruction to be patched. For hardware breakpoints and
 *            watchpoints length specifies the memory region to be monitored.
 * @param err Pointer to error code if failed to add breakpoint.
 *
 * @return 0 on success, -1 if failed to add breakpoint.
 */
@brief add a new breakpoint or watchpoint to breakpoint list
This routine adds a new breakpoint or watchpoint to breakpoint list. For
watchpoints, this routine checks that the given type/length combination is
supported on current architecture, and that debug registers are not full.

@param type GDB breakpoint type.



@param addr Breakpoint address
@param len For a software breakpoint, len specifies the size of the
instruction to be patched. For hardware breakpoints and
watchpoints length specifies the memory region to be monitored.
@param err Pointer to error code if failed to add breakpoint.

@return 0 on success, -1 if failed to add breakpoint.
@brief add a new breakpoint or watchpoint to breakpoint list This routine adds a new breakpoint or watchpoint to breakpoint list . For watchpoints this routine checks that the given type / length combination is supported on current architecture and that debug registers are not full . @param type GDB breakpoint type . @param addr Breakpoint address @param len For a software breakpoint len specifies the size of the instruction to be patched . For hardware breakpoints and watchpoints length specifies the memory region to be monitored . @param err Pointer to error code if failed to add breakpoint . @return 0 on success - 1 if failed to add breakpoint .
static int add_bp(enum gdb_bp_type type, long addr, int len,
		  enum gdb_error_code *err)
{
	if (type != GDB_SOFT_BP) {
		return add_hw_bp(addr, type, len, err);
	}
	if (mem_probe((void *)addr, SYS_MEM_SAFE_READ, len, 0, 1) == -1) {
		*err = GDB_ERROR_INVALID_MEM;
		return -1;
	}
	for (int ix = 0; ix < MAX_SW_BP; ix++) {
		if (bp_array[ix].valid == 0) {
			bp_array[ix].valid = 1;
			bp_array[ix].enabled = 0;
			bp_array[ix].addr = (gdb_instr_t *)addr;
			return 0;
		}
	}
	*err = GDB_ERROR_BP_LIST_FULL;
	return -1;
}
static int add_bp ( enum gdb_bp_type type , long addr , int len , enum gdb_error_code * err ) { if ( type != GDB_SOFT_BP ) { return add_hw_bp ( addr , type , len , err ) ; } if ( mem_probe ( ( void * ) addr , SYS_MEM_SAFE_READ , len , 0 , 1 ) == -1 ) { * err = GDB_ERROR_INVALID_MEM ; return -1 ; } for ( int ix = 0 ; ix < MAX_SW_BP ; ix ++ ) { if ( bp_array [ ix ] . valid == 0 ) { bp_array [ ix ] . valid = 1 ; bp_array [ ix ] . enabled = 0 ; bp_array [ ix ] . addr = ( gdb_instr_t * ) addr ; return 0 ; } } * err = GDB_ERROR_BP_LIST_FULL ; return -1 ; }
@brief add a new breakpoint or watchpoint to breakpoint list
 This routine adds a new breakpoint or watchpoint to breakpoint list.
@brief add a new breakpoint or watchpoint to breakpoint list This routine adds a new breakpoint or watchpoint to breakpoint list .
/* Add software breakpoint to BP list */