Home > Mobile >  How to find code from access violation address in a Delphi module?
How to find code from access violation address in a Delphi module?

Time:11-10

abc.exe is using xyz.dll. While running abc.exe(Delphi), getting an Access Violation as following

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 am 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 to find that code part ? Are there any other alternatives ?

Thanks in advance.

CodePudding user response:

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.

CodePudding user response:

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.

  • Related