Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > .class file includes debug info??

Reply
Thread Tools

.class file includes debug info??

 
 
donalmurtagh@yahoo.co.uk
Guest
Posts: n/a
 
      12-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ónal

 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      12-21-2004
[newgoups trimmed a little]

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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 don't 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


 
Reply With Quote
 
 
 
 
donalmurtagh@yahoo.co.uk
Guest
Posts: n/a
 
      12-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 will 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) would be very welcome.

Cheers,
- Don

 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      12-22-2004
(E-Mail Removed) wrote:

> 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[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;
}
}



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
netvmini.sys still not working on Windows 7 even after driver signing disabled ?! (Windows debug mode necessary for debug drivers ???) Skybuck Flying Windows 64bit 3 08-09-2009 05:54 AM
debug="false" in web.config and <%@ debug="true" ...%> in aspx file => true or false? André ASP .Net 3 08-28-2006 12:02 PM
Config Mgr Debug/Release and Web.config Compilation debug=true RonL ASP .Net 0 04-08-2006 03:50 PM
Debug (DLL MFC) -> Debug (Static MFC) ringos75 C++ 0 04-14-2005 01:50 PM
[Howto] Compiling debug Python extensions for non-debug Python Mike C. Fletcher Python 3 10-12-2003 09:37 PM



Advertisments