grijjy / justaddcode Goto Github PK
View Code? Open in Web Editor NEWCode snippets from Grijjy's Just Add Code blog
License: BSD 2-Clause "Simplified" License
Code snippets from Grijjy's Just Add Code blog
License: BSD 2-Clause "Simplified" License
To some function or class that I was able to detect emotions and gestures?
in Grijjy.ErrorReporting.pas we can not get the stacktrace report of a particular exception we catch in try... except end. I mean their is no way in a try .. except block to do something like MyReport := BuildExceptionReport(...), the only way is to catch the report in the event message. To handle this i updated the function below :
procedure TgoExceptionReporter.ReportException(const AExceptionObject: TObject;
const AExceptionAddress: Pointer);
var
E: Exception;
ExceptionMessage: String;
CallStack: TgoCallStack;
ExceptionLocation: TgoCallStackEntry;
Report: IgoExceptionReport;
I: Integer;
begin
{ Ignore exception that occur while we are already reporting another
exception. That can happen when the original exception left the application
in such a state that other exceptions would happen (cascading errors). }
if (FReportingException) then
Exit;
FReportingException := True;
try
CallStack := nil;
if (AExceptionObject = nil) then
ExceptionMessage := 'Unknown Error'
else if (AExceptionObject is Exception) then
begin
E := Exception(AExceptionObject);
ExceptionMessage := E.Message;
if (E.StackInfo <> nil) then
begin
CallStack := GetCallStack(E.StackInfo);
for I := 0 to Length(Callstack) - 1 do
begin
{ If entry in call stack is for this module, then try to translate
the routine name to Pascal. }
if (CallStack[I].ModuleAddress = FModuleAddress) then
CallStack[I].RoutineName := goCppSymbolToPascal(CallStack[I].RoutineName);
end;
end;
end
else
ExceptionMessage := 'Unknown Error (' + AExceptionObject.ClassName + ')';
ExceptionLocation.Clear;
ExceptionLocation.CodeAddress := UIntPtr(AExceptionAddress);
GetCallStackEntry(ExceptionLocation);
if (ExceptionLocation.ModuleAddress = FModuleAddress) then
ExceptionLocation.RoutineName := goCppSymbolToPascal(ExceptionLocation.RoutineName);
Report := TgoExceptionReport.Create(ExceptionMessage, ExceptionLocation, CallStack);
try
TMessageManager.DefaultManager.SendMessage(Self,
TgoExceptionReportMessage.Create(Report));
except
{ Ignore any exceptions in the report message handler. }
end;
finally
FReportingException := False;
end;
end;
and i replace it by this one :
function TgoExceptionReporter.internalBuildExceptionReport(const AExceptionObject: TObject; const AExceptionAddress: Pointer): IgoExceptionReport;
var
E: Exception;
ExceptionMessage: String;
CallStack: TgoCallStack;
ExceptionLocation: TgoCallStackEntry;
I: Integer;
begin
CallStack := nil;
if (AExceptionObject = nil) then
ExceptionMessage := 'Unknown Error'
else if (AExceptionObject is Exception) then
begin
E := Exception(AExceptionObject);
ExceptionMessage := E.Message;
if (E.StackInfo <> nil) then
begin
CallStack := GetCallStack(E.StackInfo);
for I := 0 to Length(Callstack) - 1 do
begin
{ If entry in call stack is for this module, then try to translate
the routine name to Pascal. }
if (CallStack[I].ModuleAddress = FModuleAddress) then
CallStack[I].RoutineName := goCppSymbolToPascal(CallStack[I].RoutineName);
end;
end;
end
else
ExceptionMessage := 'Unknown Error (' + AExceptionObject.ClassName + ')';
ExceptionLocation.Clear;
ExceptionLocation.CodeAddress := UIntPtr(AExceptionAddress);
GetCallStackEntry(ExceptionLocation);
if (ExceptionLocation.ModuleAddress = FModuleAddress) then
ExceptionLocation.RoutineName := goCppSymbolToPascal(ExceptionLocation.RoutineName);
result := TgoExceptionReport.Create(ExceptionMessage, ExceptionLocation, CallStack);
end;
procedure TgoExceptionReporter.ReportException(const AExceptionObject: TObject;
const AExceptionAddress: Pointer);
var
Report: IgoExceptionReport;
begin
{ Ignore exception that occur while we are already reporting another
exception. That can happen when the original exception left the application
in such a state that other exceptions would happen (cascading errors). }
if (FReportingException) then
Exit;
FReportingException := True;
try
Report := internalBuildExceptionReport(AExceptionObject, AExceptionAddress);
try
TMessageManager.DefaultManager.SendMessage(Self,
TgoExceptionReportMessage.Create(Report));
except
{ Ignore any exceptions in the report message handler. }
end;
finally
FReportingException := False;
end;
end;
class function TgoExceptionReporter.BuildExceptionReport(const AExceptionObject: TObject; const AExceptionAddress: Pointer): IgoExceptionReport;
begin
if Assigned(FInstance) then
result := FInstance.internalBuildExceptionReport(AExceptionObject, AExceptionAddress)
else
result := nil;
end;
The error report worked like a charm so far. Thank you for the great work.
But in Delphi 11.3, if you set the linker option "Options passed to LD linker" to "--version-script=goExports.vsr", Delphi cannot debug anymore (turns all breakpoints invalid, no step debug, etc).
Should the goExports.vsr file be updated in anyway? Any hints on that?
Would it be possible to add an option to TMulticastEvent
so it would call handlers in parallel instead of being stuck by them ?
The second benefit would be that handlers would run in parallel as well in place of being queued. So they don't delay and slow down one another.
In TMulticastEvent.Invoke
, the FData.Count
loop may use TTask.Run
in place of simple calls.
Hello team! First, thanks for the samples and articles, always very useful.
I'm not sure about code hooking on Mac ARM. At the time this article was written, no Mac ARM existed. On an Intel Mac the HookCode is used, but on the Mac ARM the correct is HookVMT, as in iOS?
Thank you for your work - it really helped.
But there were some questions left (maybe I'm wrong):
Just want to let you know!
Hello,
great code, just if i click Invalid obj-c call then your app crashes. Do I miss something or must be there something more done to catch that exception?
Thank you
I have just downloaded the latest version with support for 64-bit ARM MacOS.
LNG raises an exception on executing it from the Build Events -> Commands:
EInvalidOperation: Invalid line number sequence (different line numbers for same address)
I = 42
Length(ALines) = 688646
AddressDelta = 0
LineDelta = -1
Got strange linking problems which at a glance looked like they were coming from libmidas.a.
When looking further and changing from msbuild mode to compiling from IDE i saw references regarding __cxa_demangle which got me to think libgnustl_static wasn't linked.
When i added -lgnustl_static to the linker flags in delphi it compiled.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.