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., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <getopt.h>
00021 #include <gpxe/command.h>
00022 #include <gpxe/gdbstub.h>
00023 
00024 /** @file
00025  *
00026  * GDB stub command
00027  *
00028  */
00029 
00030 /**
00031  * "gdbstub" command syntax message
00032  *
00033  * @v argv              Argument list
00034  */
00035 static void gdbstub_syntax ( char **argv ) {
00036         printf ( "Usage:\n"
00037                  "  %s <transport> [<options>...]\n"
00038                  "\n"
00039                  "Start remote debugging using one of the following transports:\n"
00040                  "  serial           use serial port (if compiled in)\n"
00041                  "  udp <interface>  use UDP over network interface (if compiled in)\n",
00042                  argv[0] );
00043 }
00044 
00045 /**
00046  * The "gdbstub" command
00047  *
00048  * @v argc              Argument count
00049  * @v argv              Argument list
00050  * @ret rc              Exit code
00051  */
00052 static int gdbstub_exec ( int argc, char **argv ) {
00053         static struct option longopts[] = {
00054                 { "help", 0, NULL, 'h' },
00055                 { NULL, 0, NULL, 0 },
00056         };
00057         const char *trans_name;
00058         struct gdb_transport *trans;
00059         int c;
00060 
00061         /* Parse options */
00062         while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
00063                 switch ( c ) {
00064                 case 'h':
00065                         /* Display help text */
00066                 default:
00067                         /* Unrecognised/invalid option */
00068                         gdbstub_syntax ( argv );
00069                         return 1;
00070                 }
00071         }
00072 
00073         /* At least one argument */
00074         if ( optind == argc ) {
00075                 gdbstub_syntax ( argv );
00076                 return 1;
00077         }
00078 
00079         trans_name = argv[optind++];
00080 
00081         /* Initialise transport */
00082         trans = find_gdb_transport ( trans_name );
00083         if ( !trans ) {
00084                 printf ( "%s: no such transport (is it compiled in?)\n", trans_name );
00085                 return 1;
00086         }
00087 
00088         if ( trans->init ) {
00089                 if ( trans->init ( argc - optind, &argv[optind] ) != 0 ) {
00090                         return 1;
00091                 }
00092         }
00093 
00094         /* Enter GDB stub */
00095         gdbstub_start ( trans );
00096         return 0;
00097 }
00098 
00099 /** GDB stub commands */
00100 struct command gdbstub_commands[] __command = {
00101         {
00102                 .name = "gdbstub",
00103                 .exec = gdbstub_exec,
00104         },
00105 };

Generated on Tue Apr 6 20:01:06 2010 for gPXE by  doxygen 1.5.7.1