[Lazarus] disable the debugger capturing the OutputDebugString() messages

Bernd prof7bit at googlemail.com
Tue Jul 20 11:47:22 CEST 2010


2010/7/20 Marc Weustink <marc.weustink at cuperus.nl>:

> I hoped on a bit more recognizable MI output.
> & messages are stdoutput, so the "warning: ..." could have been a writeln
> too.

Hmm... I cannot get it to show writelns in the debugger window.

either they show up in the black console window that opens when i have
compild without -WG or the standard output will not be available at
all and the program will fail with a runtime error. In the screenshot
in my previous posting these were not normal writelns, i had all
output redirected so that every writeln goes directly to
OutpuDebugString(). Somethiing like that:

unit debugwriteln;

{use this unit and all writeln will go directly
to the attached debugger or to the system-wide
debug monitor if no debugger is attached}

{$mode objfpc}

interface

implementation

uses
  Classes,
  StreamIO,
  SysUtils,
  Windows;

type
  TDebugStream = class(TStream)
    function Write(const Buffer; Count: LongInt): LongInt; override;
  end;

var
  DebugStream: TDebugStream;

function TDebugStream.Write(const Buffer; Count: LongInt): LongInt;
var
  Msg: Ansistring;

begin
  Result := Count;
  SetLength(msg, Count);
  move(Buffer, PChar(Msg)[0], Count);
  OutputDebugString(PChar(TrimRight(Msg)));
end;


initialization
  DebugStream := TDebugStream.Create();
  AssignStream(Output, DebugStream);
  Rewrite(Output);
end.

OutputDebugString() has been increadibly useful for me already in
situations where neither a debugger can be used nor stdout is
available, not only in FPC/Lazarus but also in other languages. Only
in standalone Lazarus applications it always seems easier to write to
stdout instead.

Maybe a feature request at the GDB project would be appropriate. I'm
sure I am not the only one who would like to be able to make better
usage of this feature.

Another interesting alternative would be to include a cross platform
variant of Sven's re-implementation of OutputDebugString() (which is
completely bypassing the debugger and talking directly to the debug
monitor) in the System unit and and give Lazarus the ability to act as
a regular debug monitor on windows and use some other IPC mechanisms
on other OS to capture and display such messages. Standard output
could then by default always be redirected to this mechanism if
compiled with the -WG switch. This would be quite neat: Writeln in GUI
apps would then always go to an IDE window if the IDE is running or
simply go nowhere if no IDE and no debug monitor is present.

We could even establish an open standard for such debug monitoring on
linux because there doesn't seem to be one already.

</dream>

Bernd




More information about the Lazarus mailing list