/**
   * This test will set a breakpoint at some place in the program and will tell the launch to NOT
   * "stop on main". We will verify that the first stop is at the breakpoint that we set.
   */
  @Ignore
  @Test
  public void testNoStopAtMain() throws Throwable {
    setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
    // Set this one as well to make sure it gets ignored
    setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, "main");

    // We need to set the breakpoint before the launch is started, but the only way to do that is
    // to set it in the platorm.  Ok, but how do I get an IResource that points to my binary?
    // The current workspace is the JUnit runtime workspace instead of the workspace containing
    // the JUnit tests.

    IFile fakeFile = null;
    CDIDebugModel.createLineBreakpoint(
        EXEC_PATH + EXEC_NAME,
        fakeFile,
        ICBreakpointType.REGULAR,
        LAST_LINE_IN_MAIN + 1,
        true,
        0,
        "",
        true); //$NON-NLS-1$
    doLaunch();

    MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
    assertTrue(
        "Expected to stop at envTest but got " + stoppedEvent.getFrame().getFunction() + ":",
        stoppedEvent.getFrame().getFunction().equals("envTest"));
  }
Example #2
0
  @Test
  public void getModelDataForRegisterDataValueInDifferentNumberFormats() throws Throwable {
    MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
    IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
    String val = getModelDataForRegisterDataValue(frameDmc, IFormattedValues.NATURAL_FORMAT, 0);
    REGISTER_VALUE = val;
    assertTrue(
        "Register Value is not in NATURAL format ",
        Integer.parseInt(val) == Integer.parseInt(REGISTER_VALUE));

    val = getModelDataForRegisterDataValue(frameDmc, IFormattedValues.HEX_FORMAT, 0);
    assertTrue("Register Value is not in HEX_FORMAT ", val.startsWith("0x"));

    val = getModelDataForRegisterDataValue(frameDmc, IFormattedValues.BINARY_FORMAT, 0);
    Assert.assertEquals(
        "Register Value is not in BINARY_FORMAT ",
        Integer.toBinaryString(Integer.parseInt(REGISTER_VALUE)),
        val);

    val = getModelDataForRegisterDataValue(frameDmc, IFormattedValues.DECIMAL_FORMAT, 0);
    Assert.assertEquals(
        "Register Value is not in DECIMAL_FORMAT",
        Integer.parseInt(REGISTER_VALUE),
        Integer.parseInt(val));

    val = getModelDataForRegisterDataValue(frameDmc, IFormattedValues.OCTAL_FORMAT, 0);
    assertTrue("Register Value is not in OCTAL_FORMAT ", val.startsWith("0"));
  }
Example #3
0
 @Test
 public void getRegistersLength() throws Throwable {
   MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
   IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
   final IRegisterDMContext[] regDMCs = getRegisters(frameDmc);
   assertEquals("Wrong number of registers", get_X86_REGS().size(), regDMCs.length);
 }
  /**
   * This test will tell the launch to clear the environment variables. We will then check that the
   * variable $HOME cannot be found by the program.
   */
  @Test
  public void testClearingEnvironment() throws Throwable {
    setLaunchAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, false);
    doLaunch();

    SyncUtil.runToLocation("envTest");
    MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);

    // 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.
    final IExpressionDMContext exprDmc =
        SyncUtil.createExpression(stoppedEvent.getDMContext(), "home");
    Query<FormattedValueDMData> query =
        new Query<FormattedValueDMData>() {
          @Override
          protected void execute(DataRequestMonitor<FormattedValueDMData> rm) {
            fExpService.getFormattedExpressionValue(
                fExpService.getFormattedValueContext(exprDmc, MIExpressions.DETAILS_FORMAT), rm);
          }
        };
    try {
      fExpService.getExecutor().execute(query);
      FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS);
      assertTrue(
          "Expected 0x0 but got " + value.getFormattedValue(),
          value.getFormattedValue().equals("0x0"));
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } catch (ExecutionException e) {
      fail(e.getCause().getMessage());
    } catch (TimeoutException e) {
      fail(e.getMessage());
    }
  }
  /**
   * This test will tell the launch to set some arguments for the program. We will then check that
   * the program has the same arguments.
   */
  @Test
  public void testSettingArguments() throws Throwable {
    setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "1 2 3\n4 5 6");
    doLaunch();

    MIStoppedEvent stoppedEvent = getInitialStoppedEvent();

    // Check that argc is correct
    final IExpressionDMContext argcDmc =
        SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc");
    Query<FormattedValueDMData> query =
        new Query<FormattedValueDMData>() {
          @Override
          protected void execute(DataRequestMonitor<FormattedValueDMData> rm) {
            fExpService.getFormattedExpressionValue(
                fExpService.getFormattedValueContext(argcDmc, MIExpressions.DETAILS_FORMAT), rm);
          }
        };
    try {
      fExpService.getExecutor().execute(query);
      FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS);

      // Argc should be 7: the program name and the six arguments
      assertTrue(
          "Expected 7 but got " + value.getFormattedValue(),
          value.getFormattedValue().trim().equals("7"));
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } catch (ExecutionException e) {
      fail(e.getCause().getMessage());
    } catch (TimeoutException e) {
      fail(e.getMessage());
    }

    // Check that argv is also correct.  For simplicity we only check the last argument
    final IExpressionDMContext argvDmc =
        SyncUtil.createExpression(stoppedEvent.getDMContext(), "argv[argc-1]");
    Query<FormattedValueDMData> query2 =
        new Query<FormattedValueDMData>() {
          @Override
          protected void execute(DataRequestMonitor<FormattedValueDMData> rm) {
            fExpService.getFormattedExpressionValue(
                fExpService.getFormattedValueContext(argvDmc, MIExpressions.DETAILS_FORMAT), rm);
          }
        };
    try {
      fExpService.getExecutor().execute(query2);
      FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS);
      assertTrue(
          "Expected \"6\" but got " + value.getFormattedValue(),
          value.getFormattedValue().trim().endsWith("\"6\""));
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } catch (ExecutionException e) {
      fail(e.getCause().getMessage());
    } catch (TimeoutException e) {
      fail(e.getMessage());
    }
  }
