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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( FORBIDDEN );
26
27#include <stdio.h>
28#include <errno.h>
29#include <assert.h>
30#include <getopt.h>
31#include <ipxe/command.h>
32#include <ipxe/parseopt.h>
33#include <ipxe/gdbstub.h>
34
35/** @file
36 *
37 * GDB stub command
38 *
39 */
40
41/**
42 * Parse GDB transport name
43 *
44 * @v text Text
45 * @ret trans GDB transport
46 * @ret rc Return status code
47 */
48static int parse_gdb_transport ( const char *text,
49 struct gdb_transport **trans ) {
50
51 /* Sanity check */
52 assert ( text != NULL );
53
54 /* Find transport */
55 *trans = find_gdb_transport ( text );
56 if ( ! *trans ) {
57 printf ( "\"%s\": no such transport (is it compiled in?)\n",
58 text );
59 return -ENOTSUP;
60 }
61
62 return 0;
63}
64
65/** "gdbstub" options */
67
68/** "gdbstub" option list */
69static struct option_descriptor gdbstub_opts[] = {};
70
71/** "gdbstub" command descriptor */
74 "<transport> [<options>...]" );
75
76/**
77 * The "gdbstub" command
78 *
79 * @v argc Argument count
80 * @v argv Argument list
81 * @ret rc Return status code
82 */
83static int gdbstub_exec ( int argc, char **argv ) {
84 struct gdbstub_options opts;
85 struct gdb_transport *trans;
86 int rc;
87
88 /* Parse options */
89 if ( ( rc = parse_options ( argc, argv, &gdbstub_cmd, &opts ) ) != 0 )
90 return rc;
91
92 /* Parse transport name */
93 if ( ( rc = parse_gdb_transport ( argv[optind++], &trans ) ) != 0 )
94 return rc;
95
96 /* Initialise transport */
97 if ( trans->init ) {
98 if ( ( rc = trans->init ( argc - optind,
99 &argv[optind] ) ) != 0 ) {
100 return rc;
101 }
102 }
103
104 /* Enter GDB stub */
105 gdbstub_start ( trans );
106
107 return 0;
108}
109
110/** GDB stub commands */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
#define COMMAND(name, exec)
Definition command.h:27
Error codes.
struct gdb_transport * find_gdb_transport(const char *name)
Look up GDB transport by name.
Definition gdbstub.c:392
void gdbstub_start(struct gdb_transport *trans)
Break into the debugger using the given transport.
Definition gdbstub.c:403
GDB remote debugging.
static int parse_gdb_transport(const char *text, struct gdb_transport **trans)
Parse GDB transport name.
Definition gdbstub_cmd.c:48
static int gdbstub_exec(int argc, char **argv)
The "gdbstub" command.
Definition gdbstub_cmd.c:83
static struct command_descriptor gdbstub_cmd
"gdbstub" command descriptor
Definition gdbstub_cmd.c:72
static struct option_descriptor gdbstub_opts[]
"gdbstub" option list
Definition gdbstub_cmd.c:69
int optind
Current option index.
Definition getopt.c:52
Parse command-line options.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
Command line option parsing.
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition parseopt.h:98
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
A command descriptor.
Definition parseopt.h:78
A transport mechanism for the GDB protocol.
Definition gdbstub.h:21
int(* init)(int argc, char **argv)
Set up the transport given a list of arguments.
Definition gdbstub.h:33
"gdbstub" options
Definition gdbstub_cmd.c:66
A command-line option descriptor.
Definition parseopt.h:24
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465