2
0

windebug.pas 4.3 KB

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