__fex_sym.c revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <elf.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <procfs.h>
#include <string.h>
#define Elf_Ehdr Elf64_Ehdr
#define Elf_Phdr Elf64_Phdr
#define Elf_Shdr Elf64_Shdr
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE
#else
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Phdr Elf32_Phdr
#define Elf_Shdr Elf32_Shdr
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_ST_TYPE ELF32_ST_TYPE
#endif /* __sparcv9 */
/* semi-permanent data established by __fex_sym_init */
static int npm = 0; /* number of entries in pm */
/* transient data modified by __fex_sym */
static int phsize = 0; /* size of ph */
static int nph; /* number of entries in ph */
static int stbufsize = 0; /* size of stbuf */
static int stoffset; /* offset of string table in stbuf */
static int nsyms; /* number of symbols in stbuf */
/* get a current prmap_t list (must call this before each stack trace) */
void
{
long n;
int i;
/* clear out the previous prmap_t list */
npm = 0;
/* get the current prmap_t list */
return;
{
return;
}
close(i);
{
}
else
}
/* read ELF program headers and symbols; return -1 on error, 0 otherwise */
static int
__fex_read_syms(int fd)
{
Elf_Ehdr h;
int i, size;
/* read the ELF header */
return -1;
h.e_phentsize != sizeof(Elf_Phdr) ||
h.e_shentsize != sizeof(Elf_Shdr))
return -1;
/* get space for the program headers */
{
if (ph)
return -1;
}
/* read the program headers */
{
nph = 0;
return -1;
}
/* read the section headers */
return -1;
{
return -1;
}
/* find the symtab section header */
for (i = 0; i < h.e_shnum; i++)
{
break; /* assume there is only one */
}
{
return -1;
}
/* get space for the symbol and string tables */
{
if (stbuf)
{
return -1;
}
}
/* read the symbol and string tables */
{
return (-1);
}
return (0);
}
/* find the symbol corresponding to the given text address;
return NULL on error, symbol address otherwise */
char *
{
Elf_Sym *s;
/* see if the last prmap_t found contains the indicated address */
if (lpm)
{
goto cont;
}
/* look for a prmap_t that contains the indicated address */
for (i = 0; i < npm; i++)
{
break;
}
if (i == npm)
return NULL;
/* get an open file descriptor for the mapped object */
return NULL;
if (fd < 0)
return NULL;
/* read the program headers and symbols */
j = __fex_read_syms(fd);
if (j < 0)
return NULL;
cont:
/* compute the file offset corresponding to the mapped address */
/* find the program header containing the file offset */
for (i = 0; i < nph; i++)
{
break;
}
if (i == nph)
return NULL;
/* compute the virtual address corresponding to the file offset */
/* find the symbol in this segment with the highest value
less than or equal to the virtual address */
for (j = 0; j < nsyms; j++)
{
{
continue;
}
{
continue;
}
continue;
}
if (nm == 0)
return NULL;
/* pass back the name and return the mapped address of the symbol */
}