Delphi 10.2 multithread debug $C0000005 AV's
Asked Answered
B

0

8

Delphi 10.2 latest build 2004, win x64 VCL app.

Trying to debug my large multithread appication I faced lots of $C00000005 exceptions in strange places. Attepmpts to narrow the problem have lead me to this minimal example: create some (10 in my case are enough to see the issue) threads, compile with "use debug .dcus".

Set breakpoint at second sleep and hit F9 several times, until exception is raised.

When its raised, assembly code looks broken (look screenshot). The RIP points to the middle of the correct instruction.

When I compile the same test app for Win32, it just hangs in debugger after several F9s, so I can not even make errors screenshots.

Update:

More about the original issue caused me to start looking for debugger issue: My life app (VCL win x64) sometimes stops working with the error "a problem caused the program to stop working correctly".

Every thread has exception logging system, so since the log is empty after such fail, I was hope that beeing run in debugger it will give me some useful info.

Without breakpoints the life app sometimes (very rare, about once in 5 hours) throws an exception leads deep into system.pas (look last screen). On this screen the last System._USstrClr had nil pointer.

Excactly the same picture I have when I put breakpoint at System._USstrClr and hit F9 several times, it ends up with nil pointers.

I dont state that these 2 issues have the same reason, just trying to understand what's going on.

From what I saw this happens only in debugger.

The life app compiled with Release build does not throw exeptions, it just stops with "a problem caused the program to stop working correctly" as my users report (and with empty logs with no info about any errors).

TMyThread = class (TThread)
  procedure Execute; override;
end;

var
  frmClientTest: TfrmClientTest;
  ThreadList: TList<TMyThread>;

procedure TfrmClientTest.FormCreate(Sender: TObject);
var
  k: integer;
begin
  ThreadList:=TList<TMyThread>.Create;
  for k:=0 to 10 do ThreadList.Add(TMyThread.Create);
end;

procedure TMyThread.Execute;
begin
  FreeOnTerminate:=false;
  repeat
    sleep(100);
    sleep(200);
  until Terminated;
end;

sample

CPU: CPU

=================

The real app exception:

enter image description here

Bioscopy answered 11/3, 2018 at 18:13 Comment(10)
What happens if you run without the debugger?Portentous
@David Without breakpoint it works as expected.Waggon
@David With this test example nothing - it runs as expected. With my main application happens this "a problem caused the program to stop working correctly" Thats why looking for the issue I came to this questionBioscopy
@Michael I think the issue described in the task is a problem of debugging with breakpoints (IDE is modifying the code at same time when another thread is trying to execute it?). It is sad to see how Delphi fails here, but in real application (without breakpoints) you probably get another issue.Waggon
@AndreiGalatyn no doubts I have another issue (well I hope at least) but how do I debug it properly in case the debugger flood me with internal errors? this is the questionBioscopy
I think you need to debug the actual problem without the debugger. Debugger seems broken. Drop madExcept into the real process.Portentous
@DavidHeffernan Thanks, Im not very familiar with madExcept so Im using FastMM in full debug mode for real app hoping it show me memory corruption issues. Do you think the madExcept gives me more chance to detect the issue? its actually a very rare issue ocuring after couple days of non-stop working (the app ends up with ""a problem caused the program to stop...""Bioscopy
FastMM will find a certain class of bugs relating to heap memory. madExcept gives you stack traces at the point the exception is raised. This information is gold dust and very often leads you towards the problem. You should for sure submit a bug report about the IDE debugger. But that actually not your main problem.Portentous
I have also this kind of exception when debugging in multithread ! so i confirm the problem, without breakpoint everything work ok, with break point access violationDoorway
@loki Ive created the bugreport about the debugger issue quality.embarcadero.com/browse/RSP-20096Bioscopy

© 2022 - 2024 — McMap. All rights reserved.