Commit 1b88853a authored by Davi Arnaut's avatar Davi Arnaut

Bug#57210: remove pstack

Quoting from the bug report:

The pstack library has been included in MySQL since version
4.0.0. It's useless and should be removed.

Details: According to its own documentation, pstack only works
on Linux on x86 in 32 bit mode and requires LinuxThreads and a
statically linked binary. It doesn't really support any Linux
from 2003 or later and doesn't work on any other OS.

The --enable-pstack option is thus deprecated and has no effect.
parent 6eaa3c07
......@@ -6,6 +6,6 @@ path=`dirname $0`
extra_flags="$pentium_cflags $debug_cflags"
extra_configs="$pentium_configs $debug_configs $static_link"
extra_configs="$extra_configs --with-debug=full --with-mysqlfs --without-server --without-pstack"
extra_configs="$extra_configs --with-debug=full --with-mysqlfs --without-server"
. "$path/FINISH.sh"
......@@ -23,7 +23,6 @@ EXTRA_DIST = INSTALL-SOURCE INSTALL-WIN-SOURCE \
SUBDIRS = . include @docs_dirs@ @zlib_dir@ \
@readline_topdir@ sql-common scripts \
@pstack_dir@ \
@sql_union_dirs@ unittest \
@sql_server@ @man_dirs@ tests \
netware @libmysqld_dirs@ \
......@@ -32,7 +31,6 @@ SUBDIRS = . include @docs_dirs@ @zlib_dir@ \
DIST_SUBDIRS = . include Docs zlib \
cmd-line-utils sql-common scripts \
pstack \
strings mysys dbug extra regex libmysql libmysql_r client unittest storage plugin \
vio sql man tests \
netware libmysqld \
......
......@@ -1192,97 +1192,3 @@ library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
***************************************************************************
%%The following software may be included in this product:
pstack (part of GNU Binutils)
Use of any of this software is governed by the terms of the license below:
pstack is comprised of various .c and .h files; all begin like this:
/* bucomm.h -- binutils common include file.
Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
***************************************************************************
%%The following software may be included in this product:
libiberty.h (part of pstack GNU Binutils)
Use of any of this software is governed by the terms of the license below:
See
http://www.koders.com/c/fid99F596804BBE22C076522B848D5575F142079064.aspx
/* Function declarations for libiberty.
Written by Cygnus Support, 1994.
The libiberty library provides a number of functions which are
missing on some operating systems. We do not declare those here,
to avoid conflicts with the system header files on operating
systems that do support those functions. In this file we only
declare those functions which are specific to libiberty. */
***************************************************************************
%%The following software may be included in this product:
ieee.h (part of pstack GNU Binutils)
Use of any of this software is governed by the terms of the license below:
See
http://src.opensolaris.org/source/xref//sfw/usr/src/cmd/gdb/gdb-6.3/include/ieee.h
/* IEEE Standard 695-1980 "Universal Format for Object Modules"
header file
Contributed by Cygnus Support. */
***************************************************************************
%%The following software may be included in this product:
pstack.c (part of pstack GNU Binutils)
Use of any of this software is governed by the terms of the license below:
/*
pstack.c -- asynchronous stack trace of a running process
Copyright (c) 1999 Ross Thompson
Author: Ross Thompson
Critical bug fix: Tim Waugh
*/
/*
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
***************************************************************************
......@@ -910,46 +910,6 @@ struct request_info *req;
])
AC_SUBST(WRAPLIBS)
if test "$TARGET_LINUX" = "true"; then
AC_ARG_WITH(pstack,
[ --with-pstack Use the pstack backtrace library],
[ USE_PSTACK=$withval ],
[ USE_PSTACK=no ])
pstack_libs=
pstack_dir=
if test "$USE_PSTACK" = yes -a "$TARGET_LINUX" = "true" -a "$BASE_MACHINE_TYPE" = "i386"
then
have_libiberty= have_libbfd=
my_save_LIBS="$LIBS"
dnl I have no idea if this is a good test - can not find docs for libiberty
AC_CHECK_LIB([iberty], [fdmatch],
[have_libiberty=yes
AC_CHECK_LIB([bfd], [bfd_openr], [have_libbfd=yes], , [-liberty])])
LIBS="$my_save_LIBS"
if test x"$have_libiberty" = xyes -a x"$have_libbfd" = xyes
then
pstack_dir="pstack"
pstack_libs="../pstack/libpstack.a -lbfd -liberty"
# We must link staticly when using pstack
with_mysqld_ldflags="-all-static"
AC_SUBST([pstack_dir])
AC_SUBST([pstack_libs])
AC_DEFINE([USE_PSTACK], [1], [the pstack backtrace library])
dnl This check isn't needed, but might be nice to give some feedback....
dnl AC_CHECK_HEADER(libiberty.h,
dnl have_libiberty_h=yes,
dnl have_libiberty_h=no)
else
USE_PSTACK="no"
fi
else
USE_PSTACK="no"
fi
fi
AC_MSG_CHECKING([if we should use pstack])
AC_MSG_RESULT([$USE_PSTACK])
# Check for gtty if termio.h doesn't exists
if test "$ac_cv_header_termio_h" = "no" -a "$ac_cv_header_termios_h" = "no"
then
......@@ -1178,7 +1138,7 @@ dnl Is this the right match for DEC OSF on alpha?
sql/Makefile.in)
# Use gen_lex_hash.linux instead of gen_lex_hash
# Add library dependencies to mysqld_DEPENDENCIES
lib_DEPENDENCIES="\$(pstack_libs) \$(openssl_libs) \$(yassl_libs)"
lib_DEPENDENCIES="\$(openssl_libs) \$(yassl_libs)"
cat > $filesed << EOF
s,\(\./gen_lex_hash\)\$(EXEEXT),\1.linux,
s%\(mysqld_DEPENDENCIES = \)%\1$lib_DEPENDENCIES %
......@@ -2880,9 +2840,6 @@ esac
AC_SUBST(MAKE_BINARY_DISTRIBUTION_OPTIONS)
# Output results
if test -d "$srcdir/pstack" ; then
AC_CONFIG_FILES(pstack/Makefile pstack/aout/Makefile)
fi
if test -d "$srcdir/cmd-line-utils/readline" ; then
AC_CONFIG_FILES(cmd-line-utils/readline/Makefile)
fi
......
......@@ -20,7 +20,6 @@
/* Things we don't need in the embedded version of MySQL */
/* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */
#undef HAVE_PSTACK /* No stacktrace */
#undef HAVE_OPENSSL
#undef HAVE_SMEM /* No shared memory */
#undef HAVE_NDBCLUSTER_DB /* No NDB cluster */
......
# Copyright (C) 2000-2003, 2005 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# As pstack doesn't work on all configurations, we have to use
# the USE_PSTACK hack to get all files into distribution
#
SUBDIRS = aout
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
pkglib_LIBRARIES = libpstack.a
libpstack_a_SOURCES = bucomm.c filemode.c linuxthreads.c rddbg.c \
debug.c ieee.c pstack.c stabs.c
noinst_HEADERS = bucomm.h debug.h ieee.h budbg.h demangle.h \
linuxthreads.h pstack.h pstacktrace.h
# Don't update the files from bitkeeper
%::SCCS/s.%
noinst_HEADERS = aout64.h stab.def stab_gnu.h
# Don't update the files from bitkeeper
%::SCCS/s.%
/* `a.out' object-file definitions, including extensions to 64-bit fields */
#ifndef __A_OUT_64_H__
#define __A_OUT_64_H__
/* This is the layout on disk of the 32-bit or 64-bit exec header. */
#ifndef external_exec
struct external_exec
{
bfd_byte e_info[4]; /* magic number and stuff */
bfd_byte e_text[BYTES_IN_WORD]; /* length of text section in bytes */
bfd_byte e_data[BYTES_IN_WORD]; /* length of data section in bytes */
bfd_byte e_bss[BYTES_IN_WORD]; /* length of bss area in bytes */
bfd_byte e_syms[BYTES_IN_WORD]; /* length of symbol table in bytes */
bfd_byte e_entry[BYTES_IN_WORD]; /* start address */
bfd_byte e_trsize[BYTES_IN_WORD]; /* length of text relocation info */
bfd_byte e_drsize[BYTES_IN_WORD]; /* length of data relocation info */
};
#define EXEC_BYTES_SIZE (4 + BYTES_IN_WORD * 7)
/* Magic numbers for a.out files */
#if ARCH_SIZE==64
#define OMAGIC 0x1001 /* Code indicating object file */
#define ZMAGIC 0x1002 /* Code indicating demand-paged executable. */
#define NMAGIC 0x1003 /* Code indicating pure executable. */
/* There is no 64-bit QMAGIC as far as I know. */
#define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \
&& N_MAGIC(x) != NMAGIC \
&& N_MAGIC(x) != ZMAGIC)
#else
#define OMAGIC 0407 /* ...object file or impure executable. */
#define NMAGIC 0410 /* Code indicating pure executable. */
#define ZMAGIC 0413 /* Code indicating demand-paged executable. */
#define BMAGIC 0415 /* Used by a b.out object. */
/* This indicates a demand-paged executable with the header in the text.
It is used by 386BSD (and variants) and Linux, at least. */
#ifndef QMAGIC
#define QMAGIC 0314
#endif
# ifndef N_BADMAG
# define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \
&& N_MAGIC(x) != NMAGIC \
&& N_MAGIC(x) != ZMAGIC \
&& N_MAGIC(x) != QMAGIC)
# endif /* N_BADMAG */
#endif
#endif
#ifdef QMAGIC
#define N_IS_QMAGIC(x) (N_MAGIC (x) == QMAGIC)
#else
#define N_IS_QMAGIC(x) (0)
#endif
/* The difference between TARGET_PAGE_SIZE and N_SEGSIZE is that TARGET_PAGE_SIZE is
the finest granularity at which you can page something, thus it
controls the padding (if any) before the text segment of a ZMAGIC
file. N_SEGSIZE is the resolution at which things can be marked as
read-only versus read/write, so it controls the padding between the
text segment and the data segment (in memory; on disk the padding
between them is TARGET_PAGE_SIZE). TARGET_PAGE_SIZE and N_SEGSIZE are the same
for most machines, but different for sun3. */
/* By default, segment size is constant. But some machines override this
to be a function of the a.out header (e.g. machine type). */
#ifndef N_SEGSIZE
#define N_SEGSIZE(x) SEGMENT_SIZE
#endif
/* Virtual memory address of the text section.
This is getting very complicated. A good reason to discard a.out format
for something that specifies these fields explicitly. But til then...
* OMAGIC and NMAGIC files:
(object files: text for "relocatable addr 0" right after the header)
start at 0, offset is EXEC_BYTES_SIZE, size as stated.
* The text address, offset, and size of ZMAGIC files depend
on the entry point of the file:
* entry point below TEXT_START_ADDR:
(hack for SunOS shared libraries)
start at 0, offset is 0, size as stated.
* If N_HEADER_IN_TEXT(x) is true (which defaults to being the
case when the entry point is EXEC_BYTES_SIZE or further into a page):
no padding is needed; text can start after exec header. Sun
considers the text segment of such files to include the exec header;
for BFD's purposes, we don't, which makes more work for us.
start at TEXT_START_ADDR + EXEC_BYTES_SIZE, offset is EXEC_BYTES_SIZE,
size as stated minus EXEC_BYTES_SIZE.
* If N_HEADER_IN_TEXT(x) is false (which defaults to being the case when
the entry point is less than EXEC_BYTES_SIZE into a page (e.g. page
aligned)): (padding is needed so that text can start at a page boundary)
start at TEXT_START_ADDR, offset TARGET_PAGE_SIZE, size as stated.
Specific configurations may want to hardwire N_HEADER_IN_TEXT,
for efficiency or to allow people to play games with the entry point.
In that case, you would #define N_HEADER_IN_TEXT(x) as 1 for sunos,
and as 0 for most other hosts (Sony News, Vax Ultrix, etc).
(Do this in the appropriate bfd target file.)
(The default is a heuristic that will break if people try changing
the entry point, perhaps with the ld -e flag.)
* QMAGIC is always like a ZMAGIC for which N_HEADER_IN_TEXT is true,
and for which the starting address is TARGET_PAGE_SIZE (or should this be
SEGMENT_SIZE?) (TEXT_START_ADDR only applies to ZMAGIC, not to QMAGIC).
*/
/* This macro is only relevant for ZMAGIC files; QMAGIC always has the header
in the text. */
#ifndef N_HEADER_IN_TEXT
#define N_HEADER_IN_TEXT(x) (((x).a_entry & (TARGET_PAGE_SIZE-1)) >= EXEC_BYTES_SIZE)
#endif
/* Sun shared libraries, not linux. This macro is only relevant for ZMAGIC
files. */
#ifndef N_SHARED_LIB
#define N_SHARED_LIB(x) ((x).a_entry < TEXT_START_ADDR)
#endif
/* Returning 0 not TEXT_START_ADDR for OMAGIC and NMAGIC is based on
the assumption that we are dealing with a .o file, not an
executable. This is necessary for OMAGIC (but means we don't work
right on the output from ld -N); more questionable for NMAGIC. */
#ifndef N_TXTADDR
#define N_TXTADDR(x) \
(/* The address of a QMAGIC file is always one page in, */ \
/* with the header in the text. */ \
N_IS_QMAGIC (x) ? TARGET_PAGE_SIZE + EXEC_BYTES_SIZE : \
N_MAGIC(x) != ZMAGIC ? 0 : /* object file or NMAGIC */\
N_SHARED_LIB(x) ? 0 : \
N_HEADER_IN_TEXT(x) ? \
TEXT_START_ADDR + EXEC_BYTES_SIZE : /* no padding */\
TEXT_START_ADDR /* a page of padding */\
)
#endif
/* If N_HEADER_IN_TEXT is not true for ZMAGIC, there is some padding
to make the text segment start at a certain boundary. For most
systems, this boundary is TARGET_PAGE_SIZE. But for Linux, in the
time-honored tradition of crazy ZMAGIC hacks, it is 1024 which is
not what TARGET_PAGE_SIZE needs to be for QMAGIC. */
#ifndef ZMAGIC_DISK_BLOCK_SIZE
#define ZMAGIC_DISK_BLOCK_SIZE TARGET_PAGE_SIZE
#endif
#define N_DISK_BLOCK_SIZE(x) \
(N_MAGIC(x) == ZMAGIC ? ZMAGIC_DISK_BLOCK_SIZE : TARGET_PAGE_SIZE)
/* Offset in an a.out of the start of the text section. */
#ifndef N_TXTOFF
#define N_TXTOFF(x) \
(/* For {O,N,Q}MAGIC, no padding. */ \
N_MAGIC(x) != ZMAGIC ? EXEC_BYTES_SIZE : \
N_SHARED_LIB(x) ? 0 : \
N_HEADER_IN_TEXT(x) ? \
EXEC_BYTES_SIZE : /* no padding */\
ZMAGIC_DISK_BLOCK_SIZE /* a page of padding */\
)
#endif
/* Size of the text section. It's always as stated, except that we
offset it to `undo' the adjustment to N_TXTADDR and N_TXTOFF
for ZMAGIC files that nominally include the exec header
as part of the first page of text. (BFD doesn't consider the
exec header to be part of the text segment.) */
#ifndef N_TXTSIZE
#define N_TXTSIZE(x) \
(/* For QMAGIC, we don't consider the header part of the text section. */\
N_IS_QMAGIC (x) ? (x).a_text - EXEC_BYTES_SIZE : \
(N_MAGIC(x) != ZMAGIC || N_SHARED_LIB(x)) ? (x).a_text : \
N_HEADER_IN_TEXT(x) ? \
(x).a_text - EXEC_BYTES_SIZE: /* no padding */\
(x).a_text /* a page of padding */\
)
#endif
/* The address of the data segment in virtual memory.
It is the text segment address, plus text segment size, rounded
up to a N_SEGSIZE boundary for pure or pageable files. */
#ifndef N_DATADDR
#define N_DATADDR(x) \
(N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+N_TXTSIZE(x)) \
: (N_SEGSIZE(x) + ((N_TXTADDR(x)+N_TXTSIZE(x)-1) & ~(N_SEGSIZE(x)-1))))
#endif
/* The address of the BSS segment -- immediately after the data segment. */
#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
/* Offsets of the various portions of the file after the text segment. */
/* For {Q,Z}MAGIC, there is padding to make the data segment start on
a page boundary. Most of the time the a_text field (and thus
N_TXTSIZE) already contains this padding. It is possible that for
BSDI and/or 386BSD it sometimes doesn't contain the padding, and
perhaps we should be adding it here. But this seems kind of
questionable and probably should be BSDI/386BSD-specific if we do
do it.
For NMAGIC (at least for hp300 BSD, probably others), there is
padding in memory only, not on disk, so we must *not* ever pad here
for NMAGIC. */
#ifndef N_DATOFF
#define N_DATOFF(x) \
(N_TXTOFF(x) + N_TXTSIZE(x))
#endif
#ifndef N_TRELOFF
#define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data )
#endif
#ifndef N_DRELOFF
#define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize )
#endif
#ifndef N_SYMOFF
#define N_SYMOFF(x) ( N_DRELOFF(x) + (x).a_drsize )
#endif
#ifndef N_STROFF
#define N_STROFF(x) ( N_SYMOFF(x) + (x).a_syms )
#endif
/* Symbols */
#ifndef external_nlist
struct external_nlist {
bfd_byte e_strx[BYTES_IN_WORD]; /* index into string table of name */
bfd_byte e_type[1]; /* type of symbol */
bfd_byte e_other[1]; /* misc info (usually empty) */
bfd_byte e_desc[2]; /* description field */
bfd_byte e_value[BYTES_IN_WORD]; /* value of symbol */
};
#define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD)
#endif
struct internal_nlist {
unsigned long n_strx; /* index into string table of name */
unsigned char n_type; /* type of symbol */
unsigned char n_other; /* misc info (usually empty) */
unsigned short n_desc; /* description field */
bfd_vma n_value; /* value of symbol */
};
/* The n_type field is the symbol type, containing: */
#define N_UNDF 0 /* Undefined symbol */
#define N_ABS 2 /* Absolute symbol -- defined at particular addr */
#define N_TEXT 4 /* Text sym -- defined at offset in text seg */
#define N_DATA 6 /* Data sym -- defined at offset in data seg */
#define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
#define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
#define N_FN 0x1f /* File name of .o file */
#define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
/* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
N_DATA, or N_BSS. When the low-order bit of other types is set,
(e.g. N_WARNING versus N_FN), they are two different types. */
#define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
#define N_TYPE 0x1e
#define N_STAB 0xe0 /* If any of these bits are on, it's a debug symbol */
#define N_INDR 0x0a
/* The following symbols refer to set elements.
All the N_SET[ATDB] symbols with the same name form one set.
Space is allocated for the set in the text section, and each set
elements value is stored into one word of the space.
The first word of the space is the length of the set (number of elements).
The address of the set is made into an N_SETV symbol
whose name is the same as the name of the set.
This symbol acts like a N_DATA global symbol
in that it can satisfy undefined external references. */
/* These appear as input to LD, in a .o file. */
#define N_SETA 0x14 /* Absolute set element symbol */
#define N_SETT 0x16 /* Text set element symbol */
#define N_SETD 0x18 /* Data set element symbol */
#define N_SETB 0x1A /* Bss set element symbol */
/* This is output from LD. */
#define N_SETV 0x1C /* Pointer to set vector in data area. */
/* Warning symbol. The text gives a warning message, the next symbol
in the table will be undefined. When the symbol is referenced, the
message is printed. */
#define N_WARNING 0x1e
/* Weak symbols. These are a GNU extension to the a.out format. The
semantics are those of ELF weak symbols. Weak symbols are always
externally visible. The N_WEAK? values are squeezed into the
available slots. The value of a N_WEAKU symbol is 0. The values
of the other types are the definitions. */
#define N_WEAKU 0x0d /* Weak undefined symbol. */
#define N_WEAKA 0x0e /* Weak absolute symbol. */
#define N_WEAKT 0x0f /* Weak text symbol. */
#define N_WEAKD 0x10 /* Weak data symbol. */
#define N_WEAKB 0x11 /* Weak bss symbol. */
/* Relocations
There are two types of relocation flavours for a.out systems,
standard and extended. The standard form is used on systems where the
instruction has room for all the bits of an offset to the operand, whilst
the extended form is used when an address operand has to be split over n
instructions. Eg, on the 68k, each move instruction can reference
the target with a displacement of 16 or 32 bits. On the sparc, move
instructions use an offset of 14 bits, so the offset is stored in
the reloc field, and the data in the section is ignored.
*/
/* This structure describes a single relocation to be performed.
The text-relocation section of the file is a vector of these structures,
all of which apply to the text section.
Likewise, the data-relocation section applies to the data section. */
struct reloc_std_external {
bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */
bfd_byte r_index[3]; /* symbol table index of symbol */
bfd_byte r_type[1]; /* relocation type */
};
#define RELOC_STD_BITS_PCREL_BIG ((unsigned int) 0x80)
#define RELOC_STD_BITS_PCREL_LITTLE ((unsigned int) 0x01)
#define RELOC_STD_BITS_LENGTH_BIG ((unsigned int) 0x60)
#define RELOC_STD_BITS_LENGTH_SH_BIG 5
#define RELOC_STD_BITS_LENGTH_LITTLE ((unsigned int) 0x06)
#define RELOC_STD_BITS_LENGTH_SH_LITTLE 1
#define RELOC_STD_BITS_EXTERN_BIG ((unsigned int) 0x10)
#define RELOC_STD_BITS_EXTERN_LITTLE ((unsigned int) 0x08)
#define RELOC_STD_BITS_BASEREL_BIG ((unsigned int) 0x08)
#define RELOC_STD_BITS_BASEREL_LITTLE ((unsigned int) 0x10)
#define RELOC_STD_BITS_JMPTABLE_BIG ((unsigned int) 0x04)
#define RELOC_STD_BITS_JMPTABLE_LITTLE ((unsigned int) 0x20)
#define RELOC_STD_BITS_RELATIVE_BIG ((unsigned int) 0x02)
#define RELOC_STD_BITS_RELATIVE_LITTLE ((unsigned int) 0x40)
#define RELOC_STD_SIZE (BYTES_IN_WORD + 3 + 1) /* Bytes per relocation entry */
struct reloc_std_internal
{
bfd_vma r_address; /* Address (within segment) to be relocated. */
/* The meaning of r_symbolnum depends on r_extern. */
unsigned int r_symbolnum:24;
/* Nonzero means value is a pc-relative offset
and it should be relocated for changes in its own address
as well as for changes in the symbol or section specified. */
unsigned int r_pcrel:1;
/* Length (as exponent of 2) of the field to be relocated.
Thus, a value of 2 indicates 1<<2 bytes. */
unsigned int r_length:2;
/* 1 => relocate with value of symbol.
r_symbolnum is the index of the symbol
in files the symbol table.
0 => relocate with the address of a segment.
r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
(the N_EXT bit may be set also, but signifies nothing). */
unsigned int r_extern:1;
/* The next three bits are for SunOS shared libraries, and seem to
be undocumented. */
unsigned int r_baserel:1; /* Linkage table relative */
unsigned int r_jmptable:1; /* pc-relative to jump table */
unsigned int r_relative:1; /* "relative relocation" */
/* unused */
unsigned int r_pad:1; /* Padding -- set to zero */
};
/* EXTENDED RELOCS */
struct reloc_ext_external {
bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */
bfd_byte r_index[3]; /* symbol table index of symbol */
bfd_byte r_type[1]; /* relocation type */
bfd_byte r_addend[BYTES_IN_WORD]; /* datum addend */
};
#define RELOC_EXT_BITS_EXTERN_BIG ((unsigned int) 0x80)
#define RELOC_EXT_BITS_EXTERN_LITTLE ((unsigned int) 0x01)
#define RELOC_EXT_BITS_TYPE_BIG ((unsigned int) 0x1F)
#define RELOC_EXT_BITS_TYPE_SH_BIG 0
#define RELOC_EXT_BITS_TYPE_LITTLE ((unsigned int) 0xF8)
#define RELOC_EXT_BITS_TYPE_SH_LITTLE 3
/* Bytes per relocation entry */
#define RELOC_EXT_SIZE (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD)
enum reloc_type
{
/* simple relocations */
RELOC_8, /* data[0:7] = addend + sv */
RELOC_16, /* data[0:15] = addend + sv */
RELOC_32, /* data[0:31] = addend + sv */
/* pc-rel displacement */
RELOC_DISP8, /* data[0:7] = addend - pc + sv */
RELOC_DISP16, /* data[0:15] = addend - pc + sv */
RELOC_DISP32, /* data[0:31] = addend - pc + sv */
/* Special */
RELOC_WDISP30, /* data[0:29] = (addend + sv - pc)>>2 */
RELOC_WDISP22, /* data[0:21] = (addend + sv - pc)>>2 */
RELOC_HI22, /* data[0:21] = (addend + sv)>>10 */
RELOC_22, /* data[0:21] = (addend + sv) */
RELOC_13, /* data[0:12] = (addend + sv) */
RELOC_LO10, /* data[0:9] = (addend + sv) */
RELOC_SFA_BASE,
RELOC_SFA_OFF13,
/* P.I.C. (base-relative) */
RELOC_BASE10, /* Not sure - maybe we can do this the */
RELOC_BASE13, /* right way now */
RELOC_BASE22,
/* for some sort of pc-rel P.I.C. (?) */
RELOC_PC10,
RELOC_PC22,
/* P.I.C. jump table */
RELOC_JMP_TBL,
/* reputedly for shared libraries somehow */
RELOC_SEGOFF16,
RELOC_GLOB_DAT,
RELOC_JMP_SLOT,
RELOC_RELATIVE,
RELOC_11,
RELOC_WDISP2_14,
RELOC_WDISP19,
RELOC_HHI22, /* data[0:21] = (addend + sv) >> 42 */
RELOC_HLO10, /* data[0:9] = (addend + sv) >> 32 */
/* 29K relocation types */
RELOC_JUMPTARG,
RELOC_CONST,
RELOC_CONSTH,
/* All the new ones I can think of, for sparc v9 */
RELOC_64, /* data[0:63] = addend + sv */
RELOC_DISP64, /* data[0:63] = addend - pc + sv */
RELOC_WDISP21, /* data[0:20] = (addend + sv - pc)>>2 */
RELOC_DISP21, /* data[0:20] = addend - pc + sv */
RELOC_DISP14, /* data[0:13] = addend - pc + sv */
/* Q .
What are the other ones,
Since this is a clean slate, can we throw away the ones we dont
understand ? Should we sort the values ? What about using a
microcode format like the 68k ?
*/
NO_RELOC
};
struct reloc_internal {
bfd_vma r_address; /* offset of of data to relocate */
long r_index; /* symbol table index of symbol */
enum reloc_type r_type; /* relocation type */
bfd_vma r_addend; /* datum addend */
};
/* Q.
Should the length of the string table be 4 bytes or 8 bytes ?
Q.
What about archive indexes ?
*/
#endif /* __A_OUT_64_H__ */
/* Table of DBX symbol codes for the GNU system.
Copyright (C) 1988, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* New stab from Solaris 2. This uses an n_type of 0, which in a.out files
overlaps the N_UNDF used for ordinary symbols. In ELF files, the
debug information is in a different file section, so there is no conflict.
This symbol's n_value gives the size of the string section associated
with this file. The symbol's n_strx (relative to the just-updated
string section start address) gives the name of the source file,
e.g. "foo.c", without any path information. The symbol's n_desc gives
the count of upcoming symbols associated with this file (not including
this one). */
/* __define_stab (N_UNDF, 0x00, "UNDF") */
/* Global variable. Only the name is significant.
To find the address, look in the corresponding external symbol. */
__define_stab (N_GSYM, 0x20, "GSYM")
/* Function name for BSD Fortran. Only the name is significant.
To find the address, look in the corresponding external symbol. */
__define_stab (N_FNAME, 0x22, "FNAME")
/* Function name or text-segment variable for C. Value is its address.
Desc is supposedly starting line number, but GCC doesn't set it
and DBX seems not to miss it. */
__define_stab (N_FUN, 0x24, "FUN")
/* Data-segment variable with internal linkage. Value is its address.
"Static Sym". */
__define_stab (N_STSYM, 0x26, "STSYM")
/* BSS-segment variable with internal linkage. Value is its address. */
__define_stab (N_LCSYM, 0x28, "LCSYM")
/* Name of main routine. Only the name is significant. */
__define_stab (N_MAIN, 0x2a, "MAIN")
/* Solaris2: Read-only data symbols. */
__define_stab (N_ROSYM, 0x2c, "ROSYM")
/* Global symbol in Pascal.
Supposedly the value is its line number; I'm skeptical. */
__define_stab (N_PC, 0x30, "PC")
/* Number of symbols: 0, files,,funcs,lines according to Ultrix V4.0. */
__define_stab (N_NSYMS, 0x32, "NSYMS")
/* "No DST map for sym: name, ,0,type,ignored" according to Ultrix V4.0. */
__define_stab (N_NOMAP, 0x34, "NOMAP")
/* New stab from Solaris 2. Like N_SO, but for the object file. Two in
a row provide the build directory and the relative path of the .o from it.
Solaris2 uses this to avoid putting the stabs info into the linked
executable; this stab goes into the ".stab.index" section, and the debugger
reads the real stabs directly from the .o files instead. */
__define_stab (N_OBJ, 0x38, "OBJ")
/* New stab from Solaris 2. Options for the debugger, related to the
source language for this module. E.g. whether to use ANSI
integral promotions or traditional integral promotions. */
__define_stab (N_OPT, 0x3c, "OPT")
/* Register variable. Value is number of register. */
__define_stab (N_RSYM, 0x40, "RSYM")
/* Modula-2 compilation unit. Can someone say what info it contains? */
__define_stab (N_M2C, 0x42, "M2C")
/* Line number in text segment. Desc is the line number;
value is corresponding address. On Solaris2, the line number is
relative to the start of the current function. */
__define_stab (N_SLINE, 0x44, "SLINE")
/* Similar, for data segment. */
__define_stab (N_DSLINE, 0x46, "DSLINE")
/* Similar, for bss segment. */
__define_stab (N_BSLINE, 0x48, "BSLINE")
/* Sun's source-code browser stabs. ?? Don't know what the fields are.
Supposedly the field is "path to associated .cb file". THIS VALUE
OVERLAPS WITH N_BSLINE! */
__define_stab_duplicate (N_BROWS, 0x48, "BROWS")
/* GNU Modula-2 definition module dependency. Value is the modification time
of the definition file. Other is non-zero if it is imported with the
GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
are enough empty fields? */
__define_stab(N_DEFD, 0x4a, "DEFD")
/* New in Solaris2. Function start/body/end line numbers. */
__define_stab(N_FLINE, 0x4C, "FLINE")
/* THE FOLLOWING TWO STAB VALUES CONFLICT. Happily, one is for Modula-2
and one is for C++. Still,... */
/* GNU C++ exception variable. Name is variable name. */
__define_stab (N_EHDECL, 0x50, "EHDECL")
/* Modula2 info "for imc": name,,0,0,0 according to Ultrix V4.0. */
__define_stab_duplicate (N_MOD2, 0x50, "MOD2")
/* GNU C++ `catch' clause. Value is its address. Desc is nonzero if
this entry is immediately followed by a CAUGHT stab saying what exception
was caught. Multiple CAUGHT stabs means that multiple exceptions
can be caught here. If Desc is 0, it means all exceptions are caught
here. */
__define_stab (N_CATCH, 0x54, "CATCH")
/* Structure or union element. Value is offset in the structure. */
__define_stab (N_SSYM, 0x60, "SSYM")
/* Solaris2: Last stab emitted for module. */
__define_stab (N_ENDM, 0x62, "ENDM")
/* Name of main source file.
Value is starting text address of the compilation.
If multiple N_SO's appear, the first to contain a trailing / is the
compilation directory. The first to not contain a trailing / is the
source file name, relative to the compilation directory. Others (perhaps
resulting from cfront) are ignored.
On Solaris2, value is undefined, but desc is a source-language code. */
__define_stab (N_SO, 0x64, "SO")
/* Automatic variable in the stack. Value is offset from frame pointer.
Also used for type descriptions. */
__define_stab (N_LSYM, 0x80, "LSYM")
/* Beginning of an include file. Only Sun uses this.
In an object file, only the name is significant.
The Sun linker puts data into some of the other fields. */
__define_stab (N_BINCL, 0x82, "BINCL")
/* Name of sub-source file (#include file).
Value is starting text address of the compilation. */
__define_stab (N_SOL, 0x84, "SOL")
/* Parameter variable. Value is offset from argument pointer.
(On most machines the argument pointer is the same as the frame pointer. */
__define_stab (N_PSYM, 0xa0, "PSYM")
/* End of an include file. No name.
This and N_BINCL act as brackets around the file's output.
In an object file, there is no significant data in this entry.
The Sun linker puts data into some of the fields. */
__define_stab (N_EINCL, 0xa2, "EINCL")
/* Alternate entry point. Value is its address. */
__define_stab (N_ENTRY, 0xa4, "ENTRY")
/* Beginning of lexical block.
The desc is the nesting level in lexical blocks.
The value is the address of the start of the text for the block.
The variables declared inside the block *precede* the N_LBRAC symbol.
On Solaris2, the value is relative to the start of the current function. */
__define_stab (N_LBRAC, 0xc0, "LBRAC")
/* Place holder for deleted include file. Replaces a N_BINCL and everything
up to the corresponding N_EINCL. The Sun linker generates these when
it finds multiple identical copies of the symbols from an include file.
This appears only in output from the Sun linker. */
__define_stab (N_EXCL, 0xc2, "EXCL")
/* Modula-2 scope information. Can someone say what info it contains? */
__define_stab (N_SCOPE, 0xc4, "SCOPE")
/* End of a lexical block. Desc matches the N_LBRAC's desc.
The value is the address of the end of the text for the block.
On Solaris2, the value is relative to the start of the current function. */
__define_stab (N_RBRAC, 0xe0, "RBRAC")
/* Begin named common block. Only the name is significant. */
__define_stab (N_BCOMM, 0xe2, "BCOMM")
/* End named common block. Only the name is significant
(and it should match the N_BCOMM). */
__define_stab (N_ECOMM, 0xe4, "ECOMM")
/* Member of a common block; value is offset within the common block.
This should occur within a BCOMM/ECOMM pair. */
__define_stab (N_ECOML, 0xe8, "ECOML")
/* Solaris2: Pascal "with" statement: type,,0,0,offset */
__define_stab (N_WITH, 0xea, "WITH")
/* These STAB's are used on Gould systems for Non-Base register symbols
or something like that. FIXME. I have assigned the values at random
since I don't have a Gould here. Fixups from Gould folk welcome... */
__define_stab (N_NBTEXT, 0xF0, "NBTEXT")
__define_stab (N_NBDATA, 0xF2, "NBDATA")
__define_stab (N_NBBSS, 0xF4, "NBBSS")
__define_stab (N_NBSTS, 0xF6, "NBSTS")
__define_stab (N_NBLCS, 0xF8, "NBLCS")
/* Second symbol entry containing a length-value for the preceding entry.
The value is the length. */
__define_stab (N_LENG, 0xfe, "LENG")
/* The above information, in matrix format.
STAB MATRIX
_________________________________________________
| 00 - 1F are not dbx stab symbols |
| In most cases, the low bit is the EXTernal bit|
| 00 UNDEF | 02 ABS | 04 TEXT | 06 DATA |
| 01 |EXT | 03 |EXT | 05 |EXT | 07 |EXT |
| 08 BSS | 0A INDR | 0C FN_SEQ | 0E WEAKA |
| 09 |EXT | 0B | 0D WEAKU | 0F WEAKT |
| 10 WEAKD | 12 COMM | 14 SETA | 16 SETT |
| 11 WEAKB | 13 | 15 | 17 |
| 18 SETD | 1A SETB | 1C SETV | 1E WARNING|
| 19 | 1B | 1D | 1F FN |
|_______________________________________________|
| Debug entries with bit 01 set are unused. |
| 20 GSYM | 22 FNAME | 24 FUN | 26 STSYM |
| 28 LCSYM | 2A MAIN | 2C ROSYM | 2E |
| 30 PC | 32 NSYMS | 34 NOMAP | 36 |
| 38 OBJ | 3A | 3C OPT | 3E |
| 40 RSYM | 42 M2C | 44 SLINE | 46 DSLINE |
| 48 BSLINE*| 4A DEFD | 4C FLINE | 4E |
| 50 EHDECL*| 52 | 54 CATCH | 56 |
| 58 | 5A | 5C | 5E |
| 60 SSYM | 62 ENDM | 64 SO | 66 |
| 68 | 6A | 6C | 6E |
| 70 | 72 | 74 | 76 |
| 78 | 7A | 7C | 7E |
| 80 LSYM | 82 BINCL | 84 SOL | 86 |
| 88 | 8A | 8C | 8E |
| 90 | 92 | 94 | 96 |
| 98 | 9A | 9C | 9E |
| A0 PSYM | A2 EINCL | A4 ENTRY | A6 |
| A8 | AA | AC | AE |
| B0 | B2 | B4 | B6 |
| B8 | BA | BC | BE |
| C0 LBRAC | C2 EXCL | C4 SCOPE | C6 |
| C8 | CA | CC | CE |
| D0 | D2 | D4 | D6 |
| D8 | DA | DC | DE |
| E0 RBRAC | E2 BCOMM | E4 ECOMM | E6 |
| E8 ECOML | EA WITH | EC | EE |
| F0 | F2 | F4 | F6 |
| F8 | FA | FC | FE LENG |
+-----------------------------------------------+
* 50 EHDECL is also MOD2.
* 48 BSLINE is also BROWS.
*/
#ifndef __GNU_STAB__
/* Indicate the GNU stab.h is in use. */
#define __GNU_STAB__
#define __define_stab(NAME, CODE, STRING) NAME=CODE,
#define __define_stab_duplicate(NAME, CODE, STRING) NAME=CODE,
enum __stab_debug_code
{
#include "aout/stab.def"
LAST_UNUSED_STAB_CODE
};
#undef __define_stab
/* Definitions of "desc" field for N_SO stabs in Solaris2. */
#define N_SO_AS 1
#define N_SO_C 2
#define N_SO_ANSI_C 3
#define N_SO_CC 4 /* C++ */
#define N_SO_FORTRAN 5
#define N_SO_PASCAL 6
/* Solaris2: Floating point type values in basic types. */
#define NF_NONE 0
#define NF_SINGLE 1 /* IEEE 32-bit */
#define NF_DOUBLE 2 /* IEEE 64-bit */
#define NF_COMPLEX 3 /* Fortran complex */
#define NF_COMPLEX16 4 /* Fortran double complex */
#define NF_COMPLEX32 5 /* Fortran complex*16 */
#define NF_LDOUBLE 6 /* Long double (whatever that is) */
#endif /* __GNU_STAB_ */
/* bucomm.c -- Bin Utils COMmon code.
Copyright (C) 1991, 92, 93, 94, 95, 1997 Free Software Foundation, Inc.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* We might put this in a library someday so it could be dynamically
loaded, but for now it's not necessary. */
#include <bfd.h>
#include <libiberty.h>
#include "bucomm.h"
#include <sys/stat.h>
#include <time.h> /* ctime, maybe time_t */
#ifdef ANSI_PROTOTYPES
#include <stdarg.h>
#else
#include <varargs.h>
#endif
/* Error reporting */
char *program_name;
void
bfd_nonfatal (string)
CONST char *string;
{
CONST char *errmsg = bfd_errmsg (bfd_get_error ());
if (string)
fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
else
fprintf (stderr, "%s: %s\n", program_name, errmsg);
}
void
bfd_fatal (string)
CONST char *string;
{
bfd_nonfatal (string);
xexit (1);
}
#ifdef ANSI_PROTOTYPES
void
fatal (const char *format, ...)
{
va_list args;
fprintf (stderr, "%s: ", program_name);
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
putc ('\n', stderr);
xexit (1);
}
#else
void
fatal (va_alist)
va_dcl
{
char *Format;
va_list args;
fprintf (stderr, "%s: ", program_name);
va_start (args);
Format = va_arg (args, char *);
vfprintf (stderr, Format, args);
va_end (args);
putc ('\n', stderr);
xexit (1);
}
#endif
/* Set the default BFD target based on the configured target. Doing
this permits the binutils to be configured for a particular target,
and linked against a shared BFD library which was configured for a
different target. */
#define TARGET "elf32-i386" /* FIXME: hard-coded! */
void
set_default_bfd_target ()
{
/* The macro TARGET is defined by Makefile. */
const char *target = TARGET;
if (! bfd_set_default_target (target))
{
char *errmsg;
errmsg = (char *) xmalloc (100 + strlen (target));
sprintf (errmsg, "can't set BFD default target to `%s'", target);
bfd_fatal (errmsg);
}
}
/* After a false return from bfd_check_format_matches with
bfd_get_error () == bfd_error_file_ambiguously_recognized, print
the possible matching targets. */
void
list_matching_formats (p)
char **p;
{
fprintf(stderr, "%s: Matching formats:", program_name);
while (*p)
fprintf(stderr, " %s", *p++);
fprintf(stderr, "\n");
}
/* List the supported targets. */
void
list_supported_targets (name, f)
const char *name;
FILE *f;
{
extern bfd_target *bfd_target_vector[];
int t;
if (name == NULL)
fprintf (f, "Supported targets:");
else
fprintf (f, "%s: supported targets:", name);
for (t = 0; bfd_target_vector[t] != NULL; t++)
fprintf (f, " %s", bfd_target_vector[t]->name);
fprintf (f, "\n");
}
/* Display the archive header for an element as if it were an ls -l listing:
Mode User\tGroup\tSize\tDate Name */
void
print_arelt_descr (file, abfd, verbose)
FILE *file;
bfd *abfd;
boolean verbose;
{
struct stat buf;
if (verbose)
{
if (bfd_stat_arch_elt (abfd, &buf) == 0)
{
char modebuf[11];
char timebuf[40];
time_t when = buf.st_mtime;
CONST char *ctime_result = (CONST char *) ctime (&when);
/* POSIX format: skip weekday and seconds from ctime output. */
sprintf (timebuf, "%.12s %.4s", ctime_result + 4, ctime_result + 20);
mode_string (buf.st_mode, modebuf);
modebuf[10] = '\0';
/* POSIX 1003.2/D11 says to skip first character (entry type). */
fprintf (file, "%s %ld/%ld %6ld %s ", modebuf + 1,
(long) buf.st_uid, (long) buf.st_gid,
(long) buf.st_size, timebuf);
}
}
fprintf (file, "%s\n", bfd_get_filename (abfd));
}
/* Return the name of a temporary file in the same directory as FILENAME. */
char *
make_tempname (filename)
char *filename;
{
static char template[] = "stXXXXXX";
char *tmpname;
char *slash = strrchr (filename, '/');
#if defined (__DJGPP__) || defined (__GO32__) || defined (_WIN32)
if (slash == NULL)
slash = strrchr (filename, '\\');
#endif
if (slash != (char *) NULL)
{
char c;
c = *slash;
*slash = 0;
tmpname = xmalloc (strlen (filename) + sizeof (template) + 1);
strcpy (tmpname, filename);
strcat (tmpname, "/");
strcat (tmpname, template);
mkstemp (tmpname);
*slash = c;
}
else
{
tmpname = xmalloc (sizeof (template));
strcpy (tmpname, template);
mkstemp (tmpname);
}
return tmpname;
}
/* Parse a string into a VMA, with a fatal error if it can't be
parsed. */
bfd_vma
parse_vma (s, arg)
const char *s;
const char *arg;
{
bfd_vma ret;
const char *end;
ret = bfd_scan_vma (s, &end, 0);
if (*end != '\0')
{
fprintf (stderr, "%s: %s: bad number: %s\n", program_name, arg, s);
exit (1);
}
return ret;
}
/* bucomm.h -- binutils common include file.
Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef _BUCOMM_H
#define _BUCOMM_H
#include "ansidecl.h"
#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef __GNUC__
# undef alloca
# define alloca __builtin_alloca
#else
# if HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
# if !defined (__STDC__) && !defined (__hpux)
char *alloca ();
# else
void *alloca ();
# endif /* __STDC__, __hpux */
# endif /* alloca */
# endif /* HAVE_ALLOCA_H */
#endif
#ifndef BFD_TRUE_FALSE
#define boolean bfd_boolean
#define true TRUE
#define false FALSE
#endif
/* bucomm.c */
void bfd_nonfatal PARAMS ((CONST char *));
void bfd_fatal PARAMS ((CONST char *));
void fatal PARAMS ((CONST char *, ...));
void set_default_bfd_target PARAMS ((void));
void list_matching_formats PARAMS ((char **p));
void list_supported_targets PARAMS ((const char *, FILE *));
void print_arelt_descr PARAMS ((FILE *file, bfd *abfd, boolean verbose));
char *make_tempname PARAMS ((char *));
bfd_vma parse_vma PARAMS ((const char *, const char *));
extern char *program_name;
/* filemode.c */
void mode_string PARAMS ((unsigned long mode, char *buf));
/* version.c */
extern void print_version PARAMS ((const char *));
/* libiberty */
PTR xmalloc PARAMS ((size_t));
PTR xrealloc PARAMS ((PTR, size_t));
#endif /* _BUCOMM_H */
/* budbg.c -- Interfaces to the generic debugging information routines.
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#ifndef BUDBG_H
#define BUDBG_H
#include <stdio.h>
#ifndef BFD_TRUE_FALSE
#define boolean bfd_boolean
#define true TRUE
#define false FALSE
#endif
/* Routine used to read generic debugging information. */
extern PTR read_debugging_info PARAMS ((bfd *, asymbol **, long));
/* Routine used to print generic debugging information. */
extern boolean print_debugging_info PARAMS ((FILE *, PTR));
/* Routines used to read and write stabs information. */
extern PTR start_stab PARAMS ((PTR, bfd *, boolean, asymbol **, long));
extern boolean finish_stab PARAMS ((PTR, PTR));
extern boolean parse_stab PARAMS ((PTR, PTR, int, int, bfd_vma, const char *));
extern boolean write_stabs_in_sections_debugging_info
PARAMS ((bfd *, PTR, bfd_byte **, bfd_size_type *, bfd_byte **,
bfd_size_type *));
/* Routines used to read and write IEEE debugging information. */
extern boolean parse_ieee
PARAMS ((PTR, bfd *, const bfd_byte *, bfd_size_type));
extern boolean write_ieee_debugging_info PARAMS ((bfd *, PTR));
/* Routine used to read COFF debugging information. */
extern boolean parse_coff PARAMS ((bfd *, asymbol **, long, PTR));
#endif
/* debug.c -- Handle generic debugging information.
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* This file implements a generic debugging format. We may eventually
have readers which convert different formats into this generic
format, and writers which write it out. The initial impetus for
this was writing a convertor from stabs to HP IEEE-695 debugging
format. */
#include <stdio.h>
#include <assert.h>
#include <bfd.h>
#include "bucomm.h"
#include <libiberty.h>
#include "debug.h"
/* Global information we keep for debugging. A pointer to this
structure is the debugging handle passed to all the routines. */
struct debug_handle
{
/* A linked list of compilation units. */
struct debug_unit *units;
/* The current compilation unit. */
struct debug_unit *current_unit;
/* The current source file. */
struct debug_file *current_file;
/* The current function. */
struct debug_function *current_function;
/* The current block. */
struct debug_block *current_block;
/* The current line number information for the current unit. */
struct debug_lineno *current_lineno;
/* Mark. This is used by debug_write. */
unsigned int mark;
/* A struct/class ID used by debug_write. */
unsigned int class_id;
/* The base for class_id for this call to debug_write. */
unsigned int base_id;
/* The current line number in debug_write. */
struct debug_lineno *current_write_lineno;
unsigned int current_write_lineno_index;
/* A list of classes which have assigned ID's during debug_write.
This is linked through the next_id field of debug_class_type. */
struct debug_class_id *id_list;
/* A list used to avoid recursion during debug_type_samep. */
struct debug_type_compare_list *compare_list;
};
/* Information we keep for a single compilation unit. */
struct debug_unit
{
/* The next compilation unit. */
struct debug_unit *next;
/* A list of files included in this compilation unit. The first
file is always the main one, and that is where the main file name
is stored. */
struct debug_file *files;
/* Line number information for this compilation unit. This is not
stored by function, because assembler code may have line number
information without function information. */
struct debug_lineno *linenos;
};
/* Information kept for a single source file. */
struct debug_file
{
/* The next source file in this compilation unit. */
struct debug_file *next;
/* The name of the source file. */
const char *filename;
/* Global functions, variables, types, etc. */
struct debug_namespace *globals;
};
/* A type. */
struct debug_type
{
/* Kind of type. */
enum debug_type_kind kind;
/* Size of type (0 if not known). */
unsigned int size;
/* Type which is a pointer to this type. */
debug_type pointer;
/* Tagged union with additional information about the type. */
union
{
/* DEBUG_KIND_INDIRECT. */
struct debug_indirect_type *kindirect;
/* DEBUG_KIND_INT. */
/* Whether the integer is unsigned. */
boolean kint;
/* DEBUG_KIND_STRUCT, DEBUG_KIND_UNION, DEBUG_KIND_CLASS,
DEBUG_KIND_UNION_CLASS. */
struct debug_class_type *kclass;
/* DEBUG_KIND_ENUM. */
struct debug_enum_type *kenum;
/* DEBUG_KIND_POINTER. */
struct debug_type *kpointer;
/* DEBUG_KIND_FUNCTION. */
struct debug_function_type *kfunction;
/* DEBUG_KIND_REFERENCE. */
struct debug_type *kreference;
/* DEBUG_KIND_RANGE. */
struct debug_range_type *krange;
/* DEBUG_KIND_ARRAY. */
struct debug_array_type *karray;
/* DEBUG_KIND_SET. */
struct debug_set_type *kset;
/* DEBUG_KIND_OFFSET. */
struct debug_offset_type *koffset;
/* DEBUG_KIND_METHOD. */
struct debug_method_type *kmethod;
/* DEBUG_KIND_CONST. */
struct debug_type *kconst;
/* DEBUG_KIND_VOLATILE. */
struct debug_type *kvolatile;
/* DEBUG_KIND_NAMED, DEBUG_KIND_TAGGED. */
struct debug_named_type *knamed;
} u;
};
/* Information kept for an indirect type. */
struct debug_indirect_type
{
/* Slot where the final type will appear. */
debug_type *slot;
/* Tag. */
const char *tag;
};
/* Information kept for a struct, union, or class. */
struct debug_class_type
{
/* NULL terminated array of fields. */
debug_field *fields;
/* A mark field which indicates whether the struct has already been
printed. */
unsigned int mark;
/* This is used to uniquely identify unnamed structs when printing. */
unsigned int id;
/* The remaining fields are only used for DEBUG_KIND_CLASS and
DEBUG_KIND_UNION_CLASS. */
/* NULL terminated array of base classes. */
debug_baseclass *baseclasses;
/* NULL terminated array of methods. */
debug_method *methods;
/* The type of the class providing the virtual function table for
this class. This may point to the type itself. */
debug_type vptrbase;
};
/* Information kept for an enum. */
struct debug_enum_type
{
/* NULL terminated array of names. */
const char **names;
/* Array of corresponding values. */
bfd_signed_vma *values;
};
/* Information kept for a function. FIXME: We should be able to
record the parameter types. */
struct debug_function_type
{
/* Return type. */
debug_type return_type;
/* NULL terminated array of argument types. */
debug_type *arg_types;
/* Whether the function takes a variable number of arguments. */
boolean varargs;
};
/* Information kept for a range. */
struct debug_range_type
{
/* Range base type. */
debug_type type;
/* Lower bound. */
bfd_signed_vma lower;
/* Upper bound. */
bfd_signed_vma upper;
};
/* Information kept for an array. */
struct debug_array_type
{
/* Element type. */
debug_type element_type;
/* Range type. */
debug_type range_type;
/* Lower bound. */
bfd_signed_vma lower;
/* Upper bound. */
bfd_signed_vma upper;
/* Whether this array is really a string. */
boolean stringp;
};
/* Information kept for a set. */
struct debug_set_type
{
/* Base type. */
debug_type type;
/* Whether this set is really a bitstring. */
boolean bitstringp;
};
/* Information kept for an offset type (a based pointer). */
struct debug_offset_type
{
/* The type the pointer is an offset from. */
debug_type base_type;
/* The type the pointer points to. */
debug_type target_type;
};
/* Information kept for a method type. */
struct debug_method_type
{
/* The return type. */
debug_type return_type;
/* The object type which this method is for. */
debug_type domain_type;
/* A NULL terminated array of argument types. */
debug_type *arg_types;
/* Whether the method takes a variable number of arguments. */
boolean varargs;
};
/* Information kept for a named type. */
struct debug_named_type
{
/* Name. */
struct debug_name *name;
/* Real type. */
debug_type type;
};
/* A field in a struct or union. */
struct debug_field
{
/* Name of the field. */
const char *name;
/* Type of the field. */
struct debug_type *type;
/* Visibility of the field. */
enum debug_visibility visibility;
/* Whether this is a static member. */
boolean static_member;
union
{
/* If static_member is false. */
struct
{
/* Bit position of the field in the struct. */
unsigned int bitpos;
/* Size of the field in bits. */
unsigned int bitsize;
} f;
/* If static_member is true. */
struct
{
const char *physname;
} s;
} u;
};
/* A base class for an object. */
struct debug_baseclass
{
/* Type of the base class. */
struct debug_type *type;
/* Bit position of the base class in the object. */
unsigned int bitpos;
/* Whether the base class is virtual. */
boolean virtual;
/* Visibility of the base class. */
enum debug_visibility visibility;
};
/* A method of an object. */
struct debug_method
{
/* The name of the method. */
const char *name;
/* A NULL terminated array of different types of variants. */
struct debug_method_variant **variants;
};
/* The variants of a method function of an object. These indicate
which method to run. */
struct debug_method_variant
{
/* The physical name of the function. */
const char *physname;
/* The type of the function. */
struct debug_type *type;
/* The visibility of the function. */
enum debug_visibility visibility;
/* Whether the function is const. */
boolean constp;
/* Whether the function is volatile. */
boolean volatilep;
/* The offset to the function in the virtual function table. */
bfd_vma voffset;
/* If voffset is VOFFSET_STATIC_METHOD, this is a static method. */
#define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
/* Context of a virtual method function. */
struct debug_type *context;
};
/* A variable. This is the information we keep for a variable object.
This has no name; a name is associated with a variable in a
debug_name structure. */
struct debug_variable
{
/* Kind of variable. */
enum debug_var_kind kind;
/* Type. */
debug_type type;
/* Value. The interpretation of the value depends upon kind. */
bfd_vma val;
};
/* A function. This has no name; a name is associated with a function
in a debug_name structure. */
struct debug_function
{
/* Return type. */
debug_type return_type;
/* Parameter information. */
struct debug_parameter *parameters;
/* Block information. The first structure on the list is the main
block of the function, and describes function local variables. */
struct debug_block *blocks;
};
/* A function parameter. */
struct debug_parameter
{
/* Next parameter. */
struct debug_parameter *next;
/* Name. */
const char *name;
/* Type. */
debug_type type;
/* Kind. */
enum debug_parm_kind kind;
/* Value (meaning depends upon kind). */
bfd_vma val;
};
/* A typed constant. */
struct debug_typed_constant
{
/* Type. */
debug_type type;
/* Value. FIXME: We may eventually need to support non-integral
values. */
bfd_vma val;
};
/* Information about a block within a function. */
struct debug_block
{
/* Next block with the same parent. */
struct debug_block *next;
/* Parent block. */
struct debug_block *parent;
/* List of child blocks. */
struct debug_block *children;
/* Start address of the block. */
bfd_vma start;
/* End address of the block. */
bfd_vma end;
/* Local variables. */
struct debug_namespace *locals;
};
/* Line number information we keep for a compilation unit. FIXME:
This structure is easy to create, but can be very space
inefficient. */
struct debug_lineno
{
/* More line number information for this block. */
struct debug_lineno *next;
/* Source file. */
struct debug_file *file;
/* Line numbers, terminated by a -1 or the end of the array. */
#define DEBUG_LINENO_COUNT 10
unsigned long linenos[DEBUG_LINENO_COUNT];
/* Addresses for the line numbers. */
bfd_vma addrs[DEBUG_LINENO_COUNT];
};
/* A namespace. This is a mapping from names to objects. FIXME: This
should be implemented as a hash table. */
struct debug_namespace
{
/* List of items in this namespace. */
struct debug_name *list;
/* Pointer to where the next item in this namespace should go. */
struct debug_name **tail;
};
/* Kinds of objects that appear in a namespace. */
enum debug_object_kind
{
/* A type. */
DEBUG_OBJECT_TYPE,
/* A tagged type (really a different sort of namespace). */
DEBUG_OBJECT_TAG,
/* A variable. */
DEBUG_OBJECT_VARIABLE,
/* A function. */
DEBUG_OBJECT_FUNCTION,
/* An integer constant. */
DEBUG_OBJECT_INT_CONSTANT,
/* A floating point constant. */
DEBUG_OBJECT_FLOAT_CONSTANT,
/* A typed constant. */
DEBUG_OBJECT_TYPED_CONSTANT
};
/* Linkage of an object that appears in a namespace. */
enum debug_object_linkage
{
/* Local variable. */
DEBUG_LINKAGE_AUTOMATIC,
/* Static--either file static or function static, depending upon the
namespace is. */
DEBUG_LINKAGE_STATIC,
/* Global. */
DEBUG_LINKAGE_GLOBAL,
/* No linkage. */
DEBUG_LINKAGE_NONE
};
/* A name in a namespace. */
struct debug_name
{
/* Next name in this namespace. */
struct debug_name *next;
/* Name. */
const char *name;
/* Mark. This is used by debug_write. */
unsigned int mark;
/* Kind of object. */
enum debug_object_kind kind;
/* Linkage of object. */
enum debug_object_linkage linkage;
/* Tagged union with additional information about the object. */
union
{
/* DEBUG_OBJECT_TYPE. */
struct debug_type *type;
/* DEBUG_OBJECT_TAG. */
struct debug_type *tag;
/* DEBUG_OBJECT_VARIABLE. */
struct debug_variable *variable;
/* DEBUG_OBJECT_FUNCTION. */
struct debug_function *function;
/* DEBUG_OBJECT_INT_CONSTANT. */
bfd_vma int_constant;
/* DEBUG_OBJECT_FLOAT_CONSTANT. */
double float_constant;
/* DEBUG_OBJECT_TYPED_CONSTANT. */
struct debug_typed_constant *typed_constant;
} u;
};
/* During debug_write, a linked list of these structures is used to
keep track of ID numbers that have been assigned to classes. */
struct debug_class_id
{
/* Next ID number. */
struct debug_class_id *next;
/* The type with the ID. */
struct debug_type *type;
/* The tag; NULL if no tag. */
const char *tag;
};
/* During debug_type_samep, a linked list of these structures is kept
on the stack to avoid infinite recursion. */
struct debug_type_compare_list
{
/* Next type on list. */
struct debug_type_compare_list *next;
/* The types we are comparing. */
struct debug_type *t1;
struct debug_type *t2;
};
/* Local functions. */
static void debug_error PARAMS ((const char *));
static struct debug_name *debug_add_to_namespace
PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
enum debug_object_kind, enum debug_object_linkage));
static struct debug_name *debug_add_to_current_namespace
PARAMS ((struct debug_handle *, const char *, enum debug_object_kind,
enum debug_object_linkage));
static struct debug_type *debug_make_type
PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
static struct debug_type *debug_get_real_type PARAMS ((PTR, debug_type));
static boolean debug_write_name
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_name *));
static boolean debug_write_type
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_type *, struct debug_name *));
static boolean debug_write_class_type
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_type *, const char *));
static boolean debug_write_function
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
const char *, enum debug_object_linkage, struct debug_function *));
static boolean debug_write_block
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
struct debug_block *));
static boolean debug_write_linenos
PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
bfd_vma));
static boolean debug_set_class_id
PARAMS ((struct debug_handle *, const char *, struct debug_type *));
static boolean debug_type_samep
PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
static boolean debug_class_type_samep
PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
/* Issue an error message. */
static void
debug_error (message)
const char *message;
{
fprintf (stderr, "%s\n", message);
}
/* Add an object to a namespace. */
static struct debug_name *
debug_add_to_namespace (info, nsp, name, kind, linkage)
struct debug_handle *info;
struct debug_namespace **nsp;
const char *name;
enum debug_object_kind kind;
enum debug_object_linkage linkage;
{
struct debug_name *n;
struct debug_namespace *ns;
n = (struct debug_name *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->name = name;
n->kind = kind;
n->linkage = linkage;
ns = *nsp;
if (ns == NULL)
{
ns = (struct debug_namespace *) xmalloc (sizeof *ns);
memset (ns, 0, sizeof *ns);
ns->tail = &ns->list;
*nsp = ns;
}
*ns->tail = n;
ns->tail = &n->next;
return n;
}
/* Add an object to the current namespace. */
static struct debug_name *
debug_add_to_current_namespace (info, name, kind, linkage)
struct debug_handle *info;
const char *name;
enum debug_object_kind kind;
enum debug_object_linkage linkage;
{
struct debug_namespace **nsp;
if (info->current_unit == NULL
|| info->current_file == NULL)
{
debug_error ("debug_add_to_current_namespace: no current file");
return NULL;
}
if (info->current_block != NULL)
nsp = &info->current_block->locals;
else
nsp = &info->current_file->globals;
return debug_add_to_namespace (info, nsp, name, kind, linkage);
}
/* Return a handle for debugging information. */
PTR
debug_init ()
{
struct debug_handle *ret;
ret = (struct debug_handle *) xmalloc (sizeof *ret);
memset (ret, 0, sizeof *ret);
return (PTR) ret;
}
/* Set the source filename. This implicitly starts a new compilation
unit. */
boolean
debug_set_filename (handle, name)
PTR handle;
const char *name;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_file *nfile;
struct debug_unit *nunit;
if (name == NULL)
name = "";
nfile = (struct debug_file *) xmalloc (sizeof *nfile);
memset (nfile, 0, sizeof *nfile);
nfile->filename = name;
nunit = (struct debug_unit *) xmalloc (sizeof *nunit);
memset (nunit, 0, sizeof *nunit);
nunit->files = nfile;
info->current_file = nfile;
if (info->current_unit != NULL)
info->current_unit->next = nunit;
else
{
assert (info->units == NULL);
info->units = nunit;
}
info->current_unit = nunit;
info->current_function = NULL;
info->current_block = NULL;
info->current_lineno = NULL;
return true;
}
/* Change source files to the given file name. This is used for
include files in a single compilation unit. */
boolean
debug_start_source (handle, name)
PTR handle;
const char *name;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_file *f, **pf;
if (name == NULL)
name = "";
if (info->current_unit == NULL)
{
debug_error ("debug_start_source: no debug_set_filename call");
return false;
}
for (f = info->current_unit->files; f != NULL; f = f->next)
{
if (f->filename[0] == name[0]
&& f->filename[1] == name[1]
&& strcmp (f->filename, name) == 0)
{
info->current_file = f;
return true;
}
}
f = (struct debug_file *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->filename = name;
for (pf = &info->current_file->next;
*pf != NULL;
pf = &(*pf)->next)
;
*pf = f;
info->current_file = f;
return true;
}
/* Record a function definition. This implicitly starts a function
block. The debug_type argument is the type of the return value.
The boolean indicates whether the function is globally visible.
The bfd_vma is the address of the start of the function. Currently
the parameter types are specified by calls to
debug_record_parameter. FIXME: There is no way to specify nested
functions. */
boolean
debug_record_function (handle, name, return_type, global, addr)
PTR handle;
const char *name;
debug_type return_type;
boolean global;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_function *f;
struct debug_block *b;
struct debug_name *n;
if (name == NULL)
name = "";
if (return_type == NULL)
return false;
if (info->current_unit == NULL)
{
debug_error ("debug_record_function: no debug_set_filename call");
return false;
}
f = (struct debug_function *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->return_type = return_type;
b = (struct debug_block *) xmalloc (sizeof *b);
memset (b, 0, sizeof *b);
b->start = addr;
b->end = (bfd_vma) -1;
f->blocks = b;
info->current_function = f;
info->current_block = b;
/* FIXME: If we could handle nested functions, this would be the
place: we would want to use a different namespace. */
n = debug_add_to_namespace (info,
&info->current_file->globals,
name,
DEBUG_OBJECT_FUNCTION,
(global
? DEBUG_LINKAGE_GLOBAL
: DEBUG_LINKAGE_STATIC));
if (n == NULL)
return false;
n->u.function = f;
return true;
}
/* Record a parameter for the current function. */
boolean
debug_record_parameter (handle, name, type, kind, val)
PTR handle;
const char *name;
debug_type type;
enum debug_parm_kind kind;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_parameter *p, **pp;
if (name == NULL || type == NULL)
return false;
if (info->current_unit == NULL
|| info->current_function == NULL)
{
debug_error ("debug_record_parameter: no current function");
return false;
}
p = (struct debug_parameter *) xmalloc (sizeof *p);
memset (p, 0, sizeof *p);
p->name = name;
p->type = type;
p->kind = kind;
p->val = val;
for (pp = &info->current_function->parameters;
*pp != NULL;
pp = &(*pp)->next)
;
*pp = p;
return true;
}
/* End a function. FIXME: This should handle function nesting. */
boolean
debug_end_function (handle, addr)
PTR handle;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
if (info->current_unit == NULL
|| info->current_block == NULL
|| info->current_function == NULL)
{
debug_error ("debug_end_function: no current function");
return false;
}
if (info->current_block->parent != NULL)
{
debug_error ("debug_end_function: some blocks were not closed");
return false;
}
info->current_block->end = addr;
info->current_function = NULL;
info->current_block = NULL;
return true;
}
/* Start a block in a function. All local information will be
recorded in this block, until the matching call to debug_end_block.
debug_start_block and debug_end_block may be nested. The bfd_vma
argument is the address at which this block starts. */
boolean
debug_start_block (handle, addr)
PTR handle;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_block *b, **pb;
/* We must always have a current block: debug_record_function sets
one up. */
if (info->current_unit == NULL
|| info->current_block == NULL)
{
debug_error ("debug_start_block: no current block");
return false;
}
b = (struct debug_block *) xmalloc (sizeof *b);
memset (b, 0, sizeof *b);
b->parent = info->current_block;
b->start = addr;
b->end = (bfd_vma) -1;
/* This new block is a child of the current block. */
for (pb = &info->current_block->children;
*pb != NULL;
pb = &(*pb)->next)
;
*pb = b;
info->current_block = b;
return true;
}
/* Finish a block in a function. This matches the call to
debug_start_block. The argument is the address at which this block
ends. */
boolean
debug_end_block (handle, addr)
PTR handle;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_block *parent;
if (info->current_unit == NULL
|| info->current_block == NULL)
{
debug_error ("debug_end_block: no current block");
return false;
}
parent = info->current_block->parent;
if (parent == NULL)
{
debug_error ("debug_end_block: attempt to close top level block");
return false;
}
info->current_block->end = addr;
info->current_block = parent;
return true;
}
/* Associate a line number in the current source file and function
with a given address. */
boolean
debug_record_line (handle, lineno, addr)
PTR handle;
unsigned long lineno;
bfd_vma addr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_lineno *l;
unsigned int i;
if (info->current_unit == NULL)
{
debug_error ("debug_record_line: no current unit");
return false;
}
l = info->current_lineno;
if (l != NULL && l->file == info->current_file)
{
for (i = 0; i < DEBUG_LINENO_COUNT; i++)
{
if (l->linenos[i] == (unsigned long) -1)
{
l->linenos[i] = lineno;
l->addrs[i] = addr;
return true;
}
}
}
/* If we get here, then either 1) there is no current_lineno
structure, which means this is the first line number in this
compilation unit, 2) the current_lineno structure is for a
different file, or 3) the current_lineno structure is full.
Regardless, we want to allocate a new debug_lineno structure, put
it in the right place, and make it the new current_lineno
structure. */
l = (struct debug_lineno *) xmalloc (sizeof *l);
memset (l, 0, sizeof *l);
l->file = info->current_file;
l->linenos[0] = lineno;
l->addrs[0] = addr;
for (i = 1; i < DEBUG_LINENO_COUNT; i++)
l->linenos[i] = (unsigned long) -1;
if (info->current_lineno != NULL)
info->current_lineno->next = l;
else
info->current_unit->linenos = l;
info->current_lineno = l;
return true;
}
/* Start a named common block. This is a block of variables that may
move in memory. */
boolean
debug_start_common_block (handle, name)
PTR handle;
const char *name;
{
/* FIXME */
debug_error ("debug_start_common_block: not implemented");
return false;
}
/* End a named common block. */
boolean
debug_end_common_block (handle, name)
PTR handle;
const char *name;
{
/* FIXME */
debug_error ("debug_end_common_block: not implemented");
return false;
}
/* Record a named integer constant. */
boolean
debug_record_int_const (handle, name, val)
PTR handle;
const char *name;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_name *n;
if (name == NULL)
return false;
n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_INT_CONSTANT,
DEBUG_LINKAGE_NONE);
if (n == NULL)
return false;
n->u.int_constant = val;
return true;
}
/* Record a named floating point constant. */
boolean
debug_record_float_const (handle, name, val)
PTR handle;
const char *name;
double val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_name *n;
if (name == NULL)
return false;
n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_FLOAT_CONSTANT,
DEBUG_LINKAGE_NONE);
if (n == NULL)
return false;
n->u.float_constant = val;
return true;
}
/* Record a typed constant with an integral value. */
boolean
debug_record_typed_const (handle, name, type, val)
PTR handle;
const char *name;
debug_type type;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_name *n;
struct debug_typed_constant *tc;
if (name == NULL || type == NULL)
return false;
n = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPED_CONSTANT,
DEBUG_LINKAGE_NONE);
if (n == NULL)
return false;
tc = (struct debug_typed_constant *) xmalloc (sizeof *tc);
memset (tc, 0, sizeof *tc);
tc->type = type;
tc->val = val;
n->u.typed_constant = tc;
return true;
}
/* Record a label. */
boolean
debug_record_label (handle, name, type, addr)
PTR handle;
const char *name;
debug_type type;
bfd_vma addr;
{
/* FIXME. */
debug_error ("debug_record_label not implemented");
return false;
}
/* Record a variable. */
boolean
debug_record_variable (handle, name, type, kind, val)
PTR handle;
const char *name;
debug_type type;
enum debug_var_kind kind;
bfd_vma val;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_namespace **nsp;
enum debug_object_linkage linkage;
struct debug_name *n;
struct debug_variable *v;
if (name == NULL || type == NULL)
return false;
if (info->current_unit == NULL
|| info->current_file == NULL)
{
debug_error ("debug_record_variable: no current file");
return false;
}
if (kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
{
nsp = &info->current_file->globals;
if (kind == DEBUG_GLOBAL)
linkage = DEBUG_LINKAGE_GLOBAL;
else
linkage = DEBUG_LINKAGE_STATIC;
}
else
{
if (info->current_block == NULL)
{
debug_error ("debug_record_variable: no current block");
return false;
}
nsp = &info->current_block->locals;
linkage = DEBUG_LINKAGE_AUTOMATIC;
}
n = debug_add_to_namespace (info, nsp, name, DEBUG_OBJECT_VARIABLE, linkage);
if (n == NULL)
return false;
v = (struct debug_variable *) xmalloc (sizeof *v);
memset (v, 0, sizeof *v);
v->kind = kind;
v->type = type;
v->val = val;
n->u.variable = v;
return true;
}
/* Make a type with a given kind and size. */
/*ARGSUSED*/
static struct debug_type *
debug_make_type (info, kind, size)
struct debug_handle *info;
enum debug_type_kind kind;
unsigned int size;
{
struct debug_type *t;
t = (struct debug_type *) xmalloc (sizeof *t);
memset (t, 0, sizeof *t);
t->kind = kind;
t->size = size;
return t;
}
/* Make an indirect type which may be used as a placeholder for a type
which is referenced before it is defined. */
debug_type
debug_make_indirect_type (handle, slot, tag)
PTR handle;
debug_type *slot;
const char *tag;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_indirect_type *i;
t = debug_make_type (info, DEBUG_KIND_INDIRECT, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
i = (struct debug_indirect_type *) xmalloc (sizeof *i);
memset (i, 0, sizeof *i);
i->slot = slot;
i->tag = tag;
t->u.kindirect = i;
return t;
}
/* Make a void type. There is only one of these. */
debug_type
debug_make_void_type (handle)
PTR handle;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_VOID, 0);
}
/* Make an integer type of a given size. The boolean argument is true
if the integer is unsigned. */
debug_type
debug_make_int_type (handle, size, unsignedp)
PTR handle;
unsigned int size;
boolean unsignedp;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
t = debug_make_type (info, DEBUG_KIND_INT, size);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kint = unsignedp;
return t;
}
/* Make a floating point type of a given size. FIXME: On some
platforms, like an Alpha, you probably need to be able to specify
the format. */
debug_type
debug_make_float_type (handle, size)
PTR handle;
unsigned int size;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_FLOAT, size);
}
/* Make a boolean type of a given size. */
debug_type
debug_make_bool_type (handle, size)
PTR handle;
unsigned int size;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_BOOL, size);
}
/* Make a complex type of a given size. */
debug_type
debug_make_complex_type (handle, size)
PTR handle;
unsigned int size;
{
struct debug_handle *info = (struct debug_handle *) handle;
return debug_make_type (info, DEBUG_KIND_COMPLEX, size);
}
/* Make a structure type. The second argument is true for a struct,
false for a union. The third argument is the size of the struct.
The fourth argument is a NULL terminated array of fields. */
debug_type
debug_make_struct_type (handle, structp, size, fields)
PTR handle;
boolean structp;
bfd_vma size;
debug_field *fields;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_class_type *c;
t = debug_make_type (info,
structp ? DEBUG_KIND_STRUCT : DEBUG_KIND_UNION,
size);
if (t == NULL)
return DEBUG_TYPE_NULL;
c = (struct debug_class_type *) xmalloc (sizeof *c);
memset (c, 0, sizeof *c);
c->fields = fields;
t->u.kclass = c;
return t;
}
/* Make an object type. The first three arguments after the handle
are the same as for debug_make_struct_type. The next arguments are
a NULL terminated array of base classes, a NULL terminated array of
methods, the type of the object holding the virtual function table
if it is not this object, and a boolean which is true if this
object has its own virtual function table. */
debug_type
debug_make_object_type (handle, structp, size, fields, baseclasses,
methods, vptrbase, ownvptr)
PTR handle;
boolean structp;
bfd_vma size;
debug_field *fields;
debug_baseclass *baseclasses;
debug_method *methods;
debug_type vptrbase;
boolean ownvptr;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_class_type *c;
t = debug_make_type (info,
structp ? DEBUG_KIND_CLASS : DEBUG_KIND_UNION_CLASS,
size);
if (t == NULL)
return DEBUG_TYPE_NULL;
c = (struct debug_class_type *) xmalloc (sizeof *c);
memset (c, 0, sizeof *c);
c->fields = fields;
c->baseclasses = baseclasses;
c->methods = methods;
if (ownvptr)
c->vptrbase = t;
else
c->vptrbase = vptrbase;
t->u.kclass = c;
return t;
}
/* Make an enumeration type. The arguments are a null terminated
array of strings, and an array of corresponding values. */
debug_type
debug_make_enum_type (handle, names, values)
PTR handle;
const char **names;
bfd_signed_vma *values;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_enum_type *e;
t = debug_make_type (info, DEBUG_KIND_ENUM, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
e = (struct debug_enum_type *) xmalloc (sizeof *e);
memset (e, 0, sizeof *e);
e->names = names;
e->values = values;
t->u.kenum = e;
return t;
}
/* Make a pointer to a given type. */
debug_type
debug_make_pointer_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
if (type->pointer != DEBUG_TYPE_NULL)
return type->pointer;
t = debug_make_type (info, DEBUG_KIND_POINTER, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kpointer = type;
type->pointer = t;
return t;
}
/* Make a function returning a given type. FIXME: We should be able
to record the parameter types. */
debug_type
debug_make_function_type (handle, type, arg_types, varargs)
PTR handle;
debug_type type;
debug_type *arg_types;
boolean varargs;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_function_type *f;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_FUNCTION, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
f = (struct debug_function_type *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->return_type = type;
f->arg_types = arg_types;
f->varargs = varargs;
t->u.kfunction = f;
return t;
}
/* Make a reference to a given type. */
debug_type
debug_make_reference_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_REFERENCE, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kreference = type;
return t;
}
/* Make a range of a given type from a lower to an upper bound. */
debug_type
debug_make_range_type (handle, type, lower, upper)
PTR handle;
debug_type type;
bfd_signed_vma lower;
bfd_signed_vma upper;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_range_type *r;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_RANGE, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
r = (struct debug_range_type *) xmalloc (sizeof *r);
memset (r, 0, sizeof *r);
r->type = type;
r->lower = lower;
r->upper = upper;
t->u.krange = r;
return t;
}
/* Make an array type. The second argument is the type of an element
of the array. The third argument is the type of a range of the
array. The fourth and fifth argument are the lower and upper
bounds, respectively. The sixth argument is true if this array is
actually a string, as in C. */
debug_type
debug_make_array_type (handle, element_type, range_type, lower, upper,
stringp)
PTR handle;
debug_type element_type;
debug_type range_type;
bfd_signed_vma lower;
bfd_signed_vma upper;
boolean stringp;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_array_type *a;
if (element_type == NULL || range_type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_ARRAY, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
a = (struct debug_array_type *) xmalloc (sizeof *a);
memset (a, 0, sizeof *a);
a->element_type = element_type;
a->range_type = range_type;
a->lower = lower;
a->upper = upper;
a->stringp = stringp;
t->u.karray = a;
return t;
}
/* Make a set of a given type. For example, a Pascal set type. The
boolean argument is true if this set is actually a bitstring, as in
CHILL. */
debug_type
debug_make_set_type (handle, type, bitstringp)
PTR handle;
debug_type type;
boolean bitstringp;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_set_type *s;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_SET, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
s = (struct debug_set_type *) xmalloc (sizeof *s);
memset (s, 0, sizeof *s);
s->type = type;
s->bitstringp = bitstringp;
t->u.kset = s;
return t;
}
/* Make a type for a pointer which is relative to an object. The
second argument is the type of the object to which the pointer is
relative. The third argument is the type that the pointer points
to. */
debug_type
debug_make_offset_type (handle, base_type, target_type)
PTR handle;
debug_type base_type;
debug_type target_type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_offset_type *o;
if (base_type == NULL || target_type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_OFFSET, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
o = (struct debug_offset_type *) xmalloc (sizeof *o);
memset (o, 0, sizeof *o);
o->base_type = base_type;
o->target_type = target_type;
t->u.koffset = o;
return t;
}
/* Make a type for a method function. The second argument is the
return type, the third argument is the domain, and the fourth
argument is a NULL terminated array of argument types. */
debug_type
debug_make_method_type (handle, return_type, domain_type, arg_types, varargs)
PTR handle;
debug_type return_type;
debug_type domain_type;
debug_type *arg_types;
boolean varargs;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_method_type *m;
if (return_type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_METHOD, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
m = (struct debug_method_type *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->return_type = return_type;
m->domain_type = domain_type;
m->arg_types = arg_types;
m->varargs = varargs;
t->u.kmethod = m;
return t;
}
/* Make a const qualified version of a given type. */
debug_type
debug_make_const_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_CONST, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kconst = type;
return t;
}
/* Make a volatile qualified version of a given type. */
debug_type
debug_make_volatile_type (handle, type)
PTR handle;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (type == NULL)
return DEBUG_TYPE_NULL;
t = debug_make_type (info, DEBUG_KIND_VOLATILE, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
t->u.kvolatile = type;
return t;
}
/* Make an undefined tagged type. For example, a struct which has
been mentioned, but not defined. */
debug_type
debug_make_undefined_tagged_type (handle, name, kind)
PTR handle;
const char *name;
enum debug_type_kind kind;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
if (name == NULL)
return DEBUG_TYPE_NULL;
switch (kind)
{
case DEBUG_KIND_STRUCT:
case DEBUG_KIND_UNION:
case DEBUG_KIND_CLASS:
case DEBUG_KIND_UNION_CLASS:
case DEBUG_KIND_ENUM:
break;
default:
debug_error ("debug_make_undefined_type: unsupported kind");
return DEBUG_TYPE_NULL;
}
t = debug_make_type (info, kind, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
return debug_tag_type (handle, name, t);
}
/* Make a base class for an object. The second argument is the base
class type. The third argument is the bit position of this base
class in the object (always 0 unless doing multiple inheritance).
The fourth argument is whether this is a virtual class. The fifth
argument is the visibility of the base class. */
/*ARGSUSED*/
debug_baseclass
debug_make_baseclass (handle, type, bitpos, virtual, visibility)
PTR handle;
debug_type type;
bfd_vma bitpos;
boolean virtual;
enum debug_visibility visibility;
{
struct debug_baseclass *b;
b = (struct debug_baseclass *) xmalloc (sizeof *b);
memset (b, 0, sizeof *b);
b->type = type;
b->bitpos = bitpos;
b->virtual = virtual;
b->visibility = visibility;
return b;
}
/* Make a field for a struct. The second argument is the name. The
third argument is the type of the field. The fourth argument is
the bit position of the field. The fifth argument is the size of
the field (it may be zero). The sixth argument is the visibility
of the field. */
/*ARGSUSED*/
debug_field
debug_make_field (handle, name, type, bitpos, bitsize, visibility)
PTR handle;
const char *name;
debug_type type;
bfd_vma bitpos;
bfd_vma bitsize;
enum debug_visibility visibility;
{
struct debug_field *f;
f = (struct debug_field *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->name = name;
f->type = type;
f->static_member = false;
f->u.f.bitpos = bitpos;
f->u.f.bitsize = bitsize;
f->visibility = visibility;
return f;
}
/* Make a static member of an object. The second argument is the
name. The third argument is the type of the member. The fourth
argument is the physical name of the member (i.e., the name as a
global variable). The fifth argument is the visibility of the
member. */
/*ARGSUSED*/
debug_field
debug_make_static_member (handle, name, type, physname, visibility)
PTR handle;
const char *name;
debug_type type;
const char *physname;
enum debug_visibility visibility;
{
struct debug_field *f;
f = (struct debug_field *) xmalloc (sizeof *f);
memset (f, 0, sizeof *f);
f->name = name;
f->type = type;
f->static_member = true;
f->u.s.physname = physname;
f->visibility = visibility;
return f;
}
/* Make a method. The second argument is the name, and the third
argument is a NULL terminated array of method variants. */
/*ARGSUSED*/
debug_method
debug_make_method (handle, name, variants)
PTR handle;
const char *name;
debug_method_variant *variants;
{
struct debug_method *m;
m = (struct debug_method *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->name = name;
m->variants = variants;
return m;
}
/* Make a method argument. The second argument is the real name of
the function. The third argument is the type of the function. The
fourth argument is the visibility. The fifth argument is whether
this is a const function. The sixth argument is whether this is a
volatile function. The seventh argument is the offset in the
virtual function table, if any. The eighth argument is the virtual
function context. FIXME: Are the const and volatile arguments
necessary? Could we just use debug_make_const_type? */
/*ARGSUSED*/
debug_method_variant
debug_make_method_variant (handle, physname, type, visibility, constp,
volatilep, voffset, context)
PTR handle;
const char *physname;
debug_type type;
enum debug_visibility visibility;
boolean constp;
boolean volatilep;
bfd_vma voffset;
debug_type context;
{
struct debug_method_variant *m;
m = (struct debug_method_variant *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->physname = physname;
m->type = type;
m->visibility = visibility;
m->constp = constp;
m->volatilep = volatilep;
m->voffset = voffset;
m->context = context;
return m;
}
/* Make a static method argument. The arguments are the same as for
debug_make_method_variant, except that the last two are omitted
since a static method can not also be virtual. */
debug_method_variant
debug_make_static_method_variant (handle, physname, type, visibility,
constp, volatilep)
PTR handle;
const char *physname;
debug_type type;
enum debug_visibility visibility;
boolean constp;
boolean volatilep;
{
struct debug_method_variant *m;
m = (struct debug_method_variant *) xmalloc (sizeof *m);
memset (m, 0, sizeof *m);
m->physname = physname;
m->type = type;
m->visibility = visibility;
m->constp = constp;
m->volatilep = volatilep;
m->voffset = VOFFSET_STATIC_METHOD;
return m;
}
/* Name a type. */
debug_type
debug_name_type (handle, name, type)
PTR handle;
const char *name;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_named_type *n;
struct debug_name *nm;
if (name == NULL || type == NULL)
return DEBUG_TYPE_NULL;
if (info->current_unit == NULL
|| info->current_file == NULL)
{
debug_error ("debug_name_type: no current file");
return DEBUG_TYPE_NULL;
/* return false; */
}
t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
n = (struct debug_named_type *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->type = type;
t->u.knamed = n;
/* We always add the name to the global namespace. This is probably
wrong in some cases, but it seems to be right for stabs. FIXME. */
nm = debug_add_to_namespace (info, &info->current_file->globals, name,
DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
if (nm == NULL)
return DEBUG_TYPE_NULL;
nm->u.type = t;
n->name = nm;
return t;
}
/* Tag a type. */
debug_type
debug_tag_type (handle, name, type)
PTR handle;
const char *name;
debug_type type;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_type *t;
struct debug_named_type *n;
struct debug_name *nm;
if (name == NULL || type == NULL)
return DEBUG_TYPE_NULL;
if (info->current_file == NULL)
{
debug_error ("debug_tag_type: no current file");
return DEBUG_TYPE_NULL;
}
if (type->kind == DEBUG_KIND_TAGGED)
{
if (strcmp (type->u.knamed->name->name, name) == 0)
return type;
debug_error ("debug_tag_type: extra tag attempted");
return DEBUG_TYPE_NULL;
}
t = debug_make_type (info, DEBUG_KIND_TAGGED, 0);
if (t == NULL)
return DEBUG_TYPE_NULL;
n = (struct debug_named_type *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->type = type;
t->u.knamed = n;
/* We keep a global namespace of tags for each compilation unit. I
don't know if that is the right thing to do. */
nm = debug_add_to_namespace (info, &info->current_file->globals, name,
DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
if (nm == NULL)
return DEBUG_TYPE_NULL;
nm->u.tag = t;
n->name = nm;
return t;
}
/* Record the size of a given type. */
/*ARGSUSED*/
boolean
debug_record_type_size (handle, type, size)
PTR handle;
debug_type type;
unsigned int size;
{
#if 0
if (type->size != 0 && type->size != size)
fprintf (stderr, "Warning: changing type size from %d to %d\n",
type->size, size);
#endif
type->size = size;
return true;
}
/* Find a named type. */
debug_type
debug_find_named_type (handle, name)
PTR handle;
const char *name;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_block *b;
struct debug_file *f;
/* We only search the current compilation unit. I don't know if
this is right or not. */
if (info->current_unit == NULL)
{
debug_error ("debug_find_named_type: no current compilation unit");
return DEBUG_TYPE_NULL;
}
for (b = info->current_block; b != NULL; b = b->parent)
{
if (b->locals != NULL)
{
struct debug_name *n;
for (n = b->locals->list; n != NULL; n = n->next)
{
if (n->kind == DEBUG_OBJECT_TYPE
&& n->name[0] == name[0]
&& strcmp (n->name, name) == 0)
return n->u.type;
}
}
}
for (f = info->current_unit->files; f != NULL; f = f->next)
{
if (f->globals != NULL)
{
struct debug_name *n;
for (n = f->globals->list; n != NULL; n = n->next)
{
if (n->kind == DEBUG_OBJECT_TYPE
&& n->name[0] == name[0]
&& strcmp (n->name, name) == 0)
return n->u.type;
}
}
}
return DEBUG_TYPE_NULL;
}
/* Find a tagged type. */
debug_type
debug_find_tagged_type (handle, name, kind)
PTR handle;
const char *name;
enum debug_type_kind kind;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_unit *u;
/* We search the globals of all the compilation units. I don't know
if this is correct or not. It would be easy to change. */
for (u = info->units; u != NULL; u = u->next)
{
struct debug_file *f;
for (f = u->files; f != NULL; f = f->next)
{
struct debug_name *n;
if (f->globals != NULL)
{
for (n = f->globals->list; n != NULL; n = n->next)
{
if (n->kind == DEBUG_OBJECT_TAG
&& (kind == DEBUG_KIND_ILLEGAL
|| n->u.tag->kind == kind)
&& n->name[0] == name[0]
&& strcmp (n->name, name) == 0)
return n->u.tag;
}
}
}
}
return DEBUG_TYPE_NULL;
}
/* Get a base type. */
static struct debug_type *
debug_get_real_type (handle, type)
PTR handle;
debug_type type;
{
switch (type->kind)
{
default:
return type;
case DEBUG_KIND_INDIRECT:
if (*type->u.kindirect->slot != NULL)
return debug_get_real_type (handle, *type->u.kindirect->slot);
return type;
case DEBUG_KIND_NAMED:
case DEBUG_KIND_TAGGED:
return debug_get_real_type (handle, type->u.knamed->type);
}
/*NOTREACHED*/
}
/* Get the kind of a type. */
enum debug_type_kind
debug_get_type_kind (handle, type)
PTR handle;
debug_type type;
{
if (type == NULL)
return DEBUG_KIND_ILLEGAL;
type = debug_get_real_type (handle, type);
return type->kind;
}
/* Get the name of a type. */
const char *
debug_get_type_name (handle, type)
PTR handle;
debug_type type;
{
if (type->kind == DEBUG_KIND_INDIRECT)
{
if (*type->u.kindirect->slot != NULL)
return debug_get_type_name (handle, *type->u.kindirect->slot);
return type->u.kindirect->tag;
}
if (type->kind == DEBUG_KIND_NAMED
|| type->kind == DEBUG_KIND_TAGGED)
return type->u.knamed->name->name;
return NULL;
}
/* Get the size of a type. */
bfd_vma
debug_get_type_size (handle, type)
PTR handle;
debug_type type;
{
if (type == NULL)
return 0;
/* We don't call debug_get_real_type, because somebody might have
called debug_record_type_size on a named or indirect type. */
if (type->size != 0)
return type->size;
switch (type->kind)
{
default:
return 0;
case DEBUG_KIND_INDIRECT:
if (*type->u.kindirect->slot != NULL)
return debug_get_type_size (handle, *type->u.kindirect->slot);
return 0;
case DEBUG_KIND_NAMED:
case DEBUG_KIND_TAGGED:
return debug_get_type_size (handle, type->u.knamed->type);
}
/*NOTREACHED*/
}
/* Get the return type of a function or method type. */
debug_type
debug_get_return_type (handle, type)
PTR handle;
debug_type type;
{
if (type == NULL)
return DEBUG_TYPE_NULL;
type = debug_get_real_type (handle, type);
switch (type->kind)
{
default:
return DEBUG_TYPE_NULL;
case DEBUG_KIND_FUNCTION:
return type->u.kfunction->return_type;
case DEBUG_KIND_METHOD:
return type->u.kmethod->return_type;
}
/*NOTREACHED*/
}
/* Get the parameter types of a function or method type (except that
we don't currently store the parameter types of a function). */
const debug_type *
debug_get_parameter_types (handle, type, pvarargs)
PTR handle;
debug_type type;
boolean *pvarargs;
{
if (type == NULL)
return NULL;
type = debug_get_real_type (handle, type);
switch (type->kind)
{
default:
return NULL;
case DEBUG_KIND_FUNCTION:
*pvarargs = type->u.kfunction->varargs;
return type->u.kfunction->arg_types;
case DEBUG_KIND_METHOD:
*pvarargs = type->u.kmethod->varargs;
return type->u.kmethod->arg_types;
}
/*NOTREACHED*/
}
/* Get the target type of a type. */
debug_type
debug_get_target_type (handle, type)
PTR handle;
debug_type type;
{
if (type == NULL)
return NULL;
type = debug_get_real_type (handle, type);
switch (type->kind)
{
default:
return NULL;
case DEBUG_KIND_POINTER:
return type->u.kpointer;
case DEBUG_KIND_REFERENCE:
return type->u.kreference;
case DEBUG_KIND_CONST:
return type->u.kconst;
case DEBUG_KIND_VOLATILE:
return type->u.kvolatile;
}
/*NOTREACHED*/
}
/* Get the NULL terminated array of fields for a struct, union, or
class. */
const debug_field *
debug_get_fields (handle, type)
PTR handle;
debug_type type;
{
if (type == NULL)
return NULL;
type = debug_get_real_type (handle, type);
switch (type->kind)
{
default:
return NULL;
case DEBUG_KIND_STRUCT:
case DEBUG_KIND_UNION:
case DEBUG_KIND_CLASS:
case DEBUG_KIND_UNION_CLASS:
return type->u.kclass->fields;
}
/*NOTREACHED*/
}
/* Get the type of a field. */
/*ARGSUSED*/
debug_type
debug_get_field_type (handle, field)
PTR handle;
debug_field field;
{
if (field == NULL)
return NULL;
return field->type;
}
/* Get the name of a field. */
/*ARGSUSED*/
const char *
debug_get_field_name (handle, field)
PTR handle;
debug_field field;
{
if (field == NULL)
return NULL;
return field->name;
}
/* Get the bit position of a field. */
/*ARGSUSED*/
bfd_vma
debug_get_field_bitpos (handle, field)
PTR handle;
debug_field field;
{
if (field == NULL || field->static_member)
return (bfd_vma) -1;
return field->u.f.bitpos;
}
/* Get the bit size of a field. */
/*ARGSUSED*/
bfd_vma
debug_get_field_bitsize (handle, field)
PTR handle;
debug_field field;
{
if (field == NULL || field->static_member)
return (bfd_vma) -1;
return field->u.f.bitsize;
}
/* Get the visibility of a field. */
/*ARGSUSED*/
enum debug_visibility
debug_get_field_visibility (handle, field)
PTR handle;
debug_field field;
{
if (field == NULL)
return DEBUG_VISIBILITY_IGNORE;
return field->visibility;
}
/* Get the physical name of a field. */
const char *
debug_get_field_physname (handle, field)
PTR handle;
debug_field field;
{
if (field == NULL || ! field->static_member)
return NULL;
return field->u.s.physname;
}
/* Write out the debugging information. This is given a handle to
debugging information, and a set of function pointers to call. */
boolean
debug_write (handle, fns, fhandle)
PTR handle;
const struct debug_write_fns *fns;
PTR fhandle;
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_unit *u;
/* We use a mark to tell whether we have already written out a
particular name. We use an integer, so that we don't have to
clear the mark fields if we happen to write out the same
information more than once. */
++info->mark;
/* The base_id field holds an ID value which will never be used, so
that we can tell whether we have assigned an ID during this call
to debug_write. */
info->base_id = info->class_id;
/* We keep a linked list of classes for which was have assigned ID's
during this call to debug_write. */
info->id_list = NULL;
for (u = info->units; u != NULL; u = u->next)
{
struct debug_file *f;
boolean first_file;
info->current_write_lineno = u->linenos;
info->current_write_lineno_index = 0;
if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
return false;
first_file = true;
for (f = u->files; f != NULL; f = f->next)
{
struct debug_name *n;
if (first_file)
first_file = false;
else
{
if (! (*fns->start_source) (fhandle, f->filename))
return false;
}
if (f->globals != NULL)
{
for (n = f->globals->list; n != NULL; n = n->next)
{
if (! debug_write_name (info, fns, fhandle, n))
return false;
}
}
}
/* Output any line number information which hasn't already been
handled. */
if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
return false;
}
return true;
}
/* Write out an element in a namespace. */
static boolean
debug_write_name (info, fns, fhandle, n)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_name *n;
{
switch (n->kind)
{
case DEBUG_OBJECT_TYPE:
if (! debug_write_type (info, fns, fhandle, n->u.type, n)
|| ! (*fns->typdef) (fhandle, n->name))
return false;
return true;
case DEBUG_OBJECT_TAG:
if (! debug_write_type (info, fns, fhandle, n->u.tag, n))
return false;
return (*fns->tag) (fhandle, n->name);
case DEBUG_OBJECT_VARIABLE:
if (! debug_write_type (info, fns, fhandle, n->u.variable->type,
(struct debug_name *) NULL))
return false;
return (*fns->variable) (fhandle, n->name, n->u.variable->kind,
n->u.variable->val);
case DEBUG_OBJECT_FUNCTION:
return debug_write_function (info, fns, fhandle, n->name,
n->linkage, n->u.function);
case DEBUG_OBJECT_INT_CONSTANT:
return (*fns->int_constant) (fhandle, n->name, n->u.int_constant);
case DEBUG_OBJECT_FLOAT_CONSTANT:
return (*fns->float_constant) (fhandle, n->name, n->u.float_constant);
case DEBUG_OBJECT_TYPED_CONSTANT:
if (! debug_write_type (info, fns, fhandle, n->u.typed_constant->type,
(struct debug_name *) NULL))
return false;
return (*fns->typed_constant) (fhandle, n->name,
n->u.typed_constant->val);
default:
abort ();
return false;
}
/*NOTREACHED*/
}
/* Write out a type. If the type is DEBUG_KIND_NAMED or
DEBUG_KIND_TAGGED, then the name argument is the name for which we
are about to call typedef or tag. If the type is anything else,
then the name argument is a tag from a DEBUG_KIND_TAGGED type which
points to this one. */
static boolean
debug_write_type (info, fns, fhandle, type, name)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_type *type;
struct debug_name *name;
{
unsigned int i;
int is;
const char *tag;
/* If we have a name for this type, just output it. We only output
typedef names after they have been defined. We output type tags
whenever we are not actually defining them. */
if ((type->kind == DEBUG_KIND_NAMED
|| type->kind == DEBUG_KIND_TAGGED)
&& (type->u.knamed->name->mark == info->mark
|| (type->kind == DEBUG_KIND_TAGGED
&& type->u.knamed->name != name)))
{
if (type->kind == DEBUG_KIND_NAMED)
return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
else
{
struct debug_type *real;
unsigned int id;
real = debug_get_real_type ((PTR) info, type);
id = 0;
if ((real->kind == DEBUG_KIND_STRUCT
|| real->kind == DEBUG_KIND_UNION
|| real->kind == DEBUG_KIND_CLASS
|| real->kind == DEBUG_KIND_UNION_CLASS)
&& real->u.kclass != NULL)
{
if (real->u.kclass->id <= info->base_id)
{
if (! debug_set_class_id (info,
type->u.knamed->name->name,
real))
return false;
}
id = real->u.kclass->id;
}
return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
real->kind);
}
}
/* Mark the name after we have already looked for a known name, so
that we don't just define a type in terms of itself. We need to
mark the name here so that a struct containing a pointer to
itself will work. */
if (name != NULL)
name->mark = info->mark;
tag = NULL;
if (name != NULL
&& type->kind != DEBUG_KIND_NAMED
&& type->kind != DEBUG_KIND_TAGGED)
{
assert (name->kind == DEBUG_OBJECT_TAG);
tag = name->name;
}
switch (type->kind)
{
case DEBUG_KIND_ILLEGAL:
debug_error ("debug_write_type: illegal type encountered");
return false;
case DEBUG_KIND_INDIRECT:
if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
return (*fns->empty_type) (fhandle);
return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
name);
case DEBUG_KIND_VOID:
return (*fns->void_type) (fhandle);
case DEBUG_KIND_INT:
return (*fns->int_type) (fhandle, type->size, type->u.kint);
case DEBUG_KIND_FLOAT:
return (*fns->float_type) (fhandle, type->size);
case DEBUG_KIND_COMPLEX:
return (*fns->complex_type) (fhandle, type->size);
case DEBUG_KIND_BOOL:
return (*fns->bool_type) (fhandle, type->size);
case DEBUG_KIND_STRUCT:
case DEBUG_KIND_UNION:
if (type->u.kclass != NULL)
{
if (type->u.kclass->id <= info->base_id)
{
if (! debug_set_class_id (info, tag, type))
return false;
}
if (info->mark == type->u.kclass->mark)
{
/* We are currently outputting this struct, or we have
already output it. I don't know if this can happen,
but it can happen for a class. */
assert (type->u.kclass->id > info->base_id);
return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
type->kind);
}
type->u.kclass->mark = info->mark;
}
if (! (*fns->start_struct_type) (fhandle, tag,
(type->u.kclass != NULL
? type->u.kclass->id
: 0),
type->kind == DEBUG_KIND_STRUCT,
type->size))
return false;
if (type->u.kclass != NULL
&& type->u.kclass->fields != NULL)
{
for (i = 0; type->u.kclass->fields[i] != NULL; i++)
{
struct debug_field *f;
f = type->u.kclass->fields[i];
if (! debug_write_type (info, fns, fhandle, f->type,
(struct debug_name *) NULL)
|| ! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
f->u.f.bitsize, f->visibility))
return false;
}
}
return (*fns->end_struct_type) (fhandle);
case DEBUG_KIND_CLASS:
case DEBUG_KIND_UNION_CLASS:
return debug_write_class_type (info, fns, fhandle, type, tag);
case DEBUG_KIND_ENUM:
if (type->u.kenum == NULL)
return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
(bfd_signed_vma *) NULL);
return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
type->u.kenum->values);
case DEBUG_KIND_POINTER:
if (! debug_write_type (info, fns, fhandle, type->u.kpointer,
(struct debug_name *) NULL))
return false;
return (*fns->pointer_type) (fhandle);
case DEBUG_KIND_FUNCTION:
if (! debug_write_type (info, fns, fhandle,
type->u.kfunction->return_type,
(struct debug_name *) NULL))
return false;
if (type->u.kfunction->arg_types == NULL)
is = -1;
else
{
for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
if (! debug_write_type (info, fns, fhandle,
type->u.kfunction->arg_types[is],
(struct debug_name *) NULL))
return false;
}
return (*fns->function_type) (fhandle, is,
type->u.kfunction->varargs);
case DEBUG_KIND_REFERENCE:
if (! debug_write_type (info, fns, fhandle, type->u.kreference,
(struct debug_name *) NULL))
return false;
return (*fns->reference_type) (fhandle);
case DEBUG_KIND_RANGE:
if (! debug_write_type (info, fns, fhandle, type->u.krange->type,
(struct debug_name *) NULL))
return false;
return (*fns->range_type) (fhandle, type->u.krange->lower,
type->u.krange->upper);
case DEBUG_KIND_ARRAY:
if (! debug_write_type (info, fns, fhandle, type->u.karray->element_type,
(struct debug_name *) NULL)
|| ! debug_write_type (info, fns, fhandle,
type->u.karray->range_type,
(struct debug_name *) NULL))
return false;
return (*fns->array_type) (fhandle, type->u.karray->lower,
type->u.karray->upper,
type->u.karray->stringp);
case DEBUG_KIND_SET:
if (! debug_write_type (info, fns, fhandle, type->u.kset->type,
(struct debug_name *) NULL))
return false;
return (*fns->set_type) (fhandle, type->u.kset->bitstringp);
case DEBUG_KIND_OFFSET:
if (! debug_write_type (info, fns, fhandle, type->u.koffset->base_type,
(struct debug_name *) NULL)
|| ! debug_write_type (info, fns, fhandle,
type->u.koffset->target_type,
(struct debug_name *) NULL))
return false;
return (*fns->offset_type) (fhandle);
case DEBUG_KIND_METHOD:
if (! debug_write_type (info, fns, fhandle,
type->u.kmethod->return_type,
(struct debug_name *) NULL))
return false;
if (type->u.kmethod->arg_types == NULL)
is = -1;
else
{
for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
if (! debug_write_type (info, fns, fhandle,
type->u.kmethod->arg_types[is],
(struct debug_name *) NULL))
return false;
}
if (type->u.kmethod->domain_type != NULL)
{
if (! debug_write_type (info, fns, fhandle,
type->u.kmethod->domain_type,
(struct debug_name *) NULL))
return false;
}
return (*fns->method_type) (fhandle,
type->u.kmethod->domain_type != NULL,
is,
type->u.kmethod->varargs);
case DEBUG_KIND_CONST:
if (! debug_write_type (info, fns, fhandle, type->u.kconst,
(struct debug_name *) NULL))
return false;
return (*fns->const_type) (fhandle);
case DEBUG_KIND_VOLATILE:
if (! debug_write_type (info, fns, fhandle, type->u.kvolatile,
(struct debug_name *) NULL))
return false;
return (*fns->volatile_type) (fhandle);
case DEBUG_KIND_NAMED:
return debug_write_type (info, fns, fhandle, type->u.knamed->type,
(struct debug_name *) NULL);
case DEBUG_KIND_TAGGED:
return debug_write_type (info, fns, fhandle, type->u.knamed->type,
type->u.knamed->name);
default:
abort ();
return false;
}
}
/* Write out a class type. */
static boolean
debug_write_class_type (info, fns, fhandle, type, tag)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_type *type;
const char *tag;
{
unsigned int i;
unsigned int id;
struct debug_type *vptrbase;
if (type->u.kclass == NULL)
{
id = 0;
vptrbase = NULL;
}
else
{
if (type->u.kclass->id <= info->base_id)
{
if (! debug_set_class_id (info, tag, type))
return false;
}
if (info->mark == type->u.kclass->mark)
{
/* We are currently outputting this class, or we have
already output it. This can happen when there are
methods for an anonymous class. */
assert (type->u.kclass->id > info->base_id);
return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
type->kind);
}
type->u.kclass->mark = info->mark;
id = type->u.kclass->id;
vptrbase = type->u.kclass->vptrbase;
if (vptrbase != NULL && vptrbase != type)
{
if (! debug_write_type (info, fns, fhandle, vptrbase,
(struct debug_name *) NULL))
return false;
}
}
if (! (*fns->start_class_type) (fhandle, tag, id,
type->kind == DEBUG_KIND_CLASS,
type->size,
vptrbase != NULL,
vptrbase == type))
return false;
if (type->u.kclass != NULL)
{
if (type->u.kclass->fields != NULL)
{
for (i = 0; type->u.kclass->fields[i] != NULL; i++)
{
struct debug_field *f;
f = type->u.kclass->fields[i];
if (! debug_write_type (info, fns, fhandle, f->type,
(struct debug_name *) NULL))
return false;
if (f->static_member)
{
if (! (*fns->class_static_member) (fhandle, f->name,
f->u.s.physname,
f->visibility))
return false;
}
else
{
if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
f->u.f.bitsize, f->visibility))
return false;
}
}
}
if (type->u.kclass->baseclasses != NULL)
{
for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
{
struct debug_baseclass *b;
b = type->u.kclass->baseclasses[i];
if (! debug_write_type (info, fns, fhandle, b->type,
(struct debug_name *) NULL))
return false;
if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
b->visibility))
return false;
}
}
if (type->u.kclass->methods != NULL)
{
for (i = 0; type->u.kclass->methods[i] != NULL; i++)
{
struct debug_method *m;
unsigned int j;
m = type->u.kclass->methods[i];
if (! (*fns->class_start_method) (fhandle, m->name))
return false;
for (j = 0; m->variants[j] != NULL; j++)
{
struct debug_method_variant *v;
v = m->variants[j];
if (v->context != NULL)
{
if (! debug_write_type (info, fns, fhandle, v->context,
(struct debug_name *) NULL))
return false;
}
if (! debug_write_type (info, fns, fhandle, v->type,
(struct debug_name *) NULL))
return false;
if (v->voffset != VOFFSET_STATIC_METHOD)
{
if (! (*fns->class_method_variant) (fhandle, v->physname,
v->visibility,
v->constp,
v->volatilep,
v->voffset,
v->context != NULL))
return false;
}
else
{
if (! (*fns->class_static_method_variant) (fhandle,
v->physname,
v->visibility,
v->constp,
v->volatilep))
return false;
}
}
if (! (*fns->class_end_method) (fhandle))
return false;
}
}
}
return (*fns->end_class_type) (fhandle);
}
/* Write out information for a function. */
static boolean
debug_write_function (info, fns, fhandle, name, linkage, function)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
const char *name;
enum debug_object_linkage linkage;
struct debug_function *function;
{
struct debug_parameter *p;
struct debug_block *b;
if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
return false;
if (! debug_write_type (info, fns, fhandle, function->return_type,
(struct debug_name *) NULL))
return false;
if (! (*fns->start_function) (fhandle, name,
linkage == DEBUG_LINKAGE_GLOBAL))
return false;
for (p = function->parameters; p != NULL; p = p->next)
{
if (! debug_write_type (info, fns, fhandle, p->type,
(struct debug_name *) NULL)
|| ! (*fns->function_parameter) (fhandle, p->name, p->kind, p->val))
return false;
}
for (b = function->blocks; b != NULL; b = b->next)
{
if (! debug_write_block (info, fns, fhandle, b))
return false;
}
return (*fns->end_function) (fhandle);
}
/* Write out information for a block. */
static boolean
debug_write_block (info, fns, fhandle, block)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
struct debug_block *block;
{
struct debug_name *n;
struct debug_block *b;
if (! debug_write_linenos (info, fns, fhandle, block->start))
return false;
/* I can't see any point to writing out a block with no local
variables, so we don't bother, except for the top level block. */
if (block->locals != NULL || block->parent == NULL)
{
if (! (*fns->start_block) (fhandle, block->start))
return false;
}
if (block->locals != NULL)
{
for (n = block->locals->list; n != NULL; n = n->next)
{
if (! debug_write_name (info, fns, fhandle, n))
return false;
}
}
for (b = block->children; b != NULL; b = b->next)
{
if (! debug_write_block (info, fns, fhandle, b))
return false;
}
if (! debug_write_linenos (info, fns, fhandle, block->end))
return false;
if (block->locals != NULL || block->parent == NULL)
{
if (! (*fns->end_block) (fhandle, block->end))
return false;
}
return true;
}
/* Write out line number information up to ADDRESS. */
static boolean
debug_write_linenos (info, fns, fhandle, address)
struct debug_handle *info;
const struct debug_write_fns *fns;
PTR fhandle;
bfd_vma address;
{
while (info->current_write_lineno != NULL)
{
struct debug_lineno *l;
l = info->current_write_lineno;
while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
{
if (l->linenos[info->current_write_lineno_index]
== (unsigned long) -1)
break;
if (l->addrs[info->current_write_lineno_index] >= address)
return true;
if (! (*fns->lineno) (fhandle, l->file->filename,
l->linenos[info->current_write_lineno_index],
l->addrs[info->current_write_lineno_index]))
return false;
++info->current_write_lineno_index;
}
info->current_write_lineno = l->next;
info->current_write_lineno_index = 0;
}
return true;
}
/* Get the ID number for a class. If during the same call to
debug_write we find a struct with the same definition with the same
name, we use the same ID. This type of things happens because the
same struct will be defined by multiple compilation units. */
static boolean
debug_set_class_id (info, tag, type)
struct debug_handle *info;
const char *tag;
struct debug_type *type;
{
struct debug_class_type *c;
struct debug_class_id *l;
assert (type->kind == DEBUG_KIND_STRUCT
|| type->kind == DEBUG_KIND_UNION
|| type->kind == DEBUG_KIND_CLASS
|| type->kind == DEBUG_KIND_UNION_CLASS);
c = type->u.kclass;
if (c->id > info->base_id)
return true;
for (l = info->id_list; l != NULL; l = l->next)
{
if (l->type->kind != type->kind)
continue;
if (tag == NULL)
{
if (l->tag != NULL)
continue;
}
else
{
if (l->tag == NULL
|| l->tag[0] != tag[0]
|| strcmp (l->tag, tag) != 0)
continue;
}
if (debug_type_samep (info, l->type, type))
{
c->id = l->type->u.kclass->id;
return true;
}
}
/* There are no identical types. Use a new ID, and add it to the
list. */
++info->class_id;
c->id = info->class_id;
l = (struct debug_class_id *) xmalloc (sizeof *l);
memset (l, 0, sizeof *l);
l->type = type;
l->tag = tag;
l->next = info->id_list;
info->id_list = l;
return true;
}
/* See if two types are the same. At this point, we don't care about
tags and the like. */
static boolean
debug_type_samep (info, t1, t2)
struct debug_handle *info;
struct debug_type *t1;
struct debug_type *t2;
{
struct debug_type_compare_list *l;
struct debug_type_compare_list top;
boolean ret;
if (t1 == NULL)
return t2 == NULL;
if (t2 == NULL)
return false;
while (t1->kind == DEBUG_KIND_INDIRECT)
{
t1 = *t1->u.kindirect->slot;
if (t1 == NULL)
return false;
}
while (t2->kind == DEBUG_KIND_INDIRECT)
{
t2 = *t2->u.kindirect->slot;
if (t2 == NULL)
return false;
}
if (t1 == t2)
return true;
/* As a special case, permit a typedef to match a tag, since C++
debugging output will sometimes add a typedef where C debugging
output will not. */
if (t1->kind == DEBUG_KIND_NAMED
&& t2->kind == DEBUG_KIND_TAGGED)
return debug_type_samep (info, t1->u.knamed->type, t2);
else if (t1->kind == DEBUG_KIND_TAGGED
&& t2->kind == DEBUG_KIND_NAMED)
return debug_type_samep (info, t1, t2->u.knamed->type);
if (t1->kind != t2->kind
|| t1->size != t2->size)
return false;
/* Get rid of the trivial cases first. */
switch (t1->kind)
{
default:
break;
case DEBUG_KIND_VOID:
case DEBUG_KIND_FLOAT:
case DEBUG_KIND_COMPLEX:
case DEBUG_KIND_BOOL:
return true;
case DEBUG_KIND_INT:
return t1->u.kint == t2->u.kint;
}
/* We have to avoid an infinite recursion. We do this by keeping a
list of types which we are comparing. We just keep the list on
the stack. If we encounter a pair of types we are currently
comparing, we just assume that they are equal. */
for (l = info->compare_list; l != NULL; l = l->next)
{
if (l->t1 == t1 && l->t2 == t2)
return true;
}
top.t1 = t1;
top.t2 = t2;
top.next = info->compare_list;
info->compare_list = &top;
switch (t1->kind)
{
default:
abort ();
ret = false;
break;
case DEBUG_KIND_STRUCT:
case DEBUG_KIND_UNION:
case DEBUG_KIND_CLASS:
case DEBUG_KIND_UNION_CLASS:
if (t1->u.kclass == NULL)
ret = t2->u.kclass == NULL;
else if (t2->u.kclass == NULL)
ret = false;
else if (t1->u.kclass->id > info->base_id
&& t1->u.kclass->id == t2->u.kclass->id)
ret = true;
else
ret = debug_class_type_samep (info, t1, t2);
break;
case DEBUG_KIND_ENUM:
if (t1->u.kenum == NULL)
ret = t2->u.kenum == NULL;
else if (t2->u.kenum == NULL)
ret = false;
else
{
const char **pn1, **pn2;
bfd_signed_vma *pv1, *pv2;
pn1 = t1->u.kenum->names;
pn2 = t2->u.kenum->names;
pv1 = t1->u.kenum->values;
pv2 = t2->u.kenum->values;
while (*pn1 != NULL && *pn2 != NULL)
{
if (**pn1 != **pn2
|| *pv1 != *pv2
|| strcmp (*pn1, *pn2) != 0)
break;
++pn1;
++pn2;
++pv1;
++pv2;
}
ret = *pn1 == NULL && *pn2 == NULL;
}
break;
case DEBUG_KIND_POINTER:
ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
break;
case DEBUG_KIND_FUNCTION:
if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
|| ! debug_type_samep (info, t1->u.kfunction->return_type,
t2->u.kfunction->return_type)
|| ((t1->u.kfunction->arg_types == NULL)
!= (t2->u.kfunction->arg_types == NULL)))
ret = false;
else if (t1->u.kfunction->arg_types == NULL)
ret = true;
else
{
struct debug_type **a1, **a2;
a1 = t1->u.kfunction->arg_types;
a2 = t2->u.kfunction->arg_types;
while (*a1 != NULL && *a2 != NULL)
if (! debug_type_samep (info, *a1, *a2))
break;
ret = *a1 == NULL && *a2 == NULL;
}
break;
case DEBUG_KIND_REFERENCE:
ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
break;
case DEBUG_KIND_RANGE:
ret = (t1->u.krange->lower == t2->u.krange->lower
&& t1->u.krange->upper == t2->u.krange->upper
&& debug_type_samep (info, t1->u.krange->type,
t2->u.krange->type));
case DEBUG_KIND_ARRAY:
ret = (t1->u.karray->lower == t2->u.karray->lower
&& t1->u.karray->upper == t2->u.karray->upper
&& t1->u.karray->stringp == t2->u.karray->stringp
&& debug_type_samep (info, t1->u.karray->element_type,
t2->u.karray->element_type));
break;
case DEBUG_KIND_SET:
ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
&& debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
break;
case DEBUG_KIND_OFFSET:
ret = (debug_type_samep (info, t1->u.koffset->base_type,
t2->u.koffset->base_type)
&& debug_type_samep (info, t1->u.koffset->target_type,
t2->u.koffset->target_type));
break;
case DEBUG_KIND_METHOD:
if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
|| ! debug_type_samep (info, t1->u.kmethod->return_type,
t2->u.kmethod->return_type)
|| ! debug_type_samep (info, t1->u.kmethod->domain_type,
t2->u.kmethod->domain_type)
|| ((t1->u.kmethod->arg_types == NULL)
!= (t2->u.kmethod->arg_types == NULL)))
ret = false;
else if (t1->u.kmethod->arg_types == NULL)
ret = true;
else
{
struct debug_type **a1, **a2;
a1 = t1->u.kmethod->arg_types;
a2 = t2->u.kmethod->arg_types;
while (*a1 != NULL && *a2 != NULL)
if (! debug_type_samep (info, *a1, *a2))
break;
ret = *a1 == NULL && *a2 == NULL;
}
break;
case DEBUG_KIND_CONST:
ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
break;
case DEBUG_KIND_VOLATILE:
ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
break;
case DEBUG_KIND_NAMED:
case DEBUG_KIND_TAGGED:
ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
&& debug_type_samep (info, t1->u.knamed->type,
t2->u.knamed->type));
break;
}
info->compare_list = top.next;
return ret;
}
/* See if two classes are the same. This is a subroutine of
debug_type_samep. */
static boolean
debug_class_type_samep (info, t1, t2)
struct debug_handle *info;
struct debug_type *t1;
struct debug_type *t2;
{
struct debug_class_type *c1, *c2;
c1 = t1->u.kclass;
c2 = t2->u.kclass;
if ((c1->fields == NULL) != (c2->fields == NULL)
|| (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
|| (c1->methods == NULL) != (c2->methods == NULL)
|| (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
return false;
if (c1->fields != NULL)
{
struct debug_field **pf1, **pf2;
for (pf1 = c1->fields, pf2 = c2->fields;
*pf1 != NULL && *pf2 != NULL;
pf1++, pf2++)
{
struct debug_field *f1, *f2;
f1 = *pf1;
f2 = *pf2;
if (f1->name[0] != f2->name[0]
|| f1->visibility != f2->visibility
|| f1->static_member != f2->static_member)
return false;
if (f1->static_member)
{
if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
return false;
}
else
{
if (f1->u.f.bitpos != f2->u.f.bitpos
|| f1->u.f.bitsize != f2->u.f.bitsize)
return false;
}
/* We do the checks which require function calls last. We
don't require that the types of fields have the same
names, since that sometimes fails in the presence of
typedefs and we really don't care. */
if (strcmp (f1->name, f2->name) != 0
|| ! debug_type_samep (info,
debug_get_real_type ((PTR) info,
f1->type),
debug_get_real_type ((PTR) info,
f2->type)))
return false;
}
if (*pf1 != NULL || *pf2 != NULL)
return false;
}
if (c1->vptrbase != NULL)
{
if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
return false;
}
if (c1->baseclasses != NULL)
{
struct debug_baseclass **pb1, **pb2;
for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
*pb1 != NULL && *pb2 != NULL;
++pb1, ++pb2)
{
struct debug_baseclass *b1, *b2;
b1 = *pb1;
b2 = *pb2;
if (b1->bitpos != b2->bitpos
|| b1->virtual != b2->virtual
|| b1->visibility != b2->visibility
|| ! debug_type_samep (info, b1->type, b2->type))
return false;
}
if (*pb1 != NULL || *pb2 != NULL)
return false;
}
if (c1->methods != NULL)
{
struct debug_method **pm1, **pm2;
for (pm1 = c1->methods, pm2 = c2->methods;
*pm1 != NULL && *pm2 != NULL;
++pm1, ++pm2)
{
struct debug_method *m1, *m2;
m1 = *pm1;
m2 = *pm2;
if (m1->name[0] != m2->name[0]
|| strcmp (m1->name, m2->name) != 0
|| (m1->variants == NULL) != (m2->variants == NULL))
return false;
if (m1->variants == NULL)
{
struct debug_method_variant **pv1, **pv2;
for (pv1 = m1->variants, pv2 = m2->variants;
*pv1 != NULL && *pv2 != NULL;
++pv1, ++pv2)
{
struct debug_method_variant *v1, *v2;
v1 = *pv1;
v2 = *pv2;
if (v1->physname[0] != v2->physname[0]
|| v1->visibility != v2->visibility
|| v1->constp != v2->constp
|| v1->volatilep != v2->volatilep
|| v1->voffset != v2->voffset
|| (v1->context == NULL) != (v2->context == NULL)
|| strcmp (v1->physname, v2->physname) != 0
|| ! debug_type_samep (info, v1->type, v2->type))
return false;
if (v1->context != NULL)
{
if (! debug_type_samep (info, v1->context,
v2->context))
return false;
}
}
if (*pv1 != NULL || *pv2 != NULL)
return false;
}
}
if (*pm1 != NULL || *pm2 != NULL)
return false;
}
return true;
}
/* debug.h -- Describe generic debugging information.
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#ifndef DEBUG_H
#define DEBUG_H
/* This header file describes a generic debugging information format.
We may eventually have readers which convert different formats into
this generic format, and writers which write it out. The initial
impetus for this was writing a convertor from stabs to HP IEEE-695
debugging format. */
/* Different kinds of types. */
enum debug_type_kind
{
/* Not used. */
DEBUG_KIND_ILLEGAL,
/* Indirect via a pointer. */
DEBUG_KIND_INDIRECT,
/* Void. */
DEBUG_KIND_VOID,
/* Integer. */
DEBUG_KIND_INT,
/* Floating point. */
DEBUG_KIND_FLOAT,
/* Complex. */
DEBUG_KIND_COMPLEX,
/* Boolean. */
DEBUG_KIND_BOOL,
/* Struct. */
DEBUG_KIND_STRUCT,
/* Union. */
DEBUG_KIND_UNION,
/* Class. */
DEBUG_KIND_CLASS,
/* Union class (can this really happen?). */
DEBUG_KIND_UNION_CLASS,
/* Enumeration type. */
DEBUG_KIND_ENUM,
/* Pointer. */
DEBUG_KIND_POINTER,
/* Function. */
DEBUG_KIND_FUNCTION,
/* Reference. */
DEBUG_KIND_REFERENCE,
/* Range. */
DEBUG_KIND_RANGE,
/* Array. */
DEBUG_KIND_ARRAY,
/* Set. */
DEBUG_KIND_SET,
/* Based pointer. */
DEBUG_KIND_OFFSET,
/* Method. */
DEBUG_KIND_METHOD,
/* Const qualified type. */
DEBUG_KIND_CONST,
/* Volatile qualified type. */
DEBUG_KIND_VOLATILE,
/* Named type. */
DEBUG_KIND_NAMED,
/* Tagged type. */
DEBUG_KIND_TAGGED
};
/* Different kinds of variables. */
enum debug_var_kind
{
/* Not used. */
DEBUG_VAR_ILLEGAL,
/* A global variable. */
DEBUG_GLOBAL,
/* A static variable. */
DEBUG_STATIC,
/* A local static variable. */
DEBUG_LOCAL_STATIC,
/* A local variable. */
DEBUG_LOCAL,
/* A register variable. */
DEBUG_REGISTER
};
/* Different kinds of function parameters. */
enum debug_parm_kind
{
/* Not used. */
DEBUG_PARM_ILLEGAL,
/* A stack based parameter. */
DEBUG_PARM_STACK,
/* A register parameter. */
DEBUG_PARM_REG,
/* A stack based reference parameter. */
DEBUG_PARM_REFERENCE,
/* A register reference parameter. */
DEBUG_PARM_REF_REG
};
/* Different kinds of visibility. */
enum debug_visibility
{
/* A public field (e.g., a field in a C struct). */
DEBUG_VISIBILITY_PUBLIC,
/* A protected field. */
DEBUG_VISIBILITY_PROTECTED,
/* A private field. */
DEBUG_VISIBILITY_PRIVATE,
/* A field which should be ignored. */
DEBUG_VISIBILITY_IGNORE
};
/* A type. */
typedef struct debug_type *debug_type;
#define DEBUG_TYPE_NULL ((debug_type) NULL)
/* A field in a struct or union. */
typedef struct debug_field *debug_field;
#define DEBUG_FIELD_NULL ((debug_field) NULL)
/* A base class for an object. */
typedef struct debug_baseclass *debug_baseclass;
#define DEBUG_BASECLASS_NULL ((debug_baseclass) NULL)
/* A method of an object. */
typedef struct debug_method *debug_method;
#define DEBUG_METHOD_NULL ((debug_method) NULL)
/* The arguments to a method function of an object. These indicate
which method to run. */
typedef struct debug_method_variant *debug_method_variant;
#define DEBUG_METHOD_VARIANT_NULL ((debug_method_variant) NULL)
/* This structure is passed to debug_write. It holds function
pointers that debug_write will call based on the accumulated
debugging information. */
struct debug_write_fns
{
/* This is called at the start of each new compilation unit with the
name of the main file in the new unit. */
boolean (*start_compilation_unit) PARAMS ((PTR, const char *));
/* This is called at the start of each source file within a
compilation unit, before outputting any global information for
that file. The argument is the name of the file. */
boolean (*start_source) PARAMS ((PTR, const char *));
/* Each writer must keep a stack of types. */
/* Push an empty type onto the type stack. This type can appear if
there is a reference to a type which is never defined. */
boolean (*empty_type) PARAMS ((PTR));
/* Push a void type onto the type stack. */
boolean (*void_type) PARAMS ((PTR));
/* Push an integer type onto the type stack, given the size and
whether it is unsigned. */
boolean (*int_type) PARAMS ((PTR, unsigned int, boolean));
/* Push a floating type onto the type stack, given the size. */
boolean (*float_type) PARAMS ((PTR, unsigned int));
/* Push a complex type onto the type stack, given the size. */
boolean (*complex_type) PARAMS ((PTR, unsigned int));
/* Push a boolean type onto the type stack, given the size. */
boolean (*bool_type) PARAMS ((PTR, unsigned int));
/* Push an enum type onto the type stack, given the tag, a NULL
terminated array of names and the associated values. If there is
no tag, the tag argument will be NULL. If this is an undefined
enum, the names and values arguments will be NULL. */
boolean (*enum_type) PARAMS ((PTR, const char *, const char **,
bfd_signed_vma *));
/* Pop the top type on the type stack, and push a pointer to that
type onto the type stack. */
boolean (*pointer_type) PARAMS ((PTR));
/* Push a function type onto the type stack. The second argument
indicates the number of argument types that have been pushed onto
the stack. If the number of argument types is passed as -1, then
the argument types of the function are unknown, and no types have
been pushed onto the stack. The third argument is true if the
function takes a variable number of arguments. The return type
of the function is pushed onto the type stack below the argument
types, if any. */
boolean (*function_type) PARAMS ((PTR, int, boolean));
/* Pop the top type on the type stack, and push a reference to that
type onto the type stack. */
boolean (*reference_type) PARAMS ((PTR));
/* Pop the top type on the type stack, and push a range of that type
with the given lower and upper bounds onto the type stack. */
boolean (*range_type) PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
/* Push an array type onto the type stack. The top type on the type
stack is the range, and the next type on the type stack is the
element type. These should be popped before the array type is
pushed. The arguments are the lower bound, the upper bound, and
whether the array is a string. */
boolean (*array_type) PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma,
boolean));
/* Pop the top type on the type stack, and push a set of that type
onto the type stack. The argument indicates whether this set is
a bitstring. */
boolean (*set_type) PARAMS ((PTR, boolean));
/* Push an offset type onto the type stack. The top type on the
type stack is the target type, and the next type on the type
stack is the base type. These should be popped before the offset
type is pushed. */
boolean (*offset_type) PARAMS ((PTR));
/* Push a method type onto the type stack. If the second argument
is true, the top type on the stack is the class to which the
method belongs; otherwise, the class must be determined by the
class to which the method is attached. The third argument is the
number of argument types; these are pushed onto the type stack in
reverse order (the first type popped is the last argument to the
method). A value of -1 for the third argument means that no
argument information is available. The fourth argument is true
if the function takes a variable number of arguments. The next
type on the type stack below the domain and the argument types is
the return type of the method. All these types must be popped,
and then the method type must be pushed. */
boolean (*method_type) PARAMS ((PTR, boolean, int, boolean));
/* Pop the top type off the type stack, and push a const qualified
version of that type onto the type stack. */
boolean (*const_type) PARAMS ((PTR));
/* Pop the top type off the type stack, and push a volatile
qualified version of that type onto the type stack. */
boolean (*volatile_type) PARAMS ((PTR));
/* Start building a struct. This is followed by calls to the
struct_field function, and finished by a call to the
end_struct_type function. The second argument is the tag; this
will be NULL if there isn't one. If the second argument is NULL,
the third argument is a constant identifying this struct for use
with tag_type. The fourth argument is true for a struct, false
for a union. The fifth argument is the size. If this is an
undefined struct or union, the size will be 0 and struct_field
will not be called before end_struct_type is called. */
boolean (*start_struct_type) PARAMS ((PTR, const char *, unsigned int,
boolean, unsigned int));
/* Add a field to the struct type currently being built. The type
of the field should be popped off the type stack. The arguments
are the name, the bit position, the bit size (may be zero if the
field is not packed), and the visibility. */
boolean (*struct_field) PARAMS ((PTR, const char *, bfd_vma, bfd_vma,
enum debug_visibility));
/* Finish building a struct, and push it onto the type stack. */
boolean (*end_struct_type) PARAMS ((PTR));
/* Start building a class. This is followed by calls to several
functions: struct_field, class_static_member, class_baseclass,
class_start_method, class_method_variant,
class_static_method_variant, and class_end_method. The class is
finished by a call to end_class_type. The first five arguments
are the same as for start_struct_type. The sixth argument is
true if there is a virtual function table; if there is, the
seventh argument is true if the virtual function table can be
found in the type itself, and is false if the type of the object
holding the virtual function table should be popped from the type
stack. */
boolean (*start_class_type) PARAMS ((PTR, const char *, unsigned int,
boolean, unsigned int, boolean,
boolean));
/* Add a static member to the class currently being built. The
arguments are the field name, the physical name, and the
visibility. The type must be popped off the type stack. */
boolean (*class_static_member) PARAMS ((PTR, const char *, const char *,
enum debug_visibility));
/* Add a baseclass to the class currently being built. The type of
the baseclass must be popped off the type stack. The arguments
are the bit position, whether the class is virtual, and the
visibility. */
boolean (*class_baseclass) PARAMS ((PTR, bfd_vma, boolean,
enum debug_visibility));
/* Start adding a method to the class currently being built. This
is followed by calls to class_method_variant and
class_static_method_variant to describe different variants of the
method which take different arguments. The method is finished
with a call to class_end_method. The argument is the method
name. */
boolean (*class_start_method) PARAMS ((PTR, const char *));
/* Describe a variant to the class method currently being built.
The type of the variant must be popped off the type stack. The
second argument is the physical name of the function. The
following arguments are the visibility, whether the variant is
const, whether the variant is volatile, the offset in the virtual
function table, and whether the context is on the type stack
(below the variant type). */
boolean (*class_method_variant) PARAMS ((PTR, const char *,
enum debug_visibility,
boolean, boolean,
bfd_vma, boolean));
/* Describe a static variant to the class method currently being
built. The arguments are the same as for class_method_variant,
except that the last two arguments are omitted. The type of the
variant must be popped off the type stack. */
boolean (*class_static_method_variant) PARAMS ((PTR, const char *,
enum debug_visibility,
boolean, boolean));
/* Finish describing a class method. */
boolean (*class_end_method) PARAMS ((PTR));
/* Finish describing a class, and push it onto the type stack. */
boolean (*end_class_type) PARAMS ((PTR));
/* Push a type on the stack which was given a name by an earlier
call to typdef. */
boolean (*typedef_type) PARAMS ((PTR, const char *));
/* Push a tagged type on the stack which was defined earlier. If
the second argument is not NULL, the type was defined by a call
to tag. If the second argument is NULL, the type was defined by
a call to start_struct_type or start_class_type with a tag of
NULL and the number of the third argument. Either way, the
fourth argument is the tag kind. Note that this may be called
for a struct (class) being defined, in between the call to
start_struct_type (start_class_type) and the call to
end_struct_type (end_class_type). */
boolean (*tag_type) PARAMS ((PTR, const char *, unsigned int,
enum debug_type_kind));
/* Pop the type stack, and typedef it to the given name. */
boolean (*typdef) PARAMS ((PTR, const char *));
/* Pop the type stack, and declare it as a tagged struct or union or
enum or whatever. The tag passed down here is redundant, since
was also passed when enum_type, start_struct_type, or
start_class_type was called. */
boolean (*tag) PARAMS ((PTR, const char *));
/* This is called to record a named integer constant. */
boolean (*int_constant) PARAMS ((PTR, const char *, bfd_vma));
/* This is called to record a named floating point constant. */
boolean (*float_constant) PARAMS ((PTR, const char *, double));
/* This is called to record a typed integer constant. The type is
popped off the type stack. */
boolean (*typed_constant) PARAMS ((PTR, const char *, bfd_vma));
/* This is called to record a variable. The type is popped off the
type stack. */
boolean (*variable) PARAMS ((PTR, const char *, enum debug_var_kind,
bfd_vma));
/* Start writing out a function. The return type must be popped off
the stack. The boolean is true if the function is global. This
is followed by calls to function_parameter, followed by block
information. */
boolean (*start_function) PARAMS ((PTR, const char *, boolean));
/* Record a function parameter for the current function. The type
must be popped off the stack. */
boolean (*function_parameter) PARAMS ((PTR, const char *,
enum debug_parm_kind, bfd_vma));
/* Start writing out a block. There is at least one top level block
per function. Blocks may be nested. The argument is the
starting address of the block. */
boolean (*start_block) PARAMS ((PTR, bfd_vma));
/* Finish writing out a block. The argument is the ending address
of the block. */
boolean (*end_block) PARAMS ((PTR, bfd_vma));
/* Finish writing out a function. */
boolean (*end_function) PARAMS ((PTR));
/* Record line number information for the current compilation unit. */
boolean (*lineno) PARAMS ((PTR, const char *, unsigned long, bfd_vma));
};
/* Exported functions. */
/* The first argument to most of these functions is a handle. This
handle is returned by the debug_init function. The purpose of the
handle is to permit the debugging routines to not use static
variables, and hence to be reentrant. This would be useful for a
program which wanted to handle two executables simultaneously. */
/* Return a debugging handle. */
extern PTR debug_init PARAMS ((void));
/* Set the source filename. This implicitly starts a new compilation
unit. */
extern boolean debug_set_filename PARAMS ((PTR, const char *));
/* Change source files to the given file name. This is used for
include files in a single compilation unit. */
extern boolean debug_start_source PARAMS ((PTR, const char *));
/* Record a function definition. This implicitly starts a function
block. The debug_type argument is the type of the return value.
The boolean indicates whether the function is globally visible.
The bfd_vma is the address of the start of the function. Currently
the parameter types are specified by calls to
debug_record_parameter. */
extern boolean debug_record_function
PARAMS ((PTR, const char *, debug_type, boolean, bfd_vma));
/* Record a parameter for the current function. */
extern boolean debug_record_parameter
PARAMS ((PTR, const char *, debug_type, enum debug_parm_kind, bfd_vma));
/* End a function definition. The argument is the address where the
function ends. */
extern boolean debug_end_function PARAMS ((PTR, bfd_vma));
/* Start a block in a function. All local information will be
recorded in this block, until the matching call to debug_end_block.
debug_start_block and debug_end_block may be nested. The argument
is the address at which this block starts. */
extern boolean debug_start_block PARAMS ((PTR, bfd_vma));
/* Finish a block in a function. This matches the call to
debug_start_block. The argument is the address at which this block
ends. */
extern boolean debug_end_block PARAMS ((PTR, bfd_vma));
/* Associate a line number in the current source file with a given
address. */
extern boolean debug_record_line PARAMS ((PTR, unsigned long, bfd_vma));
/* Start a named common block. This is a block of variables that may
move in memory. */
extern boolean debug_start_common_block PARAMS ((PTR, const char *));
/* End a named common block. */
extern boolean debug_end_common_block PARAMS ((PTR, const char *));
/* Record a named integer constant. */
extern boolean debug_record_int_const PARAMS ((PTR, const char *, bfd_vma));
/* Record a named floating point constant. */
extern boolean debug_record_float_const PARAMS ((PTR, const char *, double));
/* Record a typed constant with an integral value. */
extern boolean debug_record_typed_const
PARAMS ((PTR, const char *, debug_type, bfd_vma));
/* Record a label. */
extern boolean debug_record_label
PARAMS ((PTR, const char *, debug_type, bfd_vma));
/* Record a variable. */
extern boolean debug_record_variable
PARAMS ((PTR, const char *, debug_type, enum debug_var_kind, bfd_vma));
/* Make an indirect type. The first argument is a pointer to the
location where the real type will be placed. The second argument
is the type tag, if there is one; this may be NULL; the only
purpose of this argument is so that debug_get_type_name can return
something useful. This function may be used when a type is
referenced before it is defined. */
extern debug_type debug_make_indirect_type
PARAMS ((PTR, debug_type *, const char *));
/* Make a void type. */
extern debug_type debug_make_void_type PARAMS ((PTR));
/* Make an integer type of a given size. The boolean argument is true
if the integer is unsigned. */
extern debug_type debug_make_int_type PARAMS ((PTR, unsigned int, boolean));
/* Make a floating point type of a given size. FIXME: On some
platforms, like an Alpha, you probably need to be able to specify
the format. */
extern debug_type debug_make_float_type PARAMS ((PTR, unsigned int));
/* Make a boolean type of a given size. */
extern debug_type debug_make_bool_type PARAMS ((PTR, unsigned int));
/* Make a complex type of a given size. */
extern debug_type debug_make_complex_type PARAMS ((PTR, unsigned int));
/* Make a structure type. The second argument is true for a struct,
false for a union. The third argument is the size of the struct.
The fourth argument is a NULL terminated array of fields. */
extern debug_type debug_make_struct_type
PARAMS ((PTR, boolean, bfd_vma, debug_field *));
/* Make an object type. The first three arguments after the handle
are the same as for debug_make_struct_type. The next arguments are
a NULL terminated array of base classes, a NULL terminated array of
methods, the type of the object holding the virtual function table
if it is not this object, and a boolean which is true if this
object has its own virtual function table. */
extern debug_type debug_make_object_type
PARAMS ((PTR, boolean, bfd_vma, debug_field *, debug_baseclass *,
debug_method *, debug_type, boolean));
/* Make an enumeration type. The arguments are a null terminated
array of strings, and an array of corresponding values. */
extern debug_type debug_make_enum_type
PARAMS ((PTR, const char **, bfd_signed_vma *));
/* Make a pointer to a given type. */
extern debug_type debug_make_pointer_type
PARAMS ((PTR, debug_type));
/* Make a function type. The second argument is the return type. The
third argument is a NULL terminated array of argument types. The
fourth argument is true if the function takes a variable number of
arguments. If the third argument is NULL, then the argument types
are unknown. */
extern debug_type debug_make_function_type
PARAMS ((PTR, debug_type, debug_type *, boolean));
/* Make a reference to a given type. */
extern debug_type debug_make_reference_type PARAMS ((PTR, debug_type));
/* Make a range of a given type from a lower to an upper bound. */
extern debug_type debug_make_range_type
PARAMS ((PTR, debug_type, bfd_signed_vma, bfd_signed_vma));
/* Make an array type. The second argument is the type of an element
of the array. The third argument is the type of a range of the
array. The fourth and fifth argument are the lower and upper
bounds, respectively (if the bounds are not known, lower should be
0 and upper should be -1). The sixth argument is true if this
array is actually a string, as in C. */
extern debug_type debug_make_array_type
PARAMS ((PTR, debug_type, debug_type, bfd_signed_vma, bfd_signed_vma,
boolean));
/* Make a set of a given type. For example, a Pascal set type. The
boolean argument is true if this set is actually a bitstring, as in
CHILL. */
extern debug_type debug_make_set_type PARAMS ((PTR, debug_type, boolean));
/* Make a type for a pointer which is relative to an object. The
second argument is the type of the object to which the pointer is
relative. The third argument is the type that the pointer points
to. */
extern debug_type debug_make_offset_type
PARAMS ((PTR, debug_type, debug_type));
/* Make a type for a method function. The second argument is the
return type. The third argument is the domain. The fourth
argument is a NULL terminated array of argument types. The fifth
argument is true if the function takes a variable number of
arguments, in which case the array of argument types indicates the
types of the first arguments. The domain and the argument array
may be NULL, in which case this is a stub method and that
information is not available. Stabs debugging uses this, and gets
the argument types from the mangled name. */
extern debug_type debug_make_method_type
PARAMS ((PTR, debug_type, debug_type, debug_type *, boolean));
/* Make a const qualified version of a given type. */
extern debug_type debug_make_const_type PARAMS ((PTR, debug_type));
/* Make a volatile qualified version of a given type. */
extern debug_type debug_make_volatile_type PARAMS ((PTR, debug_type));
/* Make an undefined tagged type. For example, a struct which has
been mentioned, but not defined. */
extern debug_type debug_make_undefined_tagged_type
PARAMS ((PTR, const char *, enum debug_type_kind));
/* Make a base class for an object. The second argument is the base
class type. The third argument is the bit position of this base
class in the object. The fourth argument is whether this is a
virtual class. The fifth argument is the visibility of the base
class. */
extern debug_baseclass debug_make_baseclass
PARAMS ((PTR, debug_type, bfd_vma, boolean, enum debug_visibility));
/* Make a field for a struct. The second argument is the name. The
third argument is the type of the field. The fourth argument is
the bit position of the field. The fifth argument is the size of
the field (it may be zero). The sixth argument is the visibility
of the field. */
extern debug_field debug_make_field
PARAMS ((PTR, const char *, debug_type, bfd_vma, bfd_vma,
enum debug_visibility));
/* Make a static member of an object. The second argument is the
name. The third argument is the type of the member. The fourth
argument is the physical name of the member (i.e., the name as a
global variable). The fifth argument is the visibility of the
member. */
extern debug_field debug_make_static_member
PARAMS ((PTR, const char *, debug_type, const char *,
enum debug_visibility));
/* Make a method. The second argument is the name, and the third
argument is a NULL terminated array of method variants. Each
method variant is a method with this name but with different
argument types. */
extern debug_method debug_make_method
PARAMS ((PTR, const char *, debug_method_variant *));
/* Make a method variant. The second argument is the physical name of
the function. The third argument is the type of the function,
probably constructed by debug_make_method_type. The fourth
argument is the visibility. The fifth argument is whether this is
a const function. The sixth argument is whether this is a volatile
function. The seventh argument is the index in the virtual
function table, if any. The eighth argument is the virtual
function context. */
extern debug_method_variant debug_make_method_variant
PARAMS ((PTR, const char *, debug_type, enum debug_visibility, boolean,
boolean, bfd_vma, debug_type));
/* Make a static method argument. The arguments are the same as for
debug_make_method_variant, except that the last two are omitted
since a static method can not also be virtual. */
extern debug_method_variant debug_make_static_method_variant
PARAMS ((PTR, const char *, debug_type, enum debug_visibility, boolean,
boolean));
/* Name a type. This returns a new type with an attached name. */
extern debug_type debug_name_type PARAMS ((PTR, const char *, debug_type));
/* Give a tag to a type, such as a struct or union. This returns a
new type with an attached tag. */
extern debug_type debug_tag_type PARAMS ((PTR, const char *, debug_type));
/* Record the size of a given type. */
extern boolean debug_record_type_size PARAMS ((PTR, debug_type, unsigned int));
/* Find a named type. */
extern debug_type debug_find_named_type PARAMS ((PTR, const char *));
/* Find a tagged type. */
extern debug_type debug_find_tagged_type
PARAMS ((PTR, const char *, enum debug_type_kind));
/* Get the kind of a type. */
extern enum debug_type_kind debug_get_type_kind PARAMS ((PTR, debug_type));
/* Get the name of a type. */
extern const char *debug_get_type_name PARAMS ((PTR, debug_type));
/* Get the size of a type. */
extern bfd_vma debug_get_type_size PARAMS ((PTR, debug_type));
/* Get the return type of a function or method type. */
extern debug_type debug_get_return_type PARAMS ((PTR, debug_type));
/* Get the NULL terminated array of parameter types for a function or
method type (actually, parameter types are not currently stored for
function types). This may be used to determine whether a method
type is a stub method or not. The last argument points to a
boolean which is set to true if the function takes a variable
number of arguments. */
extern const debug_type *debug_get_parameter_types PARAMS ((PTR,
debug_type,
boolean *));
/* Get the target type of a pointer or reference or const or volatile
type. */
extern debug_type debug_get_target_type PARAMS ((PTR, debug_type));
/* Get the NULL terminated array of fields for a struct, union, or
class. */
extern const debug_field *debug_get_fields PARAMS ((PTR, debug_type));
/* Get the type of a field. */
extern debug_type debug_get_field_type PARAMS ((PTR, debug_field));
/* Get the name of a field. */
extern const char *debug_get_field_name PARAMS ((PTR, debug_field));
/* Get the bit position of a field within the containing structure.
If the field is a static member, this will return (bfd_vma) -1. */
extern bfd_vma debug_get_field_bitpos PARAMS ((PTR, debug_field));
/* Get the bit size of a field. If the field is a static member, this
will return (bfd_vma) -1. */
extern bfd_vma debug_get_field_bitsize PARAMS ((PTR, debug_field));
/* Get the visibility of a field. */
extern enum debug_visibility debug_get_field_visibility
PARAMS ((PTR, debug_field));
/* Get the physical name of a field, if it is a static member. If the
field is not a static member, this will return NULL. */
extern const char *debug_get_field_physname PARAMS ((PTR, debug_field));
/* Write out the recorded debugging information. This takes a set of
function pointers which are called to do the actual writing. The
first PTR is the debugging handle. The second PTR is a handle
which is passed to the functions. */
extern boolean debug_write PARAMS ((PTR, const struct debug_write_fns *, PTR));
#endif /* DEBUG_H */
/* Defs for interface to demanglers.
Copyright 1992, 1995, 1996 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#if !defined (DEMANGLE_H)
#define DEMANGLE_H
#ifdef IN_GCC
#include "gansidecl.h"
#define PARAMS(ARGS) PROTO(ARGS)
#else /* ! IN_GCC */
#include <ansidecl.h>
#endif /* IN_GCC */
/* Options passed to cplus_demangle (in 2nd parameter). */
#define DMGL_NO_OPTS 0 /* For readability... */
#define DMGL_PARAMS (1 << 0) /* Include function args */
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
#define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */
#define DMGL_AUTO (1 << 8)
#define DMGL_GNU (1 << 9)
#define DMGL_LUCID (1 << 10)
#define DMGL_ARM (1 << 11)
/* If none of these are set, use 'current_demangling_style' as the default. */
#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM)
/* Enumeration of possible demangling styles.
Lucid and ARM styles are still kept logically distinct, even though
they now both behave identically. The resulting style is actual the
union of both. I.E. either style recognizes both "__pt__" and "__rf__"
for operator "->", even though the first is lucid style and the second
is ARM style. (FIXME?) */
extern enum demangling_styles
{
unknown_demangling = 0,
auto_demangling = DMGL_AUTO,
gnu_demangling = DMGL_GNU,
lucid_demangling = DMGL_LUCID,
arm_demangling = DMGL_ARM
} current_demangling_style;
/* Define string names for the various demangling styles. */
#define AUTO_DEMANGLING_STYLE_STRING "auto"
#define GNU_DEMANGLING_STYLE_STRING "gnu"
#define LUCID_DEMANGLING_STYLE_STRING "lucid"
#define ARM_DEMANGLING_STYLE_STRING "arm"
/* Some macros to test what demangling style is active. */
#define CURRENT_DEMANGLING_STYLE current_demangling_style
#define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
#define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU)
#define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID)
#define ARM_DEMANGLING (CURRENT_DEMANGLING_STYLE & DMGL_ARM)
extern char *
cplus_demangle PARAMS ((const char *mangled, int options));
extern int
cplus_demangle_opname PARAMS ((const char *opname, char *result, int options));
extern const char *
cplus_mangle_opname PARAMS ((const char *opname, int options));
/* Note: This sets global state. FIXME if you care about multi-threading. */
extern void
set_cplus_marker_for_demangling PARAMS ((int ch));
#endif /* DEMANGLE_H */
/* filemode.c -- make a string describing file modes
Copyright (C) 1985, 90, 91, 94, 95, 1997 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include "bfd.h"
#include "bucomm.h"
static char ftypelet PARAMS ((unsigned long));
static void setst PARAMS ((unsigned long, char *));
/* filemodestring - fill in string STR with an ls-style ASCII
representation of the st_mode field of file stats block STATP.
10 characters are stored in STR; no terminating null is added.
The characters stored in STR are:
0 File type. 'd' for directory, 'c' for character
special, 'b' for block special, 'm' for multiplex,
'l' for symbolic link, 's' for socket, 'p' for fifo,
'-' for any other file type
1 'r' if the owner may read, '-' otherwise.
2 'w' if the owner may write, '-' otherwise.
3 'x' if the owner may execute, 's' if the file is
set-user-id, '-' otherwise.
'S' if the file is set-user-id, but the execute
bit isn't set.
4 'r' if group members may read, '-' otherwise.
5 'w' if group members may write, '-' otherwise.
6 'x' if group members may execute, 's' if the file is
set-group-id, '-' otherwise.
'S' if it is set-group-id but not executable.
7 'r' if any user may read, '-' otherwise.
8 'w' if any user may write, '-' otherwise.
9 'x' if any user may execute, 't' if the file is "sticky"
(will be retained in swap space after execution), '-'
otherwise.
'T' if the file is sticky but not executable. */
#if 0
/* This is not used; only mode_string is used. */
void
filemodestring (statp, str)
struct stat *statp;
char *str;
{
mode_string ((unsigned long) statp->st_mode, str);
}
#endif
/* Get definitions for the file permission bits. */
#ifndef S_IRWXU
#define S_IRWXU 0700
#endif
#ifndef S_IRUSR
#define S_IRUSR 0400
#endif
#ifndef S_IWUSR
#define S_IWUSR 0200
#endif
#ifndef S_IXUSR
#define S_IXUSR 0100
#endif
#ifndef S_IRWXG
#define S_IRWXG 0070
#endif
#ifndef S_IRGRP
#define S_IRGRP 0040
#endif
#ifndef S_IWGRP
#define S_IWGRP 0020
#endif
#ifndef S_IXGRP
#define S_IXGRP 0010
#endif
#ifndef S_IRWXO
#define S_IRWXO 0007
#endif
#ifndef S_IROTH
#define S_IROTH 0004
#endif
#ifndef S_IWOTH
#define S_IWOTH 0002
#endif
#ifndef S_IXOTH
#define S_IXOTH 0001
#endif
/* Like filemodestring, but only the relevant part of the `struct stat'
is given as an argument. */
void
mode_string (mode, str)
unsigned long mode;
char *str;
{
str[0] = ftypelet ((unsigned long) mode);
str[1] = (mode & S_IRUSR) != 0 ? 'r' : '-';
str[2] = (mode & S_IWUSR) != 0 ? 'w' : '-';
str[3] = (mode & S_IXUSR) != 0 ? 'x' : '-';
str[4] = (mode & S_IRGRP) != 0 ? 'r' : '-';
str[5] = (mode & S_IWGRP) != 0 ? 'w' : '-';
str[6] = (mode & S_IXGRP) != 0 ? 'x' : '-';
str[7] = (mode & S_IROTH) != 0 ? 'r' : '-';
str[8] = (mode & S_IWOTH) != 0 ? 'w' : '-';
str[9] = (mode & S_IXOTH) != 0 ? 'x' : '-';
setst ((unsigned long) mode, str);
}
/* Return a character indicating the type of file described by
file mode BITS:
'd' for directories
'b' for block special files
'c' for character special files
'm' for multiplexor files
'l' for symbolic links
's' for sockets
'p' for fifos
'-' for any other file type. */
#ifndef S_ISDIR
#ifdef S_IFDIR
#define S_ISDIR(i) (((i) & S_IFMT) == S_IFDIR)
#else /* ! defined (S_IFDIR) */
#define S_ISDIR(i) (((i) & 0170000) == 040000)
#endif /* ! defined (S_IFDIR) */
#endif /* ! defined (S_ISDIR) */
#ifndef S_ISBLK
#ifdef S_IFBLK
#define S_ISBLK(i) (((i) & S_IFMT) == S_IFBLK)
#else /* ! defined (S_IFBLK) */
#define S_ISBLK(i) 0
#endif /* ! defined (S_IFBLK) */
#endif /* ! defined (S_ISBLK) */
#ifndef S_ISCHR
#ifdef S_IFCHR
#define S_ISCHR(i) (((i) & S_IFMT) == S_IFCHR)
#else /* ! defined (S_IFCHR) */
#define S_ISCHR(i) 0
#endif /* ! defined (S_IFCHR) */
#endif /* ! defined (S_ISCHR) */
#ifndef S_ISFIFO
#ifdef S_IFIFO
#define S_ISFIFO(i) (((i) & S_IFMT) == S_IFIFO)
#else /* ! defined (S_IFIFO) */
#define S_ISFIFO(i) 0
#endif /* ! defined (S_IFIFO) */
#endif /* ! defined (S_ISFIFO) */
#ifndef S_ISSOCK
#ifdef S_IFSOCK
#define S_ISSOCK(i) (((i) & S_IFMT) == S_IFSOCK)
#else /* ! defined (S_IFSOCK) */
#define S_ISSOCK(i) 0
#endif /* ! defined (S_IFSOCK) */
#endif /* ! defined (S_ISSOCK) */
#ifndef S_ISLNK
#ifdef S_IFLNK
#define S_ISLNK(i) (((i) & S_IFMT) == S_IFLNK)
#else /* ! defined (S_IFLNK) */
#define S_ISLNK(i) 0
#endif /* ! defined (S_IFLNK) */
#endif /* ! defined (S_ISLNK) */
static char
ftypelet (bits)
unsigned long bits;
{
if (S_ISDIR (bits))
return 'd';
if (S_ISLNK (bits))
return 'l';
if (S_ISBLK (bits))
return 'b';
if (S_ISCHR (bits))
return 'c';
if (S_ISSOCK (bits))
return 's';
if (S_ISFIFO (bits))
return 'p';
#ifdef S_IFMT
#ifdef S_IFMPC
if ((bits & S_IFMT) == S_IFMPC
|| (bits & S_IFMT) == S_IFMPB)
return 'm';
#endif
#ifdef S_IFNWK
if ((bits & S_IFMT) == S_IFNWK)
return 'n';
#endif
#endif
return '-';
}
/* Set the 's' and 't' flags in file attributes string CHARS,
according to the file mode BITS. */
static void
setst (bits, chars)
unsigned long bits;
char *chars;
{
#ifdef S_ISUID
if (bits & S_ISUID)
{
if (chars[3] != 'x')
/* Set-uid, but not executable by owner. */
chars[3] = 'S';
else
chars[3] = 's';
}
#endif
#ifdef S_ISGID
if (bits & S_ISGID)
{
if (chars[6] != 'x')
/* Set-gid, but not executable by group. */
chars[6] = 'S';
else
chars[6] = 's';
}
#endif
#ifdef S_ISVTX
if (bits & S_ISVTX)
{
if (chars[9] != 'x')
/* Sticky, but not executable by others. */
chars[9] = 'T';
else
chars[9] = 't';
}
#endif
}
This source diff could not be displayed because it is too large. You can view the blob instead.
/* IEEE Standard 695-1980 "Universal Format for Object Modules" header file
Contributed by Cygnus Support. */
#define N_W_VARIABLES 8
#define Module_Beginning 0xe0
typedef struct ieee_module {
char *processor;
char *module_name;
} ieee_module_begin_type;
#define Address_Descriptor 0xec
typedef struct ieee_address {
bfd_vma number_of_bits_mau;
bfd_vma number_of_maus_in_address;
unsigned char byte_order;
#define IEEE_LITTLE 0xcc
#define IEEE_BIG 0xcd
} ieee_address_descriptor_type;
typedef union ieee_w_variable {
file_ptr offset[N_W_VARIABLES];
struct {
file_ptr extension_record;
file_ptr environmental_record;
file_ptr section_part;
file_ptr external_part;
file_ptr debug_information_part;
file_ptr data_part;
file_ptr trailer_part;
file_ptr me_record;
} r;
} ieee_w_variable_type;
typedef enum ieee_record
{
ieee_number_start_enum = 0x00,
ieee_number_end_enum=0x7f,
ieee_number_repeat_start_enum = 0x80,
ieee_number_repeat_end_enum = 0x88,
ieee_number_repeat_4_enum = 0x84,
ieee_number_repeat_3_enum = 0x83,
ieee_number_repeat_2_enum = 0x82,
ieee_number_repeat_1_enum = 0x81,
ieee_module_beginning_enum = 0xe0,
ieee_module_end_enum = 0xe1,
ieee_extension_length_1_enum = 0xde,
ieee_extension_length_2_enum = 0xdf,
ieee_section_type_enum = 0xe6,
ieee_section_alignment_enum = 0xe7,
ieee_external_symbol_enum = 0xe8,
ieee_comma = 0x90,
ieee_external_reference_enum = 0xe9,
ieee_set_current_section_enum = 0xe5,
ieee_address_descriptor_enum = 0xec,
ieee_load_constant_bytes_enum = 0xed,
ieee_load_with_relocation_enum = 0xe4,
ieee_variable_A_enum = 0xc1,
ieee_variable_B_enum = 0xc2,
ieee_variable_C_enum = 0xc3,
ieee_variable_D_enum = 0xc4,
ieee_variable_E_enum = 0xc5,
ieee_variable_F_enum = 0xc6,
ieee_variable_G_enum = 0xc7,
ieee_variable_H_enum = 0xc8,
ieee_variable_I_enum = 0xc9,
ieee_variable_J_enum = 0xca,
ieee_variable_K_enum = 0xcb,
ieee_variable_L_enum = 0xcc,
ieee_variable_M_enum = 0xcd,
ieee_variable_N_enum = 0xce,
ieee_variable_O_enum = 0xcf,
ieee_variable_P_enum = 0xd0,
ieee_variable_Q_enum = 0xd1,
ieee_variable_R_enum = 0xd2,
ieee_variable_S_enum = 0xd3,
ieee_variable_T_enum = 0xd4,
ieee_variable_U_enum = 0xd5,
ieee_variable_V_enum = 0xd6,
ieee_variable_W_enum = 0xd7,
ieee_variable_X_enum = 0xd8,
ieee_variable_Y_enum = 0xd9,
ieee_variable_Z_enum = 0xda,
ieee_function_plus_enum = 0xa5,
ieee_function_minus_enum = 0xa6,
ieee_function_signed_open_b_enum = 0xba,
ieee_function_signed_close_b_enum = 0xbb,
ieee_function_unsigned_open_b_enum = 0xbc,
ieee_function_unsigned_close_b_enum = 0xbd,
ieee_function_either_open_b_enum = 0xbe,
ieee_function_either_close_b_enum = 0xbf,
ieee_record_seperator_enum = 0xdb,
ieee_e2_first_byte_enum = 0xe2,
ieee_section_size_enum = 0xe2d3,
ieee_physical_region_size_enum = 0xe2c1,
ieee_region_base_address_enum = 0xe2c2,
ieee_mau_size_enum = 0xe2c6,
ieee_m_value_enum = 0xe2cd,
ieee_section_base_address_enum = 0xe2cc,
ieee_asn_record_enum = 0xe2ce,
ieee_section_offset_enum = 0xe2d2,
ieee_value_starting_address_enum = 0xe2c7,
ieee_assign_value_to_variable_enum = 0xe2d7,
ieee_set_current_pc_enum = 0xe2d0,
ieee_value_record_enum = 0xe2c9,
ieee_nn_record = 0xf0,
ieee_at_record_enum = 0xf1,
ieee_ty_record_enum = 0xf2,
ieee_attribute_record_enum = 0xf1c9,
ieee_atn_record_enum = 0xf1ce,
ieee_external_reference_info_record_enum = 0xf1d8,
ieee_weak_external_reference_enum= 0xf4,
ieee_repeat_data_enum = 0xf7,
ieee_bb_record_enum = 0xf8,
ieee_be_record_enum = 0xf9
} ieee_record_enum_type;
typedef struct ieee_section {
unsigned int section_index;
unsigned int section_type;
char *section_name;
unsigned int parent_section_index;
unsigned int sibling_section_index;
unsigned int context_index;
} ieee_section_type;
#define IEEE_REFERENCE_BASE 11
#define IEEE_PUBLIC_BASE 32
#define IEEE_SECTION_NUMBER_BASE 1
/* Function declarations for libiberty.
Written by Cygnus Support, 1994.
The libiberty library provides a number of functions which are
missing on some operating systems. We do not declare those here,
to avoid conflicts with the system header files on operating
systems that do support those functions. In this file we only
declare those functions which are specific to libiberty. */
#ifndef LIBIBERTY_H
#define LIBIBERTY_H
#ifdef __cplusplus
extern "C" {
#endif
#include "ansidecl.h"
/* Build an argument vector from a string. Allocates memory using
malloc. Use freeargv to free the vector. */
extern char **buildargv PARAMS ((char *));
/* Free a vector returned by buildargv. */
extern void freeargv PARAMS ((char **));
/* Duplicate an argument vector. Allocates memory using malloc. Use
freeargv to free the vector. */
extern char **dupargv PARAMS ((char **));
/* Return the last component of a path name. Note that we can't use a
prototype here because the parameter is declared inconsistently
across different systems, sometimes as "char *" and sometimes as
"const char *" */
#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__)
extern char *basename PARAMS ((const char *));
#else
extern char *basename ();
#endif
/* Concatenate an arbitrary number of strings, up to (char *) NULL.
Allocates memory using xmalloc. */
extern char *concat PARAMS ((const char *, ...));
/* Check whether two file descriptors refer to the same file. */
extern int fdmatch PARAMS ((int fd1, int fd2));
/* Get the amount of time the process has run, in microseconds. */
extern long get_run_time PARAMS ((void));
/* Choose a temporary directory to use for scratch files. */
extern char *choose_temp_base PARAMS ((void));
/* Allocate memory filled with spaces. Allocates using malloc. */
extern const char *spaces PARAMS ((int count));
/* Return the maximum error number for which strerror will return a
string. */
extern int errno_max PARAMS ((void));
/* Return the name of an errno value (e.g., strerrno (EINVAL) returns
"EINVAL"). */
extern const char *strerrno PARAMS ((int));
/* Given the name of an errno value, return the value. */
extern int strtoerrno PARAMS ((const char *));
/* ANSI's strerror(), but more robust. */
extern char *xstrerror PARAMS ((int));
/* Return the maximum signal number for which strsignal will return a
string. */
extern int signo_max PARAMS ((void));
/* Return a signal message string for a signal number
(e.g., strsignal (SIGHUP) returns something like "Hangup"). */
/* This is commented out as it can conflict with one in system headers.
We still document its existence though. */
/*extern const char *strsignal PARAMS ((int));*/
/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
"SIGHUP"). */
extern const char *strsigno PARAMS ((int));
/* Given the name of a signal, return its number. */
extern int strtosigno PARAMS ((const char *));
/* Register a function to be run by xexit. Returns 0 on success. */
extern int xatexit PARAMS ((void (*fn) (void)));
/* Exit, calling all the functions registered with xatexit. */
#ifndef __GNUC__
extern void xexit PARAMS ((int status));
#else
void xexit PARAMS ((int status)) __attribute__ ((noreturn));
#endif
/* Set the program name used by xmalloc. */
extern void xmalloc_set_program_name PARAMS ((const char *));
/* Allocate memory without fail. If malloc fails, this will print a
message to stderr (using the name set by xmalloc_set_program_name,
if any) and then call xexit. */
#ifdef ANSI_PROTOTYPES
/* Get a definition for size_t. */
#include <stddef.h>
#endif
extern PTR xmalloc PARAMS ((size_t));
/* Reallocate memory without fail. This works like xmalloc.
FIXME: We do not declare the parameter types for the same reason as
xmalloc. */
extern PTR xrealloc PARAMS ((PTR, size_t));
/* Allocate memory without fail and set it to zero. This works like
xmalloc. */
extern PTR xcalloc PARAMS ((size_t, size_t));
/* Copy a string into a memory buffer without fail. */
extern char *xstrdup PARAMS ((const char *));
/* hex character manipulation routines */
#define _hex_array_size 256
#define _hex_bad 99
extern char _hex_value[_hex_array_size];
extern void hex_init PARAMS ((void));
#define hex_p(c) (hex_value (c) != _hex_bad)
/* If you change this, note well: Some code relies on side effects in
the argument being performed exactly once. */
#define hex_value(c) (_hex_value[(unsigned char) (c)])
/* Definitions used by the pexecute routine. */
#define PEXECUTE_FIRST 1
#define PEXECUTE_LAST 2
#define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST)
#define PEXECUTE_SEARCH 4
#define PEXECUTE_VERBOSE 8
/* Execute a program. */
extern int pexecute PARAMS ((const char *, char * const *, const char *,
const char *, char **, char **, int));
/* Wait for pexecute to finish. */
extern int pwait PARAMS ((int, int *, int));
#ifdef __cplusplus
}
#endif
#endif /* ! defined (LIBIBERTY_H) */
/* $Header$ */
/*
* LinuxThreads specific stuff.
*/
#include <sys/types.h>
#include <assert.h>
#include <limits.h> /* PTHREAD_THREADS_MAX */
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sched.h>
#include "linuxthreads.h"
#define AT_INT(intval) *((int32_t*)(intval))
/*
* Internal LinuxThreads variables.
* Official interface exposed to GDB.
*/
#if 1
extern volatile int __pthread_threads_debug;
extern volatile char __pthread_handles;
extern char __pthread_initial_thread;
/*extern volatile Elf32_Sym* __pthread_manager_thread;*/
extern const int __pthread_sizeof_handle;
extern const int __pthread_offsetof_descr;
extern const int __pthread_offsetof_pid;
extern volatile int __pthread_handles_num;
#endif /* 0 */
/*
* Notify others.
*/
int
linuxthreads_notify_others( const int signotify)
{
const pid_t mypid = getpid();
//const pthread_t mytid = pthread_self();
int i;
int threadcount = 0;
int threads[PTHREAD_THREADS_MAX];
int pid;
TRACE_FPRINTF((stderr, "theadcount:%d\n", __pthread_handles_num));
if (__pthread_handles_num==2) {
/* no threads beside the initial thread */
return 0;
}
/*assert(maxthreads>=3);
assert(maxthreads>=__pthread_handles_num+2);*/
// take the initial thread with us
pid = AT_INT(&__pthread_initial_thread + __pthread_offsetof_pid);
if (pid!=mypid && pid!=0)
threads[threadcount++] = pid;
// don't know why, but always handles[0]==handles[1]
for (i=1; i<__pthread_handles_num; ++i) {
const int descr = AT_INT(&__pthread_handles+i*__pthread_sizeof_handle+__pthread_offsetof_descr);
assert(descr!=0);
pid = AT_INT(descr+__pthread_offsetof_pid);
if (pid!=mypid && pid!=0)
threads[threadcount++] = pid;
}
/* TRACE_FPRINTF((stderr, "Stopping threads...")); */
//for (i=0; i<threadcount; ++i) {
// /* TRACE_FPRINTF((stderr, "%d ", threads[i])); */
// fflush(stdout);
// kill(threads[i], SIGSTOP); /* Tell thread to stop */
//}
/* TRACE_FPRINTF((stderr, " done!\n")); */
for (i=0; i<threadcount; ++i) {
TRACE_FPRINTF((stderr, "--- NOTIFYING %d\n", threads[i]));
kill(threads[i], signotify); /* Tell to print stack trace */
/* TRACE_FPRINTF((stderr, "--- WAITING FOR %d\n", threads[i])); */
/*pause(); Wait for confirmation. */
}
for (i=0; i<threadcount; ++i)
sched_yield();
for (i=0; i<threadcount; ++i) {
TRACE_FPRINTF((stderr, "--- KILLING %d\n", threads[i]));
kill(threads[i], SIGKILL); /* Tell thread die :) */
}
return __pthread_handles_num;
}
/* $Header$ */
/*
* LinuxThreads specific stuff.
*/
#ifndef pstack_linuxthreads_h_
#define pstack_linuxthreads_h_
#include <pthread.h>
#include "pstacktrace.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Tell other threads to dump stacks...
*/
int
linuxthreads_notify_others( const int signotify);
#ifdef __cplusplus
}
#endif
#endif /* pstack_linuxthreads_h_ */
/*
pstack.c -- asynchronous stack trace of a running process
Copyright (c) 1999 Ross Thompson
Author: Ross Thompson <ross@whatsis.com>
Critical bug fix: Tim Waugh
*/
/*
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* RESTRICTIONS:
pstack currently works only on Linux, only on an x86 machine running
32 bit ELF binaries (64 bit not supported). Also, for symbolic
information, you need to use a GNU compiler to generate your
program, and you can't strip symbols from the binaries. For thread
information to be dumped, you have to use the debug-aware version
of libpthread.so. (To check, run 'nm' on your libpthread.so, and
make sure that the symbol "__pthread_threads_debug" is defined.)
The details of pulling stuff out of ELF files and running through
program images is very platform specific, and I don't want to
try to support modes or machine types I can't test in or on.
If someone wants to generalize this to other architectures, I would
be happy to help and coordinate the activity. Please send me whatever
changes you make to support these machines, so that I can own the
central font of all truth (at least as regards this program).
Thanks
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <asm/ptrace.h>
#include <assert.h>
#include <fcntl.h>
#include <link.h>
#include <malloc.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <limits.h> /* PTHREAD_THREADS_MAX */
#include <bfd.h>
#include "libiberty.h"
#include "pstack.h" /* just one function */
#include "budbg.h" /* binutils stuff related to debugging symbols. */
#include "bucomm.h" /* some common stuff */
#include "debug.h" /* and more binutils stuff... */
#include "budbg.h"
#include "linuxthreads.h" /* LinuxThreads specific stuff... */
/*
* fprintf for file descriptors :) NOTE: we have to use fixed-size buffer :)(
* due to malloc's unavalaibility.
*/
int
fdprintf( int fd,
const char* fmt,...)
{
char xbuf[2048];// FIXME: enough?
va_list ap;
int r;
if (fd<0)
return -1;
va_start(ap, fmt);
r = vsnprintf(xbuf, sizeof(xbuf), fmt, ap);
va_end(ap);
return write(fd, xbuf, r);
}
int
fdputc( char c,
int fd)
{
if (fd<0)
return -1;
return write(fd, &c, sizeof(c));
}
int
fdputs( const char* s,
int fd)
{
if (fd<0)
return -1;
return write(fd, s, strlen(s));
}
/*
* Use this function to open log file.
* Flags: truncate on opening.
*/
static const char* path_format = "stack-trace-on-segv-%d.txt";
static int
open_log_file( const pthread_t tid,
const pid_t pid)
{
char fname[PATH_MAX];
int r;
snprintf(fname, sizeof(fname), path_format, tid, pid);
r = open(fname, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR);
if (r<0)
perror("open");
return r;
}
/*
* Add additional debugging information for functions.
*/
/*
* Lineno
*/
typedef struct {
int lineno;
bfd_vma addr;
} debug_lineno_t;
/*
* Block - a {} pair.
*/
typedef struct debug_block_st {
bfd_vma begin_addr; /* where did it start */
bfd_vma end_addr; /* where did it end */
struct debug_block_st* parent;
struct debug_block_st* childs;
int childs_count;
} debug_block_t;
/*
* Function parameter.
*/
typedef struct {
bfd_vma offset; /* Offset in the stack */
const char* name; /* And name. */
} debug_parameter_t;
/*
* Extra information about functions.
*/
typedef struct {
asymbol* symbol; /* mangled function name, addr */
debug_lineno_t* lines;
int lines_count;
int max_lines_count;
const char* name;
const char* filename;/* a file name it occured in... */
debug_block_t* block; /* each function has a block, or not, you know */
debug_parameter_t* argv; /* argument types. */
int argc;
int max_argc;
} debug_function_t;
/* This is the structure we use as a handle for these routines. */
struct pr_handle
{
/* File to print information to. */
FILE *f;
/* Current indentation level. */
unsigned int indent;
/* Type stack. */
struct pr_stack *stack;
/* Parameter number we are about to output. */
int parameter;
debug_block_t* block; /* current block */
debug_function_t* function; /* current function */
debug_function_t* functions; /* all functions */
int functions_size; /* current size */
int functions_maxsize; /* maximum size */
};
/* The type stack. */
struct pr_stack
{
/* Next element on the stack. */
struct pr_stack *next;
/* This element. */
char *type;
/* Current visibility of fields if this is a class. */
enum debug_visibility visibility;
/* Name of the current method we are handling. */
const char *method;
};
static void indent PARAMS ((struct pr_handle *));
static boolean push_type PARAMS ((struct pr_handle *, const char *));
static boolean prepend_type PARAMS ((struct pr_handle *, const char *));
static boolean append_type PARAMS ((struct pr_handle *, const char *));
static boolean substitute_type PARAMS ((struct pr_handle *, const char *));
static boolean indent_type PARAMS ((struct pr_handle *));
static char *pop_type PARAMS ((struct pr_handle *));
static void print_vma PARAMS ((bfd_vma, char *, boolean, boolean));
static boolean pr_fix_visibility
PARAMS ((struct pr_handle *, enum debug_visibility));
static boolean pr_start_compilation_unit PARAMS ((PTR, const char *));
static boolean pr_start_source PARAMS ((PTR, const char *));
static boolean pr_empty_type PARAMS ((PTR));
static boolean pr_void_type PARAMS ((PTR));
static boolean pr_int_type PARAMS ((PTR, unsigned int, boolean));
static boolean pr_float_type PARAMS ((PTR, unsigned int));
static boolean pr_complex_type PARAMS ((PTR, unsigned int));
static boolean pr_bool_type PARAMS ((PTR, unsigned int));
static boolean pr_enum_type
PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
static boolean pr_pointer_type PARAMS ((PTR));
static boolean pr_function_type PARAMS ((PTR, int, boolean));
static boolean pr_reference_type PARAMS ((PTR));
static boolean pr_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
static boolean pr_array_type
PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
static boolean pr_set_type PARAMS ((PTR, boolean));
static boolean pr_offset_type PARAMS ((PTR));
static boolean pr_method_type PARAMS ((PTR, boolean, int, boolean));
static boolean pr_const_type PARAMS ((PTR));
static boolean pr_volatile_type PARAMS ((PTR));
static boolean pr_start_struct_type
PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
static boolean pr_struct_field
PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
static boolean pr_end_struct_type PARAMS ((PTR));
static boolean pr_start_class_type
PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
boolean));
static boolean pr_class_static_member
PARAMS ((PTR, const char *, const char *, enum debug_visibility));
static boolean pr_class_baseclass
PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
static boolean pr_class_start_method PARAMS ((PTR, const char *));
static boolean pr_class_method_variant
PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
bfd_vma, boolean));
static boolean pr_class_static_method_variant
PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
static boolean pr_class_end_method PARAMS ((PTR));
static boolean pr_end_class_type PARAMS ((PTR));
static boolean pr_typedef_type PARAMS ((PTR, const char *));
static boolean pr_tag_type
PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
static boolean pr_typdef PARAMS ((PTR, const char *));
static boolean pr_tag PARAMS ((PTR, const char *));
static boolean pr_int_constant PARAMS ((PTR, const char *, bfd_vma));
static boolean pr_float_constant PARAMS ((PTR, const char *, double));
static boolean pr_typed_constant PARAMS ((PTR, const char *, bfd_vma));
static boolean pr_variable
PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
static boolean pr_start_function PARAMS ((PTR, const char *, boolean));
static boolean pr_function_parameter
PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
static boolean pr_start_block PARAMS ((PTR, bfd_vma));
static boolean pr_end_block PARAMS ((PTR, bfd_vma));
static boolean pr_end_function PARAMS ((PTR));
static boolean pr_lineno PARAMS ((PTR, const char *, unsigned long, bfd_vma));
static const struct debug_write_fns pr_fns =
{
pr_start_compilation_unit,
pr_start_source,
pr_empty_type,
pr_void_type,
pr_int_type,
pr_float_type,
pr_complex_type,
pr_bool_type,
pr_enum_type,
pr_pointer_type,
pr_function_type,
pr_reference_type,
pr_range_type,
pr_array_type,
pr_set_type,
pr_offset_type,
pr_method_type,
pr_const_type,
pr_volatile_type,
pr_start_struct_type,
pr_struct_field,
pr_end_struct_type,
pr_start_class_type,
pr_class_static_member,
pr_class_baseclass,
pr_class_start_method,
pr_class_method_variant,
pr_class_static_method_variant,
pr_class_end_method,
pr_end_class_type,
pr_typedef_type,
pr_tag_type,
pr_typdef,
pr_tag,
pr_int_constant,
pr_float_constant,
pr_typed_constant,
pr_variable,
pr_start_function,
pr_function_parameter,
pr_start_block,
pr_end_block,
pr_end_function,
pr_lineno
};
/* Indent to the current indentation level. */
static void
indent (info)
struct pr_handle *info;
{
unsigned int i;
for (i = 0; i < info->indent; i++)
TRACE_PUTC ((' ', info->f));
}
/* Push a type on the type stack. */
static boolean
push_type (info, type)
struct pr_handle *info;
const char *type;
{
struct pr_stack *n;
if (type == NULL)
return false;
n = (struct pr_stack *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->type = xstrdup (type);
n->visibility = DEBUG_VISIBILITY_IGNORE;
n->method = NULL;
n->next = info->stack;
info->stack = n;
return true;
}
/* Prepend a string onto the type on the top of the type stack. */
static boolean
prepend_type (info, s)
struct pr_handle *info;
const char *s;
{
char *n;
assert (info->stack != NULL);
n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
sprintf (n, "%s%s", s, info->stack->type);
free (info->stack->type);
info->stack->type = n;
return true;
}
/* Append a string to the type on the top of the type stack. */
static boolean
append_type (info, s)
struct pr_handle *info;
const char *s;
{
unsigned int len;
if (s == NULL)
return false;
assert (info->stack != NULL);
len = strlen (info->stack->type);
info->stack->type = (char *) xrealloc (info->stack->type,
len + strlen (s) + 1);
strcpy (info->stack->type + len, s);
return true;
}
/* We use an underscore to indicate where the name should go in a type
string. This function substitutes a string for the underscore. If
there is no underscore, the name follows the type. */
static boolean
substitute_type (info, s)
struct pr_handle *info;
const char *s;
{
char *u;
assert (info->stack != NULL);
u = strchr (info->stack->type, '|');
if (u != NULL)
{
char *n;
n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
memcpy (n, info->stack->type, u - info->stack->type);
strcpy (n + (u - info->stack->type), s);
strcat (n, u + 1);
free (info->stack->type);
info->stack->type = n;
return true;
}
if (strchr (s, '|') != NULL
&& (strchr (info->stack->type, '{') != NULL
|| strchr (info->stack->type, '(') != NULL))
{
if (! prepend_type (info, "(")
|| ! append_type (info, ")"))
return false;
}
if (*s == '\0')
return true;
return (append_type (info, " ")
&& append_type (info, s));
}
/* Indent the type at the top of the stack by appending spaces. */
static boolean
indent_type (info)
struct pr_handle *info;
{
unsigned int i;
for (i = 0; i < info->indent; i++)
{
if (! append_type (info, " "))
return false;
}
return true;
}
/* Pop a type from the type stack. */
static char *
pop_type (info)
struct pr_handle *info;
{
struct pr_stack *o;
char *ret;
assert (info->stack != NULL);
o = info->stack;
info->stack = o->next;
ret = o->type;
free (o);
return ret;
}
/* Print a VMA value into a string. */
static void
print_vma (vma, buf, unsignedp, hexp)
bfd_vma vma;
char *buf;
boolean unsignedp;
boolean hexp;
{
if (sizeof (vma) <= sizeof (unsigned long))
{
if (hexp)
sprintf (buf, "0x%lx", (unsigned long) vma);
else if (unsignedp)
sprintf (buf, "%lu", (unsigned long) vma);
else
sprintf (buf, "%ld", (long) vma);
}
else
{
buf[0] = '0';
buf[1] = 'x';
sprintf_vma (buf + 2, vma);
}
}
/* Start a new compilation unit. */
static boolean
pr_start_compilation_unit (p, filename)
PTR p;
const char *filename;
{
struct pr_handle *info = (struct pr_handle *) p;
assert (info->indent == 0);
/*
TRACE_FPRINTF( (info->f, "%s:\n", filename));
*/
return true;
}
/* Start a source file within a compilation unit. */
static boolean
pr_start_source (p, filename)
PTR p;
const char *filename;
{
struct pr_handle *info = (struct pr_handle *) p;
assert (info->indent == 0);
/*
TRACE_FPRINTF( (info->f, " %s:\n", filename));
*/
return true;
}
/* Push an empty type onto the type stack. */
static boolean
pr_empty_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
return push_type (info, "<undefined>");
}
/* Push a void type onto the type stack. */
static boolean
pr_void_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
return push_type (info, "void");
}
/* Push an integer type onto the type stack. */
static boolean
pr_int_type (p, size, unsignedp)
PTR p;
unsigned int size;
boolean unsignedp;
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[10];
sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
return push_type (info, ab);
}
/* Push a floating type onto the type stack. */
static boolean
pr_float_type (p, size)
PTR p;
unsigned int size;
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[10];
if (size == 4)
return push_type (info, "float");
else if (size == 8)
return push_type (info, "double");
sprintf (ab, "float%d", size * 8);
return push_type (info, ab);
}
/* Push a complex type onto the type stack. */
static boolean
pr_complex_type (p, size)
PTR p;
unsigned int size;
{
struct pr_handle *info = (struct pr_handle *) p;
if (! pr_float_type (p, size))
return false;
return prepend_type (info, "complex ");
}
/* Push a boolean type onto the type stack. */
static boolean
pr_bool_type (p, size)
PTR p;
unsigned int size;
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[10];
sprintf (ab, "bool%d", size * 8);
return push_type (info, ab);
}
/* Push an enum type onto the type stack. */
static boolean
pr_enum_type (p, tag, names, values)
PTR p;
const char *tag;
const char **names;
bfd_signed_vma *values;
{
struct pr_handle *info = (struct pr_handle *) p;
unsigned int i;
bfd_signed_vma val;
if (! push_type (info, "enum "))
return false;
if (tag != NULL)
{
if (! append_type (info, tag)
|| ! append_type (info, " "))
return false;
}
if (! append_type (info, "{ "))
return false;
if (names == NULL)
{
if (! append_type (info, "/* undefined */"))
return false;
}
else
{
val = 0;
for (i = 0; names[i] != NULL; i++)
{
if (i > 0)
{
if (! append_type (info, ", "))
return false;
}
if (! append_type (info, names[i]))
return false;
if (values[i] != val)
{
char ab[20];
print_vma (values[i], ab, false, false);
if (! append_type (info, " = ")
|| ! append_type (info, ab))
return false;
val = values[i];
}
++val;
}
}
return append_type (info, " }");
}
/* Turn the top type on the stack into a pointer. */
static boolean
pr_pointer_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
char *s;
assert (info->stack != NULL);
s = strchr (info->stack->type, '|');
if (s != NULL && s[1] == '[')
return substitute_type (info, "(*|)");
return substitute_type (info, "*|");
}
/* Turn the top type on the stack into a function returning that type. */
static boolean
pr_function_type (p, argcount, varargs)
PTR p;
int argcount;
boolean varargs;
{
struct pr_handle *info = (struct pr_handle *) p;
char **arg_types;
unsigned int len;
char *s;
assert (info->stack != NULL);
len = 10;
if (argcount <= 0)
{
arg_types = NULL;
len += 15;
}
else
{
int i;
arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
for (i = argcount - 1; i >= 0; i--)
{
if (! substitute_type (info, ""))
return false;
arg_types[i] = pop_type (info);
if (arg_types[i] == NULL)
return false;
len += strlen (arg_types[i]) + 2;
}
if (varargs)
len += 5;
}
/* Now the return type is on the top of the stack. */
s = (char *) xmalloc (len);
strcpy (s, "(|) (");
if (argcount < 0)
{
#if 0
/* Turn off unknown arguments. */
strcat (s, "/* unknown */");
#endif
}
else
{
int i;
for (i = 0; i < argcount; i++)
{
if (i > 0)
strcat (s, ", ");
strcat (s, arg_types[i]);
}
if (varargs)
{
if (i > 0)
strcat (s, ", ");
strcat (s, "...");
}
if (argcount > 0)
free (arg_types);
}
strcat (s, ")");
if (! substitute_type (info, s))
return false;
free (s);
return true;
}
/* Turn the top type on the stack into a reference to that type. */
static boolean
pr_reference_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
assert (info->stack != NULL);
return substitute_type (info, "&|");
}
/* Make a range type. */
static boolean
pr_range_type (p, lower, upper)
PTR p;
bfd_signed_vma lower;
bfd_signed_vma upper;
{
struct pr_handle *info = (struct pr_handle *) p;
char abl[20], abu[20];
assert (info->stack != NULL);
if (! substitute_type (info, ""))
return false;
print_vma (lower, abl, false, false);
print_vma (upper, abu, false, false);
return (prepend_type (info, "range (")
&& append_type (info, "):")
&& append_type (info, abl)
&& append_type (info, ":")
&& append_type (info, abu));
}
/* Make an array type. */
/*ARGSUSED*/
static boolean
pr_array_type (p, lower, upper, stringp)
PTR p;
bfd_signed_vma lower;
bfd_signed_vma upper;
boolean stringp;
{
struct pr_handle *info = (struct pr_handle *) p;
char *range_type;
char abl[20], abu[20], ab[50];
range_type = pop_type (info);
if (range_type == NULL)
return false;
if (lower == 0)
{
if (upper == -1)
sprintf (ab, "|[]");
else
{
print_vma (upper + 1, abu, false, false);
sprintf (ab, "|[%s]", abu);
}
}
else
{
print_vma (lower, abl, false, false);
print_vma (upper, abu, false, false);
sprintf (ab, "|[%s:%s]", abl, abu);
}
if (! substitute_type (info, ab))
return false;
if (strcmp (range_type, "int") != 0)
{
if (! append_type (info, ":")
|| ! append_type (info, range_type))
return false;
}
if (stringp)
{
if (! append_type (info, " /* string */"))
return false;
}
return true;
}
/* Make a set type. */
/*ARGSUSED*/
static boolean
pr_set_type (p, bitstringp)
PTR p;
boolean bitstringp;
{
struct pr_handle *info = (struct pr_handle *) p;
if (! substitute_type (info, ""))
return false;
if (! prepend_type (info, "set { ")
|| ! append_type (info, " }"))
return false;
if (bitstringp)
{
if (! append_type (info, "/* bitstring */"))
return false;
}
return true;
}
/* Make an offset type. */
static boolean
pr_offset_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
if (! substitute_type (info, ""))
return false;
t = pop_type (info);
if (t == NULL)
return false;
return (substitute_type (info, "")
&& prepend_type (info, " ")
&& prepend_type (info, t)
&& append_type (info, "::|"));
}
/* Make a method type. */
static boolean
pr_method_type (p, domain, argcount, varargs)
PTR p;
boolean domain;
int argcount;
boolean varargs;
{
struct pr_handle *info = (struct pr_handle *) p;
unsigned int len;
char *domain_type;
char **arg_types;
char *s;
len = 10;
if (! domain)
domain_type = NULL;
else
{
if (! substitute_type (info, ""))
return false;
domain_type = pop_type (info);
if (domain_type == NULL)
return false;
if (strncmp (domain_type, "class ", sizeof "class " - 1) == 0
&& strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
domain_type += sizeof "class " - 1;
else if (strncmp (domain_type, "union class ",
sizeof "union class ") == 0
&& (strchr (domain_type + sizeof "union class " - 1, ' ')
== NULL))
domain_type += sizeof "union class " - 1;
len += strlen (domain_type);
}
if (argcount <= 0)
{
arg_types = NULL;
len += 15;
}
else
{
int i;
arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
for (i = argcount - 1; i >= 0; i--)
{
if (! substitute_type (info, ""))
return false;
arg_types[i] = pop_type (info);
if (arg_types[i] == NULL)
return false;
len += strlen (arg_types[i]) + 2;
}
if (varargs)
len += 5;
}
/* Now the return type is on the top of the stack. */
s = (char *) xmalloc (len);
if (! domain)
*s = '\0';
else
strcpy (s, domain_type);
strcat (s, "::| (");
if (argcount < 0)
strcat (s, "/* unknown */");
else
{
int i;
for (i = 0; i < argcount; i++)
{
if (i > 0)
strcat (s, ", ");
strcat (s, arg_types[i]);
}
if (varargs)
{
if (i > 0)
strcat (s, ", ");
strcat (s, "...");
}
if (argcount > 0)
free (arg_types);
}
strcat (s, ")");
if (! substitute_type (info, s))
return false;
free (s);
return true;
}
/* Make a const qualified type. */
static boolean
pr_const_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
return substitute_type (info, "const |");
}
/* Make a volatile qualified type. */
static boolean
pr_volatile_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
return substitute_type (info, "volatile |");
}
/* Start accumulating a struct type. */
static boolean
pr_start_struct_type (p, tag, id, structp, size)
PTR p;
const char *tag;
unsigned int id;
boolean structp;
unsigned int size;
{
struct pr_handle *info = (struct pr_handle *) p;
info->indent += 2;
if (! push_type (info, structp ? "struct " : "union "))
return false;
if (tag != NULL)
{
if (! append_type (info, tag))
return false;
}
else
{
char idbuf[20];
sprintf (idbuf, "%%anon%u", id);
if (! append_type (info, idbuf))
return false;
}
if (! append_type (info, " {"))
return false;
if (size != 0 || tag != NULL)
{
char ab[30];
if (! append_type (info, " /*"))
return false;
if (size != 0)
{
sprintf (ab, " size %u", size);
if (! append_type (info, ab))
return false;
}
if (tag != NULL)
{
sprintf (ab, " id %u", id);
if (! append_type (info, ab))
return false;
}
if (! append_type (info, " */"))
return false;
}
if (! append_type (info, "\n"))
return false;
info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
return indent_type (info);
}
/* Output the visibility of a field in a struct. */
static boolean
pr_fix_visibility (info, visibility)
struct pr_handle *info;
enum debug_visibility visibility;
{
const char *s;
char *t;
unsigned int len;
assert (info->stack != NULL);
if (info->stack->visibility == visibility)
return true;
assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
switch (visibility)
{
case DEBUG_VISIBILITY_PUBLIC:
s = "public";
break;
case DEBUG_VISIBILITY_PRIVATE:
s = "private";
break;
case DEBUG_VISIBILITY_PROTECTED:
s = "protected";
break;
case DEBUG_VISIBILITY_IGNORE:
s = "/* ignore */";
break;
default:
abort ();
return false;
}
/* Trim off a trailing space in the struct string, to make the
output look a bit better, then stick on the visibility string. */
t = info->stack->type;
len = strlen (t);
assert (t[len - 1] == ' ');
t[len - 1] = '\0';
if (! append_type (info, s)
|| ! append_type (info, ":\n")
|| ! indent_type (info))
return false;
info->stack->visibility = visibility;
return true;
}
/* Add a field to a struct type. */
static boolean
pr_struct_field (p, name, bitpos, bitsize, visibility)
PTR p;
const char *name;
bfd_vma bitpos;
bfd_vma bitsize;
enum debug_visibility visibility;
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[20];
char *t;
if (! substitute_type (info, name))
return false;
if (! append_type (info, "; /* "))
return false;
if (bitsize != 0)
{
print_vma (bitsize, ab, true, false);
if (! append_type (info, "bitsize ")
|| ! append_type (info, ab)
|| ! append_type (info, ", "))
return false;
}
print_vma (bitpos, ab, true, false);
if (! append_type (info, "bitpos ")
|| ! append_type (info, ab)
|| ! append_type (info, " */\n")
|| ! indent_type (info))
return false;
t = pop_type (info);
if (t == NULL)
return false;
if (! pr_fix_visibility (info, visibility))
return false;
return append_type (info, t);
}
/* Finish a struct type. */
static boolean
pr_end_struct_type (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
char *s;
assert (info->stack != NULL);
assert (info->indent >= 2);
info->indent -= 2;
/* Change the trailing indentation to have a close brace. */
s = info->stack->type + strlen (info->stack->type) - 2;
assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
*s++ = '}';
*s = '\0';
return true;
}
/* Start a class type. */
static boolean
pr_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
PTR p;
const char *tag;
unsigned int id;
boolean structp;
unsigned int size;
boolean vptr;
boolean ownvptr;
{
struct pr_handle *info = (struct pr_handle *) p;
char *tv = NULL;
info->indent += 2;
if (vptr && ! ownvptr)
{
tv = pop_type (info);
if (tv == NULL)
return false;
}
if (! push_type (info, structp ? "class " : "union class "))
return false;
if (tag != NULL)
{
if (! append_type (info, tag))
return false;
}
else
{
char idbuf[20];
sprintf (idbuf, "%%anon%u", id);
if (! append_type (info, idbuf))
return false;
}
if (! append_type (info, " {"))
return false;
if (size != 0 || vptr || ownvptr || tag != NULL)
{
if (! append_type (info, " /*"))
return false;
if (size != 0)
{
char ab[20];
sprintf (ab, "%u", size);
if (! append_type (info, " size ")
|| ! append_type (info, ab))
return false;
}
if (vptr)
{
if (! append_type (info, " vtable "))
return false;
if (ownvptr)
{
if (! append_type (info, "self "))
return false;
}
else
{
if (! append_type (info, tv)
|| ! append_type (info, " "))
return false;
}
}
if (tag != NULL)
{
char ab[30];
sprintf (ab, " id %u", id);
if (! append_type (info, ab))
return false;
}
if (! append_type (info, " */"))
return false;
}
info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
return (append_type (info, "\n")
&& indent_type (info));
}
/* Add a static member to a class. */
static boolean
pr_class_static_member (p, name, physname, visibility)
PTR p;
const char *name;
const char *physname;
enum debug_visibility visibility;
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
if (! substitute_type (info, name))
return false;
if (! prepend_type (info, "static ")
|| ! append_type (info, "; /* ")
|| ! append_type (info, physname)
|| ! append_type (info, " */\n")
|| ! indent_type (info))
return false;
t = pop_type (info);
if (t == NULL)
return false;
if (! pr_fix_visibility (info, visibility))
return false;
return append_type (info, t);
}
/* Add a base class to a class. */
static boolean
pr_class_baseclass (p, bitpos, virtual, visibility)
PTR p;
bfd_vma bitpos;
boolean virtual;
enum debug_visibility visibility;
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
const char *prefix;
char ab[20];
char *s, *l, *n;
assert (info->stack != NULL && info->stack->next != NULL);
if (! substitute_type (info, ""))
return false;
t = pop_type (info);
if (t == NULL)
return false;
if (strncmp (t, "class ", sizeof "class " - 1) == 0)
t += sizeof "class " - 1;
/* Push it back on to take advantage of the prepend_type and
append_type routines. */
if (! push_type (info, t))
return false;
if (virtual)
{
if (! prepend_type (info, "virtual "))
return false;
}
switch (visibility)
{
case DEBUG_VISIBILITY_PUBLIC:
prefix = "public ";
break;
case DEBUG_VISIBILITY_PROTECTED:
prefix = "protected ";
break;
case DEBUG_VISIBILITY_PRIVATE:
prefix = "private ";
break;
default:
prefix = "/* unknown visibility */ ";
break;
}
if (! prepend_type (info, prefix))
return false;
if (bitpos != 0)
{
print_vma (bitpos, ab, true, false);
if (! append_type (info, " /* bitpos ")
|| ! append_type (info, ab)
|| ! append_type (info, " */"))
return false;
}
/* Now the top of the stack is something like "public A / * bitpos
10 * /". The next element on the stack is something like "class
xx { / * size 8 * /\n...". We want to substitute the top of the
stack in before the {. */
s = strchr (info->stack->next->type, '{');
assert (s != NULL);
--s;
/* If there is already a ':', then we already have a baseclass, and
we must append this one after a comma. */
for (l = info->stack->next->type; l != s; l++)
if (*l == ':')
break;
if (! prepend_type (info, l == s ? " : " : ", "))
return false;
t = pop_type (info);
if (t == NULL)
return false;
n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
memcpy (n, info->stack->type, s - info->stack->type);
strcpy (n + (s - info->stack->type), t);
strcat (n, s);
free (info->stack->type);
info->stack->type = n;
free (t);
return true;
}
/* Start adding a method to a class. */
static boolean
pr_class_start_method (p, name)
PTR p;
const char *name;
{
struct pr_handle *info = (struct pr_handle *) p;
assert (info->stack != NULL);
info->stack->method = name;
return true;
}
/* Add a variant to a method. */
static boolean
pr_class_method_variant (p, physname, visibility, constp, volatilep, voffset,
context)
PTR p;
const char *physname;
enum debug_visibility visibility;
boolean constp;
boolean volatilep;
bfd_vma voffset;
boolean context;
{
struct pr_handle *info = (struct pr_handle *) p;
char *method_type;
char *context_type;
assert (info->stack != NULL);
assert (info->stack->next != NULL);
/* Put the const and volatile qualifiers on the type. */
if (volatilep)
{
if (! append_type (info, " volatile"))
return false;
}
if (constp)
{
if (! append_type (info, " const"))
return false;
}
/* Stick the name of the method into its type. */
if (! substitute_type (info,
(context
? info->stack->next->next->method
: info->stack->next->method)))
return false;
/* Get the type. */
method_type = pop_type (info);
if (method_type == NULL)
return false;
/* Pull off the context type if there is one. */
if (! context)
context_type = NULL;
else
{
context_type = pop_type (info);
if (context_type == NULL)
return false;
}
/* Now the top of the stack is the class. */
if (! pr_fix_visibility (info, visibility))
return false;
if (! append_type (info, method_type)
|| ! append_type (info, " /* ")
|| ! append_type (info, physname)
|| ! append_type (info, " "))
return false;
if (context || voffset != 0)
{
char ab[20];
if (context)
{
if (! append_type (info, "context ")
|| ! append_type (info, context_type)
|| ! append_type (info, " "))
return false;
}
print_vma (voffset, ab, true, false);
if (! append_type (info, "voffset ")
|| ! append_type (info, ab))
return false;
}
return (append_type (info, " */;\n")
&& indent_type (info));
}
/* Add a static variant to a method. */
static boolean
pr_class_static_method_variant (p, physname, visibility, constp, volatilep)
PTR p;
const char *physname;
enum debug_visibility visibility;
boolean constp;
boolean volatilep;
{
struct pr_handle *info = (struct pr_handle *) p;
char *method_type;
assert (info->stack != NULL);
assert (info->stack->next != NULL);
assert (info->stack->next->method != NULL);
/* Put the const and volatile qualifiers on the type. */
if (volatilep)
{
if (! append_type (info, " volatile"))
return false;
}
if (constp)
{
if (! append_type (info, " const"))
return false;
}
/* Mark it as static. */
if (! prepend_type (info, "static "))
return false;
/* Stick the name of the method into its type. */
if (! substitute_type (info, info->stack->next->method))
return false;
/* Get the type. */
method_type = pop_type (info);
if (method_type == NULL)
return false;
/* Now the top of the stack is the class. */
if (! pr_fix_visibility (info, visibility))
return false;
return (append_type (info, method_type)
&& append_type (info, " /* ")
&& append_type (info, physname)
&& append_type (info, " */;\n")
&& indent_type (info));
}
/* Finish up a method. */
static boolean
pr_class_end_method (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
info->stack->method = NULL;
return true;
}
/* Finish up a class. */
static boolean
pr_end_class_type (p)
PTR p;
{
return pr_end_struct_type (p);
}
/* Push a type on the stack using a typedef name. */
static boolean
pr_typedef_type (p, name)
PTR p;
const char *name;
{
struct pr_handle *info = (struct pr_handle *) p;
return push_type (info, name);
}
/* Push a type on the stack using a tag name. */
static boolean
pr_tag_type (p, name, id, kind)
PTR p;
const char *name;
unsigned int id;
enum debug_type_kind kind;
{
struct pr_handle *info = (struct pr_handle *) p;
const char *t, *tag;
char idbuf[30];
switch (kind)
{
case DEBUG_KIND_STRUCT:
t = "struct ";
break;
case DEBUG_KIND_UNION:
t = "union ";
break;
case DEBUG_KIND_ENUM:
t = "enum ";
break;
case DEBUG_KIND_CLASS:
t = "class ";
break;
case DEBUG_KIND_UNION_CLASS:
t = "union class ";
break;
default:
abort ();
return false;
}
if (! push_type (info, t))
return false;
if (name != NULL)
tag = name;
else
{
sprintf (idbuf, "%%anon%u", id);
tag = idbuf;
}
if (! append_type (info, tag))
return false;
if (name != NULL && kind != DEBUG_KIND_ENUM)
{
sprintf (idbuf, " /* id %u */", id);
if (! append_type (info, idbuf))
return false;
}
return true;
}
/* Output a typedef. */
static boolean
pr_typdef (p, name)
PTR p;
const char *name;
{
struct pr_handle *info = (struct pr_handle *) p;
char *s;
if (! substitute_type (info, name))
return false;
s = pop_type (info);
if (s == NULL)
return false;
/*
indent (info);
TRACE_FPRINTF( (info->f, "typedef %s;\n", s));
*/
free (s);
return true;
}
/* Output a tag. The tag should already be in the string on the
stack, so all we have to do here is print it out. */
/*ARGSUSED*/
static boolean
pr_tag (p, name)
PTR p;
const char *name;
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
t = pop_type (info);
if (t == NULL)
return false;
/*
indent (info);
TRACE_FPRINTF( (info->f, "%s;\n", t));
*/
free (t);
return true;
}
/* Output an integer constant. */
static boolean
pr_int_constant (p, name, val)
PTR p;
const char *name;
bfd_vma val;
{
/*
struct pr_handle *info = (struct pr_handle *) p;
char ab[20];
indent (info);
print_vma (val, ab, false, false);
TRACE_FPRINTF( (info->f, "const int %s = %s;\n", name, ab));
*/
return true;
}
/* Output a floating point constant. */
static boolean
pr_float_constant (p, name, val)
PTR p;
const char *name;
double val;
{
/*
struct pr_handle *info = (struct pr_handle *) p;
indent (info);
TRACE_FPRINTF( (info->f, "const double %s = %g;\n", name, val));
*/
return true;
}
/* Output a typed constant. */
static boolean
pr_typed_constant (p, name, val)
PTR p;
const char *name;
bfd_vma val;
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
t = pop_type (info);
if (t == NULL)
return false;
/*
char ab[20];
indent (info);
print_vma (val, ab, false, false);
TRACE_FPRINTF( (info->f, "const %s %s = %s;\n", t, name, ab));
*/
free (t);
return true;
}
/* Output a variable. */
static boolean
pr_variable (p, name, kind, val)
PTR p;
const char *name;
enum debug_var_kind kind;
bfd_vma val;
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
char ab[20];
(void)ab;
if (! substitute_type (info, name))
return false;
t = pop_type (info);
if (t == NULL)
return false;
#if 0
indent (info);
switch (kind)
{
case DEBUG_STATIC:
case DEBUG_LOCAL_STATIC:
TRACE_FPRINTF( (info->f, "static "));
break;
case DEBUG_REGISTER:
TRACE_FPRINTF( (info->f, "register "));
break;
default:
break;
}
print_vma (val, ab, true, true);
TRACE_FPRINTF( (info->f, "%s /* %s */;\n", t, ab));
#else /* 0 */
#if 0
if (kind==DEBUG_STATIC || kind==DEBUG_LOCAL_STATIC) {
print_vma (val, ab, true, true);
TRACE_FPRINTF( (info->f, "STATIC_VAR: %s /* %s */;\n", t, ab));
}
#endif /* 0 */
#endif /* !0 */
free (t);
return true;
}
/* Start outputting a function. */
static boolean
pr_start_function (p, name, global)
PTR p;
const char *name;
boolean global;
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
if (! substitute_type (info, name))
return false;
t = pop_type (info);
if (t == NULL)
return false;
#if 0
indent (info);
if (! global)
TRACE_FPRINTF( (info->f, "static "));
TRACE_FPRINTF( (info->f, "%s (", t));
info->parameter = 1;
#else /* 0 */
if (info->functions_size==info->functions_maxsize) {
info->functions_maxsize *= 2;
info->functions = xrealloc(info->functions,
info->functions_maxsize*sizeof(debug_function_t));
assert(info->functions!=0);
}
/* info->functions[info->functions_size] = xmalloc(sizeof(debug_function_t)); */
info->function = &info->functions[info->functions_size];
++info->functions_size;
info->function->symbol = NULL;
info->function->lines = NULL;
info->function->lines_count = 0;
info->function->max_lines_count = 0;
info->function->name = t;
info->function->filename = NULL;
info->function->block = NULL;
info->function->argv = NULL;
info->function->argc = 0;
info->function->max_argc = 0;
#endif /* !0 */
return true;
}
/* Output a function parameter. */
static boolean
pr_function_parameter (p, name, kind, val)
PTR p;
const char *name;
enum debug_parm_kind kind;
bfd_vma val;
{
struct pr_handle *info = (struct pr_handle *) p;
debug_function_t* f = info->function;
char *t;
char ab[20];
(void)ab;
if (kind == DEBUG_PARM_REFERENCE
|| kind == DEBUG_PARM_REF_REG)
{
if (! pr_reference_type (p))
return false;
}
if (! substitute_type (info, name))
return false;
t = pop_type (info);
if (t == NULL)
return false;
#if 0
if (info->parameter != 1)
TRACE_FPRINTF( (info->f, ", "));
if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
TRACE_FPRINTF( (info->f, "register "));
print_vma (val, ab, true, true);
TRACE_FPRINTF( (info->f, "%s /* %s */", t, ab));
free (t);
++info->parameter;
#else /* 0 */
assert(f!=NULL);
if (f->argv==NULL) {
f->max_argc = 7; /* rarely anyone has more than that many args... */
f->argv = xmalloc(sizeof(debug_parameter_t)*f->max_argc);
} else if (f->argc==f->max_argc) {
f->max_argc *= 2;
f->argv = realloc(f->argv,sizeof(debug_parameter_t)*f->max_argc);
}
f->argv[f->argc].offset = val;
f->argv[f->argc].name = t;
++f->argc;
#endif /* !0 */
return true;
}
/* Start writing out a block. */
static boolean
pr_start_block (p, addr)
PTR p;
bfd_vma addr;
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[20];
debug_block_t* block = 0;
(void)ab;
#if 0
if (info->parameter > 0)
{
TRACE_FPRINTF( (info->f, ")\n"));
info->parameter = 0;
}
indent (info);
print_vma (addr, ab, true, true);
TRACE_FPRINTF( (info->f, "{ /* %s */\n", ab));
info->indent += 2;
#else
if (info->block) {
if (info->block->childs_count==0)
info->block->childs = xmalloc(sizeof(debug_block_t));
else
info->block->childs = xrealloc(info->block->childs,
info->block->childs_count*sizeof(debug_block_t));
block = &info->block->childs[info->block->childs_count];
} else {
block = xmalloc(sizeof(debug_block_t));
info->function->block = block;
}
block->begin_addr = addr;
block->end_addr = 0;
block->parent = info->block;
block->childs = NULL;
block->childs_count = 0;
info->block = block;
#endif
return true;
}
/* Write out line number information. */
static boolean
pr_lineno (p, filename, lineno, addr)
PTR p;
const char *filename;
unsigned long lineno;
bfd_vma addr;
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[20];
debug_function_t* f = info->function;
(void)ab;
#if 0
indent (info);
print_vma (addr, ab, true, true);
TRACE_FPRINTF( (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab));
#else /* 0 */
if (f==NULL) /* FIXME: skips junk silently. */
return true;
/* assert(f!=NULL); */
if (f->filename==NULL) {
f->filename = filename;
assert(f->lines==0);
f->max_lines_count = 4;
f->lines = xmalloc(sizeof(debug_lineno_t)*f->max_lines_count);
}
if (f->lines_count==f->max_lines_count) {
f->max_lines_count *= 2;
f->lines = xrealloc(f->lines, sizeof(debug_lineno_t)*f->max_lines_count);
}
f->lines[f->lines_count].lineno = lineno;
f->lines[f->lines_count].addr = addr;
++f->lines_count;
#endif /* !0 */
return true;
}
/* Finish writing out a block. */
static boolean
pr_end_block (p, addr)
PTR p;
bfd_vma addr;
{
struct pr_handle *info = (struct pr_handle *) p;
#if 0
char ab[20];
info->indent -= 2;
indent (info);
print_vma (addr, ab, true, true);
TRACE_FPRINTF( (info->f, "} /* %s */\n", ab));
#else /* 0 */
assert(info->block!=0);
info->block->end_addr = addr;
info->block = info->block->parent;
#endif /* !0 */
return true;
}
/* Finish writing out a function. */
/*ARGSUSED*/
static boolean
pr_end_function (p)
PTR p;
{
struct pr_handle *info = (struct pr_handle *) p;
assert(info->block==0);
info->function = NULL;
return true;
}
/* third parameter to segv_action. */
/* Got it after a bit of head scratching and stack dumping. */
typedef struct {
u_int32_t foo1; /* +0x00 */
u_int32_t foo2;
u_int32_t foo3;
u_int32_t foo4; /* usually 2 */
u_int32_t foo5; /* +0x10 */
u_int32_t xgs; /* always zero */
u_int32_t xfs; /* always zero */
u_int32_t xes; /* always es=ds=ss */
u_int32_t xds; /* +0x20 */
u_int32_t edi;
u_int32_t esi;
u_int32_t ebp;
u_int32_t esp; /* +0x30 */
u_int32_t ebx;
u_int32_t edx;
u_int32_t ecx;
u_int32_t eax; /* +0x40 */
u_int32_t foo11; /* usually 0xe */
u_int32_t foo12; /* usually 0x6 */
u_int32_t eip; /* instruction pointer */
u_int32_t xcs; /* +0x50 */
u_int32_t foo21; /* usually 0x2 */
u_int32_t foo22; /* second stack pointer?! Probably. */
u_int32_t xss;
u_int32_t foo31; /* +0x60 */ /* usually 0x0 */
u_int32_t foo32; /* usually 0x2 */
u_int32_t fault_addr; /* Address which caused a fault */
u_int32_t foo41; /* usually 0x2 */
} signal_regs_t;
signal_regs_t* ptrace_regs = 0; /* Tells my_ptrace to "ptrace" current process" */
/*
* my_ptrace: small wrapper around ptrace.
* Act as normal ptrace if ptrace_regs==0.
* Read data from current process if ptrace_regs!=0.
*/
static int
my_ptrace( int request,
int pid,
int addr,
int data)
{
if (ptrace_regs==0)
return ptrace(request, pid, addr, data);
/* we are tracing ourselves! */
switch (request) {
case PTRACE_ATTACH: return 0;
case PTRACE_CONT: return 0;
case PTRACE_DETACH: return 0;
case PTRACE_PEEKUSER:
switch (addr / 4) {
case EIP: return ptrace_regs->eip;
case EBP: return ptrace_regs->ebp;
default: assert(0);
}
case PTRACE_PEEKTEXT: /* FALLTHROUGH */
case PTRACE_PEEKDATA: return *(int*)(addr);
default: assert(0);
}
errno = 1; /* what to do here? */
return 1; /* failed?! */
}
#define MAXARGS 6
/*
* To minimize the number of parameters.
*/
typedef struct {
asymbol** syms; /* Sorted! */
int symcount;
debug_function_t** functions;
int functions_size;
} symbol_data_t;
/*
* Perform a search. A binary search for a symbol.
*/
static void
decode_symbol( symbol_data_t* symbol_data,
const unsigned long addr,
char* buf,
const int bufsize)
{
asymbol** syms = symbol_data->syms;
const int symcount = symbol_data->symcount;
int bottom = 0;
int top = symcount - 1;
int i;
if (symcount==0) {
sprintf(buf, "????");
return;
}
while (top>bottom+1) {
i = (top+bottom) / 2;
if (bfd_asymbol_value(syms[i])==addr) {
sprintf(buf, "%s", syms[i]->name);
return;
} else if (bfd_asymbol_value(syms[i]) > addr)
top = i;
else
bottom = i;
}
i = bottom;
if (addr<bfd_asymbol_value(syms[i]) || addr>(syms[i]->section->vma+syms[i]->section->_cooked_size))
sprintf(buf, "????");
else
sprintf(buf, "%s + 0x%lx", syms[i]->name, addr-bfd_asymbol_value(syms[i]));
}
/*
* 1. Perform a binary search for an debug_function_t.
* 2. Fill buf/bufsize with name, parameters and lineno, if found
* Or with '????' otherwise.
*/
static debug_function_t*
find_debug_function_t( symbol_data_t* symbol_data,
const pid_t pid,
const unsigned long fp, /* frame pointer */
const unsigned long addr,
char* buf, /* string buffer */
const int bufsize)/* FIXME: not used! */
{
debug_function_t** syms = symbol_data->functions;
debug_function_t* f = NULL;
debug_block_t* block = NULL;
debug_lineno_t* lineno = NULL;
const int symcount = symbol_data->functions_size;
int bottom = 0;
int top = symcount - 1;
int i;
char* bufptr = buf;
if (symcount==0) {
sprintf(buf, "????");
return NULL;
}
while (top>bottom+1) {
i = (top+bottom) / 2;
if (syms[i]->block->begin_addr==addr) {
f = syms[i];
break;
} else if (syms[i]->block->begin_addr > addr)
top = i;
else
if (syms[i]->block->end_addr >= addr) {
f = syms[i];
break;
} else
bottom = i;
}
i = bottom;
if (f!=0)
block = f->block;
else {
block = syms[i]->block;
if (block->begin_addr>=addr && block->end_addr<=addr)
f = syms[i];
}
if (f==0)
sprintf(buf, "????");
else {
/*
* Do the backtrace the GDB way...
*/
unsigned long arg;
/* assert(f->lines_count>0); */
if (f->lines_count>0) {
lineno = &f->lines[f->lines_count-1];
for (i=1; i<f->lines_count; ++i)
if (f->lines[i].addr>addr) {
lineno = &f->lines[i-1];
break;
}
}
bufptr[0] = 0;
bufptr += sprintf(bufptr, "%s+0x%lx (", f->name, addr-block->begin_addr);
for (i=0; i<f->argc; ++i) {
bufptr += sprintf(bufptr, "%s = ", f->argv[i].name);
/* FIXME: better parameter printing */
errno = 0;
arg = my_ptrace(PTRACE_PEEKDATA, pid, fp+f->argv[i].offset, 0);
assert(errno==0);
bufptr += sprintf(bufptr, "0x%x", arg);
if (i!=f->argc-1)
bufptr += sprintf(bufptr, ", ");
}
if (lineno!=0)
bufptr += sprintf(bufptr, ") at %s:%d", f->filename, lineno->lineno);
}
return f;
}
/*
* Advance through the stacks and display frames as needed.
*/
static int
my_crawl( int pid,
symbol_data_t* symbol_data,
int fout)
{
unsigned long pc = 0;
unsigned long fp = 0;
unsigned long nextfp;
unsigned long nargs;
unsigned long i;
unsigned long arg;
char buf[8096]; // FIXME: enough?
debug_function_t* f = 0;
errno = 0;
pc = my_ptrace(PTRACE_PEEKUSER, pid, EIP * 4, 0);
if (!errno)
fp = my_ptrace(PTRACE_PEEKUSER, pid, EBP * 4, 0);
if (!errno) {
#if 1
f = find_debug_function_t(symbol_data, pid, fp, pc, buf, sizeof(buf));
fdprintf(fout,"0x%08lx: %s", pc, buf);
for ( ; !errno && fp; ) {
nextfp = my_ptrace(PTRACE_PEEKDATA, pid, fp, 0);
if (errno)
break;
if (f==0) {
nargs = (nextfp - fp - 8) / 4;
if (nargs > MAXARGS)
nargs = MAXARGS;
if (nargs > 0) {
fdputs(" (", fout);
for (i = 1; i <= nargs; i++) {
arg = my_ptrace(PTRACE_PEEKDATA, pid, fp + 4 * (i + 1), 0);
if (errno)
break;
fdprintf(fout,"%lx", arg);
if (i < nargs)
fdputs(", ", fout);
}
fdputc(')', fout);
nargs = nextfp - fp - 8 - (4 * nargs);
if (!errno && nargs > 0)
fdprintf(fout," + %lx\n", nargs);
else
fdputc('\n', fout);
} else
fdputc('\n', fout);
} else
fdputc('\n', fout);
if (errno || !nextfp)
break;
pc = my_ptrace(PTRACE_PEEKDATA, pid, fp + 4, 0);
fp = nextfp;
if (errno)
break;
f = find_debug_function_t(symbol_data, pid, fp, pc, buf, sizeof(buf));
fdprintf(fout,"0x%08lx: %s", pc, buf);
}
#else /* 1 */
decode_symbol(symbol_data, pc, buf, sizeof(buf));
fdprintf(fout,"0x%08lx: %s", pc, buf);
for ( ; !errno && fp; ) {
nextfp = my_ptrace(PTRACE_PEEKDATA, pid, fp, 0);
if (errno)
break;
nargs = (nextfp - fp - 8) / 4;
if (nargs > MAXARGS)
nargs = MAXARGS;
if (nargs > 0) {
fputs(" (", fout);
for (i = 1; i <= nargs; i++) {
arg = my_ptrace(PTRACE_PEEKDATA, pid, fp + 4 * (i + 1), 0);
if (errno)
break;
fdprintf(fout,"%lx", arg);
if (i < nargs)
fputs(", ", fout);
}
fdputc(')', fout);
nargs = nextfp - fp - 8 - (4 * nargs);
if (!errno && nargs > 0)
fdprintf(fout," + %lx\n", nargs);
else
fdputc('\n', fout);
} else
fdputc('\n', fout);
if (errno || !nextfp)
break;
pc = my_ptrace(PTRACE_PEEKDATA, pid, fp + 4, 0);
fp = nextfp;
if (errno)
break;
decode_symbol(symbol_data, pc, buf, sizeof(buf));
fdprintf(fout,"0x%08lx: %s", pc, buf);
}
#endif /* !1 */
}
if (errno)
perror("my_crawl");
return errno;
}
/* layout from /usr/src/linux/arch/i386/kernel/process.c */
static void
show_regs( signal_regs_t* regs,
int fd)
{
/* long cr0 = 0L, cr2 = 0L, cr3 = 0L; */
fdprintf(fd,"\n");
fdprintf(fd,"FAULT ADDR: %08x\n", regs->fault_addr);
fdprintf(fd,"EIP: %04x:[<%08x>]",0xffff & regs->xcs,regs->eip);
if (regs->xcs & 3)
fdprintf(fd," ESP: %04x:%08x",0xffff & regs->xss,regs->esp);
/*fdprintf(fd," EFLAGS: %08lx\n",regs->eflags); */
fdprintf(fd, "\n");
fdprintf(fd,"EAX: %08x EBX: %08x ECX: %08x EDX: %08x\n",
regs->eax,regs->ebx,regs->ecx,regs->edx);
fdprintf(fd,"ESI: %08x EDI: %08x EBP: %08x",
regs->esi, regs->edi, regs->ebp);
fdprintf(fd," DS: %04x ES: %04x\n",
0xffff & regs->xds,0xffff & regs->xes);
/*
__asm__("movl %%cr0, %0": "=r" (cr0));
__asm__("movl %%cr2, %0": "=r" (cr2));
__asm__("movl %%cr3, %0": "=r" (cr3));
fprintf(stderr,"CR0: %08lx CR2: %08lx CR3: %08lx\n", cr0, cr2, cr3); */
}
/*
* Load a BFD for an executable based on PID. Return 0 on failure.
*/
static bfd*
load_bfd( const int pid)
{
char filename[512];
bfd* abfd = 0;
/* Get the contents from procfs. */
#if 1
sprintf(filename, "/proc/%d/exe", pid);
#else
sprintf(filename, "crashing");
#endif
if ((abfd = bfd_openr (filename, 0))== NULL)
bfd_nonfatal (filename);
else {
char** matching;
assert(bfd_check_format(abfd, bfd_archive)!=true);
/*
* There is no indication in BFD documentation that it should be done.
* God knows why...
*/
if (!bfd_check_format_matches (abfd, bfd_object, &matching)) {
bfd_nonfatal (bfd_get_filename (abfd));
if (bfd_get_error () == bfd_error_file_ambiguously_recognized) {
list_matching_formats (matching);
free (matching);
}
}
}
return abfd;
}
/*
* Those are for qsort. We need only function addresses, so all the others don't count.
*/
/*
* Compare two BFD::asymbol-s.
*/
static int
compare_symbols(const void* ap,
const void* bp)
{
const asymbol *a = *(const asymbol **)ap;
const asymbol *b = *(const asymbol **)bp;
if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
return 1;
else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
return -1;
return 0;
}
/*
* Compare two debug_asymbol_t-s.
*/
static int
compare_debug_function_t(const void* ap,
const void* bp)
{
const debug_function_t *a = *(const debug_function_t **)ap;
const debug_function_t *b = *(const debug_function_t **)bp;
assert(a->block!=0);
assert(b->block!=0);
{
const bfd_vma addr1 = a->block->begin_addr;
const bfd_vma addr2 = b->block->begin_addr;
if (addr1 > addr2)
return 1;
else if (addr2 > addr1)
return -1;
}
return 0;
}
/*
* Filter out (in place) symbols that are useless for stack tracing.
* COUNT is the number of elements in SYMBOLS.
* Return the number of useful symbols.
*/
static long
remove_useless_symbols( asymbol** symbols,
long count)
{
asymbol** in_ptr = symbols;
asymbol** out_ptr = symbols;
while (--count >= 0) {
asymbol *sym = *in_ptr++;
if (sym->name == NULL || sym->name[0] == '\0' || sym->value==0)
continue;
if (sym->flags & (BSF_DEBUGGING))
continue;
if (bfd_is_und_section (sym->section) || bfd_is_com_section (sym->section))
continue;
*out_ptr++ = sym;
}
return out_ptr - symbols;
}
/*
* Debugging information.
*/
static bfd* abfd = 0;
static PTR dhandle = 0;
static asymbol** syms = 0;
static long symcount = 0;
static asymbol** sorted_syms = 0;
static long sorted_symcount = 0;
static debug_function_t** functions = 0;
static int functions_size = 0;
static int sigreport = SIGUSR1;
static pthread_t segv_tid; /* What thread did SEGV? */
static pid_t segv_pid;
/*
* We'll get here after a SIGSEGV. But you can install it on other signals, too :)
* Because we are in the middle of the SIGSEGV, we are on our own. We can't do
* any malloc(), any fopen(), nothing. The last is actually a sin. We event can't
* fprintf(stderr,...)!!!
*/
static void
segv_action(int signo, siginfo_t* siginfo, void* ptr)
{
symbol_data_t symbol_data;
int fd = -1;
segv_pid = getpid();
segv_tid = pthread_self();
fd = open_log_file(segv_tid, segv_pid);
/* signal(SIGSEGV, SIG_DFL); */
ptrace_regs = (signal_regs_t*)ptr;
assert(ptrace_regs!=0);
/* Show user how guilty we are. */
fdprintf(fd,"--------- SEGV in PROCESS %d, THREAD %d ---------------\n", segv_pid, pthread_self());
show_regs(ptrace_regs, fd);
/* Some form of stack trace, too. */
fdprintf(fd, "STACK TRACE:\n");
symbol_data.syms = sorted_syms;
symbol_data.symcount = sorted_symcount;
symbol_data.functions = functions;
symbol_data.functions_size = functions_size;
my_crawl(segv_pid, &symbol_data, fd);
//fflush(stdout);
close(fd);
linuxthreads_notify_others(sigreport);
}
static void
report_action(int signo, siginfo_t* siginfo, void* ptr)
{
const int pid = getpid();
pthread_t tid = pthread_self();
symbol_data_t symbol_data;
int fd;
if (pthread_equal(tid, segv_tid)) {
/* We have already printed our stack trace... */
return;
}
fd = open_log_file(tid, pid);
fdprintf(fd, "REPORT: CURRENT PROCESS:%d, THREAD:%d\n", getpid(), pthread_self());
/* signal(SIGSEGV, SIG_DFL); */
ptrace_regs = (signal_regs_t*)ptr;
assert(ptrace_regs!=0);
/* Show user how guilty we are. */
fdprintf(fd,"--------- STACK TRACE FOR PROCESS %d, THREAD %d ---------------\n", pid, pthread_self());
show_regs(ptrace_regs, fd);
/* Some form of stack trace, too. */
fdprintf(fd, "STACK TRACE:\n");
symbol_data.syms = sorted_syms;
symbol_data.symcount = sorted_symcount;
symbol_data.functions = functions;
symbol_data.functions_size = functions_size;
my_crawl(pid, &symbol_data, fd);
//fflush(stdout);
close(fd);
/* Tell segv_thread to proceed after pause(). */
/*pthread_kill(segv_tid, sigreport);
kill(segv_pid, sigreport);
pthread_cancel(tid); */
}
/*
* Main library routine. Just call it on your program.
*/
int
pstack_install_segv_action( const char* path_format_)
{
const int pid = getpid();
struct sigaction act;
/* Store what we have to for later usage. */
path_format = path_format_;
/* We need a signal action for SIGSEGV and sigreport ! */
sigreport = SIGUSR1;
act.sa_handler = 0;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO|SA_ONESHOT; /* Just one SIGSEGV. */
act.sa_sigaction = segv_action;
act.sa_restorer = NULL;
if (sigaction(SIGSEGV, &act, NULL)!=0) {
perror("sigaction");
return 1;
}
act.sa_sigaction = report_action;
act.sa_flags = SA_SIGINFO; /* But many sigreports. */
if (sigaction(sigreport, &act, NULL)!=0) {
perror("sigaction");
return 1;
}
/* And a little setup for libiberty. */
program_name = "crashing";
xmalloc_set_program_name (program_name);
/* Umm, and initialize BFD, too */
bfd_init();
#if 0
list_supported_targets(0, stdout);
set_default_bfd_target();
#endif /* 0 */
if ((abfd = load_bfd(pid))==0)
fprintf(stderr, "BFD load failed..\n");
else {
long storage_needed= (bfd_get_file_flags(abfd) & HAS_SYMS) ?
bfd_get_symtab_upper_bound (abfd) : 0;
long i;
(void)i;
if (storage_needed < 0)
fprintf(stderr, "Symbol table size estimation failure.\n");
else if (storage_needed > 0) {
syms = (asymbol **) xmalloc (storage_needed);
symcount = bfd_canonicalize_symtab (abfd, syms);
TRACE_FPRINTF((stderr, "TOTAL: %ld SYMBOLS.\n", symcount));
/* We need debugging info, too! */
if (symcount==0 || (dhandle = read_debugging_info (abfd, syms, symcount))==0)
fprintf(stderr, "NO DEBUGGING INFORMATION FOUND.\n");
/* We make a copy of syms to sort. We don't want to sort syms
because that will screw up the relocs. */
sorted_syms = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
memcpy (sorted_syms, syms, symcount * sizeof (asymbol *));
#if 0
for (i=0; i<symcount; ++i)
if (syms[i]->name!=0 && strlen(syms[i]->name)>0 && syms[i]->value!=0)
printf("%08lx T %s\n", syms[i]->section->vma + syms[i]->value, syms[i]->name);
#endif
sorted_symcount = remove_useless_symbols (sorted_syms, symcount);
TRACE_FPRINTF((stderr, "SORTED: %ld SYMBOLS.\n", sorted_symcount));
/* Sort the symbols into section and symbol order */
qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
#if 0
for (i=0; i<sorted_symcount; ++i)
if (sorted_syms[i]->name!=0 && strlen(sorted_syms[i]->name)>0 && sorted_syms[i]->value!=0)
printf("%08lx T %s\n", sorted_syms[i]->section->vma + sorted_syms[i]->value, sorted_syms[i]->name);
#endif
/* We have symbols, we need debugging info somehow sorted out. */
if (dhandle==0) {
fprintf(stderr, "STACK TRACE WILL BE UNCOMFORTABLE.\n");
} else {
/* Start collecting the debugging information.... */
struct pr_handle info;
info.f = stdout;
info.indent = 0;
info.stack = NULL;
info.parameter = 0;
info.block = NULL;
info.function = NULL;
info.functions_size = 0;
info.functions_maxsize = 1000;
info.functions = (debug_function_t*)xmalloc(sizeof(debug_function_t)*info.functions_maxsize);
debug_write (dhandle, &pr_fns, (PTR) &info);
TRACE_FPRINTF((stdout, "\n%d DEBUG SYMBOLS\n", info.functions_size));
assert(info.functions_size!=0);
functions = xmalloc(sizeof(debug_function_t*)*info.functions_size);
functions_size = info.functions_size;
for (i=0; i<functions_size; ++i)
functions[i] = &info.functions[i];
/* Sort the symbols into section and symbol order */
qsort (functions, functions_size, sizeof(debug_function_t*),
compare_debug_function_t);
#if 0
for (i=0; i<info.functions_size; ++i)
fprintf(stdout, "%08lx T %s\n", info.functions[i].block->begin_addr, info.functions[i].name);
#endif
fflush(stdout);
}
} else /* storage_needed == 0 */
fprintf(stderr, "NO SYMBOLS FOUND.\n");
}
return 0;
}
/*********************************************************************/
/*********************************************************************/
/*********************************************************************/
/* $Header$ */
#ifndef pstack_pstack_h_
#define pstack_pstack_h_
#include "pstacktrace.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Install the stack-trace-on-SEGV handler....
*/
extern int
pstack_install_segv_action( const char* path_format);
#ifdef __cplusplus
}
#endif
#endif /* pstack_pstack_h_ */
/* $Header$ */
/*
* Debugging macros.
*/
#ifndef pstacktrace_h_
#define pstacktrace_h_
#define PSTACK_DEBUG 1
#undef PSTACK_DEBUG
#ifdef PSTACK_DEBUG
# define TRACE_PUTC(a) putc a
# define TRACE_FPUTS(a) fputs a
# define TRACE_FPRINTF(a) fprintf a
#else /* PSTACK_DEBUG */
# define TRACE_PUTC(a) (void)0
# define TRACE_FPUTS(a) (void)0
# define TRACE_FPRINTF(a) (void)0
#endif /* !PSTACK_DEBUG */
#endif /* pstacktrace_h_ */
/* rddbg.c -- Read debugging information into a generic form.
Copyright (C) 1995, 96, 1997 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* This file reads debugging information into a generic form. This
file knows how to dig the debugging information out of an object
file. */
#include <bfd.h>
#include "bucomm.h"
#include <libiberty.h>
#include "debug.h"
#include "budbg.h"
static boolean read_section_stabs_debugging_info
PARAMS ((bfd *, asymbol **, long, PTR, boolean *));
static boolean read_symbol_stabs_debugging_info
PARAMS ((bfd *, asymbol **, long, PTR, boolean *));
static boolean read_ieee_debugging_info PARAMS ((bfd *, PTR, boolean *));
static void save_stab PARAMS ((int, int, bfd_vma, const char *));
static void stab_context PARAMS ((void));
static void free_saved_stabs PARAMS ((void));
/* Read debugging information from a BFD. Returns a generic debugging
pointer. */
PTR
read_debugging_info (abfd, syms, symcount)
bfd *abfd;
asymbol **syms;
long symcount;
{
PTR dhandle;
boolean found;
dhandle = debug_init ();
if (dhandle == NULL)
return NULL;
if (! read_section_stabs_debugging_info (abfd, syms, symcount, dhandle,
&found))
return NULL;
if (bfd_get_flavour (abfd) == bfd_target_aout_flavour)
{
if (! read_symbol_stabs_debugging_info (abfd, syms, symcount, dhandle,
&found))
return NULL;
}
if (bfd_get_flavour (abfd) == bfd_target_ieee_flavour)
{
if (! read_ieee_debugging_info (abfd, dhandle, &found))
return NULL;
}
/* Try reading the COFF symbols if we didn't find any stabs in COFF
sections. */
if (! found
&& bfd_get_flavour (abfd) == bfd_target_coff_flavour
&& symcount > 0)
{
#if 0
/*
* JZ: Do we need coff?
*/
if (! parse_coff (abfd, syms, symcount, dhandle))
#else
fprintf (stderr, "%s: COFF support temporarily disabled\n",
bfd_get_filename (abfd));
return NULL;
#endif
return NULL;
found = true;
}
if (! found)
{
fprintf (stderr, "%s: no recognized debugging information\n",
bfd_get_filename (abfd));
return NULL;
}
return dhandle;
}
/* Read stabs in sections debugging information from a BFD. */
static boolean
read_section_stabs_debugging_info (abfd, syms, symcount, dhandle, pfound)
bfd *abfd;
asymbol **syms;
long symcount;
PTR dhandle;
boolean *pfound;
{
static struct
{
const char *secname;
const char *strsecname;
} names[] = { { ".stab", ".stabstr" } };
unsigned int i;
PTR shandle;
*pfound = false;
shandle = NULL;
for (i = 0; i < sizeof names / sizeof names[0]; i++)
{
asection *sec, *strsec;
sec = bfd_get_section_by_name (abfd, names[i].secname);
strsec = bfd_get_section_by_name (abfd, names[i].strsecname);
if (sec != NULL && strsec != NULL)
{
bfd_size_type stabsize, strsize;
bfd_byte *stabs, *strings;
bfd_byte *stab;
bfd_size_type stroff, next_stroff;
stabsize = bfd_section_size (abfd, sec);
stabs = (bfd_byte *) xmalloc (stabsize);
if (! bfd_get_section_contents (abfd, sec, stabs, 0, stabsize))
{
fprintf (stderr, "%s: %s: %s\n",
bfd_get_filename (abfd), names[i].secname,
bfd_errmsg (bfd_get_error ()));
return false;
}
strsize = bfd_section_size (abfd, strsec);
strings = (bfd_byte *) xmalloc (strsize);
if (! bfd_get_section_contents (abfd, strsec, strings, 0, strsize))
{
fprintf (stderr, "%s: %s: %s\n",
bfd_get_filename (abfd), names[i].strsecname,
bfd_errmsg (bfd_get_error ()));
return false;
}
if (shandle == NULL)
{
shandle = start_stab (dhandle, abfd, true, syms, symcount);
if (shandle == NULL)
return false;
}
*pfound = true;
stroff = 0;
next_stroff = 0;
for (stab = stabs; stab < stabs + stabsize; stab += 12)
{
bfd_size_type strx;
int type;
int other;
int desc;
bfd_vma value;
/* This code presumes 32 bit values. */
strx = bfd_get_32 (abfd, stab);
type = bfd_get_8 (abfd, stab + 4);
other = bfd_get_8 (abfd, stab + 5);
desc = bfd_get_16 (abfd, stab + 6);
value = bfd_get_32 (abfd, stab + 8);
if (type == 0)
{
/* Special type 0 stabs indicate the offset to the
next string table. */
stroff = next_stroff;
next_stroff += value;
}
else
{
char *f, *s;
f = NULL;
s = (char *) strings + stroff + strx;
while (s[strlen (s) - 1] == '\\'
&& stab + 12 < stabs + stabsize)
{
char *p;
stab += 12;
p = s + strlen (s) - 1;
*p = '\0';
s = concat (s,
((char *) strings
+ stroff
+ bfd_get_32 (abfd, stab)),
(const char *) NULL);
/* We have to restore the backslash, because, if
the linker is hashing stabs strings, we may
see the same string more than once. */
*p = '\\';
if (f != NULL)
free (f);
f = s;
}
save_stab (type, desc, value, s);
if (! parse_stab (dhandle, shandle, type, desc, value, s))
{
#if 0
/*
* JZ: skip the junk.
*/
stab_context ();
free_saved_stabs ();
return false;
#endif
}
/* Don't free f, since I think the stabs code
expects strings to hang around. This should be
straightened out. FIXME. */
}
}
free_saved_stabs ();
free (stabs);
/* Don't free strings, since I think the stabs code expects
the strings to hang around. This should be straightened
out. FIXME. */
}
}
if (shandle != NULL)
{
if (! finish_stab (dhandle, shandle))
return false;
}
return true;
}
/* Read stabs in the symbol table. */
static boolean
read_symbol_stabs_debugging_info (abfd, syms, symcount, dhandle, pfound)
bfd *abfd;
asymbol **syms;
long symcount;
PTR dhandle;
boolean *pfound;
{
PTR shandle;
asymbol **ps, **symend;
shandle = NULL;
symend = syms + symcount;
for (ps = syms; ps < symend; ps++)
{
symbol_info i;
bfd_get_symbol_info (abfd, *ps, &i);
if (i.type == '-')
{
const char *s;
char *f;
if (shandle == NULL)
{
shandle = start_stab (dhandle, abfd, false, syms, symcount);
if (shandle == NULL)
return false;
}
*pfound = true;
s = i.name;
f = NULL;
while (s[strlen (s) - 1] == '\\'
&& ps + 1 < symend)
{
char *sc, *n;
++ps;
sc = xstrdup (s);
sc[strlen (sc) - 1] = '\0';
n = concat (sc, bfd_asymbol_name (*ps), (const char *) NULL);
free (sc);
if (f != NULL)
free (f);
f = n;
s = n;
}
save_stab (i.stab_type, i.stab_desc, i.value, s);
if (! parse_stab (dhandle, shandle, i.stab_type, i.stab_desc,
i.value, s))
{
stab_context ();
free_saved_stabs ();
return false;
}
/* Don't free f, since I think the stabs code expects
strings to hang around. This should be straightened out.
FIXME. */
}
}
free_saved_stabs ();
if (shandle != NULL)
{
if (! finish_stab (dhandle, shandle))
return false;
}
return true;
}
/* Read IEEE debugging information. */
static boolean
read_ieee_debugging_info (abfd, dhandle, pfound)
bfd *abfd;
PTR dhandle;
boolean *pfound;
{
asection *dsec;
bfd_size_type size;
bfd_byte *contents;
/* The BFD backend puts the debugging information into a section
named .debug. */
dsec = bfd_get_section_by_name (abfd, ".debug");
if (dsec == NULL)
return true;
size = bfd_section_size (abfd, dsec);
contents = (bfd_byte *) xmalloc (size);
if (! bfd_get_section_contents (abfd, dsec, contents, 0, size))
return false;
if (! parse_ieee (dhandle, abfd, contents, size))
return false;
free (contents);
*pfound = true;
return true;
}
/* Record stabs strings, so that we can give some context for errors. */
#define SAVE_STABS_COUNT (16)
struct saved_stab
{
int type;
int desc;
bfd_vma value;
char *string;
};
static struct saved_stab saved_stabs[SAVE_STABS_COUNT];
static int saved_stabs_index;
/* Save a stabs string. */
static void
save_stab (type, desc, value, string)
int type;
int desc;
bfd_vma value;
const char *string;
{
if (saved_stabs[saved_stabs_index].string != NULL)
free (saved_stabs[saved_stabs_index].string);
saved_stabs[saved_stabs_index].type = type;
saved_stabs[saved_stabs_index].desc = desc;
saved_stabs[saved_stabs_index].value = value;
saved_stabs[saved_stabs_index].string = xstrdup (string);
saved_stabs_index = (saved_stabs_index + 1) % SAVE_STABS_COUNT;
}
/* Provide context for an error. */
static void
stab_context ()
{
int i;
fprintf (stderr, "Last stabs entries before error:\n");
fprintf (stderr, "n_type n_desc n_value string\n");
i = saved_stabs_index;
do
{
struct saved_stab *stabp;
stabp = saved_stabs + i;
if (stabp->string != NULL)
{
const char *s;
s = bfd_get_stab_name (stabp->type);
if (s != NULL)
fprintf (stderr, "%-6s", s);
else if (stabp->type == 0)
fprintf (stderr, "HdrSym");
else
fprintf (stderr, "%-6d", stabp->type);
fprintf (stderr, " %-6d ", stabp->desc);
fprintf_vma (stderr, stabp->value);
if (stabp->type != 0)
fprintf (stderr, " %s", stabp->string);
fprintf (stderr, "\n");
}
i = (i + 1) % SAVE_STABS_COUNT;
}
while (i != saved_stabs_index);
}
/* Free the saved stab strings. */
static void
free_saved_stabs ()
{
int i;
for (i = 0; i < SAVE_STABS_COUNT; i++)
{
if (saved_stabs[i].string != NULL)
{
free (saved_stabs[i].string);
saved_stabs[i].string = NULL;
}
}
saved_stabs_index = 0;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -41,7 +41,6 @@ mysqld_DEPENDENCIES= @mysql_plugin_libs@ $(SUPPORTING_LIBS) libndb.la
LDADD = $(SUPPORTING_LIBS) @ZLIB_LIBS@ @NDB_SCI_LIBS@
mysqld_LDADD = libndb.la \
@MYSQLD_EXTRA_LDFLAGS@ \
@pstack_libs@ \
@mysql_plugin_libs@ \
$(LDADD) $(CXXLDFLAGS) $(WRAPLIBS) @LIBDL@ \
$(yassl_libs) $(openssl_libs) @MYSQLD_EXTRA_LIBS@
......
......@@ -70,10 +70,8 @@
#endif
/* stack traces are only supported on linux intel */
#if defined(__linux__) && defined(__i386__) && defined(USE_PSTACK)
#if defined(__linux__) && defined(__i386__)
#define HAVE_STACK_TRACE_ON_SEGV
#include "../pstack/pstack.h"
char pstack_file_name[80];
#endif /* __linux__ */
/* We have HAVE_purify below as this speeds up the shutdown of MySQL */
......@@ -2779,14 +2777,6 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
if (!opt_bootstrap)
create_pid_file();
#ifdef HAVE_STACK_TRACE_ON_SEGV
if (opt_do_pstack)
{
sprintf(pstack_file_name,"mysqld-%lu-%%d-%%d.backtrace", (ulong)getpid());
pstack_install_segv_action(pstack_file_name);
}
#endif /* HAVE_STACK_TRACE_ON_SEGV */
/*
signal to start_signal_handler that we are ready
This works by waiting for start_signal_handler to free mutex,
......@@ -5963,9 +5953,10 @@ struct my_option my_long_options[] =
NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
#ifdef HAVE_STACK_TRACE_ON_SEGV
{"enable-pstack", OPT_DO_PSTACK, "Print a symbolic stack trace on failure.",
&opt_do_pstack, &opt_do_pstack, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
{"enable-pstack", OPT_DO_PSTACK, "Print a symbolic stack trace on failure. "
"This option is deprecated and has no effect; a symbolic stack trace will "
"be printed after a crash whenever possible.", &opt_do_pstack, &opt_do_pstack,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
#endif /* HAVE_STACK_TRACE_ON_SEGV */
{"engine-condition-pushdown",
OPT_ENGINE_CONDITION_PUSHDOWN,
......@@ -8654,6 +8645,13 @@ mysqld_get_one_option(int optid,
lower_case_table_names= argument ? atoi(argument) : 1;
lower_case_table_names_used= 1;
break;
#ifdef HAVE_STACK_TRACE_ON_SEGV
case OPT_DO_PSTACK:
sql_print_warning("'--enable-pstack' is deprecated and will be removed "
"in a future release. A symbolic stack trace will be "
"printed after a crash whenever possible.");
break;
#endif
#if defined(ENABLED_DEBUG_SYNC)
case OPT_DEBUG_SYNC_TIMEOUT:
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment