Skip to content

Commit

Permalink
Make first line of C method consistent
Browse files Browse the repository at this point in the history
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 eclipse-cdt#816
  • Loading branch information
jonahgraham committed Jan 22, 2025
1 parent 19eca42 commit 4620171
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int value() {
int a = 1; // VALUE_LINE
int value()
{ int a = 1; // VALUE_LINE
return 1;
}
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected String convertDetails(String details) {
*/
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,6 +107,8 @@ public void doBeforeTest() throws Exception {
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
Expand Down Expand Up @@ -287,8 +291,7 @@ public void testClearingEnvironment() throws Throwable {
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.
Expand Down Expand Up @@ -329,8 +332,7 @@ public void testSettingEnvironment() throws Throwable {
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".
Expand Down Expand Up @@ -390,8 +392,7 @@ public void testClearingAndSettingEnvironment() throws Throwable {
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".
Expand Down Expand Up @@ -449,7 +450,7 @@ public void testSettingArguments() throws Throwable {
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");
Expand Down
Loading

0 comments on commit 4620171

Please sign in to comment.