Techniques and tools for debugging problems on remote machines? - delphi

Users have been reporting problems/crashes/bugs that I can't reproduce on my machine. I'm finding these problems difficult to fix.
I've started using EurekaLog (fantastic!) and SmartInspect. Both these tools have helped greatly but I'm still finding it difficult to catch some problems.
I've just purchased Debugging by David Agans (and waiting for it to arrive).
Are there any other tools or techniques specific to Delphi that will help with catching these hard to find remote problems? The kinds of problems I'm finding difficult to track down are those that don't raise exceptions or have a clear cause. EurekaLog catches exceptions and SmartInspect is pretty good once I have a theory to check. But in some cases it is a seemingly random crash and there are several thousand lines of code that may may be at fault. How to narrow down to the root cause?

MadExcept is what I use, and it is fabulous. I have also used EurekaLog and find the functionality almost exactly identical, except that I have more experience and time using MadExcept. it's free for non-commercial use, and reasonably priced for commercial use.
Update: MadExcept 4 is now out and even supports 64 bit Delphi XE2 apps, and has memory-leak checking too.
When nothing blows up, I rely on heavy use of trace logging. I have a TraceMessage(integer,string) function which I call throughout all my apps, and when someone has problems I get them to click a menu item that turns up the debug trace level to the most verbose level; it gives me a complete history of everything my application did, and this has helped me even more than madExcept, to solve problems at customer sites. Customers get a crash, and that crash report sent by madexcept contains a log file (created by my app) that is attached automatically. I believe you can do this equally well with madExcept and EurekaLog. If you need a logging system you could download Log4D, or you could write your own, it's pretty simple.
For always-free, try JclDebug, which requires more work to set up, but which has worked fabulously for me, also.
For help with heap problems, learn more about fastMM (full version) debug options.
And you shouldn't forget that Delphi itself supports Remote debugging, if you can reproduce a crash on machines in your office that don't have delphi installed, use remote debug across the office network instead of installing a complete RAD Studio installation on that other machine at your work. You could also use remote debug to connect to a client PC computer across the internet, but I have not tried remote debug across the internet yet, so I can't say whether it works great over the internet or not. I do know that since remote debug doesn't support automatic deploy of the EXE file you built (you have to do that part yourself), remote debug over internet, to a client PC is more work.
You might also find lots of your problems by fixing all your hints and warnings, and then going through with CodeHealer or Pascal Analyzer (PAL) from Peganza. These static analysis tools can help you find real code problems.
If performance and memory usage are your problems, get the full version of AQTime, and use it to profile and watch your system operate. It will help you fix your memory leaks, and understand your app's runtime behaviour and memory usage, not just leaks but bottlenecks for memory and CPU usage. Some of those bottlenecks can also be the source of some odd problems. I have even used AQTime to help me find deadlocks, since it can generate traces of execution, that can help me figure out what code is running, and locate deadlocks. Update: AQTime is not installable on machines other than your main dev machine, without violating the newly modified license terms for AQTime. These terms were never this restrictive in the good old days.
If you gave more exact idea of what your problems are, I'm sure other people could give you some more ideas that are specific, but all of the above are general techniques that have served me well.

One of the best way is to use the Remote Debugger that comes with Delphi, so you can debug directly the application running on the remote machine. THe remote debugger is somewhat buggy in some Delphi releases, and requires to follow the instructions carefully to make it working, but when needed it's a tool to consider. Also check if there are updates available for your version, they could come in a separate installer for deployment on "remote" systems. Otherwise first install the remote debugger, than check if the files installed has newer versions in your local installation, and the copy tehm on the remote machine.

CodeSite has helped me a lot in these situations. Since XE it is bundled with Delphi.

Logging is the key, in this matter.
Take a look at our TSynLog class available in our Open Source SynCommons library.
It does have the JCL Debug / MadExcept features, with some additional (like customer-side profiling, and logging):
logging with a set of levels;
fast, low execution overhead;
can load .map file symbols to be used in logging;
compression of .map into binary .mab (900 KB -> 70 KB);
inclusion of the .map/.mab into the .exe;
reading of an external .map to add unit names and line numbers to a log file without .map available information at execution;
exception logging (Delphi or low-level exceptions) with unit names and line numbers;
optional stack trace with units and line numbers;
methods or procedure recursive tracing, with Enter and auto-Leave using interfaces;
high resolution time stamps, for customer-side profiling of the application execution;
set / enumerates / TList / TPersistent / TObjectList / TContainer / dynamic array JSON serialization;
per-thread or global logging;
multiple log files on the same process;
integrated log archival (in zip or any other format);
Open Source, works from Delphi 5 up to XE.

