Add qemu 2.4.0
[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
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include <stdio.h>
23 #include <errno.h>
24 #include <assert.h>
25 #include <getopt.h>
26 #include <ipxe/command.h>
27 #include <ipxe/parseopt.h>
28 #include <ipxe/gdbstub.h>
29
30 /** @file
31  *
32  * GDB stub command
33  *
34  */
35
36 /**
37  * Parse GDB transport name
38  *
39  * @v text              Text
40  * @ret trans           GDB transport
41  * @ret rc              Return status code
42  */
43 static int parse_gdb_transport ( const char *text,
44                                  struct gdb_transport **trans ) {
45
46         /* Sanity check */
47         assert ( text != NULL );
48
49         /* Find transport */
50         *trans = find_gdb_transport ( text );
51         if ( ! *trans ) {
52                 printf ( "\"%s\": no such transport (is it compiled in?)\n",
53                          text );
54                 return -ENOTSUP;
55         }
56
57         return 0;
58 }
59
60 /** "gdbstub" options */
61 struct gdbstub_options {};
62
63 /** "gdbstub" option list */
64 static struct option_descriptor gdbstub_opts[] = {};
65
66 /** "gdbstub" command descriptor */
67 static struct command_descriptor gdbstub_cmd =
68         COMMAND_DESC ( struct gdbstub_options, gdbstub_opts, 1, MAX_ARGUMENTS,
69                        "<transport> [<options>...]" );
70
71 /**
72  * The "gdbstub" command
73  *
74  * @v argc              Argument count
75  * @v argv              Argument list
76  * @ret rc              Return status code
77  */
78 static int gdbstub_exec ( int argc, char **argv ) {
79         struct gdbstub_options opts;
80         struct gdb_transport *trans;
81         int rc;
82
83         /* Parse options */
84         if ( ( rc = parse_options ( argc, argv, &gdbstub_cmd, &opts ) ) != 0 )
85                 return rc;
86
87         /* Parse transport name */
88         if ( ( rc = parse_gdb_transport ( argv[optind++], &trans ) ) != 0 )
89                 return rc;
90
91         /* Initialise transport */
92         if ( trans->init ) {
93                 if ( ( rc = trans->init ( argc - optind,
94                                           &argv[optind] ) ) != 0 ) {
95                         return rc;
96                 }
97         }
98
99         /* Enter GDB stub */
100         gdbstub_start ( trans );
101
102         return 0;
103 }
104
105 /** GDB stub commands */
106 struct command gdbstub_commands[] __command = {
107         {
108                 .name = "gdbstub",
109                 .exec = gdbstub_exec,
110         },
111 };