/*
** stabs.c for libelfsh
** 
** Started on  Mon Feb 26 04:14:06 2001 mayhem
** Last update Tue Feb 26 21:27:28 2002 mayhem
*/
#include "libelfsh.h"




/* Return the debugging symbol name giving its index in the stab string table */
char	*elfsh_get_stab_name(Elfsh32_Obj *file, Elfsh32_Stab_ent *s)
{
  char	*str;

  if (!file->stab_strtab && !elfsh_get_stab(file, NULL))
    return (NULL);
  str = file->stab_strtab->data;
  return (str + s->strindex);
}





/* Load the stab information from the file */
void		*elfsh_get_stab(Elfsh32_Obj *file, int *num)
{
  Elfsh32_Sect	*sect;
  u_int		strindex;
  u_int		index;
  u_int		nbr;

#if defined(sun)
  ELFSH_SETERROR("libelfsh: Stabs unimplemented on SUN .", NULL);
#endif

  if (!file->stab)
    {

      /* Fill the stab table */
      sect = elfsh_get_section_by_name(file, ".stab", &index, &strindex, &nbr);
      if (!sect)
        return (NULL);

      file->stab = sect;
      sect->nbr = nbr / sizeof(Elfsh32_Stab_ent);

      file->stab->data = elfsh_load_section(file, sect->shdr);
      if (!file->stab->data)
	return (NULL);


      
      /* Fill the stab string table */
      sect = elfsh_get_section_by_index(file, strindex, NULL, NULL);
      if (!sect)
	return (NULL);
      
      sect->data = elfsh_load_section(file, sect->shdr);
      if (!sect->data)
        return (NULL);

      file->stab_strtab = sect;
      sect->nbr = sect->shdr->sh_size;

    }

  
  if (num)
    *num = file->stab->nbr;

  return (file->stab->data);
}




/* Return the symbol type name giving its index in the symtype array */
u_int	elfsh_get_stab_type(Elfsh32_Stab_ent *s)
{
  return (s->type);
}



/* Not used yet */
void	*elfsh_get_stab_offset(Elfsh32_Stab_ent *s)
{
  return ((void *) ((int) (s->value)));
}






















