Blame tests/find-prologues.c

Packit 032894
/* Test program for dwarf_entry_breakpoints.
Packit 032894
   Copyright (C) 2005 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of the GNU General Public License as published by
Packit 032894
   the Free Software Foundation; either version 3 of the License, or
Packit 032894
   (at your option) any later version.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
   GNU General Public License for more details.
Packit 032894
Packit 032894
   You should have received a copy of the GNU General Public License
Packit 032894
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#include <config.h>
Packit 032894
#include <assert.h>
Packit 032894
#include <inttypes.h>
Packit 032894
#include ELFUTILS_HEADER(dwfl)
Packit 032894
#include <dwarf.h>
Packit 032894
#include <argp.h>
Packit 032894
#include <stdio.h>
Packit 032894
#include <stdio_ext.h>
Packit 032894
#include <locale.h>
Packit 032894
#include <stdlib.h>
Packit 032894
#include <string.h>
Packit 032894
#include <fnmatch.h>
Packit 032894
#include "system.h"
Packit 032894
Packit 032894
Packit 032894
struct args
Packit 032894
{
Packit 032894
  Dwfl *dwfl;
Packit 032894
  Dwarf_Die *cu;
Packit 032894
  Dwarf_Addr dwbias;
Packit 032894
  char **argv;
Packit 032894
};
Packit 032894
Packit 032894
static int
Packit 032894
handle_function (Dwarf_Die *func, void *arg)
Packit 032894
{
Packit 032894
  struct args *a = arg;
Packit 032894
Packit 032894
  const char *name = dwarf_diename (func);
Packit 032894
  char **argv = a->argv;
Packit 032894
  if (argv[0] != NULL)
Packit 032894
    {
Packit 032894
      bool match;
Packit 032894
      do
Packit 032894
	match = fnmatch (*argv, name, 0) == 0;
Packit 032894
      while (!match && *++argv);
Packit 032894
      if (!match)
Packit 032894
	return 0;
Packit 032894
    }
Packit 032894
Packit 032894
  if (dwarf_func_inline (func))
Packit 032894
    return 0;
Packit 032894
Packit 032894
  Dwarf_Addr entrypc;
Packit 032894
  if (dwarf_entrypc (func, &entrypc) != 0)
Packit 032894
    error (EXIT_FAILURE, 0, "dwarf_entrypc: %s: %s",
Packit 032894
	   dwarf_diename (func), dwarf_errmsg (-1));
Packit 032894
  entrypc += a->dwbias;
Packit 032894
Packit 032894
  printf ("%-16s %#.16" PRIx64, dwarf_diename (func), entrypc);
Packit 032894
Packit 032894
  Dwarf_Addr *bkpts = NULL;
Packit 032894
  int result = dwarf_entry_breakpoints (func, &bkpts);
Packit 032894
  if (result <= 0)
Packit 032894
    printf ("\t%s\n", dwarf_errmsg (-1));
Packit 032894
  else
Packit 032894
    {
Packit 032894
      for (int i = 0; i < result; ++i)
Packit 032894
	printf (" %#.16" PRIx64 "%s", bkpts[i] + a->dwbias,
Packit 032894
		i == result - 1 ? "\n" : "");
Packit 032894
      free (bkpts);
Packit 032894
    }
Packit 032894
Packit 032894
  return 0;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
int
Packit 032894
main (int argc, char *argv[])
Packit 032894
{
Packit 032894
  int remaining;
Packit 032894
Packit 032894
  /* Set locale.  */
Packit 032894
  (void) setlocale (LC_ALL, "");
Packit 032894
Packit 032894
  struct args a = { .dwfl = NULL, .cu = NULL };
Packit 032894
Packit 032894
  (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining,
Packit 032894
		     &a.dwfl);
Packit 032894
  assert (a.dwfl != NULL);
Packit 032894
  a.argv = &argv[remaining];
Packit 032894
Packit 032894
  int result = 0;
Packit 032894
Packit 032894
  while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL)
Packit 032894
    dwarf_getfuncs (a.cu, &handle_function, &a, 0);
Packit 032894
Packit 032894
  dwfl_end (a.dwfl);
Packit 032894
Packit 032894
  return result;
Packit 032894
}