Simple use of jdb

Source: Internet
Author: User
Tags jconsole
    • JDK built-in tools
    • Use jdb

 

Original article: http://blog.csdn.net/fenglibing/article/details/6411999

JDK built-in tools

I. javahCommand(C header and stub file generator)

Ii. JPsCommand(Java Virtual Machine Process status tool)

Iii. jstackCommand(Java stack trace)

Iv. jstatCommand(Java Virtual Machine statistics monitoring tool)

V. jmapCommand(Java memory map)

Vi. jinfoCommand(Java configuration info)

VII. jconsoleCommand(Java Monitoring and Management Console)

8. jvisualvmCommand(Java Virtual Machine Monitoring, troubleshooting, and profiling tool)

9. jhatCommand(Java heap analyse tool)

10. jdbCommand(The Java debugger)

11. References

Http://www.renren.it/a/JAVAbiancheng/JAVAzonghe/20110511/jni-example.html

Http://blog.csdn.net/gtuu0123/archive/2010/11/27/6039474.aspx

Http://blog.csdn.net/kelly859/archive/2010/07/30/5775318.aspx

Http://www.51testing.com /? Uid-77492-action-viewspace-itemid-203728

Http://blog.csdn.net/dengmc/archive/2009/05/13/4174738.aspx

Http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html

Http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jstat.html

Http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jmap.html

Http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html

 

Original article: http://www.ibm.com/developerworks/cn/java/joy-jdb/index.html

 

First, let's write a simple smallProgramBut it contains some basic object-oriented elements.

Class test {int A; int B; test (int aa, int bb) {A = AA; B = BB;} int add () {return a + B ;}} public class hehe {public static void main (string ARGs []) {int A = 2; int B = 3; int c = a + B; system. out. println (c); test KK = new test (1, 2); system. out. println (KK. add ());}}

 

 

After saving as hehe. Java, use javac-G hehe. Java for compilation. The parameter G is used to generate various debugging information and cannot be debugged without any need. If you have any problems, please refer to the helloworld strategy. The above program can be passed and can be run directly using Java hehe. The following uses this example to describe how to use jdb.

First, type jdb hehe. If the following information is displayed, the debugging class is not found. You can use the Java-classpath. Hehe command to solve the problem.

C: \ javasource> jdb heheheinitializing jdb... hehe not found>

 

 

If a message is displayed, Debugging starts and everything is normal. To debug the applet, run the appletviewer-Debug hehehe.html command.

C: \ javasource> jdb-classpath. heheinitializing jdb... 0xb0: Class (hehe)>

 

 

Recall that the debugging in VC should be to set the breakpoint before tracking. The same is true in Java. Use the Stop command to set breakpoints. Run the Run Command to start debugging and run the program to the breakpoint. the breakpoint is set in the main function.

> Stop at hehe: 18 breakpoint set at hehe: 18> runrun heherunning... main [1] breakpoint hit: Hehe. Main (hehe: 18) Main [1]

 

 

In this case, you can use the locals command to view the variables, use the step command to enter the next command, or use a separate Stop command to view the breakpoint settings. Note that B is not assigned a value.

Main [1] localsmethod arguments: local variables: ARGs = A = 2 main [1] stepmain [1] breakpoint hit: Hehe. Main (hehe: 19) Main [1]

 

 

When runningSystem. Out. println ()The following prompt is displayed:

Main [1] stepmain [1] breakpoint hit: Java. Lang. classloader. loadclass (classloader: 247)

 

 

This is because we tracked it in.PrintlnMethod, we generally do not need to do this, at this time you can use next to skip this method to enter the next sentence. Step indicates entering function tracing, and next indicates transferring to the next statement for execution. You can enter the locals and list commands at any time to view the variable value and the currently runningCode. The Arrow below indicates the place where the current program runs.

Main [1] nextmain [1] breakpoint hit: Hehe. main (hehe: 20) Main [1] list16 {17 int A = 2; 18 int B = 3; 19 int c = a + B; 20 => system. out. println (c); 21 test KK = new test (1, 2); 22 system. out. println (KK. add (); 2324} Main [1]

 

 

The next question is how to view objects. When the program runsNewWhen running the command, type locals.

Main [1] stepmain [1] breakpoint hit: test. (test: 5) Main [1] list1 class Test2 {3 int A; 4 int B; 5 => test (INT AA, int bb) 6 {7 A = AA; 8 B = BB; 9} Main [1] localsmethod arguments: local variables: This = test @ 64fd6722 AA = 1 BB = 2 main [1]

 

 

The variable value displayed at this time is a class.TestVariable value in the constructor.ThisThe object is the currently constructed object. AvailableDumpCommand.

Main [1] Dump thisThis = (TEST) 0x11a {int B = 0 int A = 0}

 

 

You can alsoMainUsed in FunctionsDump kkAndPrintCommand to view objects

Main [1] Dump kkkkk = (TEST) 0x11a {int B = 2 int A = 1} Main [1] print kkkkk = test @ 64fd6722main [1] print KK. akk. a = 1 main [1] print KK. BKK. B = 2

 

 

Last typeContCommand. If no other breakpoint exists, the program runs and exits. Debugging is complete.

Main [1] cont3> current thread "Main" died. Execution continuing...> hehe exited

 

 

The breakpoints in the above operations are all set inMainIn the function, if you want to set it in the called class method, you must useStop in yourclassname. functionnameCommand, for example:

> Stop in test. addbreakpoint set in test. add> runrun heherunning... main [1] 5 breakpoint hit: test. add (test: 11) Main [1] list7 A = AA; 8 B = BB; 9} 10 int add () 11 => {return a + B ;} 12} 13 public class hehe14 {15 public static void main (string ARGs []) Main [1]

 

 

In this way, we can set and track breakpoints in almost all the places needed in the program to view the variables.

Jdb also has many debugging methods. In addition to the most common ones above, the other important ones are clear breakpoints. Use sets the source program path and memory displays the current memory usage, GC forcibly recycles memory ,!! Repeat the preceding command to set the current thread, such as quit and exit jdb, as well as remote debugging. Here we will not introduce them one by one.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.