DebugStruct.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. unit DebugStruct;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2020 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Debug info stuff
  8. }
  9. interface
  10. uses
  11. Windows, Messages, SysUtils, MurmurHash;
  12. const
  13. { Debug client -> debugger messages }
  14. WM_Debugger_Hello = WM_USER + $700;
  15. WM_Debugger_Goodbye = WM_USER + $701;
  16. WM_Debugger_Stepped = WM_USER + $702;
  17. WM_Debugger_SteppedIntermediate = WM_USER + $703;
  18. WM_Debugger_Exception = WM_USER + $704;
  19. WM_Debugger_SetForegroundWindow = WM_USER + $705;
  20. WM_Debugger_QueryVersion = WM_USER + $706;
  21. WM_Debugger_CallStackCount = WM_USER + $707;
  22. { Debug client -> debugger WM_COPYDATA messages }
  23. CD_Debugger_ReplyW = $700;
  24. CD_Debugger_ExceptionW = $701;
  25. CD_Debugger_UninstExeW = $702;
  26. CD_Debugger_LogMessageW = $703;
  27. CD_Debugger_TempDirW = $704;
  28. CD_Debugger_CallStackW = $705;
  29. { Debugger -> debug client messages }
  30. WM_DebugClient_Detach = WM_USER + $800;
  31. WM_DebugClient_Continue = WM_USER + $801;
  32. WM_DebugClient_SetForegroundWindow = WM_USER + $803;
  33. { List of all messages the debugger may send the debug client }
  34. DebugClientMessages: array[0..3] of UINT = (
  35. WM_COPYDATA,
  36. WM_DebugClient_Detach,
  37. WM_DebugClient_Continue,
  38. WM_DebugClient_SetForegroundWindow);
  39. { Debugger -> debug client WM_COPYDATA messages }
  40. CD_DebugClient_EvaluateConstantW = $800;
  41. CD_DebugClient_EvaluateVariableEntry = $801;
  42. CD_DebugClient_CompiledCodeTextA = $802;
  43. CD_DebugClient_CompiledCodeDebugInfoA = $803;
  44. { The current format of the 'debug info' is as follows:
  45. 1. A TDebugInfoHeader record.
  46. 2. A variable number (TDebugInfoHeader.DebugEntryCount) of TDebugEntry
  47. records.
  48. 3. A variable number (TDebugInfoHeader.VariableDebugEntryCount) of
  49. TVariableDebugEntry records.
  50. 4. The ROPS compiled code, the format of which is defined by ROPS.
  51. TDebugInfoHeader.CompiledCodeTextLength specifies the size in bytes.
  52. 5. Additional debug info for the ROPS compiled code, the format of which is
  53. defined by ROPS. TDebugInfoHeader.CompiledCodeDebugInfoLength specifies
  54. the size in bytes.
  55. }
  56. const
  57. DebugInfoHeaderID = $64787369;
  58. DebugInfoHeaderVersion = 5;
  59. type
  60. PDebugInfoHeader = ^TDebugInfoHeader;
  61. TDebugInfoHeader = packed record
  62. ID: Cardinal; { = DebugInfoHeaderID }
  63. Version: Integer; { = DebugInfoHeaderVersion }
  64. DebugEntryCount: Integer;
  65. VariableDebugEntryCount: Integer;
  66. CompiledCodeTextLength: Integer;
  67. CompiledCodeDebugInfoLength: Integer;
  68. end;
  69. { TDebugEntrys associate section entries with files and line numbers }
  70. TDebugEntryKind = (deDir, deFile, deIcon, deIni, deRegistry, deInstallDelete,
  71. deUninstallDelete, deRun, deUninstallRun, deCodeLine);
  72. PDebugEntry = ^TDebugEntry;
  73. TDebugEntry = packed record
  74. FileIndex: Integer; { -1: Main script, >=0: Include file index }
  75. LineNumber: Integer; { Starts at 1 - decreased by one by the Compiler IDE on receive }
  76. Kind: Integer; { TDebugEntryKind }
  77. Index: Integer;
  78. end;
  79. { TVariableDebugEntrys associate [Code] section variable references with line
  80. numbers & column positions }
  81. PVariableDebugEntry = ^TVariableDebugEntry;
  82. TVariableDebugEntry = packed record
  83. FileIndex, LineNumber, Col: Integer; { Used by the Compiler IDE - also see TDebugEntry }
  84. Param1, Param2, Param3: Integer; { Used by Setup }
  85. Param4: array [0..127] of AnsiChar; { Used by Setup }
  86. end;
  87. function GetThreadTopWindow: HWND;
  88. function SendCopyDataMessage(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  89. Data: Pointer; Size: Cardinal): LRESULT;
  90. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  91. Data: AnsiString): LRESULT;{$IFDEF UNICODE} overload;{$ENDIF}
  92. {$IFDEF UNICODE}
  93. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  94. Data: UnicodeString): LRESULT; overload;
  95. {$ENDIF}
  96. implementation
  97. function EnumProc(Wnd: HWND; lParam: LPARAM): BOOL; stdcall;
  98. begin
  99. if IsWindowVisible(Wnd) then begin
  100. HWND(Pointer(lParam)^) := Wnd;
  101. Result := False;
  102. end
  103. else
  104. Result := True;
  105. end;
  106. function GetThreadTopWindow: HWND;
  107. begin
  108. Result := 0;
  109. EnumThreadWindows(GetCurrentThreadId, @EnumProc, LPARAM(@Result));
  110. end;
  111. function SendCopyDataMessage(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  112. Data: Pointer; Size: Cardinal): LRESULT;
  113. var
  114. CopyDataStruct: TCopyDataStruct;
  115. begin
  116. CopyDataStruct.dwData := CopyDataMsg;
  117. CopyDataStruct.cbData := Size;
  118. CopyDataStruct.lpData := Data;
  119. Result := SendMessage(DestWnd, WM_COPYDATA, WPARAM(SourceWnd),
  120. LPARAM(@CopyDataStruct));
  121. end;
  122. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  123. Data: AnsiString): LRESULT;
  124. begin
  125. { Windows 95/98/Me bug workaround: Call UniqueString to ensure the string is
  126. in writable memory. Amazingly enough, sending a WM_COPYDATA message with a
  127. read-only buffer causes a fatal page fault error. }
  128. if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
  129. IsBadWritePtr(Pointer(Data), Length(Data)*SizeOf(Data[1])) then
  130. UniqueString(Data);
  131. Result := SendCopyDataMessage(DestWnd, SourceWnd, CopyDataMsg,
  132. Pointer(Data), Length(Data)*SizeOf(Data[1]));
  133. end;
  134. {$IFDEF UNICODE}
  135. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  136. Data: UnicodeString): LRESULT;
  137. begin
  138. { Windows 95/98/Me bug workaround: Call UniqueString to ensure the string is
  139. in writable memory. Amazingly enough, sending a WM_COPYDATA message with a
  140. read-only buffer causes a fatal page fault error. }
  141. if (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
  142. IsBadWritePtr(Pointer(Data), Length(Data)*SizeOf(Data[1])) then
  143. UniqueString(Data);
  144. Result := SendCopyDataMessage(DestWnd, SourceWnd, CopyDataMsg,
  145. Pointer(Data), Length(Data)*SizeOf(Data[1]));
  146. end;
  147. {$ENDIF}
  148. end.