'How to find code from access violation address in a Delphi module?

Let me explain the problem by considering two dlls. Lets say abc.exe is using xyz.dll. While running abc.exe(Delphi), getting an Access Violation.

Project abc.exe raised exception class EAccessViolation with message 'Access Violation at address 39275E81 in module 'xyz.dll'. Write of address 737A24A4".

For some reason, I was unable to debug xyz.dll(which is also delphi). So I would like to trace the code part in xyz.dll using addresses in above message. How can I find that code part ? Are there any other alternatives?

Thanks in advance.



Solution 1:[1]

There are many third party tools to trace exceptions in source code, or you can make your own. This simple one use JCL debug procs:

procedure AnyExceptionNotify(ExceptObj: TObject; ExceptAddr: Pointer; OSException: Boolean);
var
   ExceptLines: TStringList;
begin
   ExceptLines := TStringList.Create;
   try
      JclLastExceptStackListToStrings(ExceptLines, False, False, True);
      ExceptLines.Insert(0, 'ProcessID: ' + IntToStr(GetCurrentProcessID));
      ExceptLines.Insert(1, 'ThreadID: ' + TThread.CurrentThread.ThreadID.ToString);
      ExceptLines.Insert(2, (ExceptObj as Exception).Message);
      ExceptLines.Insert(3, '[begin_stack_trace]');
      ExceptLines.Append('[end_stack_trace]');
      ExceptLines.SaveToFile('ExceptTrace.txt');
   finally
      ExceptLines.Free;
   end;
end;

initialization
   JclStartExceptionTracking;
   JclAddExceptNotifier(AnyExceptionNotify);

This way you will register any exception in your code and store the call stack of exception into file for further analysis.

Solution 2:[2]

that's All rigth ?

You can use two ways :

1 Delphi Options >Debugger Option > Embarcadero Debugge> Language Exception, unckeck all options that are in "Exception types ton ignore ".

2 Using debugger and view all objects, when you find the object with value nil you "found the problem".

Remember: The Acess violation Error is caused, by acess the object that never was created yet.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Miroslav Penchev
Solution 2 Dharman