Remote debugging info

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
Post Reply
bburtin
Advanced member
Advanced member
Posts: 78
Joined: Fri Sep 12, 2014 9:55 pm

Remote debugging info

Post by bburtin »

Here are the steps required to connect a remote debugger to the ZCS server. On the server:

zmlocalconfig tomcat_java_options

This returns the current JVM options that we pass to Tomcat.

zmlocalconfig -e tomcat_java_options=" -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n"

(Remove spaces before "suspend=n". I have no idea why the forum app puts them there).



If you need to debug code that runs during server startup, specify suspend=y instead. Note that if you do this, server startup will hang until a remote debugging session attaches to it. Feel free to use a different port number if you like.
Restart the server and make sure you're still able to read mail.
On the client:



Make sure that your source is synced to the same timestamp as the server build.

In Eclipse, choose the Run / Debug... menu option.

Choose Remote Java Application and click the New button.

Set Name to "Remote", Host to the hostname and Port to 8000.

Click Close.



Now if you ever need to debug the server, click on the down arrow next to the bug icon and choose "Remote". If you don't want to use Eclipse, connect to the server on port 8000 using any standard JDWP debugger.
bburtin
Advanced member
Advanced member
Posts: 78
Joined: Fri Sep 12, 2014 9:55 pm

Remote debugging info

Post by bburtin »

I just realized that our tomcat launcher is rejecting the -Xdebug JVM option, so the directions above will not work. I'll post a followup message once I figure out an elegant way around this.
ljm
Advanced member
Advanced member
Posts: 81
Joined: Fri Sep 12, 2014 10:10 pm

Remote debugging info

Post by ljm »

If you follow the instructions above, an error message appears in catalina.out:

zmtomcatstart: error: JVM option: -Xdebug: not allowed
As a workaround, you can:

1. edit ZimbraNative/src/launcher/zmtomcatstart.c

2. add -Xdebug and -Xrunjdwp to the AllowedJVMArgs array

3. rebuild and install zmtomcatstart
tomcat then listens on port 8000 and you are happily debugging.
kiwicmc
Advanced member
Advanced member
Posts: 51
Joined: Fri Sep 12, 2014 10:06 pm

Remote debugging info

Post by kiwicmc »

If you don't want to recompile C source, you can start tomcat with these parameters and also attach remotely. (This is for 3.1.4 BTW)
C


/opt/zimbra/jdk1.5.0_06/bin/java -Xms303m -Xmx303m -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -client -XX:NewRatio=2 -Dcatalina.base=/opt/zimbra/apache-tomcat-5.5.15 -Dcatalina.home=/opt/zimbra/apache-tomcat-5.5.15 -Djava.io.tmpdir=/opt/zimbra/apache-tomcat-5.5.15/temp -Djava.library.path=/opt/zimbra/lib/jars -Djava.endorsed.dirs=/opt/zimbra/apache-tomcat-5.5.15/common/endorsed -classpath /opt/zimbra/apache-tomcat-5.5.15/bin/bootstrap.jar:/opt/zimbra/apache-tomcat-5.5.15/bin/commons-logging-api.jar org.apache.catalina.startup.Bootstrap start

a1ex
Posts: 41
Joined: Sat Sep 13, 2014 3:11 am

Remote debugging info

Post by a1ex »

Hello,



Do you know how to start ZCS 7 in the same debug mode ?
User avatar
Greg Solovyev
Posts: 12
Joined: Wed Mar 05, 2014 11:30 am
Contact:

Remote debugging info

Post by Greg Solovyev »

ZCS 7 uses Jetty (we switched to Jetty from Tomcat in version 5) There's a way to run and debug jetty with jetty-ant plugin. Basically you run jetty as an ant task and use Eclipse remote debugging with jetty-ant plugin.

To use jetty-ant, first you need to setup a shell for service webapp.
Go to ZimbraServer directory and run:

ant -buildfile jetty-ant.xml jetty.webinf

You'll only need to do this once unless either you clean the build directory or changes things such as web.xml.

To launch jetty, run the following:

ant -buildfile jetty-ant.xml jetty.run

Note that due to a jetty-ant-plugin bug you need to set this env var:

ANT_OPTS="-Djava.library.path=~/zimbra/zdesktop/lib"

To debug, run the jetty.run target with ANT_OPTS like this:

ANT_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Djava.library.path=/opt/zimbra/lib -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y" ant -buildfile jetty-ant.xml jetty.run

This will start jetty-ant plugin but blocks on listening on port 4000.

If you run into Out Of Memory errors, you may also want to increase the memory size by adding PermSize and MaxPermSize options.

The command line will look like this with additional memory allocation options:

ANT_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Djava.library.path=/opt/zimbra/lib -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y, -XX:PermSize=64M -XX:MaxPermSize=256M" ant -buildfile jetty-ant.xml jetty.run

Now go to Eclipse and select Run/Debug... and right click on Remote Java Application to "New" a configuration. Call it anything you want such as "jetty-ant". Select any project as the debug project. Set Host/Port to localhost and 4000. Then go to Source tab and add all the projects you are interested in debugging.

Apply the configuration settings and press "Debug". This will attach the debugger to the jetty-ant process. You can see activity in the
previously blocked jetty-ant console, and debugger will stop at your break points.

To shutdown jetty, simply send Ctrl+C to the console window where you are running jetty-ant.
a1ex
Posts: 41
Joined: Sat Sep 13, 2014 3:11 am

Remote debugging info

Post by a1ex »

Hi Greg!



Thank you very much for your answer!



I'll try your steps once I managed to build Zimbra FOSS.
Post Reply