From f87673e7617a174b5ed68fcfc2db96d83d534b9f Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Thu, 22 Aug 2024 13:00:26 +0000 Subject: [PATCH] fix: Add missing check to DebugSessionImp::readFifo function Signed-off-by: Filip Hazubski --- level_zero/tools/source/debug/debug_session_imp.cpp | 8 ++++++-- .../test/unit_tests/sources/debug/debug_session_tests.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/level_zero/tools/source/debug/debug_session_imp.cpp b/level_zero/tools/source/debug/debug_session_imp.cpp index 47963c830d..2952e0c9f1 100644 --- a/level_zero/tools/source/debug/debug_session_imp.cpp +++ b/level_zero/tools/source/debug/debug_session_imp.cpp @@ -1688,7 +1688,11 @@ ze_result_t DebugSessionImp::readFifo(uint64_t vmHandle, std::vector fifoIndices(2); uint32_t fifoHeadIndex = 0, fifoTailIndex = 0; - readGpuMemory(vmHandle, reinterpret_cast(fifoIndices.data()), fifoIndices.size() * sizeof(uint32_t), gpuVa + offsetHead); + auto retVal = readGpuMemory(vmHandle, reinterpret_cast(fifoIndices.data()), fifoIndices.size() * sizeof(uint32_t), gpuVa + offsetHead); + if (retVal != ZE_RESULT_SUCCESS) { + PRINT_DEBUGGER_ERROR_LOG("Reading FIFO indices failed, error = %d\n", retVal); + return retVal; + } fifoHeadIndex = fifoIndices[0]; fifoTailIndex = fifoIndices[1]; @@ -1701,7 +1705,7 @@ ze_result_t DebugSessionImp::readFifo(uint64_t vmHandle, std::vector nodes(readSize); uint64_t currentFifoOffset = offsetFifo + (sizeof(SIP::fifo_node) * fifoTailIndex); - auto retVal = readGpuMemory(vmHandle, reinterpret_cast(nodes.data()), readSize * sizeof(SIP::fifo_node), currentFifoOffset); + retVal = readGpuMemory(vmHandle, reinterpret_cast(nodes.data()), readSize * sizeof(SIP::fifo_node), currentFifoOffset); if (retVal != ZE_RESULT_SUCCESS) { PRINT_DEBUGGER_ERROR_LOG("Reading FIFO failed, error = %d\n", retVal); return retVal; diff --git a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp index 8a944ecabc..26f30a6cd4 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp @@ -1926,6 +1926,14 @@ TEST_F(DebugSessionTestSwFifoFixture, GivenSwFifoWhenWriteGpuMemoryFailsWhileUpd EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, session->readFifo(0, threadsWithAttention)); } +TEST_F(DebugSessionTestSwFifoFixture, GivenSwFifoWhenReadGpuMemoryFailsDuringFifoIndicesReadingThenErrorReturned) { + + EXPECT_FALSE(session->stateSaveAreaHeader.empty()); + session->forcereadGpuMemoryFailOnCount = 1; + std::vector threadsWithAttention; + EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, session->readFifo(0, threadsWithAttention)); +} + TEST_F(DebugSessionTestSwFifoFixture, GivenSwFifoWhenReadGpuMemoryFailsDuringFifoReadingThenErrorReturned) { EXPECT_FALSE(session->stateSaveAreaHeader.empty());