iPXE
gdbstub_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <stdio.h>
00027 #include <errno.h>
00028 #include <assert.h>
00029 #include <getopt.h>
00030 #include <ipxe/command.h>
00031 #include <ipxe/parseopt.h>
00032 #include <ipxe/gdbstub.h>
00033 
00034 /** @file
00035  *
00036  * GDB stub command
00037  *
00038  */
00039 
00040 /**
00041  * Parse GDB transport name
00042  *
00043  * @v text              Text
00044  * @ret trans           GDB transport
00045  * @ret rc              Return status code
00046  */
00047 static int parse_gdb_transport ( const char *text,
00048                                  struct gdb_transport **trans ) {
00049 
00050         /* Sanity check */
00051         assert ( text != NULL );
00052 
00053         /* Find transport */
00054         *trans = find_gdb_transport ( text );
00055         if ( ! *trans ) {
00056                 printf ( "\"%s\": no such transport (is it compiled in?)\n",
00057                          text );
00058                 return -ENOTSUP;
00059         }
00060 
00061         return 0;
00062 }
00063 
00064 /** "gdbstub" options */
00065 struct gdbstub_options {};
00066 
00067 /** "gdbstub" option list */
00068 static struct option_descriptor gdbstub_opts[] = {};
00069 
00070 /** "gdbstub" command descriptor */
00071 static struct command_descriptor gdbstub_cmd =
00072         COMMAND_DESC ( struct gdbstub_options, gdbstub_opts, 1, MAX_ARGUMENTS,
00073                        "<transport> [<options>...]" );
00074 
00075 /**
00076  * The "gdbstub" command
00077  *
00078  * @v argc              Argument count
00079  * @v argv              Argument list
00080  * @ret rc              Return status code
00081  */
00082 static int gdbstub_exec ( int argc, char **argv ) {
00083         struct gdbstub_options opts;
00084         struct gdb_transport *trans;
00085         int rc;
00086 
00087         /* Parse options */
00088         if ( ( rc = parse_options ( argc, argv, &gdbstub_cmd, &opts ) ) != 0 )
00089                 return rc;
00090 
00091         /* Parse transport name */
00092         if ( ( rc = parse_gdb_transport ( argv[optind++], &trans ) ) != 0 )
00093                 return rc;
00094 
00095         /* Initialise transport */
00096         if ( trans->init ) {
00097                 if ( ( rc = trans->init ( argc - optind,
00098                                           &argv[optind] ) ) != 0 ) {
00099                         return rc;
00100                 }
00101         }
00102 
00103         /* Enter GDB stub */
00104         gdbstub_start ( trans );
00105 
00106         return 0;
00107 }
00108 
00109 /** GDB stub commands */
00110 struct command gdbstub_commands[] __command = {
00111         {
00112                 .name = "gdbstub",
00113                 .exec = gdbstub_exec,
00114         },
00115 };