How to debug a COM dll in Delphi? - delphi

I try to debug a COM dll (TAutoObject) in Delphi and my break point are not green.
I put my option like this :
host : c:\Program Files\Internet
Explorer\iexplore.exe
param : c:\software\test.html
My test is well lanched but no breakpoint in Delphi
what is the way to to this ?

You have to run the program which launches the COM+ object and then attach it to the process.

IE launches a sub-process which hosts non-trusted code. this is probably why your debugging settings are not working, and why attaching to the process once launched works.

Since the debugger doesn't start the file, that won't work.
IIRC you can try to "attach to process" to the process running it (iexplorer.exe), but the problem is that that doesn't allow to debug through the start of the component. (since it costs time to manually attach)
I had a different setup where I instantiated a very slightly differently compiled .ocx on a panel of a delphi app, and used that to debug. Which worked fine.d

This link Breakpoint not honored while debugging a DLL helped me debug my com dll in Delphi 5. Go to Project -> Options -> Linker -> check mark "Include remote debug symbols". I couldn't tell you why it worked. Delphi 5's help provided the following description:
Include remote debug symbols Check this if you are using remote debugging.

You also need to have integrated debugging turned on. Its on the general tab of the debugger options.
In the past what I have done is to create a separate program which invoked my COM object and used it as the target for debugging rather than the standard host. This simplifies things and also allows you to create specific repeatable tests of known issues to aid in smoke testing later.

you can also use tools like CodeSite.

Related

How to debug plugin to a closed-source exe?

I am writing a plugin for the AIMP music player, which is itself closed source but has documentation for adding plugins. The interface is available in Delphi, hence I am figuring out how to use RAD Studio Delphi 10.3 Community Edition.
I have stumbled upon a situation that is either of these:
Something is wrong with how I call the AIMP Methods or how I set up the parameters
Something is wrong with the Method I am calling
I have set up the Run Parameters so that the AIMP Program is actually launched when I press "Run". I have also enabled Tools > Options > Debugger > Embarcadero Debuggers > Debug spawned processes. However, the program did not stop at my breakpoint and there was a grey X icon displayed in front of the breakpoint.
Turns out this was because I also had a version of the compiled dll in the AIMP Plugin directory so it was loading that old version and not my newly compiled one. But even when I remove the old version... how can I get it to actually call the new version?
When I build my dll and paste it into AIMP's Plugin directory, it will be loaded and the settings screen reflects that. I can even show a Message Box when the settings are being modified by the user. But copying the dll over means I can't stop at breakpoints.
How can I make the debugger stop at my breakpoint so that I can step through the program, ideally being able to see the values of local variables?
Under Project > Options > Building > Delphi Compiler there is the option Output directory. Setting this path for the relevant Build Configurations to the AIMP Plugin directory did the trick, as suggested by #Brian in this comment.

Delphi 2010 remote debugging - unable to get breakpoints working

I recently posted this question about my inability to get Delphi 2010 working with remote debugging. I have not had any success and decided to post up a simple step-by-step test technique that might highlight what I'm doing wrong. THIS IS REALLY IMPORTANT to me - I've used Delphi since V1.0 and earn my living from it. Being stuck like this is a pain and its keeping me on Delphi 7.
Anyway, here goes.
Ensure that Delphi 2010 has updates 4&5.
Fire up Delphi 2010, then File | New | VCL Forms App. Put a button on the form, put 'ShowMessage( 'hello' ) in the button OnClick event. Save the project and its unit in a local folder "C:\scratch". Build the project, run it, click the button, 'hello' appears, all fine.
On a networked PC (194.168.1.64), create a new folder "c:\DebugTest" and share it with R/W access.
On 194.168.1.64 install the Remote Debugger from the latest download on the Embarcadero Website (RemoteDebugger_upd2.exe). CLick rmtdbg140.exe to run. Accept the 'un-block' message from the firewall.
Edit the DEBUG build configuration compiler settings with Output directory=\192.168.1.64\DebugTest and unit output directory = c:\scratch - see
Edit the Linking settings to set Debug Information=True, Include remote debug symbols=True. See
Leave compiling settings at defaults. See
Do a full build. The relevant project exe 'project2.exe' and 'project2.rsm' appear in the remote folder \192.168.1.64\DebugTest. Blue dots are visible in Unit2 in the IDE.
Set a breakpoint on the 'ShowMessage' line (the button OnClick event).
Use 'Run' | 'Load Process' with Remote path=c:\DebugTest\Project2.exe, Remote Host=192.168.1.64 and Working directory=c:\DebugTest see
Click 'Load'. The visible breakpoint is immediately disabled, the project starts running and opens the CPU window and stops. Pressing f9 cause the exe to run fully on the remote machine, the button works, you just cannot debug it.
I've tried various 'obvious' things like firewall off but all to no avail. Could some kind person suggest further ideas?
Many thanks.
Well, for me the problem has now been solved, although as a 'work around' and after significant interaction with Embarcadero and an upgrade to XE (which also did not work).
It would appear that the remote debugger is flaky (or possibly just picky) in its ability to load rsm (remote symbols) files - they are still looking into why mine wont load. My rsm file is big at around 50Mb although this is no problem for Delphi 7's remote debugger.
The work around involved upgrading to Delphi XE and then choosing the compiler link option 'Place Debug Information in separate TDS file'. This seems to create a tds file onthe remote target instead of a rsm file and breakpoints then work fine.
I've submitted my rsm and tds files to Embarcadero for investigation as to why this happens.
What Windows OS? Maybe run rmtdbg140.exe as admin.
I run D2010 remote debugging on XP versus XP. My How-To is at http://blog.runbits.com/post/Remote-debugging-Delphi.aspx
I had this problem. Installing Update 4 for Delphi 2010 solved my problem. It is also listed in the list of fixed problems of Update 4.
It is imperative to have correct time zone and clock on remote system. In my case I set up remote debugging and when I load process the breakpoints turned green. I checked remote system timezone and clock, set it right and remote dubugger worked again.

