Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging OutputDebugString calls in Delphi

I've some "rogue" OutputDebugString call in my application which prints out "T", but I can't just locate it.

Is it possible somehow to set breakpoint on OutputDebugString -function and see where it is called from?

I'm using Delphi 2009.

like image 337
Harriv Avatar asked Nov 23 '10 17:11

Harriv


People also ask

How to do debugging in delphi?

Debugging delphi source files You need to go to "project->options->compiler" on this tab you need to check the "use debug DCUs". After that you need to build your project again and you can run your application. From now on breakpoints also stop in Delphi source files.

How do I view OutputDebugString?

OutputDebugString( ) is a Windows method for emitting a text string to some output device (window/file/external debugger). Lazarus will show these messages in the IDE Window: Event Log accessible from Main menu > View > Debug Windows > Event Log.

What is OutputDebugString?

The debugapi. h header defines OutputDebugString as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant.


1 Answers

How many calls to OutputDebugString are there in your project? You can use the "Find in Files" dialog to find them all, and if they aren't too many, there shouldn't be a problem.

Otherwise, you could - of course - use a search and replace and replace all OutputDebugString( with raise Exception.Create(.

You could also write a function

procedure OutputDebugString(const Str: string);
begin
  raise Exception.Create(Str);
end;

in a unit used by every other unit in the project. If only this new unit is declared after Windows.pas in the uses list, this new function will be used instead of the Windows.pas one.

Update

Yes, you can place breakpoints inside Windows.pas. First, in your project, go to Project Options, and under Debugging, select "Use debug DCUs". Then you can go to Windows.pas and place a breakpoint at line 30769:

procedure OutputDebugString; external kernel32 name 'OutputDebugStringW';
like image 109
Andreas Rejbrand Avatar answered Oct 01 '22 01:10

Andreas Rejbrand