1 From d6f67f7d833b4e2039f832355fb0edd65522c9f4 Mon Sep 17 00:00:00 2001
2 From: Ulrich Drepper <drepper@gmail.com>
3 Date: Sat, 14 May 2011 10:46:17 -0400
4 Subject: [PATCH] Handle recursive calls in backtrace better
9 sysdeps/ia64/backtrace.c | 27 +++++++++++++++++++++++----
10 3 files changed, 36 insertions(+), 10 deletions(-)
12 2011-05-14 Ulrich Drepper <drepper@gmail.com>
15 * sysdeps/ia64/backtrace.c (struct trace_reg): Add cfa element.
16 (dummy_getcfa): New function.
17 (init): Get _Unwind_GetCFA address, use dummy if not found.
18 (backtrace_helper): In recursion check, also check whether CFA changes.
19 (__backtrace): Completely initialize arg.
21 diff --git a/sysdeps/ia64/backtrace.c b/sysdeps/ia64/backtrace.c
22 index 5cefb86..d4ff291 100644
23 --- a/sysdeps/ia64/backtrace.c
24 +++ b/sysdeps/ia64/backtrace.c
26 /* Return backtrace of current program state.
27 - Copyright (C) 2003, 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
28 + Copyright (C) 2003-2005, 2007, 2009, 2011 Free Software Foundation, Inc.
29 This file is part of the GNU C Library.
30 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
43 static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *);
44 static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *);
45 +static _Unwind_Word (*unwind_getcfa) (struct _Unwind_Context *);
46 static void *libgcc_handle;
49 +/* Dummy version in case libgcc_s does not contain the real code. */
51 +dummy_getcfa (struct _Unwind_Context *ctx __attribute__ ((unused)))
60 @@ -47,10 +59,13 @@ init (void)
61 unwind_getip = __libc_dlsym (libgcc_handle, "_Unwind_GetIP");
62 if (unwind_getip == NULL)
63 unwind_backtrace = NULL;
64 + unwind_getcfa = (__libc_dlsym (libgcc_handle, "_Unwind_GetCFA")
68 # define unwind_backtrace _Unwind_Backtrace
69 # define unwind_getip _Unwind_GetIP
70 +# define unwind_getcfa _Unwind_GetCFA
73 static _Unwind_Reason_Code
74 @@ -65,8 +80,12 @@ backtrace_helper (struct _Unwind_Context *ctx, void *a)
75 arg->array[arg->cnt] = (void *) unwind_getip (ctx);
77 /* Check whether we make any progress. */
78 - if (arg->cnt > 0 && arg->array[arg->cnt - 1] == arg->array[arg->cnt])
79 + _Unwind_Word cfa = unwind_getcfa (ctx);
81 + if (arg->cnt > 0 && arg->array[arg->cnt - 1] == arg->array[arg->cnt]
83 return _URC_END_OF_STACK;
86 if (++arg->cnt == arg->size)
87 return _URC_END_OF_STACK;
88 @@ -78,7 +97,7 @@ __backtrace (array, size)
92 - struct trace_arg arg = { .array = array, .size = size, .cnt = -1 };
93 + struct trace_arg arg = { .array = array, .cfa = 0, .size = size, .cnt = -1 };
95 __libc_once_define (static, once);