[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 19/20] mcdstub: break/watchpoints added
|
From: |
Nicolas Eder |
|
Subject: |
[PATCH v3 19/20] mcdstub: break/watchpoints added |
|
Date: |
Tue, 7 Nov 2023 14:03:22 +0100 |
---
include/mcdstub/mcdstub.h | 46 +++++++++++++++
mcdstub/mcdstub.c | 116 ++++++++++++++++++++++++++++++++++++++
2 files changed, 162 insertions(+)
diff --git a/include/mcdstub/mcdstub.h b/include/mcdstub/mcdstub.h
index c55d52d2a7..53e5926ff5 100644
--- a/include/mcdstub/mcdstub.h
+++ b/include/mcdstub/mcdstub.h
@@ -785,6 +785,52 @@ int mcd_read_write_memory(CPUState *cpu, AddressSpace
*address_space,
MemTxAttrs attributes, vaddr addr, uint8_t *buf, uint64_t len,
bool is_write);
+/**
+ * handle_breakpoint_insert() - Handler for inserting a break- or watchpoint.
+ *
+ * This function extracts the CPU, breakpoint type and address from the
+ * parameters and calls :c:func:`mcd_breakpoint_insert` to insert the
+ * breakpoint.
+ * @params: GArray with all TCP packet parameters.
+ */
+void handle_breakpoint_insert(GArray *params, void *user_ctx);
+
+/**
+ * handle_breakpoint_remove() - Handler for inserting a break- or watchpoint.
+ *
+ * This function extracts the CPU, breakpoint type and address from the
+ * parameters and calls :c:func:`mcd_breakpoint_remove` to insert the
+ * breakpoint.
+ * @params: GArray with all TCP packet parameters.
+ */
+void handle_breakpoint_remove(GArray *params, void *user_ctx);
+
+/**
+ * mcd_breakpoint_insert() - Inserts a break- or watchpoint.
+ *
+ * This function evaluates the received breakpoint type and translates it
+ * to a known GDB breakpoint type.
+ * Then it calls cpu_breakpoint_insert or cpu_watchpoint_insert depending on
+ * the type.
+ * @cpu: CPU to which the breakpoint should be added.
+ * @addr: Address of the breakpoint.
+ * @type: Breakpoint type.
+ */
+int mcd_breakpoint_insert(CPUState *cpu, int type, vaddr addr);
+
+/**
+ * mcd_breakpoint_remove() - Removes a break- or watchpoint.
+ *
+ * This function evaluates the received breakpoint type and translates it
+ * to a known GDB breakpoint type.
+ * Then it calls cpu_breakpoint_remove or cpu_watchpoint_remove depending on
+ * the type.
+ * @cpu: CPU from which the breakpoint should be removed.
+ * @addr: Address of the breakpoint.
+ * @type: Breakpoint type.
+ */
+int mcd_breakpoint_remove(CPUState *cpu, int type, vaddr addr);
+
/**
* mcd_get_address_space() - Returnes the correct QEMU address space name
* @cpu: CPUState
diff --git a/mcdstub/mcdstub.c b/mcdstub/mcdstub.c
index 8dc1e6a71d..68e9cdf531 100644
--- a/mcdstub/mcdstub.c
+++ b/mcdstub/mcdstub.c
@@ -570,6 +570,32 @@ int mcd_handle_packet(const char *line_buf)
cmd_parser = &write_mem_cmd_desc;
}
break;
+ case TCP_CHAR_BREAKPOINT_INSERT:
+ {
+ static MCDCmdParseEntry handle_breakpoint_insert_cmd_desc = {
+ .handler = handle_breakpoint_insert,
+ };
+ handle_breakpoint_insert_cmd_desc.cmd =
+ (char[2]) { TCP_CHAR_BREAKPOINT_INSERT, '\0' };
+ strcpy(handle_breakpoint_insert_cmd_desc.schema,
+ (char[4]) { ARG_SCHEMA_CORENUM, ARG_SCHEMA_INT,
+ ARG_SCHEMA_UINT64_T, '\0' });
+ cmd_parser = &handle_breakpoint_insert_cmd_desc;
+ }
+ break;
+ case TCP_CHAR_BREAKPOINT_REMOVE:
+ {
+ static MCDCmdParseEntry handle_breakpoint_remove_cmd_desc = {
+ .handler = handle_breakpoint_remove,
+ };
+ handle_breakpoint_remove_cmd_desc.cmd =
+ (char[2]) { TCP_CHAR_BREAKPOINT_REMOVE, '\0' };
+ strcpy(handle_breakpoint_remove_cmd_desc.schema,
+ (char[4]) { ARG_SCHEMA_CORENUM, ARG_SCHEMA_INT,
+ ARG_SCHEMA_UINT64_T, '\0' });
+ cmd_parser = &handle_breakpoint_remove_cmd_desc;
+ }
+ break;
default:
/* command not supported */
mcd_put_packet("");
@@ -1880,3 +1906,93 @@ void handle_write_memory(GArray *params, void *user_ctx)
/* send acknowledge */
mcd_put_packet(TCP_EXECUTION_SUCCESS);
}
+
+int mcd_breakpoint_insert(CPUState *cpu, int type, vaddr addr)
+{
+ /* translate the type to known gdb types and function call*/
+ int bp_type = 0;
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ if (cc->gdb_stop_before_watchpoint) {
+ /* bp_type |= BP_STOP_BEFORE_ACCESS; */
+ }
+ int return_value = 0;
+ switch (type) {
+ case MCD_BREAKPOINT_HW:
+ return_value = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL);
+ return return_value;
+ case MCD_BREAKPOINT_READ:
+ bp_type |= BP_GDB | BP_MEM_READ;
+ return_value = cpu_watchpoint_insert(cpu, addr, 4, bp_type, NULL);
+ return return_value;
+ case MCD_BREAKPOINT_WRITE:
+ bp_type |= BP_GDB | BP_MEM_WRITE;
+ return_value = cpu_watchpoint_insert(cpu, addr, 4, bp_type, NULL);
+ return return_value;
+ case MCD_BREAKPOINT_RW:
+ bp_type |= BP_GDB | BP_MEM_ACCESS;
+ return_value = cpu_watchpoint_insert(cpu, addr, 4, bp_type, NULL);
+ return return_value;
+ default:
+ return -ENOSYS;
+ }
+}
+
+int mcd_breakpoint_remove(CPUState *cpu, int type, vaddr addr)
+{
+ /* translate the type to known gdb types and function call*/
+ int bp_type = 0;
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ if (cc->gdb_stop_before_watchpoint) {
+ /* bp_type |= BP_STOP_BEFORE_ACCESS; */
+ }
+ int return_value = 0;
+ switch (type) {
+ case MCD_BREAKPOINT_HW:
+ return_value = cpu_breakpoint_remove(cpu, addr, BP_GDB);
+ return return_value;
+ case MCD_BREAKPOINT_READ:
+ bp_type |= BP_GDB | BP_MEM_READ;
+ return_value = cpu_watchpoint_remove(cpu, addr, 4, bp_type);
+ return return_value;
+ case MCD_BREAKPOINT_WRITE:
+ bp_type |= BP_GDB | BP_MEM_WRITE;
+ return_value = cpu_watchpoint_remove(cpu, addr, 4, bp_type);
+ return return_value;
+ case MCD_BREAKPOINT_RW:
+ bp_type |= BP_GDB | BP_MEM_ACCESS;
+ return_value = cpu_watchpoint_remove(cpu, addr, 4, bp_type);
+ return return_value;
+ default:
+ return -ENOSYS;
+ }
+}
+
+void handle_breakpoint_insert(GArray *params, void *user_ctx)
+{
+ /* 1. get parameter data */
+ uint32_t cpu_id = get_param(params, 0)->cpu_id;
+ uint32_t type = get_param(params, 1)->data_uint32_t;
+ uint64_t address = get_param(params, 2)->data_uint64_t;
+ /* 2. insert breakpoint and send reply */
+ CPUState *cpu = mcd_get_cpu(cpu_id);
+ if (mcd_breakpoint_insert(cpu, type, address) != 0) {
+ mcd_put_packet(TCP_EXECUTION_ERROR);
+ } else {
+ mcd_put_packet(TCP_EXECUTION_SUCCESS);
+ }
+}
+
+void handle_breakpoint_remove(GArray *params, void *user_ctx)
+{
+ /* 1. get parameter data */
+ uint32_t cpu_id = get_param(params, 0)->cpu_id;
+ uint32_t type = get_param(params, 1)->data_uint32_t;
+ uint64_t address = get_param(params, 2)->data_uint64_t;
+ /* 2. remove breakpoint and send reply */
+ CPUState *cpu = mcd_get_cpu(cpu_id);
+ if (mcd_breakpoint_remove(cpu, type, address) != 0) {
+ mcd_put_packet(TCP_EXECUTION_ERROR);
+ } else {
+ mcd_put_packet(TCP_EXECUTION_SUCCESS);
+ }
+}
--
2.34.1
- [PATCH v3 05/20] mcdstub: tcp packet processing added, (continued)
- [PATCH v3 05/20] mcdstub: tcp packet processing added, Nicolas Eder, 2023/11/07
- [PATCH v3 20/20] mcdstub: updated MAINTAINERS file and fully activated the mcdstub in the meson build system, Nicolas Eder, 2023/11/07
- [PATCH v3 18/20] mcdstub: read/write to memory added: This also includes various helper functions in the QEMU memory code, Nicolas Eder, 2023/11/07
- [PATCH v3 02/20] mcdstub gdbstub: new DebugClass and DebugState introduced. They are used to abstract the debugger details behind a QOM. This is currently used in the cpu_handle_guest_debug function, Nicolas Eder, 2023/11/07
- [PATCH v3 11/20] mcdstub: reset and trigger queries added, Nicolas Eder, 2023/11/07
- [PATCH v3 06/20] mcdstub: open/close server functions and trigger/reset data added. User for initial connection with an mcd client, Nicolas Eder, 2023/11/07
- [PATCH v3 12/20] mcdstub: missing parse_reg_xml function for parsing gdb register xml files added, Nicolas Eder, 2023/11/07
- [PATCH v3 13/20] mcdstub: added queries for memory spaces, register groups and registers, Nicolas Eder, 2023/11/07
- [PATCH v3 19/20] mcdstub: break/watchpoints added,
Nicolas Eder <=
- [PATCH v3 14/20] mcdstub: missing handle_query_state function added, Nicolas Eder, 2023/11/07
- [PATCH v3 04/20] mcdstub: added header with defines specific to the mcd tcp packet communication, Nicolas Eder, 2023/11/07
- [PATCH v3 16/20] mcdstub: function construct for resets added, Nicolas Eder, 2023/11/07
- [PATCH v3 15/20] mcdstub: added go, break and step functionality and all corresponding functions, Nicolas Eder, 2023/11/07
- [PATCH v3 03/20] gdbstub: moving code so that it can be easier accessed from outside the gdbstub: fromhex and tohex functions moved to a cutils header. GDBRegisterState moved to gdbstub.h, Nicolas Eder, 2023/11/07
- [PATCH v3 17/20] mcdstub: reading/writing registers added, Nicolas Eder, 2023/11/07
- Re: [PATCH v3 00/20] first version of mcdstub, Philippe Mathieu-Daudé, 2023/11/08