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:
The Exception.StackTrace
was introduced in Delphi 2009 that extended these [WayBack] Exception Members:
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
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. |
Like this:
Like Loading...
Posted in Delphi, Development, FastMM, Software Development | Leave a Comment »
Posted by jpluimers on 2018/06/01
I had to find strings containing ” of object”, but not starting with a “)”, so the regex became this:
[^)] of object
Source: [WayBack] Regex – Does not contain certain Characters – Stack Overflow
–jeroen
Like this:
Like Loading...
Posted in Development, RegEx, Software Development | Leave a Comment »