“Unknown function at TMethodImplementationIntercept”
Posted by jpluimers on 2018/06/01
Reminder to self: when you get Unknown function at TMethodImplementationIntercept
in a Delphi stack trace from the Exception.StackTrace
property or FastMM memory report:
- Ensure you generate a .MAP or .TDS file with full debug information
- Copy the .MAP or .TDS files to directory of your EXE.
Via:
- [WayBack] 0006512: jcl-2.7.0.5676/Delphi XE7: StackTrackExample not working – Project JEDI – Issue Tracker
- [WayBack] Problem using portable viewer
The Exception.StackTrace
was introduced in Delphi 2009 that extended these [WayBack] Exception Members:
- [WayBack] Exception.StackTrace Property serviced by this method:
- [WayBack] Exception.StackInfo Property filled by this method:
- [WayBack] Exception.BaseException Property (recursively
Self
or the innermostInnerException
) - [WayBack] Exception.InnerException Property
- freed by [WayBack] Exception.Destroy Destructor
- [WayBack] Exception.RaisingException Method
- [WayBack] Exception.SetInnerException Method
- [WayBack] Exception.ToString Method
Some notes:
- Fields where you can put hooks in; if there is no hook in place, they won’t be used:
- [WayBack] Exception.GetExceptionStackInfoProc Field
GetExceptionStackInfoProc: function (P: PExceptionRecord): Pointer;
- This function is called to return an opaque data structure that contains stack information for the given exception information record. This function will be called when the exception is about to be raised or if this is an external exception such as an Access Violation, called soon after the object is created.
- [WayBack] Exception.CleanUpStackInfoProc Field
CleanUpStackInfoProc: procedure (Info: Pointer);
- This function is called when the destructor is called to clean up any data associated with the given opaque data structure.
- [WayBack] Exception.GetStackInfoStringProc Field
GetStackInfoStringProc: function (Info: Pointer): string;
- This function is called to return a string representation of the opaque data structure returned by GetExceptionStackInfoProc
- [WayBack] Exception.GetExceptionStackInfoProc Field
TMethodImplementationIntercept
was introduced in the System.Rtti unit of Delphi XE6 [WayBack]:
–jeroen
Example code:
unit ExceptionHelperUnit; | |
interface | |
uses | |
System.SysUtils; | |
type | |
ExceptionHelper = class helper for Exception | |
public | |
function Describe: string; | |
class procedure RaiseNotImplementedException(const aClass: TClass; const aMethodName: string); | |
class function GetStackTrace: string; | |
end; | |
implementation | |
uses | |
System.RTLConsts, | |
System.SysConst; | |
type | |
EStackTraceException = class(Exception); // EProgrammerNotFound to make it really clear this is only to be used in very limited places ?? | |
{ ExceptionHelper } | |
function ExceptionHelper.Describe: string; | |
var | |
lStackTrace: string; | |
begin | |
Result := inherited ToString(); | |
if Self is EInOutError then | |
if Result = System.RTLConsts.SInvalidFileName then | |
Result := System.SysConst.SInvalidFileName; | |
if Assigned(StackInfo) then | |
lStackTrace := StackTrace | |
else | |
lStackTrace := 'empty'; | |
Result := Format('Exception'#13#10'%s at $%p: %s'#13#10'with StackTrace'#13#10'%s', [ClassName, ExceptAddr, Result, lStackTrace]); | |
end; | |
class function ExceptionHelper.GetStackTrace: string; | |
begin | |
try | |
Result := 'Get StackTrace via Exception.'; | |
raise EStackTraceException.Create(Result) at ReturnAddress; | |
except | |
on E: EStackTraceException do | |
Result := E.StackTrace; | |
end; | |
end; | |
class procedure ExceptionHelper.RaiseNotImplementedException(const aClass: TClass; const aMethodName: string); | |
begin | |
raise ENotImplemented.CreateFmt('Method %s.%s is not implemented.', [aClass.ClassName, aMethodName]); | |
end; | |
end. |
Leave a Reply