vaseboot/VasEBoot-core/gdb/gdb.c

101 lines
3.2 KiB
C

/* gdb.c - gdb remote stub module */
/*
* Copyright (C) 2003 Free Software Foundation, Inc.
* Copyright (C) 2006 Lubomir Kundrak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <VasEBoot/types.h>
#include <VasEBoot/misc.h>
#include <VasEBoot/mm.h>
#include <VasEBoot/err.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/normal.h>
#include <VasEBoot/term.h>
#include <VasEBoot/cpu/gdb.h>
#include <VasEBoot/gdb.h>
#include <VasEBoot/serial.h>
#include <VasEBoot/i18n.h>
VasEBoot_MOD_LICENSE ("GPLv3+");
static VasEBoot_err_t
VasEBoot_cmd_gdbstub (struct VasEBoot_command *cmd __attribute__ ((unused)),
int argc, char **args)
{
struct VasEBoot_serial_port *port;
if (argc < 1)
return VasEBoot_error (VasEBoot_ERR_BAD_ARGUMENT, "port required");
port = VasEBoot_serial_find (args[0]);
if (!port)
return VasEBoot_errno;
VasEBoot_gdb_port = port;
/* TRANSLATORS: at this position VasEBoot waits for the user to do an action
in remote debugger, namely to tell it to establish connection. */
VasEBoot_puts_ (N_("Now connect the remote debugger, please."));
VasEBoot_gdb_breakpoint ();
return 0;
}
static VasEBoot_err_t
VasEBoot_cmd_gdbstop (struct VasEBoot_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
VasEBoot_gdb_port = NULL;
return 0;
}
static VasEBoot_err_t
VasEBoot_cmd_gdb_break (struct VasEBoot_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
if (!VasEBoot_gdb_port)
return VasEBoot_error (VasEBoot_ERR_BAD_ARGUMENT, "No GDB stub is running");
VasEBoot_gdb_breakpoint ();
return 0;
}
static VasEBoot_command_t cmd, cmd_stop, cmd_break;
VasEBoot_MOD_INIT (gdb)
{
VasEBoot_gdb_idtinit ();
cmd = VasEBoot_register_command ("gdbstub", VasEBoot_cmd_gdbstub,
N_("PORT"),
/* TRANSLATORS: GDB stub is a small part of
GDB functionality running on local host
which allows remote debugger to
connect to it. */
N_("Start GDB stub on given port"));
cmd_break = VasEBoot_register_command ("gdbstub_break", VasEBoot_cmd_gdb_break,
/* TRANSLATORS: this refers to triggering
a breakpoint so that the user will land
into GDB. */
0, N_("Break into GDB"));
cmd_stop = VasEBoot_register_command ("gdbstub_stop", VasEBoot_cmd_gdbstop,
0, N_("Stop GDB stub"));
}
VasEBoot_MOD_FINI (gdb)
{
VasEBoot_unregister_command (cmd);
VasEBoot_unregister_command (cmd_stop);
VasEBoot_gdb_idtrestore ();
}