Saturday 3 July 2021

IBM Engineering Rhapsody Tip #98 - Debugging user Java plugins running in Rhapsody

When you write a lot of add-ons for IBM Rhapsody, it becomes very helpful to be able to debug them. This can be a little more difficult when they're running inside the Rhapsody processes, rather than as an external Java application. There are lots of reasons for running in process though, not least because they run an order of magnitude faster, and you can tie them to a profile that adds things like menu commands and properties to control it. In this video I show how it's possible to debug them as remote java applications enabling you to set breakpoints and step through the code in Eclipse, even though the code is running in Rhapsody. You first need to add some changes to your Rhapsody ini file though. The video illustrates. Hopefully, it helps someone out there. p.s. This is a real life example.


Here's the transcript for those that need it:

This video demonstrates how it's possible to debug user-written Java plugins running in the Rhapsody process using Eclipse. 

Java add-ons for Rhapsody can be written to run as applications outside of Rhapsody, or as plugins running in the Rhapsody process (as here). Plugins can be loaded by a profile. 

A certain amount of debugging can be done using instrumentation. It doesn't always work though. In this case, I'm expecting my plugin listener to detect the event and automatically move it into an 'interfaces' package.

To determine what is happening, I want to use the Eclipse debugger to set breakpoints and step through the plugin as it runs inside of Rhapsody.

It's possible to do this by first adding some JVM settings to the rhapsody.ini file. As Rhapsody reads/writes the .ini file, always create a backup and make sure Rhapsody is closed before editing.

The JVM section is where the Java Virtual Machine that Rhapsody will use is specified.

I've added the Debug1, Debug2 and Debug3 options to my .ini file before, hence I just need to include them in Options list for the JVM.

[JVM]
Options=ClassPath,LibPath,Debug1,Debug2,Debug3
Debug1=-Xnoagent
Debug2=-Xdebug
Debug3=-Xrunjdwp:transport=dt_socket,address=6743,server=y,suspend=y

Now when I run Rhapsody and an attempt is made to load a plugin into the Rhapsody JVM, it will wait for a remote debug connection.

To get the Eclipse debugger to connect we need to run a Remote Java Application configuration and change the port number for the Remote Java Application to 6743.

VoilĂ , the debugger connects with the waiting plugin running in the Rhapsody JVM.

It's now possible to run the application as normal, but set breakpoints in the plugin code. E.g., I'll set a breakpoint in the Java plugin.

That's strange...

To reload the plugin code, I need to exit Rhapsody not just close the project.

Doh!! (an unnecessary space, but I can fix it)

Hope that helps. Interested in MBSE/UML or Rhapsody training or customizations then email me.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.