 |
 |
 |
 |
|
|
-
Launch StackTrace. (Please read our Licensing terms.)
From the Process menu select Thread Dump. Enter the target Process ID or use the "..." button to select one.
Use at least one or a combination of the following options:
- Thread dump - returns a thread dump of the target process.
- Use Ctrl-Break - Sends QUIT signal to the process. Do not use this option if your process was started with the -Xrs VM option (a Windows service for example) because the process will exit.
- System properties - returns System.getProperties() for the target process.
- Memory usage - returns Runtime.freeMemory(), Runtime.totalMemory(), and Runtime.maxMemory().
- Process command line - returns the command line used to start the target process.
- Force GC - calls System.gc() inside the target process.
- Create console - creates a console for a process if it does not have one.
- Keep remote thread running - creates a remote thread in the target process which waits for an event to make a thread dump.
It helps when the regular thread dump procedure cannot be executed because of the system global locks.
The result of the selected operations will appear inside the StackTrace editor window.
The current version of the product supports JDKs 1.1 through 6.0 on Windows, JDKs 1.3 through 5.0 on Mac OS X (PPC only),and JDKs 1.4 through 6.0 on Linux x86.
It cannot work with processes started in a different session under Windows Terminal Server Environment.
The standalone version provides a service with a web based UI and command line tools which can be used as a workaround for this problem.
This issue can be avoided by using VNC or PCAnywhere or starting the Remote Client with the console option: mstsc.exe /console
-
Due to limitations in the Windows debugging API, it is not possible to run StackTrace in one session and get a thread dump from a process running in a different session. This is a common scenario when an application is running as a service and the user starts StackTrace by using Remote client to a Terminal server.
The easiest way to get around this limitation is by using the StackTrace service from version 2.0+. It is running in session 0, so it should not be a problem getting thread dumps or any other information from processes in the same session.
It is also possible to run the Remote client in session 0: mstsc.exe /console
The console argument is supported only for Windows XP or higher.
-
First you have to download and install the standalone version of StackTrace.
It has to be installed on the computer where you intend to use it.
Copy the System ID from the License dialog of the tool. From a computer with Internet access open the following URL
http://www.adaptj.com/download/evaluate/2.5.15
Enter the System ID in the text field and press the request button. You will receive an email with the license information.
-
When StackTrace fails to work, please send a bug report to support@adaptj.com, check the support forums for possible solutions, or enter a new case here.
The following information will be useful:
1. What is your OS?
2. What JDK were you using?
3. Do you use a remote client and a Terminal server?
4. The error message from the editor and the output from the DebugView tool.
-
With StackTrace you can record and replay the mouse and the key events for a Java application.
Start a BeanShell console for the target process.
From the Process menu select Scripts... Enter the target process ID and select <Open BeanShell console>. In the console type:
bsh % m = awtMacro();
bsh % m.record();
Press <Enter> to stop recording.
Use the mouse or the keyboard to execute some commands inside the target application. Go back to the console and press <Enter> to stop recording.
The recorded commands can be replayed by using the macro object.
bsh % m.play();
To print the recorded script:
bsh % m.print();
The script is actually a regular Java class which can be saved, edited, and loaded again.
To print all available methods and properties:
bsh % m.help();
For SWT use swtMacro().
-
StackTrace can print all AWT events for a running application. First you have to start a BeanShell console for the target process.
From the Process menu select Scripts... Enter the target process ID and select <Open BeanShell console>.
In the console type:
bsh % dumpAwtEvents(-1);
Press <Enter> to stop the event listener
The events will be printed in the console till you press <Enter>
DumpAwtEvents accepts one parameter. It is a bit mask of the event types declared in java.awt.AWTEvent.
For example: dumpAwtEvents(java.awt.AWTEvent.WINDOW_EVENT_MASK|java.awt.AWTEvent.PAINT_EVENT_MASK); will print only the paint and the window events. Value of -1 means all events.
-
With StackTrace you can call methods or change properties on any object instance by using the BeanShell scripting language. The interpreter is being injected and it runs inside the target process.
In order to get a reference to a UI component you can use the selectOnRelease or selectOnEnter commands.
In the console type:
bsh % c = selectOnRelease();
Press <Enter> to select the last component.
Now click on the target component. Press <Enter> in the console. The variable c is a reference to the component instance. It can be used to change its color for example c.setBackground(java.awt.Color.RED).
-
With StackTrace you can take a snapshot of a component into an offscreen buffer
and then save it to a file in JPEG format.
First you have to start a BeanShell console for the target process.
From the Process menu select Scripts... Enter the target process ID and select <Open BeanShell console>. In the console type:
bsh % c = selectOnRelease();
Press <Enter> to select the last component.
java.awt.TextField[textfield0,105,3,271x23,text=,editable,selection=0-0]
Now click on the target component. Press <Enter> in the console. The variable c is a reference to the component instance.
bsh % snapshot(c, new java.io.File("/tmp/image.jpg"));
-
StackTrace 2.0 introduces an experimental command line tool (launch.exe) which can be used instead of the standard JDK launcher (java.exe or javaw.exe). It takes the target process ID as an additional parameter. For example the following Java program:
java -classpath myjar1.jar;myjar2.jar some.package.Main
Can be started inside an already running JVM like this:
launch -classpath myjar1.jar;myjar2.jar {pid} some.package.Main
Where {pid} is the ID of the target process.
-
Please, read the following article to understand why it is not a good idea to stop/suspend threads in Java - Why is Thread.stop deprecated?
If you still want to do it here is how:
Start a BeanShell console inside the target process. Get a reference to the thread object by using the StackTrace threads command.
bsh % threads();
It returns and array of all active threads inside the process. Invoke the desired method call:
bsh % threads()[5].suspend();
-
This functionality is available only with JDK 6 or higher.
Attach the BeanShell console to the target process. Locate the class object you want to patch. The easiest way to do that is by using instrument().getAllLoadedClasses(). This command returns an array of all currently loaded classes.
If the variable clazz is a reference to the class object being replaced, the following command will load the new class:
bsh % redefine(clazz, read($file("C:/temp/classes/com/test/MyClass.class")));
The following command will load back the old class:
bsh % redefine(clazz);
The redefinition may change method bodies, the constant pool and attributes. The redefinition must not add, remove or rename fields or methods, change the signatures of methods, or change inheritance. These restrictions may be lifted in future versions of the JDK. The class file bytes are not checked, verified and installed until after the transformations have been applied. If the resultant bytes are in error, this method will throw an exception.
If this method throws an exception, no classes have been redefined.
-
There are plenty of IDEs and standalone debuggers for Java but almost all of them suffer from the limitations of JPDA. The regular Java debugger cannot attach to an already running application if it is not started in debug mode.
It is not possible to see or change the stack, the local variables (if there is no debug information), and the execution flow.
StackTrace does not have a pretty GUI for that but it does provide all the missing functionality.
Here is a summary of the StackTrace debugging features:
- attach to an already running application (Java 6 and higher)
- set method breakpoints
- step over the bytecode
- display the method stack and local variables
- modify the method stack and local variables
- change the execution flow (skip lines)
- execute additional bytecode instructions
- modify the return value and ignore exceptions
Attach the remote console to your target application and use the breakpoint command. Type help("breakpoint"); in the console for more information.
|
|
 |
|