2021-02-23 17:57:27 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2021 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2021-06-02 15:24:43 +00:00
|
|
|
#include "level_zero/core/source/debugger/debugger_l0.h"
|
2021-07-22 22:32:05 +00:00
|
|
|
#include "level_zero/tools/source/debug/eu_thread.h"
|
|
|
|
|
#include <level_zero/ze_api.h>
|
2021-02-23 17:57:27 +00:00
|
|
|
#include <level_zero/zet_api.h>
|
|
|
|
|
|
2021-07-22 22:32:05 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
2021-02-23 17:57:27 +00:00
|
|
|
struct _zet_debug_session_handle_t {};
|
|
|
|
|
|
|
|
|
|
namespace L0 {
|
|
|
|
|
|
|
|
|
|
struct Device;
|
|
|
|
|
|
|
|
|
|
struct DebugSession : _zet_debug_session_handle_t {
|
|
|
|
|
virtual ~DebugSession() = default;
|
|
|
|
|
DebugSession() = delete;
|
|
|
|
|
|
2021-03-18 18:18:25 +00:00
|
|
|
static DebugSession *create(const zet_debug_config_t &config, Device *device, ze_result_t &result);
|
2021-02-23 17:57:27 +00:00
|
|
|
|
|
|
|
|
static DebugSession *fromHandle(zet_debug_session_handle_t handle) { return static_cast<DebugSession *>(handle); }
|
|
|
|
|
inline zet_debug_session_handle_t toHandle() { return this; }
|
|
|
|
|
|
2021-03-03 12:09:39 +00:00
|
|
|
virtual bool closeConnection() = 0;
|
2021-03-23 17:08:18 +00:00
|
|
|
virtual ze_result_t initialize() = 0;
|
2021-03-03 12:09:39 +00:00
|
|
|
|
2021-04-07 17:58:26 +00:00
|
|
|
virtual ze_result_t readEvent(uint64_t timeout, zet_debug_event_t *event) = 0;
|
2021-04-20 16:02:43 +00:00
|
|
|
virtual ze_result_t interrupt(ze_device_thread_t thread) = 0;
|
|
|
|
|
virtual ze_result_t resume(ze_device_thread_t thread) = 0;
|
|
|
|
|
virtual ze_result_t readMemory(ze_device_thread_t thread, const zet_debug_memory_space_desc_t *desc, size_t size, void *buffer) = 0;
|
|
|
|
|
virtual ze_result_t writeMemory(ze_device_thread_t thread, const zet_debug_memory_space_desc_t *desc, size_t size, const void *buffer) = 0;
|
|
|
|
|
virtual ze_result_t acknowledgeEvent(const zet_debug_event_t *event) = 0;
|
2021-06-22 18:45:53 -04:00
|
|
|
virtual ze_result_t readRegisters(ze_device_thread_t thread, uint32_t type, uint32_t start, uint32_t count, void *pRegisterValues) = 0;
|
|
|
|
|
virtual ze_result_t writeRegisters(ze_device_thread_t thread, uint32_t type, uint32_t start, uint32_t count, void *pRegisterValues) = 0;
|
2021-06-25 13:55:49 +00:00
|
|
|
static ze_result_t getRegisterSetProperties(Device *device, uint32_t *pCount, zet_debug_regset_properties_t *pRegisterSetProperties);
|
2021-08-03 19:11:11 +00:00
|
|
|
MOCKABLE_VIRTUAL bool areRequestedThreadsStopped(ze_device_thread_t thread);
|
2021-04-07 17:58:26 +00:00
|
|
|
|
2021-03-03 12:09:39 +00:00
|
|
|
Device *getConnectedDevice() { return connectedDevice; }
|
|
|
|
|
|
2021-07-28 17:30:15 +00:00
|
|
|
static bool isThreadAll(ze_device_thread_t thread) {
|
|
|
|
|
return thread.slice == UINT32_MAX && thread.subslice == UINT32_MAX && thread.eu == UINT32_MAX && thread.thread == UINT32_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool isSingleThread(ze_device_thread_t thread) {
|
|
|
|
|
return thread.slice != UINT32_MAX && thread.subslice != UINT32_MAX && thread.eu != UINT32_MAX && thread.thread != UINT32_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool areThreadsEqual(ze_device_thread_t thread, ze_device_thread_t thread2) {
|
|
|
|
|
return thread.slice == thread2.slice && thread.subslice == thread2.subslice && thread.eu == thread2.eu && thread.thread == thread2.thread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool checkSingleThreadWithinDeviceThread(ze_device_thread_t checkedThread, ze_device_thread_t thread) {
|
|
|
|
|
if (DebugSession::isThreadAll(thread)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool threadMatch = (thread.thread == checkedThread.thread) || thread.thread == UINT32_MAX;
|
|
|
|
|
bool euMatch = (thread.eu == checkedThread.eu) || thread.eu == UINT32_MAX;
|
|
|
|
|
bool subsliceMatch = (thread.subslice == checkedThread.subslice) || thread.subslice == UINT32_MAX;
|
|
|
|
|
bool sliceMatch = (thread.slice == checkedThread.slice) || thread.slice == UINT32_MAX;
|
|
|
|
|
|
|
|
|
|
return threadMatch && euMatch && subsliceMatch && sliceMatch;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-15 11:52:19 +00:00
|
|
|
static void printBitmask(uint8_t *bitmask, size_t bitmaskSize);
|
|
|
|
|
|
2021-07-28 17:30:15 +00:00
|
|
|
virtual ze_device_thread_t convertToPhysical(ze_device_thread_t thread, uint32_t &deviceIndex);
|
|
|
|
|
virtual EuThread::ThreadId convertToThreadId(ze_device_thread_t thread);
|
|
|
|
|
virtual ze_device_thread_t convertToApi(EuThread::ThreadId threadId);
|
|
|
|
|
|
2021-10-08 00:40:12 +00:00
|
|
|
ze_result_t sanityMemAccessThreadCheck(ze_device_thread_t thread, const zet_debug_memory_space_desc_t *desc);
|
|
|
|
|
|
2021-02-23 17:57:27 +00:00
|
|
|
protected:
|
2021-07-30 08:07:42 +00:00
|
|
|
DebugSession(const zet_debug_config_t &config, Device *device);
|
2021-05-07 15:27:56 +00:00
|
|
|
virtual void startAsyncThread() = 0;
|
|
|
|
|
|
2021-07-30 08:07:42 +00:00
|
|
|
virtual bool isBindlessSystemRoutine();
|
2021-06-02 15:24:43 +00:00
|
|
|
virtual bool readModuleDebugArea() = 0;
|
2021-09-22 17:24:29 +00:00
|
|
|
virtual ze_result_t readSbaBuffer(EuThread::ThreadId threadId, SbaTrackedAddresses &sbaBuffer) = 0;
|
2021-07-30 08:07:42 +00:00
|
|
|
|
2021-09-21 18:18:16 +00:00
|
|
|
void fillDevicesFromThread(ze_device_thread_t thread, std::vector<uint8_t> &devices);
|
|
|
|
|
|
2021-09-13 13:53:11 +00:00
|
|
|
std::vector<EuThread::ThreadId> getSingleThreadsForDevice(uint32_t deviceIndex, ze_device_thread_t physicalThread, const NEO::HardwareInfo &hwInfo);
|
2021-07-22 22:32:05 +00:00
|
|
|
|
2021-11-04 19:05:30 +00:00
|
|
|
size_t getPerThreadScratchOffset(size_t ptss, EuThread::ThreadId threadId);
|
|
|
|
|
|
2021-06-02 15:24:43 +00:00
|
|
|
DebugAreaHeader debugArea;
|
2021-07-22 22:32:05 +00:00
|
|
|
|
2021-07-30 08:07:42 +00:00
|
|
|
Device *connectedDevice = nullptr;
|
2021-07-22 22:32:05 +00:00
|
|
|
std::map<uint64_t, std::unique_ptr<EuThread>> allThreads;
|
2021-05-07 15:27:56 +00:00
|
|
|
};
|
|
|
|
|
|
2021-06-16 10:42:34 +00:00
|
|
|
} // namespace L0
|