1 | /* gdb.c - gdb remote stub module */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2003 Free Software Foundation, Inc. |
---|
4 | * Copyright (C) 2006 Lubomir Kundrak |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 3 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <grub/types.h> |
---|
22 | #include <grub/misc.h> |
---|
23 | #include <grub/mm.h> |
---|
24 | #include <grub/err.h> |
---|
25 | #include <grub/dl.h> |
---|
26 | #include <grub/normal.h> |
---|
27 | #include <grub/term.h> |
---|
28 | #include <grub/cpu/gdb.h> |
---|
29 | #include <grub/gdb.h> |
---|
30 | #include <grub/serial.h> |
---|
31 | #include <grub/i18n.h> |
---|
32 | |
---|
33 | GRUB_MOD_LICENSE ("GPLv3+"); |
---|
34 | |
---|
35 | static grub_err_t |
---|
36 | grub_cmd_gdbstub (struct grub_command *cmd __attribute__ ((unused)), |
---|
37 | int argc, char **args) |
---|
38 | { |
---|
39 | struct grub_serial_port *port; |
---|
40 | if (argc < 1) |
---|
41 | return grub_error (GRUB_ERR_BAD_ARGUMENT, "port required"); |
---|
42 | port = grub_serial_find (args[0]); |
---|
43 | if (!port) |
---|
44 | return grub_errno; |
---|
45 | grub_gdb_port = port; |
---|
46 | /* TRANSLATORS: at this position GRUB waits for the user to do an action |
---|
47 | in remote debugger, namely to tell it to establish connection. */ |
---|
48 | grub_puts_ (N_("Now connect the remote debugger, please.")); |
---|
49 | grub_gdb_breakpoint (); |
---|
50 | return 0; |
---|
51 | } |
---|
52 | |
---|
53 | static grub_err_t |
---|
54 | grub_cmd_gdbstop (struct grub_command *cmd __attribute__ ((unused)), |
---|
55 | int argc __attribute__ ((unused)), |
---|
56 | char **args __attribute__ ((unused))) |
---|
57 | { |
---|
58 | grub_gdb_port = NULL; |
---|
59 | return 0; |
---|
60 | } |
---|
61 | |
---|
62 | static grub_err_t |
---|
63 | grub_cmd_gdb_break (struct grub_command *cmd __attribute__ ((unused)), |
---|
64 | int argc __attribute__ ((unused)), |
---|
65 | char **args __attribute__ ((unused))) |
---|
66 | { |
---|
67 | if (!grub_gdb_port) |
---|
68 | return grub_error (GRUB_ERR_BAD_ARGUMENT, "No GDB stub is running"); |
---|
69 | grub_gdb_breakpoint (); |
---|
70 | return 0; |
---|
71 | } |
---|
72 | |
---|
73 | static grub_command_t cmd, cmd_stop, cmd_break; |
---|
74 | |
---|
75 | GRUB_MOD_INIT (gdb) |
---|
76 | { |
---|
77 | grub_gdb_idtinit (); |
---|
78 | cmd = grub_register_command ("gdbstub", grub_cmd_gdbstub, |
---|
79 | N_("PORT"), |
---|
80 | /* TRANSLATORS: GDB stub is a small part of |
---|
81 | GDB functionality running on local host |
---|
82 | which allows remote debugger to |
---|
83 | connect to it. */ |
---|
84 | N_("Start GDB stub on given port")); |
---|
85 | cmd_break = grub_register_command ("gdbstub_break", grub_cmd_gdb_break, |
---|
86 | /* TRANSLATORS: this refers to triggering |
---|
87 | a breakpoint so that the user will land |
---|
88 | into GDB. */ |
---|
89 | 0, N_("Break into GDB")); |
---|
90 | cmd_stop = grub_register_command ("gdbstub_stop", grub_cmd_gdbstop, |
---|
91 | 0, N_("Stop GDB stub")); |
---|
92 | } |
---|
93 | |
---|
94 | GRUB_MOD_FINI (gdb) |
---|
95 | { |
---|
96 | grub_unregister_command (cmd); |
---|
97 | grub_unregister_command (cmd_stop); |
---|
98 | grub_gdb_idtrestore (); |
---|
99 | } |
---|
100 | |
---|