toolchain: add new debugging tool using magenta_debug

This commit is contained in:
2026-06-06 17:54:20 +01:00
parent 5bb36a916c
commit a6bdcc6c49
40 changed files with 2211 additions and 1 deletions
+105
View File
@@ -0,0 +1,105 @@
#include "context.h"
#include "event.h"
#include "repl.h"
#include <fx/cmdline/cmd.h>
#include <magenta/debug/packet.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
static struct debug_context ctx = {0};
enum {
CMD_ROOT,
OPT_REMOTE,
OPT_REMOTE_ADDRESS,
OPT_REMOTE_PORT,
};
static void on_event(struct debug_context *ctx, struct packet *packet)
{
event_handle(ctx, packet);
}
static int mxdbg(
const fx_command *self,
const fx_arglist *opt,
const fx_array *args)
{
debug_context_init(&ctx);
ctx.ctx_on_event = on_event;
char *ep = NULL;
const char *ip_address = NULL;
const char *port_cstr = NULL;
fx_arglist_get_string(
opt,
OPT_REMOTE,
OPT_REMOTE_ADDRESS,
0,
&ip_address);
fx_arglist_get_string(opt, OPT_REMOTE, OPT_REMOTE_PORT, 0, &port_cstr);
int err = 0;
if (ip_address && port_cstr) {
long port = strtol(port_cstr, &ep, 10);
if (*ep) {
fprintf(stderr,
"'%s' is not a valid port number.\n",
port_cstr);
return -1;
}
printf("connecting to %s:%ld...\n", ip_address, port);
err = debug_context_connect_net(&ctx, ip_address, port);
} else {
printf("no target specified\n");
return 0;
}
if (err != 0) {
printf("connection failed\n");
return err;
}
debug_context_start_threads(&ctx);
err = repl(&ctx);
debug_context_cleanup(&ctx);
return err;
}
FX_COMMAND(CMD_ROOT, FX_COMMAND_INVALID_ID)
{
FX_COMMAND_NAME("mxdbg");
FX_COMMAND_DESC("Magenta kernel debugger.");
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(mxdbg);
FX_COMMAND_OPTION(OPT_REMOTE)
{
FX_OPTION_LONG_NAME("remote");
FX_OPTION_SHORT_NAME('r');
FX_OPTION_DESC("The TCP/IP address and port to connect to.");
FX_OPTION_ARG(OPT_REMOTE_ADDRESS)
{
FX_ARG_NAME("ip-address");
FX_ARG_NR_VALUES(1);
}
FX_OPTION_ARG(OPT_REMOTE_PORT)
{
FX_ARG_NAME("port");
FX_ARG_NR_VALUES(1);
}
}
}
int main(int argc, const char **argv)
{
return fx_command_dispatch(CMD_ROOT, argc, argv);
}