You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gdbstub_cmd.c 2.5KB

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