Breakpoints not working in Delphi 6 DirectShow source filter

I'm trying to debug my DirectShow source filter. I'm using Delphi Pro 6 on Windows XP along with the DSPACK component library. I'm using Skype as my host application, which I set in the Parameters option in the Run menu, for testing my source filter DLL (ax file extension). Skype runs fine and I see a stream of my OutputDebugString messages in the Event Viewer, but none of my breakpoints are ever hit. In my Project Settings I have optimizations off, stack frames on, debug DCUs on, Range Checking on, and Overflow checking on. Each time I modify my code and run a test I:
Do a full build
Unregister the DirectShow filter (regsvr32 /u)
Register the DirectShow filter (regsvr32)
Run Skype as my Host application from the IDE
When an Exception occurs, the IDE does trap it and pops up an error dialog box with the option to view the assembler code in the CPU window. However none of my breakpoints are being hit. Can anyone tell me how to get breakpoints working?
Thanks.
Along with the debug option indicated by Mason Wheeler, use a full map file. And make sure that there aren't old DCUs and BPLs in the search path.
Also, consider using EurekaLog or MadExcept - even the trial versions should be able to show you what's gong on when it blows up.
Sounds to me like you're building with debug information off, either in the project options or with a $D- switch somewhere in the code or in an include file. Check to make sure you've got debug information available.

Delphi 2009 only halts at breakpoints in one unit

I'm experiencing problems with debugging in Delphi 2009's IDE. Since having moved old projects that had been created using Delphi 7 to this version, all breakpoints except for those in one unit are neglected. I couldn't figure out which unit that is, but that seems to change from time to time.
Enabling debug DCU's overcomes this phenomena, but I don't want to step inside RTL/VCL units. Only those used by my project, like the Version 7 IDE did with standard settings.
Chances are when you first moved the project to D2009 you built your units without debug info. Now that those units have been created, they don't get rebuilt every time. What you are probably seeing is that the breakpoint only works in the unit you're currently editing and making changes to. This is consistent with the fact that the compiler knows to rebuild that unit (with the now properly set debug flags), and that unit only.
The solution is the make sure the Debug configuration is selected and then do a full build.
Delphi 2009 comes with different build configurations. Make sure you've got Debug build mode set, not Release mode, and that the debug compile option is turned on.

Why is DebugHook not set to 1 in my Delphi add-in DLL?

When I'm running my COM Office add-in from within the Delphi 5 IDE (using any of the office applications as the host), breakpoints work fine (when using remote debugging symbols and a properly set output folder), but none of the non-delphi exceptions (like access violations) in my code triggers the IDE to break at that point. In stead, the IDE stops at the manual re-raise in the try...except wrappers in any of my outer safecall methods.
I noticed that for some reason the DebugHook global was set to 0 (while as far as I know it should always be set to 1 when running from within the IDE). Moreover, setting it to 1 manually during the initialization of my DLL actually fixes the issue: the IDE now neatly stops at the line where my experimental (read: crappy) code triggers the exception.
The questions is: why? Why do I need to do this manually? Shouldn't the IDE set this for me? Did I forget a major important setting somewhere triggering this behaviour?
If for some reason the Delphi evaluator is unable to lookup the DebugHook global, it would be unable to set that value. Try to compile/run the DLL from the IDE and set the "host application" in the Run|Parameters dialog to the the Office app you intend to call your DLL from. It is possible that this may be a bug in how the evaluator uses the remote debug symbols.
In recent versions of Delphi there's an Option under Debugger for "Debug spawned processes" or something to that effect. Is that option present in Delphi5, and is it set?
Not sure whether this will help, because I have not encountered the behavior you describe.

Resources