Example #6
0
 @Test
 public void writeRegisterHEXFormat() throws Throwable {
   MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
   IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
   String regValue = "0x10";
   int regIndex = 3;
   writeRegister(frameDmc, 3, regValue, IFormattedValues.HEX_FORMAT);
   String val = getModelDataForRegisterDataValue(frameDmc, IFormattedValues.HEX_FORMAT, regIndex);
   assertTrue(
       "Failed writing register. New value should have been " + regValue, regValue.equals(val));
 }
  /**
   * This test will tell the launch to "stop on main" at method stopAtOther(), which we will then
   * verify.
   */
  @Test
  public void testStopAtOther() throws Throwable {
    setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true);
    setLaunchAttribute(
        ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, "stopAtOther");
    doLaunch();

    MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
    assertTrue(
        "Expected to stop at stopAtOther but got " + stoppedEvent.getFrame().getFunction() + ":",
        stoppedEvent.getFrame().getFunction().equals("stopAtOther"));
  }
Example #8
0
 @Test
 @Ignore
 public void writeRegisterBinaryFormat() throws Throwable {
   MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
   IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
   // String regValue = "0100101001";
   String regValue = "10";
   int regIndex = 3;
   writeRegister(frameDmc, 3, regValue, IFormattedValues.BINARY_FORMAT);
   String val =
       getModelDataForRegisterDataValue(frameDmc, IFormattedValues.BINARY_FORMAT, regIndex);
   assertTrue(
       "Failed writing register. New value should have been " + regValue + " instead of " + val,
       regValue.equals(val));
 }
  /** This test will tell the launch to "stop on main" at method main(), which we will verify. */
  @Test
  public void testStopAtMain() throws Throwable {
    setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true);
    setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, "main");
    doLaunch();

    MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
    assertTrue(
        "Expected to stop at main:27 but got "
            + stoppedEvent.getFrame().getFunction()
            + ":"
            + Integer.toString(stoppedEvent.getFrame().getLine()),
        stoppedEvent.getFrame().getFunction().equals("main")
            && stoppedEvent.getFrame().getLine() == 27);
  }
Example #10
0
  @Test
  public void getRegisters() throws Throwable {
    MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
    IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
    final IRegisterDMContext[] regDMCs = getRegisters(frameDmc);
    List<String> regNames = get_X86_REGS();

    Query<IRegisterDMData[]> query =
        new Query<IRegisterDMData[]>() {
          @Override
          protected void execute(DataRequestMonitor<IRegisterDMData[]> rm) {
            final IRegisterDMData[] datas = new IRegisterDMData[regDMCs.length];
            rm.setData(datas);
            final CountingRequestMonitor countingRm = new ImmediateCountingRequestMonitor(rm);
            countingRm.setDoneCount(regDMCs.length);
            for (int i = 0; i < regDMCs.length; i++) {
              final int index = i;
              fRegService.getRegisterData(
                  regDMCs[index],
                  new ImmediateDataRequestMonitor<IRegisterDMData>(countingRm) {
                    @Override
                    protected void handleSuccess() {
                      datas[index] = getData();
                      countingRm.done();
                    }
                  });
            }
          }
        };

    fSession.getExecutor().execute(query);

    IRegisterDMData[] datas = query.get();

    for (IRegisterDMData data : datas) {
      String regName = data.getName();
      Assert.assertFalse(
          "GDB does not support register name: " + regName, !regNames.contains(regName));
    }
  }
