2018-04-20 20:44:14 +08:00
|
|
|
/*
|
2020-02-23 05:21:06 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-04-20 20:44:14 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-04-20 20:44:14 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "source_level_debugger_library.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 01:46:50 +08:00
|
|
|
#include "helpers/string.h"
|
2018-04-20 20:44:14 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2018-04-20 20:44:14 +08:00
|
|
|
|
2018-04-23 20:26:03 +08:00
|
|
|
bool DebuggerLibrary::debuggerActive = false;
|
2018-04-20 20:44:14 +08:00
|
|
|
bool DebuggerLibrary::isLibraryAvailable = false;
|
|
|
|
DebuggerLibraryInterceptor *DebuggerLibrary::interceptor = nullptr;
|
|
|
|
|
|
|
|
void *DebuggerLibrary::getProcAddress(const std::string &procName) {
|
|
|
|
if (procName == "notifyNewDevice") {
|
|
|
|
return reinterpret_cast<void *>(notifyNewDevice);
|
|
|
|
} else if (procName == "notifySourceCode") {
|
|
|
|
return reinterpret_cast<void *>(notifySourceCode);
|
|
|
|
} else if (procName == "getDebuggerOption") {
|
|
|
|
return reinterpret_cast<void *>(getDebuggerOption);
|
|
|
|
} else if (procName == "notifyKernelDebugData") {
|
|
|
|
return reinterpret_cast<void *>(notifyKernelDebugData);
|
|
|
|
} else if (procName == "init") {
|
|
|
|
return reinterpret_cast<void *>(init);
|
2018-04-23 20:26:03 +08:00
|
|
|
} else if (procName == "isDebuggerActive") {
|
|
|
|
return reinterpret_cast<void *>(isDebuggerActive);
|
2018-05-02 20:27:55 +08:00
|
|
|
} else if (procName == "notifyDeviceDestruction") {
|
|
|
|
return reinterpret_cast<void *>(notifyDeviceDestruction);
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
OsLibrary *DebuggerLibrary::load(const std::string &name) {
|
|
|
|
if (isLibraryAvailable) {
|
|
|
|
return new DebuggerLibrary();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DebuggerLibrary::notifyNewDevice(GfxDbgNewDeviceData *newDevice) {
|
|
|
|
if (interceptor) {
|
|
|
|
interceptor->newDeviceArgIn = *newDevice;
|
|
|
|
interceptor->newDeviceCalled = true;
|
2018-04-23 20:26:03 +08:00
|
|
|
return interceptor->newDeviceRetVal;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
2018-04-23 20:26:03 +08:00
|
|
|
return IgfxdbgRetVal::IGFXDBG_SUCCESS;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int DebuggerLibrary::notifySourceCode(GfxDbgSourceCode *sourceCode) {
|
|
|
|
if (interceptor) {
|
|
|
|
interceptor->sourceCodeArgIn = *sourceCode;
|
|
|
|
interceptor->sourceCodeCalled = true;
|
2018-05-02 20:27:55 +08:00
|
|
|
if (interceptor->sourceCodeArgOut && sourceCode->sourceNameMaxLen > 0) {
|
|
|
|
memcpy_s(sourceCode->sourceName, sourceCode->sourceNameMaxLen, interceptor->sourceCodeArgOut->sourceName, interceptor->sourceCodeArgOut->sourceNameMaxLen);
|
|
|
|
}
|
2018-04-23 20:26:03 +08:00
|
|
|
return interceptor->sourceCodeRetVal;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
2018-04-23 20:26:03 +08:00
|
|
|
return IgfxdbgRetVal::IGFXDBG_SUCCESS;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int DebuggerLibrary::getDebuggerOption(GfxDbgOption *option) {
|
|
|
|
if (interceptor) {
|
|
|
|
interceptor->optionArgIn = *option;
|
|
|
|
interceptor->optionCalled = true;
|
|
|
|
|
2018-05-11 19:30:07 +08:00
|
|
|
if (interceptor->optionArgOut && option->valueLen >= interceptor->optionArgOut->valueLen) {
|
2018-04-20 20:44:14 +08:00
|
|
|
memcpy_s(option->value, option->valueLen, interceptor->optionArgOut->value, interceptor->optionArgOut->valueLen);
|
2018-05-11 19:30:07 +08:00
|
|
|
} else {
|
|
|
|
memset(option->value, 0, option->valueLen);
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
|
|
|
return interceptor->optionRetVal;
|
|
|
|
}
|
2018-04-23 20:26:03 +08:00
|
|
|
return IgfxdbgRetVal::IGFXDBG_SUCCESS;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int DebuggerLibrary::notifyKernelDebugData(GfxDbgKernelDebugData *kernelDebugData) {
|
|
|
|
if (interceptor) {
|
|
|
|
interceptor->kernelDebugDataArgIn = *kernelDebugData;
|
|
|
|
interceptor->kernelDebugDataCalled = true;
|
2018-04-23 20:26:03 +08:00
|
|
|
return interceptor->kernelDebugDataRetVal;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
2018-04-23 20:26:03 +08:00
|
|
|
return IgfxdbgRetVal::IGFXDBG_SUCCESS;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int DebuggerLibrary::init(GfxDbgTargetCaps *targetCaps) {
|
|
|
|
if (interceptor) {
|
|
|
|
interceptor->targetCapsArgIn = *targetCaps;
|
2018-04-23 20:26:03 +08:00
|
|
|
interceptor->initCalled = true;
|
|
|
|
return interceptor->initRetVal;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
2018-04-23 20:26:03 +08:00
|
|
|
return IgfxdbgRetVal::IGFXDBG_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DebuggerLibrary::isDebuggerActive(void) {
|
|
|
|
return debuggerActive ? 1 : 0;
|
2018-04-20 20:44:14 +08:00
|
|
|
}
|
2018-05-02 20:27:55 +08:00
|
|
|
|
|
|
|
int DebuggerLibrary::notifyDeviceDestruction(GfxDbgDeviceDestructionData *deviceDestruction) {
|
|
|
|
if (interceptor) {
|
|
|
|
interceptor->deviceDestructionArgIn = *deviceDestruction;
|
|
|
|
interceptor->deviceDestructionCalled = true;
|
|
|
|
return interceptor->deviceDestructionRetVal;
|
|
|
|
}
|
|
|
|
return IgfxdbgRetVal::IGFXDBG_SUCCESS;
|
|
|
|
}
|