// -*-C++-*- 

/*  inc/Backtrace.hpp  */

/*
 * Author: Philogelos A. <Philogelos@yahoo.com>
 * Maintainer: Philogelos A.
 * Keywords: C++, library, containers
 *
 * Copyright (C) 1999 Philogelos A.
 *
 * This file is part of Quercus Robusta.
 *
 * Quercus Robusta is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this software; see the file COPYING.LIB.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */



#ifndef __BACKTRACE_HPP__
#define __BACKTRACE_HPP__

/* $Id$ */

#include "Object.hpp"
#include "defines.h"

class List;
class DataWrapper;
class DumbDictionary;

/**

   @author Philogelos
   @created
*/
class Backtrace : public virtual Object
{

  /**
	 Creates empty backtrace.
   */
public: Backtrace();

  /**
   */
public: virtual ~Backtrace();

  /**
	 Fills this object with current backtrace.
  */
public: virtual void fill();
  
  /**
	 Returns address of AFRAME frame in recorded stack.
  */
public: virtual void *getFrame( Index aFrame ) const;
  
  /**
	 True iff stack recording was truncated
	 (due to technical limitations).
  */
public: virtual boolean isTruncated() const;
  
  /**
	 Returns filled stack depth.
	 Frames [ 0 .. getDepth() ) are valid.
  */
public: virtual Index getDepth() const;
  
  /**
	 No checks on address is done. 
  */
public: virtual void setAddress( Index aFrame, void *anAddress );
public: virtual boolean isValidFrame( Index aFrame ) const;
  
public: virtual List *getFrames() const;
  
public: static void *getAddressAtFrame( Index aFrame );
public: static boolean isInitialFrame( void *anAddress );
public: String getNameFor( void *anAddress ) const;

  /** 
	  call this from main()!
   */
public: static void initBacktrace();
  
  /**
   */
public: virtual String  toString() const;

  /**
   */
public:  virtual String  getString() const;

  /**
   */
public:  virtual String  getClassName() const;

protected: boolean loadSymTableFor( const char *anImage ) const;
  
protected: List *frames;
protected: boolean truncated;

protected: mutable boolean tableLoaded;
protected: mutable DumbDictionary *table;
      
protected: static void *crt0Address;
protected: static boolean initialised;
  
#if defined( TESTING )
public: boolean tester( int aParam ) const;
#endif
};


/* $Log$ */

/* __BACKTRACE_HPP__ */
#endif