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.

190 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. ds.c
  5. Abstract:
  6. Dumps symbols found on the stack.
  7. Author:
  8. Keith Moore (keithmo) 12-Nov-1999
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #define NUM_STACK_SYMBOLS_TO_DUMP 48
  15. //
  16. // Public functions.
  17. //
  18. DECLARE_API( ds )
  19. /*++
  20. Routine Description:
  21. Dumps symbols found on the stack.
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. --*/
  27. {
  28. ULONG_PTR startingAddress;
  29. ULONG_PTR stack;
  30. ULONG i;
  31. ULONG result;
  32. CHAR symbol[MAX_SYMBOL_LENGTH];
  33. ULONG_PTR offset;
  34. PCHAR format;
  35. BOOLEAN validSymbolsOnly = FALSE;
  36. SNAPSHOT_EXTENSION_DATA();
  37. //
  38. // Skip leading blanks.
  39. //
  40. while (*args == ' ' || *args == '\t')
  41. {
  42. args++;
  43. }
  44. if (*args == '-')
  45. {
  46. args++;
  47. switch (*args)
  48. {
  49. case 'v' :
  50. case 'V' :
  51. validSymbolsOnly = TRUE;
  52. args++;
  53. break;
  54. default :
  55. PrintUsage( "ds" );
  56. return;
  57. }
  58. }
  59. while (*args == ' ')
  60. {
  61. args++;
  62. }
  63. //
  64. // By default, start at the current stack location. Otherwise,
  65. // start at the given address.
  66. //
  67. if (!*args)
  68. {
  69. #if defined(_X86_)
  70. args = "esp";
  71. #elif defined(_AMD64_)
  72. args = "rsp";
  73. #elif defined(_IA64_)
  74. args = "sp";
  75. #else
  76. #error "unsupported CPU"
  77. #endif
  78. }
  79. startingAddress = GetExpression( args );
  80. if (startingAddress == 0)
  81. {
  82. dprintf( "!inetdbg.ds: cannot evaluate \"%s\"\n", args );
  83. return;
  84. }
  85. //
  86. // Ensure startingAddress is properly aligned.
  87. //
  88. startingAddress &= ~(sizeof(ULONG_PTR) - 1);
  89. //
  90. // Read the stack.
  91. //
  92. for (i = 0 ; i < NUM_STACK_SYMBOLS_TO_DUMP ; startingAddress += sizeof(ULONG_PTR) )
  93. {
  94. if (CheckControlC())
  95. {
  96. break;
  97. }
  98. if (!ReadMemory(
  99. startingAddress,
  100. &stack,
  101. sizeof(stack),
  102. &result
  103. ))
  104. {
  105. dprintf( "ds: cannot read memory @ %p\n", startingAddress );
  106. return;
  107. }
  108. GetSymbol( (PVOID)stack, symbol, &offset );
  109. if (symbol[0] == '\0')
  110. {
  111. if (validSymbolsOnly)
  112. {
  113. continue;
  114. }
  115. format = "%p : %p\n";
  116. }
  117. else if (offset == 0)
  118. {
  119. format = "%p : %p : %s\n";
  120. }
  121. else
  122. {
  123. format = "%p : %p : %s+0x%lx\n";
  124. }
  125. dprintf(
  126. format,
  127. startingAddress,
  128. stack,
  129. symbol,
  130. offset
  131. );
  132. i++;
  133. }
  134. dprintf(
  135. "!ulkd.ds %s%lx to dump next block\n",
  136. validSymbolsOnly ? "-v " : "",
  137. startingAddress
  138. );
  139. } // ds