1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-03-28 14:56:28 +01:00

Make first line of C method consistent

The tests were relying on specific number of executable lines
in a function. However on some gdb/gcc combinations stopping
at a function stops at the line with the `{` and some
on the first line witin that function. Much of the tests
here assumed that latter. By using line tags we don't need
to worry about exact number of executable lines between entry
and area of interest. And by placing first line of code on
the same line as the opening `{` of the function, we can
have consistent stop locations when stepping into a function.

Part of #816
This commit is contained in:
Jonah Graham 2024-12-28 12:32:51 -05:00
parent b1e0121177
commit dc77c1f3bb
6 changed files with 97 additions and 96 deletions

View file

@ -19,7 +19,7 @@ int envTest() {
char *home, *launchTest;
home = getenv("HOME");
launchTest = getenv("LAUNCHTEST");
return 0;
return 0; // END_ENV_TEST_LINE
}
int main (int argc, char *argv[])
@ -29,7 +29,7 @@ int main (int argc, char *argv[])
var = 3;
var = 4; // three_steps_back_from_b_stopAtOther
var = 5;
stopAtOther(); // main_init
stopAtOther(); // MAIN_INIT_LINE
reverseTest(); // tests assume that every line between first and last
envTest(); // is steppable, so no blank lines allowed.
return 36; // LAST_LINE_IN_MAIN

View file

