summaryrefslogtreecommitdiff
path: root/libbacktrace/edtest.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-06-12 03:25:04 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-06-12 03:25:04 +0000
commitd1609a232616d0a85f2f7bd9ebf4dae4b11fd481 (patch)
tree9b4b2fbd658631dc5cb019d57ba0843423218b4b /libbacktrace/edtest.c
parent1e7a4be3a1f37e9feb5b5b3a6a1f9a31d7a2cd7e (diff)
downloadgcc-d1609a232616d0a85f2f7bd9ebf4dae4b11fd481.tar.gz
elf.c (backtrace_initialize): Always set *fileline_fn.
* elf.c (backtrace_initialize): Always set *fileline_fn. * ttest.c: New file. * btest.c: Move support functions into testlib.c. Change calls to check to pass file name. * testlib.c: New file, copied from (part of) btest.c. * testlib.h: New file, declarations for testlib.c. * edtest.c: Use testlib.h and testlib.c. * configure.ac: Test for -pthread, set HAVE_PTHREAD conditional. * Makefile.am (btest_SOURCES): Add testlib.c. (edtest_SOURCES): Likewise. (CHECK_PROGRAMS): Add ttest if HAVE_PTHREAD. (ttest_SOURCES, ttest_CFLAGS, ttest_LDADD): Define. * configure, Makefile.in: Rebuild. From-SVN: r249111
Diffstat (limited to 'libbacktrace/edtest.c')
-rw-r--r--libbacktrace/edtest.c147
1 files changed, 1 insertions, 146 deletions
diff --git a/libbacktrace/edtest.c b/libbacktrace/edtest.c
index daf4dd9f0be..54c705cb1ba 100644
--- a/libbacktrace/edtest.c
+++ b/libbacktrace/edtest.c
@@ -41,19 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. */
#include "backtrace-supported.h"
#include "internal.h"
-#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
-# define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\')
-#else
-# define IS_DIR_SEPARATOR(c) ((c) == '/')
-#endif
-
-/* The backtrace state. */
-
-static void *state;
-
-/* The number of failures. */
-
-int failures = 0;
+#include "testlib.h"
static int test1 (void) __attribute__ ((noinline, unused));
static int test1 (void) __attribute__ ((noinline, unused));
@@ -68,128 +56,6 @@ test1 (void)
return f2 (__LINE__) + 1;
}
-/* Used to collect backtrace info. */
-
-struct info
-{
- char *filename;
- int lineno;
- char *function;
-};
-
-/* Return the base name in a path. */
-
-static const char *
-base (const char *p)
-{
- const char *last;
- const char *s;
-
- last = NULL;
- for (s = p; *s != '\0'; ++s)
- {
- if (IS_DIR_SEPARATOR (*s))
- last = s + 1;
- }
- return last != NULL ? last : p;
-}
-
-/* Check an entry in a struct info array. */
-
-static void
-check (const char *name, int index, const struct info *all, int want_lineno,
- const char *want_function, const char *want_file, int *failed)
-{
- if (*failed)
- return;
- if (all[index].filename == NULL || all[index].function == NULL)
- {
- fprintf (stderr, "%s: [%d]: missing file name or function name\n",
- name, index);
- *failed = 1;
- return;
- }
- if (strcmp (base (all[index].filename), want_file) != 0)
- {
- fprintf (stderr, "%s: [%d]: got %s expected %s\n", name, index,
- all[index].filename, want_file);
- *failed = 1;
- }
- if (all[index].lineno != want_lineno)
- {
- fprintf (stderr, "%s: [%d]: got %d expected %d\n", name, index,
- all[index].lineno, want_lineno);
- *failed = 1;
- }
- if (strcmp (all[index].function, want_function) != 0)
- {
- fprintf (stderr, "%s: [%d]: got %s expected %s\n", name, index,
- all[index].function, want_function);
- *failed = 1;
- }
-}
-
-/* Passed to backtrace callback function. */
-
-struct bdata
-{
- struct info *all;
- size_t index;
- size_t max;
- int failed;
-};
-
-/* An error callback passed to backtrace. */
-
-static void
-error_callback_one (void *vdata, const char *msg, int errnum)
-{
- struct bdata *data = (struct bdata *) vdata;
-
- fprintf (stderr, "%s", msg);
- if (errnum > 0)
- fprintf (stderr, ": %s", strerror (errnum));
- fprintf (stderr, "\n");
- data->failed = 1;
-}
-
-/* The backtrace callback function. */
-
-static int
-callback_one (void *vdata, uintptr_t pc ATTRIBUTE_UNUSED,
- const char *filename, int lineno, const char *function)
-{
- struct bdata *data = (struct bdata *) vdata;
- struct info *p;
-
- if (data->index >= data->max)
- {
- fprintf (stderr, "callback_one: callback called too many times\n");
- data->failed = 1;
- return 1;
- }
-
- p = &data->all[data->index];
- if (filename == NULL)
- p->filename = NULL;
- else
- {
- p->filename = strdup (filename);
- assert (p->filename != NULL);
- }
- p->lineno = lineno;
- if (function == NULL)
- p->function = NULL;
- else
- {
- p->function = strdup (function);
- assert (p->function != NULL);
- }
- ++data->index;
-
- return 0;
-}
-
int
f3 (int f1line, int f2line)
{
@@ -232,17 +98,6 @@ f3 (int f1line, int f2line)
return failures;
}
-static void
-error_callback_create (void *data ATTRIBUTE_UNUSED, const char *msg,
- int errnum)
-{
- fprintf (stderr, "%s", msg);
- if (errnum > 0)
- fprintf (stderr, ": %s", strerror (errnum));
- fprintf (stderr, "\n");
- exit (EXIT_FAILURE);
-}
-
int
main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{