Related

Delphi 7 Application and Microsoft Security Essentials

We have a Delphi 7 application running on numerous client machines. Recently, some of the client machines started using Microsoft Security Essentials. It started identifying our executable as malware and promptly shut it down. The message displayed by MS Security essentials is:
"Security Essentials detected items on your PC that it doesn't recognize......"
Odd thing is it does not always occur at the same option in the application. You can do the very same operation on subsequent logins and sometimes it works and other times security essentials closes it down. This makes it extremely hard to narrow down to a specific cause in our application.
I tried running the application with elevated account privileges and was still able to get it to fail. I was unable to duplicate the issue when running a Delphi XE2 compile of the same application.
Any ideas about what to look for? We are really trying to avoid adding our application to the Security Essentials exclusion list. Our application has never been identified as a problem with varying security programs (norton, mcaffee, etc.).
I once had a similar issue with an executable built using Delphi(7), though it had nothing to do with Delphi-7. It just so happens that some part of the executable matches some virus signature or the AV heuristic scan suspects that something is wrong with the executable. One thing you can try is to change some of the compiler settings such as Debug options. Changing Debug Information or using debug DCUs might result in a slightly different byte sequences in the final executable.

Memory leaks not happening in a Virtual machine but pops up when ran natively

I develop with Delphi 2010 in a VM, the app runs well inside the VM in any ways within the ide, alone with or without Eurekalog using mainly DevExpress grids and AidAim SQLMemtables.
When the same App is ran on the host (ie directly on windows) the eurekalog finds memory leaks on the SQLMemtable dataset component and sometimes but often enough to make it impossible to release it crashes on a simple Dataset.refresh. It is very hard to debug because in the debug environemnt it works.
Anyone would have any idea what is going on, I am at loss of ideas here
Thank you for your help
Regards
Philippe Watel
Your external dependencies (dlls) differ on both machines? Also consider using Delphi's remote debugger and log more details to find out more details about your problem.

Delphi: Application error logging in the field

Using Delphi 7, I wonder if there is a free component which will collect diagnostic information as my application runs at a remote site and will help me to debug error reports.
Maybe it records each menu item selected, control clicked, text input, etc? Maybe it just dumps the stack on a crash. Maybe it does something else ...
I don't mind adding code (e.g at the start and end of each procedure), as that might generate more useful info than a fully automatic system.
I am not sure if the solution ought to "phone home" or if it is enough to produce a text file which can be emailed to me.
Any suggestions?
with the crash debuging have a look at MadExcept
http://www.madshi.net/madExceptDescription.htm
madExcept was built to help you locating crashes in your software. Whenever there's a crash/exception in your program, madExcept will automatically catch it, analyze it, collect lots of useful information, and give the end user the possibility to send you a full bug report.
free for non-commercial usage, inexpensive for commercial usage
or JclDebug from the JEDI Code Library
http://www.delphi-jedi.org/
A Blog Posting about it can be found here
http://www.gnegg.ch/2002/12/jcldebug/
EDIT: This seems to be a very good example on how to use JCLDebug
http://robstechcorner.blogspot.com/2009/04/finding-hard-to-reproduce-errors.html
I use EurekaLog http://www.eurekalog.com
It does the call stack, memory contents, other apps running, a good description of the machine, OS, patches, etc.., It can (with user permission, and if configured to to so) take a screenshot, ask the user for input (what were you doing when it crashed?), etc.. It can send the dump via e-mail, post to http, post directly to bug trackers like Mantis and FogBugz, or just leave it on the system. It's great, and well supported.
Also, here's a link to a similar question
Compare Delphi Exception Handlers
Have you looked at the open-source JclDebug from Project Jedi? Here's a nice succinct write-up on JclDebug.
Imagine you could get a detailed
error-report containing a full
callstack of where the error occured
combined with information about file
and line-number. This report could be
generated directly on the users
computer and be sent to you via email
or directly via the internet, using a
custom procedure - even directly
creating entries in the
bugtracking-tool you are using.
This and more is made possible by the
Project JEDI - more accuratly, the
JCL-Subproject with its
JclDebug-Framework. When you have
completed the installation of the
package, a new Menu Option called
"Inser JCL Debug Data" will be added
to the Project-Menu of your
Delphi-IDE.
There is a great delphi porting of the most known opensource logging framework written in java, Log4J: it is called Log4Delphi.
http://log4delphi.sourceforge.net
I downloaded it, extended and used with my projects with success.
Best features: opensource, Apache license, very well documented, simple to extend it, power design: with the concept of appender, you could build up your custom appender and use it to send logging data from remote customer computer to your head quarter using UDP protocol.
Try it, and let me know :-)
PS: the project seems to be discontinued, but it is mature and I'd used it without memory overload and cpu overhead problems.
The log4Delphi project has been dormant for 4 years but I have been granted access to update the dormant Log4Delphi project and I have rolled up 4 years of bugfixes and patches into the latest 0.8 release available on Source-forge. I use this library in production and have found it to very stable and reliable and easy to use.
Log4Delphi Downloads Page