@ -1,4 +1,4 @@
int value() {
int a = 1; // VALUE_LINE
int value()
{ int a = 1; // VALUE_LINE
return 1;
}

View file

@ -1,82 +1,80 @@
#include "StepIntoSelection.h"
int foo() {
int i = 0; // FOO_LINE
int foo()
{ int i = 0; // FOO_LINE
return 1;
}
int bar(int i) {
int b = 0; // BAR_LINE
int bar(int i)
{ int b = 0; // BAR_LINE
return i + b;
}
int add(int a) {
return a + 1; // ADD_WITH_ARG_LINE
int add(int a)
{ return a + 1; // ADD_WITH_ARG_LINE
}
int add() {
return 1; // ADD_NO_ARG_LINE
int add()
{ return 1; // ADD_NO_ARG_LINE
}
int recursiveTest(int a) {
if (a == 1) return a;
int recursiveTest(int a)
{ if (a == 1) return a;
return a + recursiveTest(--a); // The test expects this line to be exactly 2 lines below the first line of the method
return a + recursiveTest(--a); // RECURSIVE_LINE
}
int sameLineTest() {
foo();
int sameLineTest()
{ foo();
return 0;
}
int sameLineBreakpointTest() {
bar(foo());
int sameLineBreakpointTest()
{ bar(foo());
return 0;
}
int doubleMethodTest() {
int a = 0;
bar(foo()); // The test expects this line to be one line below the star of the method
int doubleMethodTest()
{ int a = 0;
bar(foo()); // DOUBLE_METHOD_LINE
return 0;
}
int laterLineTest() {
int i = 0;
int laterLineTest()
{ int i = 0; // LATER_LINE_ENTRY_LINE
i++;
i++;
foo(); // The test expects this line to be exactly 3 lines below the first line of the method
foo(); // LATER_LINE_LINE
i++;
i++;
return 0;
}
int laterLineNotHitTest() {
int i = 0;
int laterLineNotHitTest()
{ int i = 0;
if (i==100) { // Won't hit
foo(); // The test expects this line to be exactly 2 lines below the first line of the method
foo(); // LATER_LINE_NOT_HIT_LINE
}
i++;
i++;
return 0;
}
int laterLineDifferentFileTest() {
int b = 0;
value(); // Must be one line below start of the method
// value() is from .h header file
int laterLineDifferentFileTest()
{ int b = 0;
value(); // LATER_LINE_DIFFERENT_FILE_LINE
}
int differentFileTest() {
return 0;
int differentFileTest()
{ return 0;
}
int methodWithDiffArgsNumberTest() {
return add() + add(2);
int methodWithDiffArgsNumberTest()
{ return add() + add(2);
}
int main() {
sameLineTest();
int main()
{ sameLineTest();
laterLineTest();
laterLineNotHitTest();
doubleMethodTest();

View file

@ -174,7 +174,7 @@ public class CommandLineArgsTest extends BaseParametrizedTestCase {
*/
protected void checkArguments(String... expected) throws Throwable {
MIStoppedEvent stoppedEvent = runToTag("main_init");
MIStoppedEvent stoppedEvent = runToTag("MAIN_INIT_LINE");
// Check that argc is correct
final IExpressionDMContext argcDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc");

View file

@ -72,11 +72,13 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
protected static final String SOURCE_NAME = "LaunchConfigurationAndRestartTestApp.cc";
protected static final String[] LINE_TAGS = new String[] { "FIRST_LINE_IN_MAIN", "LAST_LINE_IN_MAIN",
"three_steps_back_from_b_stopAtOther" };
"three_steps_back_from_b_stopAtOther", "END_ENV_TEST_LINE", "MAIN_INIT_LINE" };
protected int FIRST_LINE_IN_MAIN;
protected int LAST_LINE_IN_MAIN;
protected int three_steps_back_from_b_stopAtOther;
protected int END_ENV_TEST_LINE;
protected int MAIN_INIT_LINE;
// The exit code returned by the test program
private static final int TEST_EXIT_CODE = 36;
@ -105,6 +107,8 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
FIRST_LINE_IN_MAIN = getLineForTag("FIRST_LINE_IN_MAIN");
LAST_LINE_IN_MAIN = getLineForTag("LAST_LINE_IN_MAIN");
three_steps_back_from_b_stopAtOther = getLineForTag("three_steps_back_from_b_stopAtOther");
END_ENV_TEST_LINE = getLineForTag("END_ENV_TEST_LINE");
MAIN_INIT_LINE = getLineForTag("MAIN_INIT_LINE");
}
@Override
@ -287,8 +291,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
setLaunchAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, false);
doLaunch();
SyncUtil.runToLocation("envTest");
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(END_ENV_TEST_LINE));
// The program has stored the content of $HOME into a variable called 'home'.
// Let's verify this variable is 0x0 which means $HOME does not exist.
@ -329,8 +332,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
setLaunchAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
doLaunch();
SyncUtil.runToLocation("envTest");
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(END_ENV_TEST_LINE));
// The program has stored the content of $LAUNCHTEST into a variable called 'launchTest'.
// Let's verify this variable is set to "IS SET".
@ -390,8 +392,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
setLaunchAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
doLaunch();
SyncUtil.runToLocation("envTest");
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(END_ENV_TEST_LINE));
// The program has stored the content of $LAUNCHTEST into a variable called 'launchTest'.
// Let's verify this variable is set to "IS SET".
@ -449,7 +450,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "1 2 3\n4 5 6");
doLaunch();
MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(MAIN_INIT_LINE));
// Check that argc is correct
final IExpressionDMContext argcDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc");

View file

@ -65,9 +65,16 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
protected int VALUE_LINE;
protected int ADD_WITH_ARG_LINE;
protected int ADD_NO_ARG_LINE;
protected int DOUBLE_METHOD_LINE;
protected int LATER_LINE_LINE;
protected int LATER_LINE_NOT_HIT_LINE;
protected int LATER_LINE_DIFFERENT_FILE_LINE;
protected int RECURSIVE_LINE;
protected int LATER_LINE_ENTRY_LINE;
protected static final String[] SOURCE_LINE_TAGS = { "FOO_LINE", "BAR_LINE", "ADD_WITH_ARG_LINE",
"ADD_NO_ARG_LINE", };
protected static final String[] SOURCE_LINE_TAGS = { "FOO_LINE", "BAR_LINE", "ADD_WITH_ARG_LINE", "ADD_NO_ARG_LINE",
"DOUBLE_METHOD_LINE", "LATER_LINE_LINE", "LATER_LINE_NOT_HIT_LINE", "LATER_LINE_DIFFERENT_FILE_LINE",
"RECURSIVE_LINE", "LATER_LINE_ENTRY_LINE" };
protected static final String[] HEADER_LINE_TAGS = { "VALUE_LINE", };
//Target Functions
@ -121,6 +128,12 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
VALUE_LINE = getLineForTag("VALUE_LINE");
ADD_WITH_ARG_LINE = getLineForTag("ADD_WITH_ARG_LINE");
ADD_NO_ARG_LINE = getLineForTag("ADD_NO_ARG_LINE");
DOUBLE_METHOD_LINE = getLineForTag("DOUBLE_METHOD_LINE");
LATER_LINE_LINE = getLineForTag("LATER_LINE_LINE");
LATER_LINE_NOT_HIT_LINE = getLineForTag("LATER_LINE_NOT_HIT_LINE");
LATER_LINE_DIFFERENT_FILE_LINE = getLineForTag("LATER_LINE_DIFFERENT_FILE_LINE");
RECURSIVE_LINE = getLineForTag("RECURSIVE_LINE");
LATER_LINE_ENTRY_LINE = getLineForTag("LATER_LINE_ENTRY_LINE");
}
@Override
@ -242,10 +255,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
FunctionDeclaration targetFunction = funcFoo;
int line = stoppedEvent.getFrame().getLine() + 3; // The method to stepInto is three lines below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, targetFunction, false);
validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, FOO_LINE, originalDepth + 1);
}
@ -259,10 +271,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
FunctionDeclaration targetFunction = funcValue;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_DIFFERENT_FILE_LINE, targetFunction, false);
validateLocation(suspendedEvent, targetFunction.getElementName(), HEADER_NAME, VALUE_LINE, originalDepth + 1);
}
@ -277,10 +288,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
FunctionDeclaration targetFunction = funcFoo;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, false);
validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, FOO_LINE, originalDepth + 1);
}
@ -295,10 +305,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
FunctionDeclaration targetFunction = funcBar;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, false);
validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, BAR_LINE, originalDepth + 1);
}
@ -314,10 +323,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
FunctionDeclaration targetFunction = funcRecursive;
int line = stoppedEvent.getFrame().getLine() + 2; // The method to stepInto is two lines below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
RECURSIVE_LINE, targetFunction, false);
validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, finalLine, originalDepth + 1);
}
@ -330,21 +338,21 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
public void atPreviousLine() throws Throwable {
String functionName = "laterLineTest";
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(functionName);
int originalLine = stoppedEvent.getFrame().getLine();
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
// Step past the function call
stoppedEvent = SyncUtil.step(4, StepType.STEP_OVER);
while (stoppedEvent.getFrame().getLine() <= LATER_LINE_LINE) {
stoppedEvent = SyncUtil.step(1, StepType.STEP_OVER);
}
// Set a bp one line below. We will check that this breakpoint hits when a stepInto is done
int bpline = originalLine + 4 + 1;
int bpline = LATER_LINE_LINE + 2;
SyncUtil.addBreakpoint(Integer.toString(bpline));
FunctionDeclaration targetFunction = funcFoo;
int line = originalLine + 3; // The method to stepInto is three lines below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, targetFunction, false);
validateLocation(suspendedEvent, functionName, SOURCE_NAME, bpline, originalDepth);
}
@ -360,10 +368,10 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
FunctionDeclaration targetFunction = funcFoo;
int line = stoppedEvent.getFrame().getLine() + 2; // The method to stepInto is two lines below the start of the method
// Except we'll never reach it
// Set a bp a couple of lines below. We will check that this breakpoint hits and the stepInto is cancelled
int bpline = line + 2;
int line = LATER_LINE_NOT_HIT_LINE; // The method to stepInto is two lines below the start of the method
// Except we'll never reach it
// Set a bp a couple of lines below. We will check that this breakpoint hits and the stepInto is cancelled
int bpline = LATER_LINE_NOT_HIT_LINE + 2;
SyncUtil.addBreakpoint(Integer.toString(bpline));
// StepInto the method
@ -388,22 +396,21 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
String functionName = "laterLineTest";
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(functionName);
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
int originalLine = stoppedEvent.getFrame().getLine();
// Set a breakpoint before the stepInto line
SyncUtil.addBreakpoint(Integer.toString(originalLine + 1));
int bpline = LATER_LINE_LINE - 1;
SyncUtil.addBreakpoint(Integer.toString(bpline));
int line = originalLine + 3; // The method to stepInto is three lines below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
funcFoo, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, funcFoo, false);
validateLocation(suspendedEvent, functionName, SOURCE_NAME, originalLine + 1, originalDepth);
validateLocation(suspendedEvent, functionName, SOURCE_NAME, bpline, originalDepth);
// Make sure the step to selection operation is no longer active by triggering a run to line before the step into selection line
suspendedEvent = triggerRunToLine(stoppedEvent.getDMContext(), SOURCE_NAME, originalLine + 2, false);
suspendedEvent = triggerRunToLine(stoppedEvent.getDMContext(), SOURCE_NAME, LATER_LINE_LINE, false);
validateLocation(suspendedEvent, functionName, SOURCE_NAME, originalLine + 2, originalDepth);
validateLocation(suspendedEvent, functionName, SOURCE_NAME, LATER_LINE_LINE, originalDepth);
}
/**
@ -414,19 +421,16 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
public void atLaterLineSkipBreakpoints() throws Throwable {
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("laterLineTest");
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
int originalLine = stoppedEvent.getFrame().getLine();
// Set two breakpoints before the stepInto line
SyncUtil.addBreakpoint(Integer.toString(originalLine + 1));
SyncUtil.addBreakpoint(Integer.toString(originalLine + 2));
int line = originalLine + 3; // The method to stepInto is three lines below the start of the method
SyncUtil.addBreakpoint(Integer.toString(LATER_LINE_LINE - 2));
SyncUtil.addBreakpoint(Integer.toString(LATER_LINE_LINE - 1));
FunctionDeclaration targetFunction = funcFoo;
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, true);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, targetFunction, true);
validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, FOO_LINE, originalDepth + 1);
}
@ -440,10 +444,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
SyncUtil.addBreakpoint(Integer.toString(foo_line));
FunctionDeclaration targetFunction = funcBar;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false); // Set not to skip breakpoints, but it should have no effect
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, false); // Set not to skip breakpoints, but it should have no effect
validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, BAR_LINE, originalDepth + 1);
}
@ -480,10 +483,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
SyncUtil.addBreakpoint(Integer.toString(foo_line));
FunctionDeclaration targetFunction = funcBar;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, true); // Set skip breakpoints, which should have non impact
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, true); // Set skip breakpoints, which should have non impact
validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, BAR_LINE, originalDepth + 1);
}