| 2182 | } |
| 2183 | |
| 2184 | void DebuggerTestBase::testReturnValueVariable() |
| 2185 | { |
| 2186 | struct ReturnValue |
| 2187 | { |
| 2188 | QString type; |
| 2189 | QString value; |
| 2190 | }; |
| 2191 | |
| 2192 | const auto verifyReturnValueVariable = [this](const std::optional<ReturnValue>& expectedReturnValue = {}) { |
| 2193 | const auto watchesIndex = variableCollection()->index(0, 0); |
| 2194 | COMPARE_DATA(watchesIndex, Watches::sectionTitle()); |
| 2195 | if (isLldb() && expectedReturnValue) { |
| 2196 | // NOTE: the Abort mode merely returns from this lambda to prevent a crash; the test proceeds then. |
| 2197 | QEXPECT_FAIL("", "LLDB-MI never sends a field \"gdb-result-var\"", Abort); |
| 2198 | } |
| 2199 | QCOMPARE_EQ(variableCollection()->rowCount(watchesIndex), expectedReturnValue.has_value()); |
| 2200 | if (expectedReturnValue) { |
| 2201 | const auto returnValueVariableIndex = [&watchesIndex, this](int column) { |
| 2202 | return variableCollection()->index(0, column, watchesIndex); |
| 2203 | }; |
| 2204 | |
| 2205 | QCOMPARE_NE(variableCollection()->watches()->returnValueVariable(), nullptr); |
| 2206 | QCOMPARE_EQ(variableCollection()->watches()->returnValueVariable(), |
| 2207 | variableCollection()->itemForIndex(returnValueVariableIndex(0))); |
| 2208 | COMPARE_DATA(returnValueVariableIndex(0), Watches::returnValueVariableDisplayName()); |
| 2209 | COMPARE_DATA(returnValueVariableIndex(1), expectedReturnValue->value); |
| 2210 | COMPARE_DATA(returnValueVariableIndex(2), expectedReturnValue->type); |
| 2211 | } |
| 2212 | }; |
| 2213 | |
| 2214 | #define VERIFY_RETURN_VALUE_VARIABLE(...) \ |
| 2215 | do { \ |
| 2216 | verifyReturnValueVariable(__VA_ARGS__); \ |
| 2217 | RETURN_IF_TEST_FAILED(); \ |
| 2218 | } while (false) |
| 2219 | |
| 2220 | auto* const session = createTestDebugSession(); |
| 2221 | TestLaunchConfiguration cfg("debuggee_debugeereturnvalues"); |
| 2222 | const auto fileUrl = QUrl::fromLocalFile(findSourceFile("debugeereturnvalues.cpp")); |
| 2223 | |
| 2224 | constexpr std::array functionBodyLines{13, 18}; |
| 2225 | for (const auto miLine : functionBodyLines) { |
| 2226 | breakpoints()->addCodeBreakpoint(fileUrl, miLine - 1); |
| 2227 | } |
| 2228 | |
| 2229 | constexpr auto secondFunctionStepOutLine = 40; |
| 2230 | breakpoints()->addCodeBreakpoint(fileUrl, secondFunctionStepOutLine - 1); |
| 2231 | |
| 2232 | ActiveStateSessionSpy sessionSpy(session); |
| 2233 | START_DEBUGGING_AND_WAIT_FOR_PAUSED_STATE_E(session, cfg, sessionSpy); |
| 2234 | QCOMPARE(currentMiLine(session), functionBodyLines[0]); |
| 2235 | // Initially a return value variable does not exist. |
| 2236 | VERIFY_RETURN_VALUE_VARIABLE(); |
| 2237 | |
| 2238 | STEP_OUT_AND_WAIT_FOR_PAUSED_STATE(session, sessionSpy); |
| 2239 | QCOMPARE(currentMiLine(session), 39); |
| 2240 | // KDevelop creates a return value variable after stepping out of a non-void function. |
| 2241 | VERIFY_RETURN_VALUE_VARIABLE(ReturnValue{"int", "5"}); |
nothing calls this directly
no test coverage detected