mirror of https://github.com/mchr3k/org.intrace
List classes button, Example ant target
This commit is contained in:
parent
e8075a07d1
commit
b6a1da985d
Binary file not shown.
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 86 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="lib/traceagent.jar" sourcepath="/org.intrace"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="genbin"/>
|
||||
<classpathentry kind="lib" path="lib/tools.jar"/>
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -1,55 +0,0 @@
|
|||
package org.intrace.sandbox;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TraceExample
|
||||
{
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
otherMain("123");
|
||||
}
|
||||
|
||||
public static void otherMain(String arg) throws Exception
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
InnerTest.foo();
|
||||
workMethod("foobar");
|
||||
}
|
||||
}
|
||||
|
||||
private static void workMethod(String foo)
|
||||
{
|
||||
long currentTime = System.currentTimeMillis();
|
||||
System.setProperty("a",foo);
|
||||
intArrayMethod(new int[] {1,2,3});
|
||||
if ((currentTime % 2) == 0)
|
||||
{
|
||||
System.setProperty("a","Even time");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.setProperty("a","Odd time");
|
||||
}
|
||||
}
|
||||
|
||||
private static void intArrayMethod(int[] intArg)
|
||||
{
|
||||
System.setProperty("a",Arrays.toString(intArg));
|
||||
}
|
||||
|
||||
private static class InnerTest
|
||||
{
|
||||
private static void foo()
|
||||
{
|
||||
System.setProperty("a","bar");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
package org.test.intrace;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.jdi.Bootstrap;
|
||||
import com.sun.jdi.Field;
|
||||
import com.sun.jdi.IncompatibleThreadStateException;
|
||||
import com.sun.jdi.LocalVariable;
|
||||
import com.sun.jdi.ReferenceType;
|
||||
import com.sun.jdi.StackFrame;
|
||||
import com.sun.jdi.ThreadReference;
|
||||
import com.sun.jdi.VirtualMachine;
|
||||
import com.sun.jdi.VirtualMachineManager;
|
||||
import com.sun.jdi.connect.AttachingConnector;
|
||||
import com.sun.jdi.connect.Connector.Argument;
|
||||
|
||||
public class DebugTest
|
||||
{
|
||||
private static final String field = "Foo";
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int ii = 10;
|
||||
threadID(Thread.currentThread().getId());
|
||||
System.out.println(ii);
|
||||
System.out.println(field);
|
||||
}
|
||||
|
||||
private static void threadID(long id)
|
||||
{
|
||||
Thread dbg = new Thread(new Debugger(Thread.currentThread().getId(),
|
||||
Thread.currentThread().getName()));
|
||||
dbg.start();
|
||||
try
|
||||
{
|
||||
dbg.join();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
// Throw away
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Debugger implements Runnable
|
||||
{
|
||||
private final String name;
|
||||
private final long id;
|
||||
|
||||
public Debugger(long id, String name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
|
||||
List<AttachingConnector> connectors = vmm.attachingConnectors();
|
||||
for (AttachingConnector connector : connectors)
|
||||
{
|
||||
if (connector.name().contains("SocketAttach"))
|
||||
{
|
||||
try
|
||||
{
|
||||
Map<String, Argument> args = connector.defaultArguments();
|
||||
args.get("hostname").setValue("localhost");
|
||||
args.get("port").setValue("8000");
|
||||
VirtualMachine vm = connector.attach(args);
|
||||
useVM(vm);
|
||||
vm.dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void useVM(VirtualMachine vm)
|
||||
{
|
||||
List<ThreadReference> threads = vm.allThreads();
|
||||
for (ThreadReference thread : threads)
|
||||
{
|
||||
if (name.equals(thread.name()))
|
||||
{
|
||||
thread.suspend();
|
||||
try
|
||||
{
|
||||
int ii = 0;
|
||||
for (StackFrame frame : thread.frames())
|
||||
{
|
||||
if (matchingFrame(frame))
|
||||
{
|
||||
StackFrame callingFrame = thread.frame(ii + 1);
|
||||
useFrame(callingFrame);
|
||||
}
|
||||
ii++;
|
||||
}
|
||||
thread.resume();
|
||||
}
|
||||
catch (IncompatibleThreadStateException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchingFrame(StackFrame frame)
|
||||
{
|
||||
if ("threadID".equals(frame.location().method().name())
|
||||
&& (frame.getArgumentValues().size() == 1)
|
||||
&& (frame.getArgumentValues().get(0).toString()
|
||||
.equals(Long
|
||||
.toString(id))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void useFrame(StackFrame frame)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.out.println("Fields:");
|
||||
ReferenceType type = frame.location().declaringType();
|
||||
for (Field field : type.fields())
|
||||
{
|
||||
System.out.println(field.name() + " => " + type.getValue(field));
|
||||
}
|
||||
System.out.println("\nLocal Variables:");
|
||||
for (LocalVariable variable : frame.visibleVariables())
|
||||
{
|
||||
if (!variable.isArgument())
|
||||
{
|
||||
System.out.println(variable.name() + " => "
|
||||
+ frame.getValue(variable));
|
||||
}
|
||||
}
|
||||
System.out.println("\nDone\n");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -167,13 +167,23 @@
|
|||
</target>
|
||||
|
||||
|
||||
<target name="example" depends="jar">
|
||||
<java classname="org.example.intrace.TraceExample" fork="true">
|
||||
<arg value="" />
|
||||
<classpath>
|
||||
<pathelement path="./build/test" />
|
||||
</classpath>
|
||||
<jvmarg value="-javaagent:build/jars/traceagent.jar=[instru-true" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="findbugs" depends="jar">
|
||||
|
||||
<mkdir dir="./reports/findbugs" />
|
||||
|
||||
<!-- Findbugs Trace Agent -->
|
||||
<jar destfile="./reports/findbugs/traceagent_findbugs.jar" compress="false" manifest="conf/META-INF/MANIFEST.MF">
|
||||
<!-- Build Findbugs Trace Agent (Don't include ASM classes) -->
|
||||
<jar destfile="./reports/findbugs/traceagent_findbugs.jar" compress="false" manifest="conf/META-INF/MANIFEST.MF">
|
||||
<fileset dir="./build/classes" includes="**/agent/**/*.class" />
|
||||
<fileset dir="./build/classes" includes="**/output/**/*.class" />
|
||||
<fileset dir="./build/classes" includes="**/shared/*.class" />
|
||||
|
|
@ -190,11 +200,7 @@
|
|||
<sourcePath path="./src" />
|
||||
<class location="./reports/findbugs/traceagent_findbugs.jar" />
|
||||
</findbugs>
|
||||
|
||||
</target>
|
||||
|
||||
|
||||
|
||||
<target name="deploy" description="Copy agent jar to another project" depends="build, test, jar" >
|
||||
<copy file="./build/jars/traceagent.jar" tofile="../org.intrace.test/lib/traceagent.jar" overwrite="true" />
|
||||
</target>
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
@ -11,6 +11,7 @@ import java.lang.instrument.Instrumentation;
|
|||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.security.CodeSource;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -230,11 +231,13 @@ public class ClassTransformer implements ClassFileTransformer
|
|||
}
|
||||
catch (RuntimeException th)
|
||||
{
|
||||
// Ensure the JVM doesn't silently swallow an unchecked exception
|
||||
th.printStackTrace();
|
||||
throw th;
|
||||
}
|
||||
catch (Error th)
|
||||
{
|
||||
// Ensure the JVM doesn't silently swallow an unchecked exception
|
||||
th.printStackTrace();
|
||||
throw th;
|
||||
}
|
||||
|
|
@ -395,6 +398,7 @@ public class ClassTransformer implements ClassFileTransformer
|
|||
*/
|
||||
public List<String> getResponse(String message)
|
||||
{
|
||||
List<String> responses = new ArrayList<String>();
|
||||
AgentSettings oldSettings = new AgentSettings(settings);
|
||||
settings.parseArgs(message);
|
||||
|
||||
|
|
@ -430,7 +434,13 @@ public class ClassTransformer implements ClassFileTransformer
|
|||
retransformModifiedClasses();
|
||||
instrumentLoadedClasses();
|
||||
}
|
||||
else if (message.equals("[listmodifiedclasses"))
|
||||
{
|
||||
responses.add(modifiedClasses.toString());
|
||||
}
|
||||
|
||||
return AgentHelper.getResponses(message);
|
||||
responses.addAll(AgentHelper.getResponses(message));
|
||||
|
||||
return responses;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public class ClientStrings
|
|||
public static final String DISABLE_SAVECLASSES = "Don't Save Classes";
|
||||
public static final String ENABLE_VERBOSEMODE = "Enable Verbose Mode";
|
||||
public static final String DISABLE_VERBOSEMODE = "Disable Verbose Mode";
|
||||
public static final String LIST_MODIFIED_CLASSES = "List Modifed Classes";
|
||||
|
||||
public static final String ENABLE_EE_TRACE = "Enable Entry/Exit Trace";
|
||||
public static final String DISABLE_EE_TRACE = "Disable Entry/Exit Trace";
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ public class TraceWindow
|
|||
private Button toggleAllowJarInstru = null;
|
||||
private Button toggleSaveClassFiles = null;
|
||||
private Button toggleVerboseMode = null;
|
||||
private Button listModifiedClasses = null;
|
||||
private Button toggleFileOutputButton = null;
|
||||
private Button toggleNetworkTraceButton = null;
|
||||
private TabFolder outputTabFolder = null;
|
||||
|
|
@ -168,6 +169,18 @@ public class TraceWindow
|
|||
"[verbose-true", "[verbose-false");
|
||||
}
|
||||
});
|
||||
listModifiedClasses = new Button(sShell, SWT.LEFT);
|
||||
listModifiedClasses.setText(ClientStrings.LIST_MODIFIED_CLASSES);
|
||||
listModifiedClasses.setLayoutData(gridData);
|
||||
listModifiedClasses
|
||||
.addMouseListener(new org.eclipse.swt.events.MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseUp(org.eclipse.swt.events.MouseEvent e)
|
||||
{
|
||||
getModifiedClasses();
|
||||
}
|
||||
});
|
||||
traceSettingsLabel = new Label(sShell, SWT.NONE);
|
||||
traceSettingsLabel.setText("Trace Settings:");
|
||||
sShell.addShellListener(new org.eclipse.swt.events.ShellAdapter()
|
||||
|
|
@ -274,20 +287,21 @@ public class TraceWindow
|
|||
clearTextButton = new Button(sShell, SWT.LEFT);
|
||||
clearTextButton.setText("Clear Text");
|
||||
clearTextButton.setLayoutData(gridData);
|
||||
clearTextButton
|
||||
.addMouseListener(new org.eclipse.swt.events.MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseUp(org.eclipse.swt.events.MouseEvent e)
|
||||
{
|
||||
sShell.getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
statusTextArea.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
clearTextButton.addMouseListener(new org.eclipse.swt.events.MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseUp(org.eclipse.swt.events.MouseEvent e)
|
||||
{
|
||||
sShell.getDisplay().asyncExec(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
statusTextArea.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
toggleNetworkTraceButton
|
||||
.addMouseListener(new org.eclipse.swt.events.MouseAdapter()
|
||||
{
|
||||
|
|
@ -356,7 +370,7 @@ public class TraceWindow
|
|||
gridData3.grabExcessVerticalSpace = true;
|
||||
gridData3.heightHint = 99999;
|
||||
gridData3.widthHint = 99999;
|
||||
gridData3.verticalSpan = 21;
|
||||
gridData3.verticalSpan = 22;
|
||||
gridData3.grabExcessHorizontalSpace = true;
|
||||
composite = new Composite(sShell, SWT.NONE);
|
||||
composite.setLayoutData(gridData3);
|
||||
|
|
@ -379,7 +393,7 @@ public class TraceWindow
|
|||
callersTree = new Tree(outputTabFolder, SWT.BORDER);
|
||||
callersTreeRoot = new TreeItem(callersTree, SWT.NULL);
|
||||
callersTreeRoot.setText("Callers");
|
||||
|
||||
|
||||
textOutputTabItem = new TabItem(outputTabFolder, SWT.NONE);
|
||||
textOutputTabItem.setControl(statusTextArea);
|
||||
textOutputTabItem.setText("Text Output");
|
||||
|
|
@ -392,11 +406,11 @@ public class TraceWindow
|
|||
{
|
||||
Rectangle parentSize = parent.getBounds();
|
||||
Rectangle mySize = shell.getBounds();
|
||||
|
||||
|
||||
int locationX, locationY;
|
||||
locationX = (parentSize.width - mySize.width) / 2 + parentSize.x;
|
||||
locationY = (parentSize.height - mySize.height) / 2 + parentSize.y;
|
||||
|
||||
|
||||
shell.setLocation(new Point(locationX, locationY));
|
||||
shell.open();
|
||||
}
|
||||
|
|
@ -492,6 +506,42 @@ public class TraceWindow
|
|||
});
|
||||
}
|
||||
|
||||
private void getModifiedClasses()
|
||||
{
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
controlThread.sendMessage("[listmodifiedclasses");
|
||||
String modifiedClasses = controlThread.getMessage();
|
||||
if (modifiedClasses.length() <= 2)
|
||||
{
|
||||
addMessage("*** No modified classes");
|
||||
}
|
||||
else
|
||||
{
|
||||
modifiedClasses = modifiedClasses
|
||||
.substring(
|
||||
1,
|
||||
modifiedClasses.length() - 1);
|
||||
if (modifiedClasses.indexOf(",") == -1)
|
||||
{
|
||||
addMessage("*** Modified: " + modifiedClasses);
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] classNames = modifiedClasses.split(",");
|
||||
for (String className : classNames)
|
||||
{
|
||||
addMessage("*** Modified: " + className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void setRegex(final String regex)
|
||||
{
|
||||
sShell.getDisplay().asyncExec(new Runnable()
|
||||
|
|
@ -578,6 +628,7 @@ public class TraceWindow
|
|||
chooseText(toggleVerboseMode, settingsData.verboseMode,
|
||||
ClientStrings.ENABLE_VERBOSEMODE,
|
||||
ClientStrings.DISABLE_VERBOSEMODE);
|
||||
listModifiedClasses.setEnabled(true);
|
||||
|
||||
chooseText(toggleEntryExitButton, settingsData.entryExitEnabled,
|
||||
ClientStrings.ENABLE_EE_TRACE,
|
||||
|
|
@ -623,17 +674,18 @@ public class TraceWindow
|
|||
toggleAllowJarInstru.setEnabled(false);
|
||||
toggleSaveClassFiles.setEnabled(false);
|
||||
toggleVerboseMode.setEnabled(false);
|
||||
|
||||
listModifiedClasses.setEnabled(false);
|
||||
|
||||
toggleEntryExitButton.setEnabled(false);
|
||||
toggleBranchButton.setEnabled(false);
|
||||
toggleArgsButton.setEnabled(false);
|
||||
|
||||
|
||||
callersStateButton.setEnabled(false);
|
||||
|
||||
|
||||
toggleStdOutButton.setEnabled(false);
|
||||
toggleFileOutputButton.setEnabled(false);
|
||||
toggleNetworkTraceButton.setEnabled(false);
|
||||
|
||||
|
||||
dumpSettingsButton.setEnabled(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.test.intrace;
|
||||
package org.example.intrace;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
Loading…
Reference in New Issue