[PATCH v4 07/16] Print backtrace in a signal-safe manner

Chase Douglas chase.douglas at canonical.com
Thu May 24 09:58:57 PDT 2012


On 05/23/2012 09:49 PM, Peter Hutterer wrote:
> On Mon, May 14, 2012 at 02:14:28PM -0700, Chase Douglas wrote:
>> Backtraces are often printed in signal context, such as when a segfault
>> occurs.
>>
>> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
>> ---
>>  os/backtrace.c |   49 +++++++++++++++++++++++++++++--------------------
>>  1 file changed, 29 insertions(+), 20 deletions(-)
>>
>> diff --git a/os/backtrace.c b/os/backtrace.c
>> index 81348f4..d41c3f3 100644
>> --- a/os/backtrace.c
>> +++ b/os/backtrace.c
>> @@ -45,29 +45,37 @@ xorg_backtrace(void)
>>      int size, i;
>>      Dl_info info;
>>  
>> -    ErrorF("\n");
>> -    ErrorF("Backtrace:\n");
>> +    ErrorSigSafe("\n");
>> +    ErrorSigSafe("Backtrace:\n");
>>      size = backtrace(array, 64);
>>      for (i = 0; i < size; i++) {
>>          int rc = dladdr(array[i], &info);
>>  
>>          if (rc == 0) {
>> -            ErrorF("%d: ?? [%p]\n", i, array[i]);
>> +            ErrorSigSafe("%u: ?? [%p]\n", i, array[i]);
>>              continue;
>>          }
>>          mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
>>          if (info.dli_saddr)
>> -            ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
>> -                   info.dli_sname,
>> -                   (long unsigned int) ((char *) array[i] -
>> -                                        (char *) info.dli_saddr), array[i]);
>> +            ErrorSigSafe(
>> +                "%u: %s (%s+0x%x) [%p]\n",
>> +                i,
>> +                mod,
>> +                info.dli_sname,
>> +                (long unsigned int)((char *) array[i] -
>> +                                    (char *) info.dli_saddr),
>> +                array[i]);
>>          else
>> -            ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
>> -                   info.dli_fbase,
>> -                   (long unsigned int) ((char *) array[i] -
>> -                                        (char *) info.dli_fbase), array[i]);
>> +            ErrorSigSafe(
>> +                "%u: %s (%s+0x%x) [%p]\n",
> 
> typo: this should be "%u: %s (%p+0x%lx) [%p]\n" (note the %p, not %s). The
> backtrace looks like garbage otherwise.
> 
> Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> otherwise

Thanks, I've fixed this up.

-- Chase


More information about the xorg-devel mailing list