/*
** stab.c for elfsh
** 
** Started on  Fri Nov  2 15:18:56 2001 mayhem
** Last update Thu Feb 28 20:37:13 2002 mayhem
*/
#include "elfsh.h"





/* Display the stab section */
int			display_stab(Elfsh32_Obj *file, argv_t *args)
{
  Elfsh32_Stab_ent	*entry;
  regex_t		*tmp;
  char			*name;
  char			*type;
  u_int			num;
  u_int			index;
  u_int			typenum;
  char			buff[256];

  if ((entry = elfsh_get_stab(file, &num)) == NULL)
    RET(-1);
  
  tmp = (REGX_IS_USED(args->stab_use_regx) ? &args->stab_regx : 
	 REGX_IS_USED(args->gl_use_regx)   ? &args->gl_regx   : NULL);
  
  puts("\n[STAB TABLE]");
  
  for (index = 0; index < num; index++)
    {

      if ((name = elfsh_get_stab_name(file, entry + index)) == NULL)
	RET(-1);
  
      typenum = elfsh_get_stab_type(entry + index);
      type = (typenum > STAB_MAX ? NULL : elfsh_stab_type[typenum]);
      
      
      snprintf(buff, sizeof(buff), "%10p : \t %s \nType \t   : \t %s \n",
	       elfsh_get_stab_offset(entry + index),
	       (name == NULL || name[0] == 0x00 ? "NULL" : name),
	       (type == NULL || type[0] == 0x00 ? "NULL" : type));
      
      
      if (!tmp || (tmp && type && !regexec(tmp, buff, 0, 0, 0)))
	puts(buff);
      
      
    }

  return (0);
}


