windebug.pas 4.2 KB

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