[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 07/18] mcdstub: mcdserver initialization functions added
From: |
Nicolas Eder |
Subject: |
[PATCH v5 07/18] mcdstub: mcdserver initialization functions added |
Date: |
Wed, 20 Dec 2023 17:25:44 +0100 |
---
debug/mcdstub/mcdstub.c | 154 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 154 insertions(+)
diff --git a/debug/mcdstub/mcdstub.c b/debug/mcdstub/mcdstub.c
index 4d8d5d956a..0df436719e 100644
--- a/debug/mcdstub/mcdstub.c
+++ b/debug/mcdstub/mcdstub.c
@@ -22,9 +22,12 @@
#include "qemu/cutils.h"
#include "qemu/module.h"
#include "qemu/error-report.h"
+#include "qemu/debug.h"
#include "qapi/error.h"
#include "chardev/char.h"
#include "chardev/char-fe.h"
+#include "hw/cpu/cluster.h"
+#include "hw/boards.h"
#include "sysemu/cpus.h"
#include "sysemu/hw_accel.h"
#include "sysemu/runstate.h"
@@ -109,6 +112,39 @@ static void mcd_chr_event(void *opaque, QEMUChrEvent event)
{
}
+/**
+ * init_query_cmds_table() - Initializes all query functions.
+ *
+ * This function adds all query functions to the mcd_query_cmds_table. This
+ * includes their command string, handler function and parameter schema.
+ * @mcd_query_cmds_table: Lookup table with all query commands.
+ */
+static void init_query_cmds_table(MCDCmdParseEntry *mcd_query_cmds_table)
+{}
+
+/**
+ * mcd_set_stop_cpu() - Sets c_cpu to the just stopped CPU.
+ *
+ * @cpu: The CPU state.
+ */
+static void mcd_set_stop_cpu(CPUState *cpu)
+{
+ mcdserver_state.c_cpu = cpu;
+}
+
+/**
+ * mcd_init_debug_class() - initialize mcd-specific DebugClass
+ */
+static void mcd_init_debug_class(void){
+ Object *obj;
+ obj = object_new(TYPE_DEBUG);
+ DebugState *ds = DEBUG(obj);
+ DebugClass *dc = DEBUG_GET_CLASS(ds);
+ dc->set_stop_cpu = mcd_set_stop_cpu;
+ MachineState *ms = MACHINE(qdev_get_machine());
+ ms->debug_state = ds;
+}
+
/**
* mcd_init_mcdserver_state() - Initializes the mcdserver_state struct.
*
@@ -119,6 +155,35 @@ static void mcd_chr_event(void *opaque, QEMUChrEvent event)
*/
static void mcd_init_mcdserver_state(void)
{
+ g_assert(!mcdserver_state.init);
+ memset(&mcdserver_state, 0, sizeof(MCDState));
+ mcdserver_state.init = true;
+ mcdserver_state.str_buf = g_string_new(NULL);
+ mcdserver_state.mem_buf = g_byte_array_sized_new(MAX_PACKET_LENGTH);
+ mcdserver_state.last_packet = g_byte_array_sized_new(MAX_PACKET_LENGTH +
4);
+
+ /*
+ * What single-step modes are supported is accelerator dependent.
+ * By default try to use no IRQs and no timers while single
+ * stepping so as to make single stepping like a typical ICE HW step.
+ */
+ mcdserver_state.supported_sstep_flags =
+ accel_supported_gdbstub_sstep_flags();
+ mcdserver_state.sstep_flags = SSTEP_ENABLE | SSTEP_NOIRQ | SSTEP_NOTIMER;
+ mcdserver_state.sstep_flags &= mcdserver_state.supported_sstep_flags;
+
+ /* init query table */
+ init_query_cmds_table(mcdserver_state.mcd_query_cmds_table);
+
+ /* at this time the cpu hans't been started! -> set cpu_state */
+ mcd_cpu_state_st cpu_state = {
+ .state = CORE_STATE_HALTED,
+ .info_str = STATE_STR_INIT_HALTED,
+ };
+ mcdserver_state.cpu_state = cpu_state;
+
+ /* create new debug object */
+ mcd_init_debug_class();
}
/**
@@ -128,6 +193,84 @@ static void mcd_init_mcdserver_state(void)
*/
static void reset_mcdserver_state(void)
{
+ g_free(mcdserver_state.processes);
+ mcdserver_state.processes = NULL;
+ mcdserver_state.process_num = 0;
+}
+
+/**
+ * mcd_create_default_process() - Creates a default process for debugging.
+ *
+ * This function creates a new, not yet attached, process with an ID one above
+ * the previous maximum ID.
+ * @s: A MCDState object.
+ */
+static void mcd_create_default_process(MCDState *s)
+{
+ MCDProcess *process;
+ int max_pid = 0;
+
+ if (mcdserver_state.process_num) {
+ max_pid = s->processes[s->process_num - 1].pid;
+ }
+
+ s->processes = g_renew(MCDProcess, s->processes, ++s->process_num);
+ process = &s->processes[s->process_num - 1];
+
+ /* We need an available PID slot for this process */
+ assert(max_pid < UINT32_MAX);
+
+ process->pid = max_pid + 1;
+ process->attached = false;
+}
+
+/**
+ * find_cpu_clusters() - Returns the CPU cluster of the child object.
+ *
+ * @param[in] child Object with unknown CPU cluster.
+ * @param[in] opaque Pointer to an MCDState object.
+ */
+static int find_cpu_clusters(Object *child, void *opaque)
+{
+ if (object_dynamic_cast(child, TYPE_CPU_CLUSTER)) {
+ MCDState *s = (MCDState *) opaque;
+ CPUClusterState *cluster = CPU_CLUSTER(child);
+ MCDProcess *process;
+
+ s->processes = g_renew(MCDProcess, s->processes, ++s->process_num);
+
+ process = &s->processes[s->process_num - 1];
+ assert(cluster->cluster_id != UINT32_MAX);
+ process->pid = cluster->cluster_id + 1;
+ process->attached = false;
+
+ return 0;
+ }
+
+ return object_child_foreach(child, find_cpu_clusters, opaque);
+}
+
+/**
+ * pid_order() - Compares process IDs.
+ *
+ * This function returns -1 if process "a" has a ower process ID than "b".
+ * If "b" has a lower ID than "a" 1 is returned and if they are qual 0 is
+ * returned.
+ * @a: Process a.
+ * @b: Process b.
+ */
+static int pid_order(const void *a, const void *b)
+{
+ MCDProcess *pa = (MCDProcess *) a;
+ MCDProcess *pb = (MCDProcess *) b;
+
+ if (pa->pid < pb->pid) {
+ return -1;
+ } else if (pa->pid > pb->pid) {
+ return 1;
+ } else {
+ return 0;
+ }
}
/**
@@ -141,6 +284,17 @@ static void reset_mcdserver_state(void)
*/
static void create_processes(MCDState *s)
{
+ object_child_foreach(object_get_root(), find_cpu_clusters, s);
+
+ if (mcdserver_state.processes) {
+ /* Sort by PID */
+ qsort(mcdserver_state.processes,
+ mcdserver_state.process_num,
+ sizeof(mcdserver_state.processes[0]),
+ pid_order);
+ }
+
+ mcd_create_default_process(s);
}
int mcdserver_start(const char *device)
--
2.34.1
- [PATCH v5 00/18] first version of mcdstub, Nicolas Eder, 2023/12/20
- [PATCH v5 01/18] gdbstub, mcdstub: file and build structure adapted to accomodate for the mcdstub, Nicolas Eder, 2023/12/20
- [PATCH v5 11/18] mcdstub: system and core queries added, Nicolas Eder, 2023/12/20
- [PATCH v5 02/18] gdbstub: hex conversion functions moved to cutils.h, Nicolas Eder, 2023/12/20
- [PATCH v5 10/18] mcdstub: open and close server functions added, Nicolas Eder, 2023/12/20
- [PATCH v5 03/18] gdbstub: GDBRegisterState moved to gdbstub.h so it can be used outside of the gdbstub, Nicolas Eder, 2023/12/20
- [PATCH v5 05/18] mcdstub: memory helper functions added, Nicolas Eder, 2023/12/20
- [PATCH v5 04/18] gdbstub: DebugClass added to system mode., Nicolas Eder, 2023/12/20
- [PATCH v5 07/18] mcdstub: mcdserver initialization functions added,
Nicolas Eder <=
- [PATCH v5 08/18] cutils: qemu_strtou32 function added, Nicolas Eder, 2023/12/20
- [PATCH v5 12/18] mcdstub: all core specific queries added, Nicolas Eder, 2023/12/20
- [PATCH v5 06/18] mcdstub: -mcd start option added, mcd specific defines added, Nicolas Eder, 2023/12/20
- [PATCH v5 09/18] mcdstub: TCP packet plumbing added, Nicolas Eder, 2023/12/20
- [PATCH v5 13/18] mcdstub: go, step and break added, Nicolas Eder, 2023/12/20
- [PATCH v5 15/18] mcdstub: skeleton for reset handling added, Nicolas Eder, 2023/12/20
- [PATCH v5 14/18] mcdstub: state query added, Nicolas Eder, 2023/12/20
- [PATCH v5 16/18] mcdstub: register access added, Nicolas Eder, 2023/12/20
- [PATCH v5 17/18] mcdstub: memory access added, Nicolas Eder, 2023/12/20
- [PATCH v5 18/18] mcdstub: break/watchpoints added, Nicolas Eder, 2023/12/20