Debugging Delphi Application on Non Development Environment

I am attempting to use WinDBG or another debugger to debug a CodeGear Delphi 2007 Windows application on a remote machine. I have been unable to produce symbol files for WinDBG.
Is there a way to use WinDBG or another debugger to debug Delphi applications on a system that doesn't include the IDE?
Edit1
The remote debugger is not an option here. I am able to remote in to the end user PC, but I am unable to use the remote debugger due to firewall restrictions.
Edit2
I am able to remote in to the machine, but can not connect the CodeGear remote debugger due to firewall restrictions.
How about the remote debugger? Build your app with remote debug symbols and debug from your development machine across the network.
instead, i rely on MadExcept stack tracing and some logging features. my application is distributed worldwide & this has been sufficient.
You can try generating a map file and then convert it to a dbg file using map2dbg from
http://code.google.com/p/map2dbg/
Then you can load the dbg file in WinDbg.
Disclaimer: I had faced a similar issue but I managed to do remote debugging and didn't have to do all this. So I am not sure this will work. But if you try it then do let us know if it works.
I'm afraid this is one more of those "I don't have an actual answer" answers, but it might just help...
Have you considered adding logging to your application? I've heard great things about SmartInspect. With it, you can log all sorts of information, including stack traces and "watches" (variables).
Another logging product for Delphi is EurekaLog.
In Delphi you could use Run -> Attach to Process, select the remote machine and select the process you'd like to debug.
http://sourceforge.net/projects/tds2dbg/ can be used to convert Delphi's TDS debug files to DBG files. This gives basic symbol information -- functions, classes, units, but not variables. Enough for a reasonable call stack, and with a bit of knowledge, enough to debug Delphi apps live and with dumps.
I've written about some of Delphi+WinDBG experiences on my blog: https://marc.durdin.net/2015/11/windbg-and-delphi-a-collection-of-posts/
Thank you all for the great suggestions and interesting products.
To solve this specific issue, the "best" way I found uses the OutputDebugString located in the Windows namespace. This, along with Debug View from Sysinternals, will allow me to gather debug information and sort through it pretty quickly.
If you decide to use this method, make sure everything is wrapped in ANSI formatting. IE:
OutputDebugString(PAnsiChar(string1 + string2));
This makes sure that string1 and string2 are combined and then converted in to ANSI Characters.
I probably should have just started dumping text to a file for something quick and dirty, but this will allow a non-debugging version to emit debugging messages.

Delphi debugger?

I'm finishing an internship at a company and have just been thrown onto this project for the last month where the program is built upon an engine that they "failed" to buy the source code for. Now I've been given the task of finding out why it is failing, on only certain conditions and customer feedback hasn't been great. The main developer for the project is also out on leave for several months.
I have the engine install and know the language it was written in (delphi6?).
note which I have never had to use
I have our products msi.
I'm expected to go through the regular app and pinpoint the problem. I suspect it is something to do with fields not being re-initialized properly.
Is there a way to attach a debugger to the exe to see callstacks and all that hotness?
Any help that would avoid countless use cases would be received gratefully.
You can attach the Delphi debugger to any running process (like all other win32 debuggers out there) but I don't think the experience will be near what you expect. Delphi produces really tight executables which means the info for building human readable callstacks or any kind of "hotness" are simply not there.
Your only chance is in that if your application is a Debug release. In that case, Delphi debugger should help more than a generic debugger.
You might also want to have a look at this thread - Is there a program to decompile Delphi?
In Delphi 2006 (not sure about 6) you can attach the debugger to a running process.
You only get assembler instructions, registers, flags, memory dump and stack (hex). Hope that is enough.
Nice, I tried to attach to the ide/debugger and they disallowed that ;-).

Resources