Debugging OutputDebugString calls in Delphi
Asked Answered
G

2

5

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.

Gorey answered 23/11, 2010 at 17:18 Comment(0)
P
13

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';
Pallas answered 23/11, 2010 at 17:29 Comment(2)
Too many spread across project and components.. I'm not even sure if the message is coming from own or third party code.Gorey
if it's not your code but some unit you use (indirectly) the call could also go to OutputDebugStringA.Tabbie
A
7
  • Run your application.
  • Put it on pause.
  • Open View/Debug windows/Modules window.
  • Search for kernel32.dll. Double click it.
  • Search for OutputDebugStringA. Double click it.
  • CPU window opens. Set a breakpoint at very first line.
  • Search for OutputDebugStringW. Double click it.
  • CPU window opens. Set a breakpoint at very first line.

Done.

Now any call to OutputDebugString from your application will break at breakpoint. You can also turn on logging in breakpoint properties to log call stack.

Aldarcy answered 27/11, 2010 at 3:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.