Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

gdbstub_cmd.c 2.7KB

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