1

I'm writing scripts with a Java api which compile to class files and are executed out of my perspective on a virtual machine (I don't have access to this virtual machine and can't debug my class files from within.) These scripts require observable data to execute and don't run properly unless they've been executed within this virtual machine. As a consequence of the way that these class files are executed, to my knowledge, I can't debug them with my IDE's built-in debugger.

I don't really have the coding vocabulary to even search for answers to that last statement, so please correct me if I'm wrong.

Anyways, the only way which I've determined will allow me to debug these scripts is the classic print-statement method. It's horrible. But it works. And it seems that the entire community for the api uses this method.

I had the idea that I could use reflection to grab information from my classes as they're executing, but this still doesn't give me access to the line-by-line debugging that I'm looking for.

What I'd like to do is monitor the execution of my script step-by-step (every calculation the VM does) and store information about those calculations (variable "foo" in class "bar" becomes 4 on line "soandso") as a sort of running cache which dumps to the system console whenever an error occurs.

Is this possible?

YoungHobbit
  • 13,254
  • 9
  • 50
  • 73
  • 1
    You should consider a logger. It's just like print statements except you can specify log levels ( debug, info, warning, error) and you can choose to write to a file as well as stdout ( like a print statement ). If you have access to the virtual machine , you can download the logs as well. – algrebe Sep 17 '16 at 03:50
  • Which IDE are you using which doesn't allow debugging? – Codebender Sep 17 '16 at 03:53
  • 1
    Not sure I quite follow the question, is Java remote debugging what you need to do? This is doable with Eclipse at least. – paisanco Sep 17 '16 at 04:07
  • a logger certainly would be a step up, but this would still result in the kind of 'insert print statement -> run -> read if the program made it to my print statement, delete that print statement, repeat' debugging that I'm trying to avoid. – user6841516 Sep 17 '16 at 04:19
  • I'll look into Java remote debugging as I'm using eclipse. Thanks! – user6841516 Sep 17 '16 at 04:19

1 Answers1

0

You can take a look at dynamic proxies.

Here is a very good explanation of it.

With a dynamic proxy you can output (log, send as mail, ...) the method that is beeing called and the parameters that are passed to the method.

It's not exactly what you are looking for but maybe it will help you.

Community
  • 1
  • 1
Lµk4s
  • 66
  • 7