Having trouble fixing XGraphics.setFont crash

Scott Gilbertson scottg@mantatest.com
Thu Dec 12 10:46:00 GMT 2002


Background info: I'm trying to assess the state of xlib font support.  So
far, I think I've determined that with things as they are, you have to set
the font for the XGraphics object in the component's paint method, rather
than just doing a setFont on the component itself (I'll look closer once I
get past the current problem).

Anyhow, XGraphics.setFont blows up when statically linked (see code and
trace below), and I'm stuck.  My stuff is based on gcc 3.2.1 (patched only
in libjava - I think the program will act the same without the patches), and
I've compiled the Red Hat glibc-2.2.93 and XFree86-4.2.0 with that compiler.
There seems to be something funny going on with locale data (something not
getting linked in properly?).  Looking at the glibc sources, I can't see why
it would link fine, but crash at runtime.  I'm sure gdb would be a big help,
if only I could get it to work with gcj programs (keeps aborting at
__sigsuspend).

Realizing that this could be a problem with glibc or X, I tried compiling a
simple C program which calls "isspace" (which inlines __ctype_b_loc, and is
involved in the crash).  The C program works fine.  That program's symbol
list includes "__ctype_b_loc", which is the apparent culprit in the trace
below.  I claim that narrows it down to a problem with the way either the X
static libraries or libjava are built.

To narrow things down further, I found a sample X program which calls
XLoadQueryFont, at the following URL:
http://www.visi.com/~grante/Xtut/basicwn.html
I modified the "load_font" function to set the font name to something which
will force X's locale stuff to run (it looks for "-*" at the end of the font
name):
     "*-helvetica-bold-r-*-*-240-*-*-*-*-*"
This program runs fine, even statically linked.  That would seem to rule out
any basic sort of problem with glibc or X.

Therefore I think the problem is gcj-specific or libjava-specific.  Perhaps,
for example, gcj links something which overrides a necessary part of glibc.
If that's the case, though, I'd have expected the same problem in a dynamic
executable. It's frustrating.

Any ideas?

----------------------------------------------------------------------------
----------------------
Build procedure (kinda crazy, I know - forces inclusion of entire libgcjx):
rm -rf libgcjx
mkdir libgcjx
cd libgcjx ; ar -xo /usr/lib/libgcjx.a ; cd ..
ld -r -o libgcjx.o libgcjx/*.o
gcj -O2 -c -o Xcrash1.o Xcrash1.java
# Build the dynamic executable
gcj --main=Xcrash1 -o Xcrash1.dynamic
Xcrash1.o -v -Dawt.toolkit=gnu.awt.xlib.XToolkit -L/usr/X11R6/lib -lX11 -lst
dc++ -lpthread   ./libgcjx.o
# Build the static executable
gcj --main=Xcrash1 -static -static-libgcc -save-temps
./libgcjx.o -v -Dawt.toolkit=gnu.awt.xlib.XToolkit -L/usr/X11R6/lib -lX11 -l
stdc++ -lpthread    Xcrash1.o  -o Xcrash1
----------------------------------------------------------------------------
----------------------
Source code:
import java.awt.*;

/**
 * Demonstrate crash while setting fonts with X peers.
 * Compiled dynamically, works OK - statically, crashes.
 * There's a segv in __ctype_b_loc, called from parse_line,
 * ultimately from XLoadQueryFont.
 */
public class Xcrash1
{
 static public void main( String[] args )
 {
  Frame f = new Frame()
  {
   public void paint( Graphics g )
   {
    g.setFont( new Font( "helvetica", 1, 14 ) );
    super.paint(g);
   }
  };
  f.pack();
  f.setVisible(true);
  f.repaint();
 }
}
----------------------------------------------------------------------------
----------------------
Backtrace of core dump:
GNU gdb Red Hat Linux (5.2.1-5rh)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
Core was generated by `./Xcrash1'.
Program terminated with signal 6, Aborted.
#0  0x081500b1 in __kill () at __kill:-1
 in __kill
(gdb) (gdb) #0  0x081500b1 in __kill () at __kill:-1
#1  0x080878ef in pthread_kill (thread=23672, signo=-1084242060) at
signals.c:65
#2  0x08087bb7 in raise (sig=6) at signals.c:181
#3  0x081503c9 in abort () at ../sysdeps/generic/abort.c:88
#4  0x08096c2c in _Jv_Throw (value=0x83a8ff0) at
../../../gcc/libjava/exception.cc:110
#5  0x0808cfd4 in catch_segv (_dummy=138055664) at
../../../gcc/libjava/prims.cc:112
#6  0x0808cfe9 in catch_segv(int) () at ../../../gcc/libjava/prims.cc:121
#7  <signal handler called>
#8  0x0814c62c in __ctype_b_loc () at ../include/ctype.h:31
#9  0x08070045 in parse_line ()
#10 0x080700d4 in _XlcParsePath ()
#11 0x0807090e in _XlcLocaleDirName ()
#12 0x0806fb35 in _XlcDynamicLoad ()
#13 0x08065286 in _XOpenLC ()
#14 0x08065415 in _XlcCurrentLC ()
#15 0x08052e67 in _XF86LoadQueryLocaleFont ()
#16 0x08051f65 in XLoadQueryFont ()
#17 0x080494fc in gnu::gcj::xlib::Font::loadFont(gnu::gcj::xlib::Display*,
java::lang::String*) (display=0xbf5fdd3c, lfdNamePattern=0x83cb530) at
../../../gcc/libjava/gnu/gcj/xlib/natFont.cc:29




More information about the Java mailing list