gdb.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include <grub/types.h>
  21. #include <grub/misc.h>
  22. #include <grub/mm.h>
  23. #include <grub/err.h>
  24. #include <grub/dl.h>
  25. #include <grub/normal.h>
  26. #include <grub/term.h>
  27. #include <grub/cpu/gdb.h>
  28. #include <grub/gdb.h>
  29. #include <grub/serial.h>
  30. #include <grub/i18n.h>
  31. GRUB_MOD_LICENSE ("GPLv3+");
  32. static grub_err_t
  33. grub_cmd_gdbstub (struct grub_command *cmd __attribute__ ((unused)),
  34. int argc, char **args)
  35. {
  36. struct grub_serial_port *port;
  37. if (argc < 1)
  38. return grub_error (GRUB_ERR_BAD_ARGUMENT, "port required");
  39. port = grub_serial_find (args[0]);
  40. if (!port)
  41. return grub_errno;
  42. grub_gdb_port = port;
  43. /* TRANSLATORS: at this position GRUB waits for the user to do an action
  44. in remote debugger, namely to tell it to establish connection. */
  45. grub_puts_ (N_("Now connect the remote debugger, please."));
  46. grub_gdb_breakpoint ();
  47. return 0;
  48. }
  49. static grub_err_t
  50. grub_cmd_gdbstop (struct grub_command *cmd __attribute__ ((unused)),
  51. int argc __attribute__ ((unused)),
  52. char **args __attribute__ ((unused)))
  53. {
  54. grub_gdb_port = NULL;
  55. return 0;
  56. }
  57. static grub_err_t
  58. grub_cmd_gdb_break (struct grub_command *cmd __attribute__ ((unused)),
  59. int argc __attribute__ ((unused)),
  60. char **args __attribute__ ((unused)))
  61. {
  62. if (!grub_gdb_port)
  63. return grub_error (GRUB_ERR_BAD_ARGUMENT, "No GDB stub is running");
  64. grub_gdb_breakpoint ();
  65. return 0;
  66. }
  67. static grub_command_t cmd, cmd_stop, cmd_break;
  68. GRUB_MOD_INIT (gdb)
  69. {
  70. grub_gdb_idtinit ();
  71. cmd = grub_register_command_lockdown ("gdbstub", grub_cmd_gdbstub,
  72. N_("PORT"),
  73. /*
  74. * TRANSLATORS: GDB stub is a small part of
  75. * GDB functionality running on local host
  76. * which allows remote debugger to
  77. * connect to it.
  78. */
  79. N_("Start GDB stub on given port"));
  80. cmd_break = grub_register_command_lockdown ("gdbstub_break", grub_cmd_gdb_break,
  81. /*
  82. * TRANSLATORS: this refers to triggering
  83. * a breakpoint so that the user will land
  84. * into GDB.
  85. */
  86. 0, N_("Break into GDB"));
  87. cmd_stop = grub_register_command_lockdown ("gdbstub_stop", grub_cmd_gdbstop,
  88. 0, N_("Stop GDB stub"));
  89. }
  90. GRUB_MOD_FINI (gdb)
  91. {
  92. grub_unregister_command (cmd);
  93. grub_unregister_command (cmd_break);
  94. grub_unregister_command (cmd_stop);
  95. grub_gdb_idtrestore ();
  96. }