windebug.pas 4.3 KB

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