2323#include " igfx_debug_interchange_types.h"
2424
2525#include " runtime/helpers/debug_helpers.h"
26+ #include " runtime/program/kernel_info.h"
2627#include " runtime/source_level_debugger/source_level_debugger.h"
2728#include " runtime/os_interface/os_interface.h"
2829
@@ -32,39 +33,68 @@ const char *SourceLevelDebugger::notifySourceCodeSymbol = "notifySourceCode";
3233const char *SourceLevelDebugger::getDebuggerOptionSymbol = " getDebuggerOption" ;
3334const char *SourceLevelDebugger::notifyKernelDebugDataSymbol = " notifyKernelDebugData" ;
3435const char *SourceLevelDebugger::initSymbol = " init" ;
36+ const char *SourceLevelDebugger::isDebuggerActiveSymbol = " isDebuggerActive" ;
3537
3638class SourceLevelDebugger ::SourceLevelDebuggerInterface {
3739 public:
3840 SourceLevelDebuggerInterface () = default ;
3941 ~SourceLevelDebuggerInterface () = default ;
4042
41- typedef int (*pfNotifyNewDevice)(GfxDbgNewDeviceData *data);
42- typedef int (*pfNotifySourceCode)(GfxDbgSourceCode *data);
43- typedef int (*pfGetDebuggerOption)(GfxDbgOption *);
44- typedef int (*pfNotifyKernelDebugData)(GfxDbgKernelDebugData *data);
45- typedef int (*pfInit)(GfxDbgTargetCaps *data);
46-
47- pfNotifyNewDevice fNotifyNewDevice = nullptr ;
48- pfNotifySourceCode fNotifySourceCode = nullptr ;
49- pfGetDebuggerOption fGetDebuggerOption = nullptr ;
50- pfNotifyKernelDebugData fNotifyKernelDebugData = nullptr ;
51- pfInit fInit = nullptr ;
43+ typedef int (*NotifyNewDeviceFunction)(GfxDbgNewDeviceData *data);
44+ typedef int (*NotifySourceCodeFunction)(GfxDbgSourceCode *data);
45+ typedef int (*GetDebuggerOptionFunction)(GfxDbgOption *);
46+ typedef int (*NotifyKernelDebugDataFunction)(GfxDbgKernelDebugData *data);
47+ typedef int (*InitFunction)(GfxDbgTargetCaps *data);
48+ typedef int (*IsDebuggerActiveFunction)(void );
49+
50+ NotifyNewDeviceFunction notifyNewDeviceFunc = nullptr ;
51+ NotifySourceCodeFunction notifySourceCodeFunc = nullptr ;
52+ GetDebuggerOptionFunction getDebuggerOptionFunc = nullptr ;
53+ NotifyKernelDebugDataFunction notifyKernelDebugDataFunc = nullptr ;
54+ InitFunction initFunc = nullptr ;
55+ IsDebuggerActiveFunction isDebuggerActive = nullptr ;
5256};
5357
54- SourceLevelDebugger::SourceLevelDebugger () {
55- debuggerLibrary.reset (SourceLevelDebugger::loadDebugger ());
58+ SourceLevelDebugger *SourceLevelDebugger::create () {
59+ auto library = SourceLevelDebugger::loadDebugger ();
60+ if (library) {
61+ auto isActiveFunc = reinterpret_cast <SourceLevelDebuggerInterface::IsDebuggerActiveFunction>(library->getProcAddress (isDebuggerActiveSymbol));
62+ int result = isActiveFunc ();
63+ if (result == 1 ) {
64+ // pass library ownership to Source Level Debugger
65+ return new SourceLevelDebugger (library);
66+ }
67+ delete library;
68+ }
69+ return nullptr ;
70+ }
71+ SourceLevelDebugger::SourceLevelDebugger (OsLibrary *library) {
72+ debuggerLibrary.reset (library);
5673
5774 if (debuggerLibrary.get () == nullptr ) {
5875 return ;
5976 }
60- interface = new SourceLevelDebuggerInterface;
77+ sourceLevelDebuggerInterface = new SourceLevelDebuggerInterface;
6178 getFunctions ();
62- isActive = true ;
79+
80+ if (sourceLevelDebuggerInterface->isDebuggerActive == nullptr ) {
81+ return ;
82+ }
83+
84+ int result = sourceLevelDebuggerInterface->isDebuggerActive ();
85+ if (result == 1 ) {
86+ UNRECOVERABLE_IF (sourceLevelDebuggerInterface->getDebuggerOptionFunc == nullptr );
87+ UNRECOVERABLE_IF (sourceLevelDebuggerInterface->initFunc == nullptr );
88+ UNRECOVERABLE_IF (sourceLevelDebuggerInterface->notifyKernelDebugDataFunc == nullptr );
89+ UNRECOVERABLE_IF (sourceLevelDebuggerInterface->notifyNewDeviceFunc == nullptr );
90+ UNRECOVERABLE_IF (sourceLevelDebuggerInterface->notifySourceCodeFunc == nullptr );
91+ isActive = true ;
92+ }
6393}
6494
6595SourceLevelDebugger::~SourceLevelDebugger () {
66- if (interface ) {
67- delete interface ;
96+ if (sourceLevelDebuggerInterface ) {
97+ delete sourceLevelDebuggerInterface ;
6898 }
6999}
70100
@@ -75,11 +105,12 @@ bool SourceLevelDebugger::isDebuggerActive() {
75105void SourceLevelDebugger::getFunctions () {
76106 UNRECOVERABLE_IF (debuggerLibrary.get () == nullptr );
77107
78- interface->fNotifyNewDevice = reinterpret_cast <SourceLevelDebuggerInterface::pfNotifyNewDevice>(debuggerLibrary->getProcAddress (notifyNewDeviceSymbol));
79- interface->fNotifySourceCode = reinterpret_cast <SourceLevelDebuggerInterface::pfNotifySourceCode>(debuggerLibrary->getProcAddress (notifySourceCodeSymbol));
80- interface->fGetDebuggerOption = reinterpret_cast <SourceLevelDebuggerInterface::pfGetDebuggerOption>(debuggerLibrary->getProcAddress (getDebuggerOptionSymbol));
81- interface->fNotifyKernelDebugData = reinterpret_cast <SourceLevelDebuggerInterface::pfNotifyKernelDebugData>(debuggerLibrary->getProcAddress (notifyKernelDebugDataSymbol));
82- interface->fInit = reinterpret_cast <SourceLevelDebuggerInterface::pfInit>(debuggerLibrary->getProcAddress (initSymbol));
108+ sourceLevelDebuggerInterface->notifyNewDeviceFunc = reinterpret_cast <SourceLevelDebuggerInterface::NotifyNewDeviceFunction>(debuggerLibrary->getProcAddress (notifyNewDeviceSymbol));
109+ sourceLevelDebuggerInterface->notifySourceCodeFunc = reinterpret_cast <SourceLevelDebuggerInterface::NotifySourceCodeFunction>(debuggerLibrary->getProcAddress (notifySourceCodeSymbol));
110+ sourceLevelDebuggerInterface->getDebuggerOptionFunc = reinterpret_cast <SourceLevelDebuggerInterface::GetDebuggerOptionFunction>(debuggerLibrary->getProcAddress (getDebuggerOptionSymbol));
111+ sourceLevelDebuggerInterface->notifyKernelDebugDataFunc = reinterpret_cast <SourceLevelDebuggerInterface::NotifyKernelDebugDataFunction>(debuggerLibrary->getProcAddress (notifyKernelDebugDataSymbol));
112+ sourceLevelDebuggerInterface->initFunc = reinterpret_cast <SourceLevelDebuggerInterface::InitFunction>(debuggerLibrary->getProcAddress (initSymbol));
113+ sourceLevelDebuggerInterface->isDebuggerActive = reinterpret_cast <SourceLevelDebuggerInterface::IsDebuggerActiveFunction>(debuggerLibrary->getProcAddress (isDebuggerActiveSymbol));
83114}
84115
85116void SourceLevelDebugger::notifyNewDevice (uint32_t deviceHandle) const {
@@ -88,7 +119,7 @@ void SourceLevelDebugger::notifyNewDevice(uint32_t deviceHandle) const {
88119 newDevice.version = IGFXDBG_CURRENT_VERSION;
89120 newDevice.dh = reinterpret_cast <GfxDeviceHandle>(static_cast <uint64_t >(deviceHandle));
90121 newDevice.udh = GfxDeviceHandle (0 );
91- interface-> fNotifyNewDevice (&newDevice);
122+ sourceLevelDebuggerInterface-> notifyNewDeviceFunc (&newDevice);
92123 }
93124}
94125void SourceLevelDebugger::notifySourceCode (uint32_t deviceHandle, const char *source, size_t sourceSize) const {
@@ -103,7 +134,7 @@ void SourceLevelDebugger::notifySourceCode(uint32_t deviceHandle, const char *so
103134 sourceCode.sourceName = &fileName[0 ];
104135 sourceCode.sourceNameMaxLen = sizeof (fileName);
105136
106- interface-> fNotifySourceCode (&sourceCode);
137+ sourceLevelDebuggerInterface-> notifySourceCodeFunc (&sourceCode);
107138 }
108139}
109140
@@ -116,7 +147,7 @@ bool SourceLevelDebugger::isOptimizationDisabled() const {
116147 option.valueLen = sizeof (value);
117148 option.value = &value;
118149
119- int result = interface-> fGetDebuggerOption (&option);
150+ int result = sourceLevelDebuggerInterface-> getDebuggerOptionFunc (&option);
120151 if (result == 1 ) {
121152 if (option.value [0 ] == ' 1' ) {
122153 return true ;
@@ -126,8 +157,33 @@ bool SourceLevelDebugger::isOptimizationDisabled() const {
126157 return false ;
127158}
128159
129- void SourceLevelDebugger::notifyKernelDebugData () const {
130- GfxDbgKernelDebugData kernelDebugData;
131- interface->fNotifyKernelDebugData (&kernelDebugData);
160+ void SourceLevelDebugger::notifyKernelDebugData (uint32_t deviceHandle, const KernelInfo *kernelInfo) const {
161+ if (isActive) {
162+ GfxDbgKernelDebugData kernelDebugData;
163+ kernelDebugData.hDevice = reinterpret_cast <GfxDeviceHandle>(static_cast <uint64_t >(deviceHandle));
164+ kernelDebugData.version = IGFXDBG_CURRENT_VERSION;
165+ kernelDebugData.hProgram = reinterpret_cast <GenRtProgramHandle>(0 );
166+
167+ kernelDebugData.kernelName = kernelInfo->name .c_str ();
168+ kernelDebugData.kernelBinBuffer = const_cast <void *>(kernelInfo->heapInfo .pKernelHeap );
169+ kernelDebugData.KernelBinSize = kernelInfo->heapInfo .pKernelHeader ->KernelHeapSize ;
170+
171+ kernelDebugData.dbgVisaBuffer = kernelInfo->debugData .vIsa ;
172+ kernelDebugData.dbgVisaSize = kernelInfo->debugData .vIsaSize ;
173+ kernelDebugData.dbgGenIsaBuffer = kernelInfo->debugData .genIsa ;
174+ kernelDebugData.dbgGenIsaSize = kernelInfo->debugData .genIsaSize ;
175+
176+ sourceLevelDebuggerInterface->notifyKernelDebugDataFunc (&kernelDebugData);
177+ }
178+ }
179+
180+ void SourceLevelDebugger::initialize (bool useLocalMemory) {
181+ if (isActive) {
182+ GfxDbgTargetCaps caps = {IGFXDBG_CURRENT_VERSION, useLocalMemory};
183+ int result = sourceLevelDebuggerInterface->initFunc (&caps);
184+ if (static_cast <IgfxdbgRetVal>(result) != IgfxdbgRetVal::IGFXDBG_SUCCESS) {
185+ isActive = false ;
186+ }
187+ }
132188}
133189} // namespace OCLRT
0 commit comments