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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <stdio.h>
  19. #include <getopt.h>
  20. #include <gpxe/command.h>
  21. #include <gpxe/gdbstub.h>
  22. /** @file
  23. *
  24. * GDB stub command
  25. *
  26. */
  27. /**
  28. * "gdbstub" command syntax message
  29. *
  30. * @v argv Argument list
  31. */
  32. static void gdbstub_syntax ( char **argv ) {
  33. printf ( "Usage:\n"
  34. " %s <transport> [<options>...]\n"
  35. "\n"
  36. "Start remote debugging using one of the following transports:\n"
  37. " serial use serial port (if compiled in)\n"
  38. " udp <interface> use UDP over network interface (if compiled in)\n",
  39. argv[0] );
  40. }
  41. /**
  42. * The "gdbstub" command
  43. *
  44. * @v argc Argument count
  45. * @v argv Argument list
  46. * @ret rc Exit code
  47. */
  48. static int gdbstub_exec ( int argc, char **argv ) {
  49. static struct option longopts[] = {
  50. { "help", 0, NULL, 'h' },
  51. { NULL, 0, NULL, 0 },
  52. };
  53. const char *trans_name;
  54. struct gdb_transport *trans;
  55. int c;
  56. /* Parse options */
  57. while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
  58. switch ( c ) {
  59. case 'h':
  60. /* Display help text */
  61. default:
  62. /* Unrecognised/invalid option */
  63. gdbstub_syntax ( argv );
  64. return 1;
  65. }
  66. }
  67. /* At least one argument */
  68. if ( optind == argc ) {
  69. gdbstub_syntax ( argv );
  70. return 1;
  71. }
  72. trans_name = argv[optind++];
  73. /* Initialise transport */
  74. trans = find_gdb_transport ( trans_name );
  75. if ( !trans ) {
  76. printf ( "%s: no such transport (is it compiled in?)\n", trans_name );
  77. return 1;
  78. }
  79. if ( trans->init ) {
  80. if ( trans->init ( argc - optind, &argv[optind] ) != 0 ) {
  81. return 1;
  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. };