symintOpen.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include "symint.h"
#include <stdio.h>
#include <fcntl.h>
#include "debug.h"
/* * * * * *
* symintFcns.c -- symbol information interface routines.
*
* these routines form a symbol information access
* interface, for the profilers to get at object file
* information. this interface was designed to aid
* in the COFF to ELF conversion of prof, lprof and friends.
*
*/
/* * * * * *
* _symintOpen(aout_name)
* aout_name - char string file name of object file
* to open.
*
* returns PROF_FILE * - pointer to the PROF_FILE structure built,
* or NULL if fails.
*/
/* * * * * *
*
* .H 3 "Executable File Open and Close"
*
* Under COFF, the routine ldopen, given a file name, returns a pointer to a
* structure called an LDFILE. This descriptor is then passed to each of
* the library routines (such as read header, read symbol table entry, etc)
* to access the information contained in the file. These calls are spread
* throughout the profiling code.
*
* Under ELF, the file must be opened using a system open call. The file
* descriptor is then passed to a routine which returns a pointer to an
* Elf structure. This pointer is then passed along to another routine which
* returns a different pointer which is in turn passed along to another
* routine. In an attempt to avoid disturbing the current format of the
* code (by having to pass around different types of pointers), we plan to
* build a PROF_FILE descriptor which will then be passed around in the
* same way as the pointer to LDFILE.
*
* Thus, for ELF, an open will consist of opening the file and extracting
* enough from it to fill in the PROF_FILE structure. The code for the
* open is as follows; the code for building the symbol table (extracting
* information from the sections to fill an array of PROF_SYMBOLS) has
* yet to be written.
*
*/
/* * * * * *
* #defines and globals.
*/
static char
*fail_open_s = "Unable to open file",
*fail_begin_s = "Unable to read (begin) file",
*fail_ehdr_s = "Unable to get elf header in",
*fail_sec_s = "Unable to get section",
*fail_shd_s = "Unable to get header for section",
*fail_dat_s = "Unable to get data for section",
*fail_sym_s = "Cannot find symbol table section in",
*fail_line_s = "Cannot find line number section in",
*fail_debug_s = "Cannot find debug section in",
*fail_pfsym_s = "Unable to process symbols in",
*fail_buf_s = "Data buffer is null for section"
;
/* * * * * *
* this routine loads the symbols into the PROF_SYMBOL
* array.
*/
/* * * * * *
* this points at the name of the executable.
*/
static char *executableName;
/* * * * * *
* section_data_p() - return ptr to section data,
* given section ptr and name of section.
*/
static
Elf_Data *
char *str;
{
return(dat_p);
}
char *aout_name; {
/*
* Elf file open operation
*
* - point at executable's name, globally
* - open file
* - align to current version
* - read the elf descriptor and header
* - read header-names section descriptor, header, and data
* - allocate space for all the section hdrs (pf_shdarr_p).
* - set a pointer to the header-names buffer
* - search the section headers for
* - debug section header and data
* - line section header and data
* - symbol table header, data, strings, and number of symbols
* and copy each section hdr into our array.
* - populate the PROF_SYMBOL array and anchor it in (pf_symarr_p).
*/
int k;
DEBUG_LOC("_symintOpen: top");
_err_exit("name of executable is null\n");
}
_err_exit("Elf library out of date");
if (
= elf_begin(
(Elf *) 0
)
) == NULL
)
DEBUG_LOC("_symintOpen: after call to getehdr");
DEBUG_LOC("_symintOpen: after call to getdata (for header names)");
{
int i;
char *s;
i = 0;
tscn_p = 0;
if (strcmp(s, SCN_NAME_DEBUG) == 0) {
DEBUG_LOC("_symintOpen: found debug section");
} else if (strcmp(s, SCN_NAME_LINE) == 0) {
DEBUG_LOC("_symintOpen: found line section");
} else if (strcmp(s, SCN_NAME_SYM) == 0) {
DEBUG_LOC("_symintOpen: found symbol section");
} else if (strcmp(s, SCN_NAME_SST) == 0) {
DEBUG_LOC("_symintOpen: found symbol table strings");
}
i++;
}
}
if (!pfile_p->pf_symdat_p) {
}
#if isLPROF
if (!pfile_p->pf_linedat_p) {
}
if (!pfile_p->pf_debugdat_p) {
}
#endif
DEBUG_LOC("_symintOpen: after for loop that reads the sections");
DEBUG_LOC("_symintOpen: before call to _symintLoad");
DEBUG_LOC("_symintOpen: after call to _symintLoad");
/*
* At this point we might want to include some consistency
* checks to be sure all is well. For example, we can check
* symbol table consistency by comparing "the product of the
* number of symbols and the size of each symbol" to "the
* length of the symbol table data".
*
* Also, NULL may be a proper value (e.g., the debugger
* information when there is none) for some things that
* we cannot afford to be without. We should check these
* at this point also.
*/
DEBUG_LOC("_symintOpen: bottom");
return( pfile_p );
}