Thanks for your suggestion. I understand your "approximate approach" to
mean that if I write a shell script which "greps" a .class file for the
words "LocalVariableTable" and "LineNumberTable", it will tell me
whether the .class file contains debug info.
Yes, or any other file scanning tool that you are comfortable with.
One thing I've just now discovered is that the JDK 1.5.0 javac seems to include
a "LineNumberTable" whatever the value of the compile-time flags, so that part
of the test may be of no use to you (depending on which part of the debugging
information you want to know about).
I'm not too sure what you mean by "parsing the classfile (use whatever
bytecode library comes to hand)." Do you mean that I should write a
Java program, that will tell me whether the file contains debug info?
If so, any suggestions about how I might achieve this in Java (or some
other language) would be very welcome.
Well, I mean that you /could/ "write a Java program [etc]". I'm not
recommending you /do/ it unless you need to be able to tell /for sure/ what
debugging information is present. My guess is that you /don't/ need to be so
certain.
Actually it's not difficult to do using something like BCEL, the bytecode
library from the Apache Jakarta project. I was going to add a few pointers to
how to do it (should you decide you need it) but it turns out to be easer just
to post code, so I've appended a /very quick/ hack to the end of this. All it
does is loads each classfile named on the command line. Loops over each
class's methods. For each method it looks to see if there is
LocalVariableTable (or LineNumberTable, but that's commented out), and prints
the names of the classes that have at least one method with the required data.
-- chris
======== QUICK HACK =========
import java.io.*;
import org.apache.bcel.classfile.*;
public class IsDebug
{
public static void
main(String[] args)
throws IOException
{
for (int i = 0; i < args.length; i++)
if (hasDebugInfo(args
))
System.out.println(args);
}
public static boolean
hasDebugInfo(String filename)
throws IOException
{
ClassParser parser = new ClassParser(filename);
JavaClass clazz = parser.parse();
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++)
if (hasDebugInfo(methods))
return true;
return false;
}
public static boolean
hasDebugInfo(Method method)
throws IOException
{
if (method.getLocalVariableTable() != null)
return true;
/*
* interestingly, JDK 1.5.0 (and possibly earlier) seems to include
* a line number table whatever the compile-time flags so this test
* may not be much use.
if (method.getLineNumberTable() != null)
return true;
*/
return false;
}
}