Wednesday, December 19, 2012

How to display Chinese in Graphviz

Graphviz is a very handy tool for drawing plots and firgures.

However, it is not straight forward to display Chinese characters in the generated plots.

One example is as follows using DOT:
node [shape=box,style=dashed,height=0.3,fontname="C:\Windows\Fonts\NSimSun Regular.ttf",fontsize=12]; "你好"; "whr you are ∀";

where you can write UTF-8 encoded Chinese characters in the source file, and alternatively you can write it in xml-like unicode numbers like  "∀" (i.e. ∀). More importantly, you need to specify the Chinese font file such that Graphviz can really display the Chinese characters, since by default Graphviz can hardly find the correct font to use for Chinese characters.

Tuesday, December 18, 2012

How to use JDB on Linux

JDB is quite a powerful debugging tool for Java programs, especially for multi-threading Java programs.

JDB can be found in the JDK package.

You can also learn how to use JDB by reading the manual of JDB (using command "man jdb").

Here I only show the useful parts that I found:
(1) you can run your Java program as usual with the additional option "-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
(2) now you can start JDB using command "jdb -attach 8000"
(3) in JDB, you can first use "suspend" to suspend your JAVA program, and then use "threads" to see the thread list of the JAVA program; if you want to see what code is each thread running, you can use "where 0x22" (0x22 is the thread id which is from the thread list); after finishing debugging, you can use "resume" to resume your JAVA program.
(4) if you want to exit JDB and let your JAVA program go on running, you can simply press Control-C