Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bytemanproject/byteman
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed Jul 25, 2012
2 parents 69958cb + 92a4704 commit f6ada62
Showing 1 changed file with 35 additions and 8 deletions.
Expand Up @@ -163,17 +163,44 @@ public void setRedirectedSubmissionsFile(File redirectedSubmissionsFile)
* @throws Exception in case of failure.
*/
public void injectOnCall(Class clazz, String methodName, String action) throws Exception
{
injectOnMethod(clazz, methodName, "true", action, "ENTRY");
}

/**
* Inject an action to take place upon exit of the specified class.method
*
* @param clazz The Class in which the injection point resides.
* @param methodName The method which should be intercepted.
* @param action The action that should take place upon invocation of the method.
* @throws Exception in case of failure.
*/
public void injectOnExit(Class clazz, String methodName, String action) throws Exception
{
injectOnMethod(clazz, methodName, "true", action, "EXIT");
}

/**
* Inject an action to take place at a given point within the specified class.method
*
* @param clazz The Class in which the injection point resides.
* @param methodName The method which should be intercepted.
* @param action The action that should take place upon invocation of the method.
* @param where the injection point e.g. "ENTRY".
* @throws Exception in case of failure.
*/
public void injectOnMethod(Class clazz, String methodName, String condition, String action, String where) throws Exception
{
String className = clazz.getCanonicalName();
String ruleName = this.getClass().getCanonicalName()+"_"+className+"_"+methodName+"_callinjection";
String ruleName = this.getClass().getCanonicalName()+"_"+className+"_"+methodName+"_injectionat"+where;

RuleBuilder ruleBuilder = new RuleBuilder(ruleName);
ruleBuilder.onClass(className).inMethod(methodName).atEntry();
ruleBuilder.onClass(className).inMethod(methodName).at(where);
ruleBuilder.usingHelper(BytemanTestHelper.class);
ruleBuilder.whenTrue().doAction(action);
ruleBuilder.when(condition).doAction(action);

String ruleText = ruleBuilder.toString();
installScript("onCall"+className+"."+methodName, ruleText);
installScript("onCall"+className+"."+methodName+"."+where, ruleText);
}

/**
Expand Down Expand Up @@ -282,7 +309,7 @@ public void crashAtMethodEntry(String className, String methodName) throws Excep
*/
public void crashAtMethod(String className, String methodName, String where) throws Exception
{
String ruleName = this.getClass().getCanonicalName()+"_"+className+"_"+methodName+"_crashatexit";
String ruleName = this.getClass().getCanonicalName()+"_"+className+"_"+methodName+"_crashat"+where;

String action = "debug(\"killing JVM\"), killJVM()";

Expand All @@ -291,7 +318,7 @@ public void crashAtMethod(String className, String methodName, String where) thr
ruleBuilder.usingHelper(BytemanTestHelper.class);
ruleBuilder.whenTrue().doAction(action);

installScript("crash"+className+"."+methodName, ruleBuilder.toString());
installScript("crash"+className+"."+methodName+"."+where, ruleBuilder.toString());
}

/**
Expand All @@ -303,7 +330,7 @@ public void crashAtMethod(String className, String methodName, String where) thr
* @param scriptString The text of the script i.e. one or more Rules.
* @throws Exception in case of failure.
*/
private void installScript(String scriptName, String scriptString)
public void installScript(String scriptName, String scriptString)
throws Exception
{
System.out.println("installing: "+scriptString);
Expand Down Expand Up @@ -407,4 +434,4 @@ public void removeAllInstrumentation() throws Exception
submit.deleteScripts(installedScripts);
removeLocalState();
}
}
}

0 comments on commit f6ada62

Please sign in to comment.