This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

__frame_state_for checks


Attached you'll find a little test program that does some basic
testing of __frame_state_for.  It checks from within the comparison
function whether we can find the frame state for its caller (qsort,
bsearch, etc.).  Basically, this tests whether the frame info included
in the newly built libc.so can be interpreted by the unwinder.

I'm not quite sure where we should add this test.  Probably the
directory where the new __frame_state_for implementation will end up.
There also should be a way to avoid running this test on platforms
that don't have __frame_state_for.  The test itself could go in now,
it doesn't depend on the new __frame_state_for implementation.

Mark


/* Tests for __frame_state_for.
   Copyright (C) 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Mark Kettenis <kettenis@gnu.org>, 2001.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include <search.h>
#include <stdio.h>
#include <stdlib.h>

/* Prototype for our test function.  */
extern int do_test (int argc, char *argv[]);

/* This defines the `main' function and some more.  */
#include <test-skeleton.c>

struct frame_state;

/* Not declared in any header.  */
extern struct frame_state *__frame_state_for (void *, struct frame_state *);

/* Exit status.  */
int result = EXIT_SUCCESS;

int
compare (const void *a, const void *b)
{
  /* 1K should be enough for all currently supported platforms.  */
  struct frame_state *udata = alloca (1024);

  /* The tests below are arranged such that this function is always
     called such that A or B always contains a pointer to the name of
     the function being tested.  */
  const char *func = *(char **) a ?: *(char **)b;
  void *pc;

  puts (func);

  pc = __builtin_extract_return_addr (__builtin_return_address (0)) - 1;
  if (__frame_state_for (pc, udata) == NULL)
    {
      fprintf (stderr, "Cannot find frame info for %s\n", func);
      result = EXIT_FAILURE;
    }

  return 0;
}

int
do_test (int argc, char *argv[])
{
  {
    void *root = NULL;
    char *key1 = NULL;
    char *key2 = "tsearch";

    tsearch (&key1, &root, compare);
    tsearch (&key2, &root, compare);
  }

  {
    char *key = "lfind";
    char *array[] = { key, NULL };
    int nmemb = 2;

    lfind (&key, array, &nmemb, sizeof (char), compare);
  }

  {
    char *key = "lsearch";
    char *array[] = { key, NULL };
    int nmemb = 2;

    lsearch (&key, array, &nmemb, sizeof (char), compare);
  }

  {
    char *key = "bsearch";
    char *array[] = { key, NULL };

    bsearch (&key, array, 2, sizeof (char *), compare);
  }

  {
    char *func = "qsort";
    char *array[] = { func, NULL };

    qsort (array, 2, sizeof (char *), compare);
  }

  return result;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]