dbgdwarf.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. dbgdwarf.c
  5. Abstract:
  6. This module implements the glue functions that connect the rest of the
  7. debugger to the DWARF symbol library.
  8. Author:
  9. Evan Green 17-Dec-2015
  10. Environment:
  11. Debug
  12. --*/
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <minoca/lib/types.h>
  17. #include <minoca/lib/status.h>
  18. #include <minoca/lib/im.h>
  19. #include <minoca/debug/spproto.h>
  20. #include <minoca/debug/dbgext.h>
  21. #include "dbgrprof.h"
  22. #include "dbgapi.h"
  23. #include "symbols.h"
  24. #include "dbgrcomm.h"
  25. #include "dwarf.h"
  26. #include <assert.h>
  27. #include <errno.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. //
  31. // ---------------------------------------------------------------- Definitions
  32. //
  33. //
  34. // ------------------------------------------------------ Data Type Definitions
  35. //
  36. //
  37. // ----------------------------------------------- Internal Function Prototypes
  38. //
  39. //
  40. // -------------------------------------------------------------------- Globals
  41. //
  42. //
  43. // ------------------------------------------------------------------ Functions
  44. //
  45. INT
  46. DwarfTargetRead (
  47. PDWARF_CONTEXT Context,
  48. ULONGLONG TargetAddress,
  49. ULONGLONG Size,
  50. ULONG AddressSpace,
  51. PVOID Buffer
  52. )
  53. /*++
  54. Routine Description:
  55. This routine performs a read from target memory.
  56. Arguments:
  57. Context - Supplies a pointer to the DWARF context.
  58. TargetAddress - Supplies the address to read from.
  59. Size - Supplies the number of bytes to read.
  60. AddressSpace - Supplies the address space identifier. Supply 0 for normal
  61. memory.
  62. Buffer - Supplies a pointer where the read data will be returned on success.
  63. Return Value:
  64. 0 on success.
  65. Returns an error number on failure.
  66. --*/
  67. {
  68. ULONG BytesRead;
  69. PDEBUGGER_CONTEXT DebuggerContext;
  70. INT Status;
  71. PDEBUG_SYMBOLS Symbols;
  72. Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
  73. DebuggerContext = Symbols->HostContext;
  74. assert(DebuggerContext != NULL);
  75. assert(AddressSpace == 0);
  76. Status = DbgReadMemory(DebuggerContext,
  77. TRUE,
  78. TargetAddress,
  79. Size,
  80. Buffer,
  81. &BytesRead);
  82. if (Status != 0) {
  83. return Status;
  84. }
  85. if (BytesRead != Size) {
  86. return EFAULT;
  87. }
  88. return 0;
  89. }
  90. INT
  91. DwarfTargetReadRegister (
  92. PDWARF_CONTEXT Context,
  93. ULONG Register,
  94. PULONGLONG Value
  95. )
  96. /*++
  97. Routine Description:
  98. This routine reads a register value.
  99. Arguments:
  100. Context - Supplies a pointer to the DWARF context.
  101. Register - Supplies the register to read.
  102. Value - Supplies a pointer where the value will be returned on success.
  103. Return Value:
  104. 0 on success.
  105. Returns an error number on failure.
  106. --*/
  107. {
  108. PDEBUGGER_CONTEXT DebuggerContext;
  109. PREGISTERS_UNION Registers;
  110. INT Status;
  111. PDEBUG_SYMBOLS Symbols;
  112. Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
  113. DebuggerContext = Symbols->HostContext;
  114. assert(DebuggerContext != NULL);
  115. Registers = Symbols->RegistersContext;
  116. if (Registers == NULL) {
  117. Registers = &(DebuggerContext->FrameRegisters);
  118. }
  119. Status = DbgGetRegister(DebuggerContext, Registers, Register, Value);
  120. return Status;
  121. }
  122. INT
  123. DwarfTargetWriteRegister (
  124. PDWARF_CONTEXT Context,
  125. ULONG Register,
  126. ULONGLONG Value
  127. )
  128. /*++
  129. Routine Description:
  130. This routine writes a register value.
  131. Arguments:
  132. Context - Supplies a pointer to the DWARF context.
  133. Register - Supplies the register to write.
  134. Value - Supplies the new value of the register.
  135. Return Value:
  136. 0 on success.
  137. Returns an error number on failure.
  138. --*/
  139. {
  140. PDEBUGGER_CONTEXT DebuggerContext;
  141. PREGISTERS_UNION Registers;
  142. INT Status;
  143. PDEBUG_SYMBOLS Symbols;
  144. Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
  145. DebuggerContext = Symbols->HostContext;
  146. assert(DebuggerContext != NULL);
  147. Registers = Symbols->RegistersContext;
  148. if (Registers == NULL) {
  149. Registers = &(DebuggerContext->FrameRegisters);
  150. }
  151. Status = DbgSetRegister(DebuggerContext, Registers, Register, Value);
  152. return Status;
  153. }
  154. PSTR
  155. DwarfGetRegisterName (
  156. PDWARF_CONTEXT Context,
  157. ULONG Register
  158. )
  159. /*++
  160. Routine Description:
  161. This routine returns a string containing the name of the given register.
  162. Arguments:
  163. Context - Supplies a pointer to the application context.
  164. Register - Supplies the register number.
  165. Return Value:
  166. Returns a pointer to a constant string containing the name of the register.
  167. --*/
  168. {
  169. PDEBUG_SYMBOLS Symbols;
  170. Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
  171. return DbgGetRegisterName(Symbols->Machine, Register);
  172. }
  173. //
  174. // --------------------------------------------------------- Internal Functions
  175. //