Shared.DebugStruct.pas 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. unit Shared.DebugStruct;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2024 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;
  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. StepOutMarker: Boolean;
  79. end;
  80. { TVariableDebugEntrys associate [Code] section variable references with line
  81. numbers & column positions }
  82. PVariableDebugEntry = ^TVariableDebugEntry;
  83. TVariableDebugEntry = packed record
  84. FileIndex, LineNumber, Col: Integer; { Used by the Compiler IDE - also see TDebugEntry }
  85. Param1, Param2, Param3: Integer; { Used by Setup }
  86. Param4: array [0..127] of AnsiChar; { Used by Setup }
  87. end;
  88. function GetThreadTopWindow: HWND;
  89. function SendCopyDataMessage(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  90. Data: Pointer; Size: Cardinal): LRESULT;
  91. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  92. Data: AnsiString): LRESULT; overload;
  93. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  94. Data: UnicodeString): LRESULT; overload;
  95. implementation
  96. function EnumProc(Wnd: HWND; lParam: LPARAM): BOOL; stdcall;
  97. begin
  98. if IsWindowVisible(Wnd) then begin
  99. HWND(Pointer(lParam)^) := Wnd;
  100. Result := False;
  101. end
  102. else
  103. Result := True;
  104. end;
  105. function GetThreadTopWindow: HWND;
  106. begin
  107. Result := 0;
  108. EnumThreadWindows(GetCurrentThreadId, @EnumProc, LPARAM(@Result));
  109. end;
  110. function SendCopyDataMessage(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  111. Data: Pointer; Size: Cardinal): LRESULT;
  112. var
  113. CopyDataStruct: TCopyDataStruct;
  114. begin
  115. CopyDataStruct.dwData := CopyDataMsg;
  116. CopyDataStruct.cbData := Size;
  117. CopyDataStruct.lpData := Data;
  118. Result := SendMessage(DestWnd, WM_COPYDATA, WPARAM(SourceWnd),
  119. LPARAM(@CopyDataStruct));
  120. end;
  121. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  122. Data: AnsiString): LRESULT;
  123. begin
  124. Result := SendCopyDataMessage(DestWnd, SourceWnd, CopyDataMsg,
  125. Pointer(Data), Length(Data)*SizeOf(Data[1]));
  126. end;
  127. function SendCopyDataMessageStr(DestWnd, SourceWnd: HWND; CopyDataMsg: DWORD;
  128. Data: UnicodeString): LRESULT;
  129. begin
  130. Result := SendCopyDataMessage(DestWnd, SourceWnd, CopyDataMsg,
  131. Pointer(Data), Length(Data)*SizeOf(Data[1]));
  132. end;
  133. end.