views:

101

answers:

3

I'm sorry if the title is confusing but I couldn't think of anything similar to call it. What I'm looking for is if there is any sort of tool (or eclipse plugin, etc) that will log all the translated lines from a program. For example:

int b = 20;
for (int x = 0; x < z; x++)
b = b + 5;

Would get translated into

b = 20
for (int x = 0; 0 < 50; 0++)
b = 20 + 5;

I ask because it seems it wouldn't be too difficult to implement relatively, since we can debug one line at a time and I think it would save an enormous amount of time. If you could just go through a log file and look for your error and check out exactly what line the problem occurred on and the context that caused it then debugging would be a lot easier. XDebug for PHP has function level traces so you can see the value of the variables passed in your program, and have that dumped to a log. I found that it saved me a large amount of debugging time. The problems were usually obvious and easy to fix then.

It would sure beat adding logging statements.

EDIT: I want to clarify that I am not looking for a traditional debugger ala Eclipse style. I'm simply looking for a overall logging of the variables and states.

+2  A: 

Eclipse and any IDE worth its salt comes with a debugger that can do this and much more. Rather than print out traces, you can have the program halt at any specific line of code (whenever it is reached, or only when specific conditions are met) and inspect the state of variables at that point, as well as modify variables and execute arbitrary statements to see their return value.

For web applications where the code is running on a server, you can even connect the debugger via the network to a remote JVM.

Here's a tutorial on how to use the eclipse debugger. There's even a plugin that allows you to use it for PHP code.

Michael Borgwardt
Unfortunately that is the exact opposite of what I want to do. I know how to use the debugger well but to have to step through a large amount of code takes a much longer time than just viewing the code as it would be once it's all executed. Hence why I'm looking for this tool.
John Baker
I don't get it. To me it sounds like what you describe would take much longer than using a debugger and setting some breakpoints, and yield much less useful results (that variable substitution thing is rather primitive and useless with code that's not completely sequential).
Michael Borgwardt
BTW, do you know how to use conditional breakpoints? those can speed up the debugging process dramatically in some cases.
Michael Borgwardt
How on earth could looking through all that code be helpful? The whole trick is narrowing down your error quickly. Code that's layered properly should help you pinpoint where to look based on what's gone wrong.
duffymo
Yes I am familiar with conditional breakpoints, and they are quite helpful. I have found that being able to look at the source output doesn't take much time at all. I wrote a toy language that I use from time to time and have found it cut down my debugging time quite a bit. Otherwise I'm force to keep setting breakpoints further and further up the code until I get the to the actual source. Even something like step back would be helpful.
John Baker
I still have the feeling that you're somehow not using the debugger in the most efficient way. I usually have a pretty good idea where something goes wrong, so that's where I set the breakpoint. When it is hit, then the eclipse debugger shows me the entire stacktrace and I can inspect local variables at each level - usually that is all the information I need.
Michael Borgwardt
There's another debugger feature that I learned about only recently myself and can be very useful: "drop to frame" allows you to go back to the beginning of the method, in case you single-stepped too far.
Michael Borgwardt
+1  A: 

I think Trace may be what you want, although in practice, I would expect a good debugger with expression evaluation and conditional breakpoints might solve your overall problem more quickly. Note that Trace is written to the JPDA and its code is available.

Kathy Van Stone
Great I'll have a look! thank you
John Baker
I had a look but it doesn't seem like I have any access at all to any of the variables that are being used. It just shows the progression of method calls. That is neat, but not too useful. I may be missing something though, not sure if there is more to it
John Baker
You might, however, use the code as a start to write a variant that does show the variables. I believe they are available to the JPDA.
Kathy Van Stone
ah ok, thanks. I am thinking I'll just write a eclipse plugin for it. Either way works I suppose. We'll see. Thanks for the info.
John Baker
A: 

I don't understand how such a tool would work. What would it do for conditionals? For user input?

int x=getUserInput();
print(x);  // What would your translator show for this line?

Also, it sounds a bit like any such tool could be used to solve the Halting Problem...just look at the last line.

Alex Feinman
it would show print (value of x here. eg. 10);
John Baker
But what would that value be? It could be anything.
Alex Feinman
I think the point is that it could be anything. You want to to print whatever the input was in that case.
John Baker