.class file includes debug info??
4 Message(s) by 2 Author(s) originally posted in java misc
| From: donalmurtagh |
Date: Tuesday, December 21, 2004
|
Hi,
I'm looking for a
command -like utility which can read a .
class file and
tell you whether it includes debug information, i.e. whether it was
built with the -g
option of JAVAc.
Thanks in Advance,
D=F3nal
| From: Chris Uppal |
Date: Tuesday, December 21, 2004
|
[newgoups trimmed a little]
wrote in message:
I'm looking for a command-like utility which can read a .class file and
tell you whether it includes debug information, i.e. whether it was
built with the -g option of JAVAc.
You could find out by
parsing the classfile (use whatever bytecode
library
comes to hand). But that might be overkill for your application. If so, then
an approximate approach like checking whether the .class file contains the
strings "LocalVariableTable" and "LineNumberTable" (with that exact case)
should be a good approximation, provided that you you do not mind a small risk
of false positives.
That last test "works" -- if it does -- because the
debugging info is stored as
so-called "attributes" with those names; attributes are
named sub-sections of
the classfile.
-- chris
| From: donalmurtagh |
Date: Wednesday, December 22, 2004
|
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'll tell me
whether the .class file contains debug info.
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)'d be very welcome.
Cheers,
- Don
| From: Chris Uppal |
Date: Wednesday, December 22, 2004
|
wrote in message:
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'll tell me
whether the .class file contains debug info.
Yes, or any other file scanning
tool that you are comfortable with.
One thing I have 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)'d 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 /do not/ 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 have 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
method s. 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[i]))
System.out.println(args[i]);
}
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[i]))
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;
}
}
Next Message: newbie question
Blogs related to .class file includes debug info??
Debug java util MissingResourceException
Javac will compile *.
java into *.
class in a target directory such as
... choose package resources into a jar
file, say, connection-
info.jar , which is included
... resources directory,
include resources directory in runtime classpath.
...
RE: Hello World
This is simply a standard
Java application, and can be compiled with javac
... This is done after compiling your aspect
class files, (ie after running javac).
... perform much better (no need to run in
debug mode, which using HotSwap,
...
Open Letter to the CF Server Team
This feature request also
includes being able to view and control the JDBC connection pool from the CFAdmin.
... Also, being able to control whether
class files are saved to disk, the cached queries number, and the number of templates
...
TeamCity FAQ (updated)
**/*Test.
java is the template of the test
class name. You can also exclude some classes from testing. To do so, put a minus sign before the template. The sample below
includes all test
files from modules ending with "-est" and excludes
...
EJB basics
Also, when things go wrong they can be more difficult to
debug.
... EJB-JAR
files are zip
files that contain
Java classes and all the other
files needed for deployment.
... The next step is to compile the source code into
class files.
...
Logging With Log4J!
The download package
includes the source code. Unzip the downloaded
file ... A Logger is a
class that does logging for you. Loggers are named entities and
... Log4J supports the following Log Levels:
DEBUG,
INFO, WARN, ERROR & FATAL
...