iPXE
gdbstub_cmd.c
Go to the documentation of this file.
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 */
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 };
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int optind
Current option index.
Definition: getopt.c:51
struct gdb_transport * find_gdb_transport(const char *name)
Look up GDB transport by name.
Definition: gdbstub.c:392
Error codes.
A command-line command.
Definition: command.h:9
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
static int gdbstub_exec(int argc, char **argv)
The "gdbstub" command.
Definition: gdbstub_cmd.c:82
"gdbstub" options
Definition: gdbstub_cmd.c:65
A command descriptor.
Definition: parseopt.h:77
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
Assertions.
Parse command-line options.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
void gdbstub_start(struct gdb_transport *trans)
Break into the debugger using the given transport.
Definition: gdbstub.c:403
Command line option parsing.
static union @437 opts
"cert<xxx>" option list
const char * name
Name of the command.
Definition: command.h:11
GDB remote debugging.
int(* init)(int argc, char **argv)
Set up the transport given a list of arguments.
Definition: gdbstub.h:32
static struct option_descriptor gdbstub_opts[]
"gdbstub" option list
Definition: gdbstub_cmd.c:68
A command-line option descriptor.
Definition: parseopt.h:23
static struct command_descriptor gdbstub_cmd
"gdbstub" command descriptor
Definition: gdbstub_cmd.c:71
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
static int parse_gdb_transport(const char *text, struct gdb_transport **trans)
Parse GDB transport name.
Definition: gdbstub_cmd.c:47
struct command gdbstub_commands [] __command
GDB stub commands.
Definition: gdbstub_cmd.c:110
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
A transport mechanism for the GDB protocol.
Definition: gdbstub.h:20