Added DebuggerIsAttached

This commit is contained in:
Alex 2023-03-14 00:01:44 +02:00
parent 59d547d9c4
commit c046b079f2
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
4 changed files with 24 additions and 14 deletions

View File

@ -52,9 +52,9 @@ int LockClass::Lock(const char *FunctionName)
LockData.StackPointerAttempt = (uintptr_t)__builtin_frame_address(0);
Retry:
unsigned int i = 0;
while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < 0x10000000)
while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < (DebuggerIsAttached ? 0x100000 : 0x10000000))
CPU::Pause();
if (i >= 0x10000000)
if (i >= (DebuggerIsAttached ? 0x100000 : 0x10000000))
{
DeadLock(LockData);
goto Retry;
@ -89,15 +89,14 @@ void LockClass::TimeoutDeadLock(SpinLockData Lock, uint64_t Timeout)
if (CoreData != nullptr)
CCore = CoreData->ID;
warn("Potential deadlock in lock '%s' held by '%s'! %ld %s in queue. Interrupts are %s. Core %ld is being held by %ld. Timeout in %ld",
uint64_t Counter = TimeManager->GetCounter();
warn("Potential deadlock in lock '%s' held by '%s'! %ld %s in queue. Interrupts are %s. Core %ld is being held by %ld. Timeout in %ld (%ld ticks remaining).",
Lock.AttemptingToGet, Lock.CurrentHolder,
Lock.Count, Lock.Count > 1 ? "locks" : "lock",
CPU::Interrupts(CPU::Check) ? "enabled" : "disabled",
CCore, Lock.Core, this->DeadLocks, Timeout);
CCore, Lock.Core, Timeout, Timeout - Counter);
// TODO: Print on screen too.
uint64_t Counter = TimeManager->GetCounter();
if (Timeout < Counter)
{
warn("Unlocking lock '%s' because of timeout. (%ld < %ld)", Lock.AttemptingToGet, Timeout, Counter);
@ -117,13 +116,13 @@ int LockClass::TimeoutLock(const char *FunctionName, uint64_t Timeout)
Atomic<uint64_t> Target = 0;
Retry:
unsigned int i = 0;
while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < 0x10000000)
while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < (DebuggerIsAttached ? 0x100000 : 0x10000000))
CPU::Pause();
if (i >= 0x10000000)
if (i >= (DebuggerIsAttached ? 0x100000 : 0x10000000))
{
if (Target == 0)
Target = TimeManager->CalculateTarget(Timeout);
TimeoutDeadLock(LockData, Target);
if (Target.Load() == 0)
Target.Store(TimeManager->CalculateTarget(Timeout));
TimeoutDeadLock(LockData, Target.Load());
goto Retry;
}
LockData.Count++;

View File

@ -15,6 +15,8 @@
#include "Core/smbios.hpp"
#include "Tests/t.h"
bool DebuggerIsAttached = false;
#ifdef DEBUG
bool EnableExternalMemoryTracer = false; /* This can be modified while we are debugging with GDB. */
char mExtTrkLog[MEM_TRK_MAX_SIZE];
@ -182,6 +184,13 @@ EXTERNC NIF void Main(BootInfo *Info)
Interrupts::Initialize(0);
KPrint("Initializing CPU Features");
CPU::InitializeFeatures(0);
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
{
KPrint("\eFFA500Debugger detected! (TCG Virtual Machine)");
DebuggerIsAttached = true;
}
KPrint("Loading Kernel Symbols");
KernelSymbolTable = new SymbolResolver::Symbols((uintptr_t)Info->Kernel.FileBase);
KPrint("Reading Kernel Parameters");

View File

@ -28,12 +28,13 @@ test_mem_new_delete::~test_mem_new_delete()
}
extern bool EnableExternalMemoryTracer;
extern bool DebuggerIsAttached;
void TestMemoryAllocation()
{
if (EnableExternalMemoryTracer)
if (EnableExternalMemoryTracer || DebuggerIsAttached)
{
debug("The test is disabled when the external memory tracer is enabled.");
debug("The test is disabled when the external memory tracer or a debugger is enabled.");
return;
}

View File

@ -20,6 +20,7 @@
#endif
extern struct BootInfo *bInfo;
extern bool DebuggerIsAttached;
#ifdef __cplusplus
#ifdef DEBUG