This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: walking the stack


On Mon, 2002-04-15 at 01:37, Bryce McKinlay wrote:
> Interesting. I was thinking of something similar for stack trace 
> printing, as an alternative to the dlsym/addr2line/demangling stuff we 
> do now. That would allow us to get a trace even from a stripped binary 
> by utilizing the reflection data.

I don't think what I'm doing will give you enough resolution.  I just
put jrtbegin and jrtend around crtbegin and crtend to determine the
extent of the text section for the main executable and every shared
library it loads.  This will definitely work for ELF systems.  I don't
know how to do this for Win32.

There's also two other special PC ranges, AccessController.doPrivileged
and the reflection code for invoking methods.  If we come across
AccessController.doPrivileged while walking the stack, then we stop at
its caller's stack frame (unless it's the reflection code, in which
case, we keep on going 'til we're not in the reflection code). 

libunwind sounds perfect if it lets me do callbacks at each stack
frame.   I'll just keep using backtrace() for now until libunwind, or
something like it, becomes available.

-------------------------------------------------------------------------
#
# This spec file is read by gcj when linking.
# It is used to specify the standard libraries we need in order
# to link with libgcj.
#
%rename startfile startfileorig
*startfile: %(startfileorig) jrtbegin.o

%rename endfile endfileorig
*endfile: jrtend.o %(endfileorig) 

%rename lib liborig
*lib: -lgcj -lm @LIBICONV@ @GCSPEC@ @THREADSPEC@ @ZLIBSPEC@ @SYSTEMSPEC@ %(libgcc) %(liborig)

*jc1: @HASH_SYNC_SPEC@ @DIVIDESPEC@ @CHECKREFSPEC@ @JC1GCSPEC@ @EXCEPTIONSPEC@ -fkeep-inline-functions

-------------------------------------------------------------------------

// jrtbegin.cc -- Java Runtime Support

/* Copyright (C) 2002  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

#include <config.h>
#include <jvm.h>
#include <java/lang/Thread.h>

static int constr ();

static void *jtb_list[]
  __attribute__ ((unused, section(".jtb"), aligned(sizeof(void*))))
  = { (void *) &constr };

static int
constr ()
{
  _Jv_RegisterProgramTextRange 
    (jtb_list[0], jtb_list[1],
     gcj::runtimeInitialized ?
     java::lang::Thread::currentThread()->getContextClassLoader() : 0);
  return 0;
}

// This horrible hack is used to force the generation of a constructor
// function to call constr().  If g++ supported the constructor function
// attribute we wouldn't have to resort to this.
static int why_doesnt_gxx_support_constructor_function_attributes = 
  constr ();

-------------------------------------------------------------------------

// jrtend.cc -- Java Runtime Support

/* Copyright (C) 2002  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

// Force C++ compiler to use Java-style exceptions.
#pragma GCC java_exceptions

static int jrt_end_text __attribute__((section(".text")));

static void *jtb_list_1
  __attribute__((unused, section(".jtb"), aligned(sizeof(void*))))
  = (void *) &jrt_end_text;

-------------------------------------------------------------------------




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]