windebug.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 2000 by Pierre Muller
  4. Windows specific debugger routines for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Unit windebug;
  12. {$H-}
  13. interface
  14. {$ifndef NODEBUG}
  15. type
  16. DebuggeeState = (Running_State,Stopped_State);
  17. procedure ChangeDebuggeeWindowTitleTo(State : DebuggeeState);
  18. function CygDrivePrefix : string;
  19. const
  20. main_pid_valid : boolean = false;
  21. {$endif NODEBUG}
  22. implementation
  23. {$ifndef NODEBUG}
  24. uses
  25. {$ifdef GDBMI}
  26. gdbmiint,
  27. {$else GDBMI}
  28. gdbint,
  29. {$endif GDBMI}
  30. strings,
  31. windows;
  32. const
  33. CygDrivePrefixKey1 = 'Software';
  34. CygDrivePrefixKey2 = 'Cygnus Solutions';
  35. CygDrivePrefixKey3 = 'Cygwin';
  36. CygDrivePrefixKey4 = 'mounts v2';
  37. CygDrivePrefixKey = 'cygdrive prefix';
  38. function CygDrivePrefix : string;
  39. var
  40. i : longint;
  41. length : dword;
  42. Value : PAnsiChar;
  43. _type : dword;
  44. Key,NKey : HKey;
  45. begin
  46. Length:=0;
  47. Key:=HKEY_CURRENT_USER;
  48. i := RegOpenKeyEx(Key, CygDrivePrefixKey1, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  49. if i=ERROR_SUCCESS then
  50. begin
  51. Key:=NKey;
  52. i := RegOpenKeyEx(Key, CygDrivePrefixKey2, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  53. end;
  54. if i=ERROR_SUCCESS then
  55. begin
  56. RegCloseKey(Key);
  57. Key:=NKey;
  58. i := RegOpenKeyEx(Key, CygDrivePrefixKey3, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  59. end;
  60. if i=ERROR_SUCCESS then
  61. begin
  62. RegCloseKey(Key);
  63. Key:=NKey;
  64. i := RegOpenKeyEx(Key, CygDrivePrefixKey4, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  65. end;
  66. if i=ERROR_SUCCESS then
  67. begin
  68. RegCloseKey(Key);
  69. Key:=NKey;
  70. i := RegQueryValueEx( Key, CygDrivePrefixKey, nil, @_type, nil, @length);
  71. end;
  72. if i<>ERROR_SUCCESS then
  73. CygDrivePrefix:='/cygdrive'
  74. else
  75. Begin
  76. GetMem(Value,Length);
  77. i := RegQueryValueEx( Key, CygDrivePrefixKey, nil, @_type, LPByte(Value), @length);
  78. if i<>ERROR_SUCCESS then
  79. CygDrivePrefix:='/cygdrive'
  80. else
  81. CygDrivePrefix:=StrPas(Value);
  82. FreeMem(Value,Length);
  83. End;
  84. if Key<>HKEY_CURRENT_USER then
  85. RegCloseKey(Key);
  86. end;
  87. const
  88. MaxTitleLength = 512;
  89. main_pid : longint = 0;
  90. function GetWindowHandle(H : HWND; state : LPARAM) : WINBOOL;stdcall;
  91. var pTitle, pEnd, pNewTitle : PAnsiChar;
  92. len : longint;
  93. begin
  94. GetWindowHandle:=true;
  95. GetMem(pTitle,MaxTitleLength);
  96. { we want all windows !! }
  97. if (GetWindowThreadProcessId(H,nil)=inferior_pid) or
  98. main_pid_valid and (GetWindowThreadProcessId(H,nil)=main_pid) then
  99. begin
  100. if not main_pid_valid then
  101. begin
  102. main_pid:=inferior_pid;
  103. main_pid_valid:=true;
  104. end;
  105. len:=GetWindowText(H,pTitle,MaxTitleLength);
  106. if DebuggeeState(State) = Stopped_State then
  107. begin
  108. GetMem(pNewTitle,len+50);
  109. pEnd:=strpos(pTitle,'... running under FP debugger');
  110. if assigned(pEnd) then
  111. pEnd^:=#0;
  112. pEnd:=strpos(pTitle,'... stopped by FP debugger');
  113. if assigned(pEnd) then
  114. pEnd^:=#0;
  115. strcopy(pNewTitle,pTitle);
  116. strcat(pNewTitle,'... stopped by FP debugger');
  117. SetWindowText(H,pNewTitle);
  118. FreeMem(pNewTitle,len+50);
  119. end
  120. else if DebuggeeState(State) = Running_State then
  121. begin
  122. GetMem(pNewTitle,len+50);
  123. pEnd:=strpos(pTitle,'... stopped by FP debugger');
  124. if assigned(pEnd) then
  125. pEnd^:=#0;
  126. pEnd:=strpos(pTitle,'... running under FP debugger');
  127. if assigned(pEnd) then
  128. pEnd^:=#0;
  129. strcopy(pNewTitle,pTitle);
  130. strcat(pNewTitle,'... running under FP debugger');
  131. SetWindowText(H,pNewTitle);
  132. FreeMem(pNewTitle,len+50);
  133. end;
  134. end;
  135. FreeMem(pTitle,MaxTitleLength);
  136. end;
  137. procedure ChangeDebuggeeWindowTitleTo(State : DebuggeeState);
  138. begin
  139. EnumWindows(EnumWindowsProc(@GetWindowHandle),longint(State));
  140. end;
  141. {$endif NODEBUG}
  142. end.