These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / hci / commands / gdbstub_cmd.c
1 /*
2  * Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <stdio.h>
27 #include <errno.h>
28 #include <assert.h>
29 #include <getopt.h>
30 #include <ipxe/command.h>
31 #include <ipxe/parseopt.h>
32 #include <ipxe/gdbstub.h>
33
34 /** @file
35  *
36  * GDB stub command
37  *
38  */
39
40 /**
41  * Parse GDB transport name
42  *
43  * @v text              Text
44  * @ret trans           GDB transport
45  * @ret rc              Return status code
46  */
47 static int parse_gdb_transport ( const char *text,
48                                  struct gdb_transport **trans ) {
49
50         /* Sanity check */
51         assert ( text != NULL );
52
53         /* Find transport */
54         *trans = find_gdb_transport ( text );
55         if ( ! *trans ) {
56                 printf ( "\"%s\": no such transport (is it compiled in?)\n",
57                          text );
58                 return -ENOTSUP;
59         }
60
61         return 0;
62 }
63
64 /** "gdbstub" options */
65 struct gdbstub_options {};
66
67 /** "gdbstub" option list */
68 static struct option_descriptor gdbstub_opts[] = {};
69
70 /** "gdbstub" command descriptor */
71 static struct command_descriptor gdbstub_cmd =
72         COMMAND_DESC ( struct gdbstub_options, gdbstub_opts, 1, MAX_ARGUMENTS,
73                        "<transport> [<options>...]" );
74
75 /**
76  * The "gdbstub" command
77  *
78  * @v argc              Argument count
79  * @v argv              Argument list
80  * @ret rc              Return status code
81  */
82 static int gdbstub_exec ( int argc, char **argv ) {
83         struct gdbstub_options opts;
84         struct gdb_transport *trans;
85         int rc;
86
87         /* Parse options */
88         if ( ( rc = parse_options ( argc, argv, &gdbstub_cmd, &opts ) ) != 0 )
89                 return rc;
90
91         /* Parse transport name */
92         if ( ( rc = parse_gdb_transport ( argv[optind++], &trans ) ) != 0 )
93                 return rc;
94
95         /* Initialise transport */
96         if ( trans->init ) {
97                 if ( ( rc = trans->init ( argc - optind,
98                                           &argv[optind] ) ) != 0 ) {
99                         return rc;
100                 }
101         }
102
103         /* Enter GDB stub */
104         gdbstub_start ( trans );
105
106         return 0;
107 }
108
109 /** GDB stub commands */
110 struct command gdbstub_commands[] __command = {
111         {
112                 .name = "gdbstub",
113                 .exec = gdbstub_exec,
114         },
115 };