Example #11
0
  @Test
  public void compareRegisterForMultipleExecutionContexts() throws Throwable {

    // Run past the line that creates a thread and past the sleep that
    // follows it. This is a bit tricky because the code that creates the
    // thread is conditional depending on environment. Run to the printf
    // before it (which is common), then do step operations over the
    // non-common code (but same number of lines)
    SyncUtil.runToLine(SRC_NAME, Integer.toString(MIRunControlTest.LINE_MAIN_PRINTF));
    SyncUtil.step(StepType.STEP_OVER); // over the printf
    SyncUtil.step(StepType.STEP_OVER); // over the create-thread call
    MIStoppedEvent stoppedEvent =
        SyncUtil.step(
            StepType.STEP_OVER, TestsPlugin.massageTimeout(2000)); // over the one second sleep

    // Get the thread IDs
    final IContainerDMContext containerDmc =
        DMContexts.getAncestorOfType(stoppedEvent.getDMContext(), IContainerDMContext.class);

    final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();
    final DataRequestMonitor<IExecutionDMContext[]> drm =
        new DataRequestMonitor<IExecutionDMContext[]>(fRegService.getExecutor(), null) {
          @Override
          protected void handleCompleted() {
            if (isSuccess()) {
              wait.setReturnInfo(getData());
            }
            wait.waitFinished(getStatus());
          }
        };

    fRegService
        .getExecutor()
        .submit(
            new Runnable() {
              public void run() {
                fRunControl.getExecutionContexts(containerDmc, drm);
              }
            });
    wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
    Assert.assertTrue(wait.getMessage(), wait.isOK());

    IExecutionDMContext[] ctxts = (IExecutionDMContext[]) wait.getReturnInfo();
    wait.waitReset();

    Assert.assertNotNull(ctxts);
    Assert.assertTrue(ctxts.length > 1);

    int tid1 = ((IMIExecutionDMContext) ctxts[0]).getThreadId();
    int tid2 = ((IMIExecutionDMContext) ctxts[1]).getThreadId();

    // Get execution context to thread 2
    IExecutionDMContext execDmc = SyncUtil.createExecutionContext(containerDmc, tid2);
    IFrameDMContext frameDmc2 = SyncUtil.getStackFrame(execDmc, 0);

    String thread2RegVal0 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 0);
    String thread2RegVal1 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 1);
    String thread2RegVal2 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 2);
    String thread2RegVal3 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 3);
    String thread2RegVal4 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 4);
    String thread2RegVal5 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 5);

    // Get execution context to thread 1
    execDmc = SyncUtil.createExecutionContext(containerDmc, tid1);
    IFrameDMContext frameDmc1 = SyncUtil.getStackFrame(execDmc, 0);
    getModelDataForRegisterDataValue(frameDmc1, IFormattedValues.NATURAL_FORMAT, 0);

    // Re-set the execution context to 2 and Fetch from the Cache
    String dupliThread2RegVal0 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 0);
    String dupliThread2RegVal1 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 1);
    String dupliThread2RegVal2 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 2);
    String dupliThread2RegVal3 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 3);
    String dupliThread2RegVal4 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 4);
    String dupliThread2RegVal5 =
        getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 5);

    // If Values not equal , then context haven't been re-set properly
    assertTrue(
        "Multiple context not working. Execution Context is not reset to 2",
        thread2RegVal0.equals(dupliThread2RegVal0));
    assertTrue(
        "Multiple context not working. Execution Context is not reset to 2",
        thread2RegVal1.equals(dupliThread2RegVal1));
    assertTrue(
        "Multiple context not working. Execution Context is not reset to 2",
        thread2RegVal2.equals(dupliThread2RegVal2));
    assertTrue(
        "Multiple context not working. Execution Context is not reset to 2",
        thread2RegVal3.equals(dupliThread2RegVal3));
    assertTrue(
        "Multiple context not working. Execution Context is not reset to 2",
        thread2RegVal4.equals(dupliThread2RegVal4));
    assertTrue(
        "Multiple context not working. Execution Context is not reset to 2",
        thread2RegVal5.equals(dupliThread2RegVal5));
  }
  /**
   * This test will tell the launch to set some arguments for the program. We will then check that
   * the program has the same arguments. See bug 381804
   */
  @Test
  public void testSettingArgumentsWithSymbols() throws Throwable {
    // Set a argument with double quotes and spaces, which should be considered a single argument
    String argumentToPreserveSpaces = "--c=\"c < s: 'a' t: 'b'>\"";
    String argumentUsedByGDB = "\"--c=c < s: 'a' t: 'b'>\"";

    setLaunchAttribute(
        ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, argumentToPreserveSpaces);
    doLaunch();

    MIStoppedEvent stoppedEvent = getInitialStoppedEvent();

    // Check that argc is correct
    final IExpressionDMContext argcDmc =
        SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc");
    Query<FormattedValueDMData> query =
        new Query<FormattedValueDMData>() {
          @Override
          protected void execute(DataRequestMonitor<FormattedValueDMData> rm) {
            fExpService.getFormattedExpressionValue(
                fExpService.getFormattedValueContext(argcDmc, MIExpressions.DETAILS_FORMAT), rm);
          }
        };
    try {
      fExpService.getExecutor().execute(query);
      FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS);

      // Argc should be 2: the program name and the one arguments
      assertTrue(
          "Expected 2 but got " + value.getFormattedValue(),
          value.getFormattedValue().trim().equals("2"));
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } catch (ExecutionException e) {
      fail(e.getCause().getMessage());
    } catch (TimeoutException e) {
      fail(e.getMessage());
    }

    // Check that argv is also correct.
    final IExpressionDMContext argvDmc =
        SyncUtil.createExpression(stoppedEvent.getDMContext(), "argv[argc-1]");
    Query<FormattedValueDMData> query2 =
        new Query<FormattedValueDMData>() {
          @Override
          protected void execute(DataRequestMonitor<FormattedValueDMData> rm) {
            fExpService.getFormattedExpressionValue(
                fExpService.getFormattedValueContext(argvDmc, MIExpressions.DETAILS_FORMAT), rm);
          }
        };
    try {
      fExpService.getExecutor().execute(query2);
      FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS);
      assertTrue(
          "Expected \"" + argumentUsedByGDB + "\" but got " + value.getFormattedValue(),
          value.getFormattedValue().trim().endsWith(argumentUsedByGDB));
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } catch (ExecutionException e) {
      fail(e.getCause().getMessage());
    } catch (TimeoutException e) {
      fail(e.getMessage());
    }
  }
  /**
   * This test will tell the launch to set a new environment variable LAUNCHTEST. We will then check
   * that this new variable can be read by the program.
   */
  @Test
  public void testSettingEnvironment() throws Throwable {
    setLaunchAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);

    Map<String, String> map = new HashMap<String, String>(1);
    map.put("LAUNCHTEST", "IS SET");
    setLaunchAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
    doLaunch();

    SyncUtil.runToLocation("envTest");
    MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);

    // The program has stored the content of $LAUNCHTEST into a variable called 'launchTest'.
    // Let's verify this variable is set to "IS SET".
    final IExpressionDMContext exprDmc =
        SyncUtil.createExpression(stoppedEvent.getDMContext(), "launchTest");
    Query<FormattedValueDMData> query =
        new Query<FormattedValueDMData>() {
          @Override
          protected void execute(DataRequestMonitor<FormattedValueDMData> rm) {
            fExpService.getFormattedExpressionValue(
                fExpService.getFormattedValueContext(exprDmc, MIExpressions.DETAILS_FORMAT), rm);
          }
        };
    try {
      fExpService.getExecutor().execute(query);
      FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS);
      assertTrue(
          "Expected a string ending with \"IS SET\" but got " + value.getFormattedValue(),
          value.getFormattedValue().trim().endsWith("\"IS SET\""));
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } catch (ExecutionException e) {
      fail(e.getCause().getMessage());
    } catch (TimeoutException e) {
      fail(e.getMessage());
    }

    // Check that the normal environment is there by checking that $HOME (which is stored in 'home"
    // exists.
    final IExpressionDMContext exprDmc2 =
        SyncUtil.createExpression(stoppedEvent.getDMContext(), "home");
    Query<FormattedValueDMData> query2 =
        new Query<FormattedValueDMData>() {
          @Override
          protected void execute(DataRequestMonitor<FormattedValueDMData> rm) {
            fExpService.getFormattedExpressionValue(
                fExpService.getFormattedValueContext(exprDmc2, MIExpressions.DETAILS_FORMAT), rm);
          }
        };
    try {
      fExpService.getExecutor().execute(query2);
      FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS);
      assertFalse("Expected something else than 0x0", value.getFormattedValue().equals("0x0"));
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } catch (ExecutionException e) {
      fail(e.getCause().getMessage());
    } catch (TimeoutException e) {
      fail(e.getMessage());
    }
  }
 @Test
 public void getFullPath() throws Throwable {
   doLaunch();
   MIStoppedEvent stopped = getInitialStoppedEvent();
   fFullProgramPath = stopped.getFrame().getFullname();
 }