windebug.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. {$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. gdbint,
  26. strings,
  27. windows;
  28. const
  29. CygDrivePrefixKey1 = 'Software';
  30. CygDrivePrefixKey2 = 'Cygnus Solutions';
  31. CygDrivePrefixKey3 = 'Cygwin';
  32. CygDrivePrefixKey4 = 'mounts v2';
  33. CygDrivePrefixKey = 'cygdrive prefix';
  34. function CygDrivePrefix : string;
  35. var
  36. i : longint;
  37. length : dword;
  38. Value : pchar;
  39. _type : dword;
  40. Key,NKey : HKey;
  41. begin
  42. Length:=0;
  43. Key:=HKEY_CURRENT_USER;
  44. i := RegOpenKeyEx(Key, CygDrivePrefixKey1, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  45. if i=ERROR_SUCCESS then
  46. begin
  47. Key:=NKey;
  48. i := RegOpenKeyEx(Key, CygDrivePrefixKey2, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  49. end;
  50. if i=ERROR_SUCCESS then
  51. begin
  52. RegCloseKey(Key);
  53. Key:=NKey;
  54. i := RegOpenKeyEx(Key, CygDrivePrefixKey3, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  55. end;
  56. if i=ERROR_SUCCESS then
  57. begin
  58. RegCloseKey(Key);
  59. Key:=NKey;
  60. i := RegOpenKeyEx(Key, CygDrivePrefixKey4, 0, KEY_ENUMERATE_SUB_KEYS, @NKey);
  61. end;
  62. if i=ERROR_SUCCESS then
  63. begin
  64. RegCloseKey(Key);
  65. Key:=NKey;
  66. i := RegQueryValueEx( Key, CygDrivePrefixKey, nil, @_type, nil, @length);
  67. end;
  68. if i<>ERROR_SUCCESS then
  69. CygDrivePrefix:='/cygdrive'
  70. else
  71. Begin
  72. GetMem(Value,Length);
  73. i := RegQueryValueEx( Key, CygDrivePrefixKey, nil, @_type, LPByte(Value), @length);
  74. if i<>ERROR_SUCCESS then
  75. CygDrivePrefix:='/cygdrive'
  76. else
  77. CygDrivePrefix:=StrPas(Value);
  78. FreeMem(Value,Length);
  79. End;
  80. if Key<>HKEY_CURRENT_USER then
  81. RegCloseKey(Key);
  82. end;
  83. const
  84. MaxTitleLength = 512;
  85. main_pid : longint = 0;
  86. function GetWindowHandle(H : HWND; state : LPARAM) : WINBOOL;stdcall;
  87. var pTitle, pEnd, pNewTitle : pchar;
  88. len : longint;
  89. begin
  90. GetWindowHandle:=true;
  91. GetMem(pTitle,MaxTitleLength);
  92. { we want all windows !! }
  93. if (GetWindowThreadProcessId(H,nil)=inferior_pid) or
  94. main_pid_valid and (GetWindowThreadProcessId(H,nil)=main_pid) then
  95. begin
  96. if not main_pid_valid then
  97. begin
  98. main_pid:=inferior_pid;
  99. main_pid_valid:=true;
  100. end;
  101. len:=GetWindowText(H,pTitle,MaxTitleLength);
  102. if DebuggeeState(State) = Stopped_State then
  103. begin
  104. GetMem(pNewTitle,len+50);
  105. pEnd:=strpos(pTitle,'... running under FP debugger');
  106. if assigned(pEnd) then
  107. pEnd^:=#0;
  108. pEnd:=strpos(pTitle,'... stopped by FP debugger');
  109. if assigned(pEnd) then
  110. pEnd^:=#0;
  111. strcopy(pNewTitle,pTitle);
  112. strcat(pNewTitle,'... stopped by FP debugger');
  113. SetWindowText(H,pNewTitle);
  114. FreeMem(pNewTitle,len+50);
  115. end
  116. else if DebuggeeState(State) = Running_State then
  117. begin
  118. GetMem(pNewTitle,len+50);
  119. pEnd:=strpos(pTitle,'... stopped by FP debugger');
  120. if assigned(pEnd) then
  121. pEnd^:=#0;
  122. pEnd:=strpos(pTitle,'... running under FP debugger');
  123. if assigned(pEnd) then
  124. pEnd^:=#0;
  125. strcopy(pNewTitle,pTitle);
  126. strcat(pNewTitle,'... running under FP debugger');
  127. SetWindowText(H,pNewTitle);
  128. FreeMem(pNewTitle,len+50);
  129. end;
  130. end;
  131. FreeMem(pTitle,MaxTitleLength);
  132. end;
  133. procedure ChangeDebuggeeWindowTitleTo(State : DebuggeeState);
  134. begin
  135. EnumWindows(EnumWindowsProc(@GetWindowHandle),longint(State));
  136. end;
  137. {$endif NODEBUG}
  138. end.