Source code of Windows XP (NT5)
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.

109 lines
2.3 KiB

  1. /*** debugger.c - Debugger functions
  2. *
  3. * This module contains all the debug functions.
  4. *
  5. * Copyright (c) 1996,1997 Microsoft Corporation
  6. * Author: Michael Tsang (MikeTs)
  7. * Created 09/18/96
  8. *
  9. * MODIFICATION HISTORY
  10. */
  11. #include "pch.h"
  12. #ifdef DEBUGGER
  13. /*** Miscellaneous Constants
  14. */
  15. #define MAX_CMDLINE_LEN 255
  16. /*** Local function prototypes
  17. */
  18. LONG LOCAL DbgExecuteCmd(PDBGCMD pDbgCmds, PSZ pszCmd);
  19. /*** Local data
  20. */
  21. PSZ pszTokenSeps = " \t\n";
  22. /***LP Debugger - generic debugger entry point
  23. *
  24. * ENTRY
  25. * pDbgCmds -> debugger command table
  26. * pszPrompt -> prompt string
  27. *
  28. * EXIT
  29. * None
  30. */
  31. VOID LOCAL Debugger(PDBGCMD pDbgCmds, PSZ pszPrompt)
  32. {
  33. char szCmdLine[MAX_CMDLINE_LEN + 1];
  34. PSZ psz;
  35. for (;;)
  36. {
  37. ConPrompt(pszPrompt, szCmdLine, sizeof(szCmdLine));
  38. if ((psz = STRTOK(szCmdLine, pszTokenSeps)) != NULL)
  39. {
  40. if (DbgExecuteCmd(pDbgCmds, psz) == DBGERR_QUIT)
  41. break;
  42. }
  43. }
  44. } //Debugger
  45. /***LP DbgExecuteCmd - execute a debugger command
  46. *
  47. * ENTRY
  48. * pDbgCmds -> debugger command table
  49. * pszCmd -> command string
  50. *
  51. * EXIT-SUCCESS
  52. * returns DBGERR_NONE or DBGERR_QUIT
  53. * EXIT-FAILURE
  54. * returns negative error code
  55. */
  56. LONG LOCAL DbgExecuteCmd(PDBGCMD pDbgCmds, PSZ pszCmd)
  57. {
  58. LONG rc = DBGERR_NONE;
  59. int i;
  60. ULONG dwNumArgs = 0, dwNonSWArgs = 0;
  61. for (i = 0; pDbgCmds[i].pszCmd != NULL; i++)
  62. {
  63. if (STRCMP(pszCmd, pDbgCmds[i].pszCmd) == 0)
  64. {
  65. if (pDbgCmds[i].dwfCmd & CMDF_QUIT)
  66. {
  67. rc = DBGERR_QUIT;
  68. }
  69. else if ((pDbgCmds[i].pArgTable == NULL) ||
  70. ((rc = DbgParseArgs(pDbgCmds[i].pArgTable, &dwNumArgs,
  71. &dwNonSWArgs, pszTokenSeps)) ==
  72. ARGERR_NONE))
  73. {
  74. if (pDbgCmds[i].pfnCmd != NULL)
  75. rc = pDbgCmds[i].pfnCmd(NULL, NULL, dwNumArgs, dwNonSWArgs);
  76. }
  77. else
  78. rc = DBGERR_PARSE_ARGS;
  79. break;
  80. }
  81. }
  82. if (pDbgCmds[i].pszCmd == NULL)
  83. {
  84. DBG_ERROR(("invalid command - %s", pszCmd));
  85. rc = DBGERR_INVALID_CMD;
  86. }
  87. return rc;
  88. } //DbgExecuteCmd
  89. #endif //ifdef DEBUGGER