aboutsummaryrefslogtreecommitdiff
path: root/gnu/usr.bin/gdb/bfd/syms.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/gdb/bfd/syms.c')
-rw-r--r--gnu/usr.bin/gdb/bfd/syms.c238
1 files changed, 134 insertions, 104 deletions
diff --git a/gnu/usr.bin/gdb/bfd/syms.c b/gnu/usr.bin/gdb/bfd/syms.c
index 89ac00124e3c..23a70f5e3ea9 100644
--- a/gnu/usr.bin/gdb/bfd/syms.c
+++ b/gnu/usr.bin/gdb/bfd/syms.c
@@ -22,20 +22,20 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
SECTION
Symbols
- BFD trys to maintain as much symbol information as it can when
+ BFD tries to maintain as much symbol information as it can when
it moves information from file to file. BFD passes information
to applications though the <<asymbol>> structure. When the
application requests the symbol table, BFD reads the table in
the native form and translates parts of it into the internal
- format. To maintain more than the infomation passed to
- applications some targets keep some information `behind the
- scenes', in a structure only the particular back end knows
+ format. To maintain more than the information passed to
+ applications, some targets keep some information ``behind the
+ scenes'' in a structure only the particular back end knows
about. For example, the coff back end keeps the original
symbol table structure as well as the canonical structure when
a BFD is read in. On output, the coff back end can reconstruct
the output symbol table so that no information is lost, even
information unique to coff which BFD doesn't know or
- understand. If a coff symbol table was read, but was written
+ understand. If a coff symbol table were read, but were written
through an a.out back end, all the coff specific information
would be lost. The symbol table of a BFD
is not necessarily read in until a canonicalize request is
@@ -43,8 +43,8 @@ SECTION
application with pointers to the canonical information. To
output symbols, the application provides BFD with a table of
pointers to pointers to <<asymbol>>s. This allows applications
- like the linker to output a symbol as read, since the `behind
- the scenes' information will be still available.
+ like the linker to output a symbol as it was read, since the ``behind
+ the scenes'' information will be still available.
@menu
@* Reading Symbols::
@* Writing Symbols::
@@ -55,57 +55,63 @@ SECTION
INODE
Reading Symbols, Writing Symbols, Symbols, Symbols
SUBSECTION
- Reading Symbols
+ Reading symbols
- There are two stages to reading a symbol table from a BFD;
+ There are two stages to reading a symbol table from a BFD:
allocating storage, and the actual reading process. This is an
- excerpt from an appliction which reads the symbol table:
+ excerpt from an application which reads the symbol table:
-| unsigned int storage_needed;
+| long storage_needed;
| asymbol **symbol_table;
-| unsigned int number_of_symbols;
-| unsigned int i;
-|
-| storage_needed = get_symtab_upper_bound (abfd);
-|
+| long number_of_symbols;
+| long i;
+|
+| storage_needed = bfd_get_symtab_upper_bound (abfd);
+|
+| if (storage_needed < 0)
+| FAIL
+|
| if (storage_needed == 0) {
| return ;
| }
-| symbol_table = (asymbol **) bfd_xmalloc (storage_needed);
+| symbol_table = (asymbol **) xmalloc (storage_needed);
| ...
-| number_of_symbols =
-| bfd_canonicalize_symtab (abfd, symbol_table);
-|
+| number_of_symbols =
+| bfd_canonicalize_symtab (abfd, symbol_table);
+|
+| if (number_of_symbols < 0)
+| FAIL
+|
| for (i = 0; i < number_of_symbols; i++) {
| process_symbol (symbol_table[i]);
| }
All storage for the symbols themselves is in an obstack
- connected to the BFD, and is freed when the BFD is closed.
+ connected to the BFD; it is freed when the BFD is closed.
INODE
Writing Symbols, typedef asymbol, Reading Symbols, Symbols
SUBSECTION
- Writing Symbols
+ Writing symbols
Writing of a symbol table is automatic when a BFD open for
writing is closed. The application attaches a vector of
pointers to pointers to symbols to the BFD being written, and
fills in the symbol count. The close and cleanup code reads
through the table provided and performs all the necessary
- operations. The outputing code must always be provided with an
- 'owned' symbol; one which has come from another BFD, or one
- which has been created using <<bfd_make_empty_symbol>>. An
+ operations. The BFD output code must always be provided with an
+ ``owned'' symbol: one which has come from another BFD, or one
+ which has been created using <<bfd_make_empty_symbol>>. Here is an
example showing the creation of a symbol table with only one element:
| #include "bfd.h"
-| main()
+| main()
| {
| bfd *abfd;
| asymbol *ptrs[2];
| asymbol *new;
-|
+|
| abfd = bfd_openw("foo","a.out-sunos-big");
| bfd_set_format(abfd, bfd_object);
| new = bfd_make_empty_symbol(abfd);
@@ -113,23 +119,23 @@ SUBSECTION
| new->section = bfd_make_section_old_way(abfd, ".text");
| new->flags = BSF_GLOBAL;
| new->value = 0x12345;
-|
+|
| ptrs[0] = new;
| ptrs[1] = (asymbol *)0;
-|
+|
| bfd_set_symtab(abfd, ptrs, 1);
| bfd_close(abfd);
| }
-|
-| ./makesym
+|
+| ./makesym
| nm foo
| 00012345 A dummy_symbol
Many formats cannot represent arbitary symbol information; for
- instance the <<a.out>> object format does not allow an
+ instance, the <<a.out>> object format does not allow an
arbitary number of sections. A symbol pointing to a section
which is not one of <<.text>>, <<.data>> or <<.bss>> cannot
- be described.
+ be described.
*/
@@ -153,7 +159,7 @@ SUBSECTION
CODE_FRAGMENT
.
-.typedef struct symbol_cache_entry
+.typedef struct symbol_cache_entry
.{
. {* A pointer to the BFD which owns the symbol. This information
. is necessary so that a back end can work out what additional
@@ -167,7 +173,7 @@ CODE_FRAGMENT
.
. struct _bfd *the_bfd; {* Use bfd_asymbol_bfd(sym) to access this field. *}
.
-. {* The text of the symbol. The name is left alone, and not copied - the
+. {* The text of the symbol. The name is left alone, and not copied; the
. application may not alter it. *}
. CONST char *name;
.
@@ -188,7 +194,7 @@ CODE_FRAGMENT
. value is the offset into the section of the data. *}
.#define BSF_GLOBAL 0x02
.
-. {* The symbol has global scope, and is exported. The value is
+. {* The symbol has global scope and is exported. The value is
. the offset into the section of the data. *}
.#define BSF_EXPORT BSF_GLOBAL {* no real difference *}
.
@@ -249,9 +255,12 @@ CODE_FRAGMENT
. for ELF STT_FILE symbols. *}
.#define BSF_FILE 0x4000
.
+. {* Symbol is from dynamic linking information. *}
+.#define BSF_DYNAMIC 0x8000
+.
. flagword flags;
.
-. {* A pointer to the section to which this symbol is
+. {* A pointer to the section to which this symbol is
. relative. This will always be non NULL, there are special
. sections for undefined and absolute symbols *}
. struct sec *section;
@@ -268,39 +277,53 @@ CODE_FRAGMENT
#include "libbfd.h"
#include "aout/stab_gnu.h"
-
+
/*
DOCDD
INODE
symbol handling functions, , typedef asymbol, Symbols
SUBSECTION
- Symbol Handling Functions
+ Symbol handling functions
*/
/*
FUNCTION
- get_symtab_upper_bound
+ bfd_get_symtab_upper_bound
DESCRIPTION
- Returns the number of bytes required in a vector of pointers
- to <<asymbols>> for all the symbols in the supplied BFD,
+ Return the number of bytes required to store a vector of pointers
+ to <<asymbols>> for all the symbols in the BFD @var{abfd},
including a terminal NULL pointer. If there are no symbols in
- the BFD, then 0 is returned.
+ the BFD, then return 0. If an error occurs, return -1.
-.#define get_symtab_upper_bound(abfd) \
-. BFD_SEND (abfd, _get_symtab_upper_bound, (abfd))
+.#define bfd_get_symtab_upper_bound(abfd) \
+. BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
*/
/*
FUNCTION
+ bfd_is_local_label
+
+SYNOPSIS
+ boolean bfd_is_local_label(bfd *abfd, asymbol *sym);
+
+DESCRIPTION
+ Return true if the given symbol @var{sym} in the BFD @var{abfd} is
+ a compiler generated local label, else return false.
+.#define bfd_is_local_label(abfd, sym) \
+. BFD_SEND (abfd, _bfd_is_local_label,(abfd, sym))
+*/
+
+/*
+FUNCTION
bfd_canonicalize_symtab
DESCRIPTION
- Supplied a BFD and a pointer to an uninitialized vector of
- pointers. This reads in the symbols from the BFD, and fills in
- the table with pointers to the symbols, and a trailing NULL.
- The routine returns the actual number of symbol pointers not
+ Read the symbols from the BFD @var{abfd}, and fills in
+ the vector @var{location} with pointers to the symbols and
+ a trailing NULL.
+ Return the actual number of symbol pointers, not
including the NULL.
@@ -315,12 +338,13 @@ DESCRIPTION
FUNCTION
bfd_set_symtab
-DESCRIPTION
- Provided a table of pointers to symbols and a count, writes to
- the output BFD the symbols when closed.
-
SYNOPSIS
- boolean bfd_set_symtab (bfd *, asymbol **, unsigned int );
+ boolean bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int count);
+
+DESCRIPTION
+ Arrange that when the output BFD @var{abfd} is closed,
+ the table @var{location} of @var{count} pointers to symbols
+ will be written.
*/
boolean
@@ -329,10 +353,11 @@ bfd_set_symtab (abfd, location, symcount)
asymbol **location;
unsigned int symcount;
{
- if ((abfd->format != bfd_object) || (bfd_read_p (abfd))) {
- bfd_error = invalid_operation;
- return false;
- }
+ if ((abfd->format != bfd_object) || (bfd_read_p (abfd)))
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return false;
+ }
bfd_get_outsymbols (abfd) = location;
bfd_get_symcount (abfd) = symcount;
@@ -343,35 +368,40 @@ bfd_set_symtab (abfd, location, symcount)
FUNCTION
bfd_print_symbol_vandf
-DESCRIPTION
- Prints the value and flags of the symbol supplied to the stream file.
-
SYNOPSIS
void bfd_print_symbol_vandf(PTR file, asymbol *symbol);
+
+DESCRIPTION
+ Print the value and flags of the @var{symbol} supplied to the
+ stream @var{file}.
*/
void
-DEFUN(bfd_print_symbol_vandf,(file, symbol),
-PTR file AND
-asymbol *symbol)
+bfd_print_symbol_vandf (arg, symbol)
+ PTR arg;
+ asymbol *symbol;
{
+ FILE *file = (FILE *) arg;
flagword type = symbol->flags;
- if (symbol->section != (asection *)NULL)
- {
- fprintf_vma(file, symbol->value+symbol->section->vma);
- }
- else
- {
- fprintf_vma(file, symbol->value);
- }
- fprintf(file," %c%c%c%c%c%c%c",
- (type & BSF_LOCAL) ? 'l':' ',
- (type & BSF_GLOBAL) ? 'g' : ' ',
- (type & BSF_WEAK) ? 'w' : ' ',
- (type & BSF_CONSTRUCTOR) ? 'C' : ' ',
- (type & BSF_WARNING) ? 'W' : ' ',
- (type & BSF_INDIRECT) ? 'I' : ' ',
- (type & BSF_DEBUGGING) ? 'd' :' ');
-
+ if (symbol->section != (asection *) NULL)
+ {
+ fprintf_vma (file, symbol->value + symbol->section->vma);
+ }
+ else
+ {
+ fprintf_vma (file, symbol->value);
+ }
+
+ /* This presumes that a symbol can not be both BSF_DEBUGGING and
+ BSF_DYNAMIC. */
+ fprintf (file, " %c%c%c%c%c%c%c",
+ (type & BSF_LOCAL) ? 'l' : ' ',
+ (type & BSF_GLOBAL) ? 'g' : ' ',
+ (type & BSF_WEAK) ? 'w' : ' ',
+ (type & BSF_CONSTRUCTOR) ? 'C' : ' ',
+ (type & BSF_WARNING) ? 'W' : ' ',
+ (type & BSF_INDIRECT) ? 'I' : ' ',
+ (type & BSF_DEBUGGING) ? 'd'
+ : (type & BSF_DYNAMIC) ? 'D' : ' ');
}
@@ -380,10 +410,10 @@ FUNCTION
bfd_make_empty_symbol
DESCRIPTION
- This function creates a new <<asymbol>> structure for the BFD,
- and returns a pointer to it.
+ Create a new <<asymbol>> structure for the BFD @var{abfd}
+ and return a pointer to it.
- This routine is necessary, since each back end has private
+ This routine is necessary because each back end has private
information surrounding the <<asymbol>>. Building your own
<<asymbol>> and pointing to it will not create the private
information, and will cause problems later on.
@@ -397,7 +427,7 @@ FUNCTION
bfd_make_debug_symbol
DESCRIPTION
- This function creates a new <<asymbol>> structure for the BFD,
+ Create a new <<asymbol>> structure for the BFD @var{abfd},
to be used as a debugging symbol. Further details of its use have
yet to be worked out.
@@ -411,10 +441,11 @@ struct section_to_type
char type;
};
-/* Map COFF section names to POSIX/BSD single-character symbol types.
+/* Map section names to POSIX/BSD single-character symbol types.
This table is probably incomplete. It is sorted for convenience of
adding entries. Since it is so short, a linear search is used. */
-static CONST struct section_to_type stt[] = {
+static CONST struct section_to_type stt[] =
+{
{"*DEBUG*", 'N'},
{".bss", 'b'},
{".data", 'd'},
@@ -426,7 +457,7 @@ static CONST struct section_to_type stt[] = {
};
/* Return the single-character symbol type corresponding to
- COFF section S, or '?' for an unknown COFF section. */
+ section S, or '?' for an unknown COFF section. */
static char
coff_section_type (s)
@@ -453,27 +484,27 @@ FUNCTION
DESCRIPTION
Return a character corresponding to the symbol
- class of symbol, or '?' for an unknown class.
+ class of @var{symbol}, or '?' for an unknown class.
SYNOPSIS
int bfd_decode_symclass(asymbol *symbol);
*/
int
-DEFUN(bfd_decode_symclass,(symbol),
-asymbol *symbol)
+bfd_decode_symclass (symbol)
+ asymbol *symbol;
{
char c;
if (bfd_is_com_section (symbol->section))
return 'C';
- if (symbol->section == &bfd_und_section)
+ if (bfd_is_und_section (symbol->section))
return 'U';
- if (symbol->section == &bfd_ind_section)
+ if (bfd_is_ind_section (symbol->section))
return 'I';
- if (!(symbol->flags & (BSF_GLOBAL|BSF_LOCAL)))
+ if (!(symbol->flags & (BSF_GLOBAL | BSF_LOCAL)))
return '?';
- if (symbol->section == &bfd_abs_section)
+ if (bfd_is_abs_section (symbol->section))
c = 'a';
else if (symbol->section)
c = coff_section_type (symbol->section->name);
@@ -484,8 +515,8 @@ asymbol *symbol)
return c;
/* We don't have to handle these cases just yet, but we will soon:
- N_SETV: 'v';
- N_SETA: 'l';
+ N_SETV: 'v';
+ N_SETA: 'l';
N_SETT: 'x';
N_SETD: 'z';
N_SETB: 's';
@@ -507,21 +538,20 @@ SYNOPSIS
*/
void
-DEFUN(bfd_symbol_info,(symbol, ret),
- asymbol *symbol AND
- symbol_info *ret)
+bfd_symbol_info (symbol, ret)
+ asymbol *symbol;
+ symbol_info *ret;
{
ret->type = bfd_decode_symclass (symbol);
if (ret->type != 'U')
- ret->value = symbol->value+symbol->section->vma;
+ ret->value = symbol->value + symbol->section->vma;
else
ret->value = 0;
ret->name = symbol->name;
}
void
-bfd_symbol_is_absolute()
+bfd_symbol_is_absolute ()
{
- abort();
+ abort ();
}
-