[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1117849: libc6: backtrace returns frames with incorrect offset



Package: libc6
Version: 2.36-9+deb12u13
Severity: normal
Tags: upstream
X-Debbugs-Cc: kaloian@doganov.org, yavor@gnu.org

The backtrace function returns frames with incorrect offset, pointing
to the next statement instead of the active one.  Using the example
program from the manual (info '(libc)Backtraces'), I tried different
Debian versions from current unstable backwards and found out the last
system that gave proper results was Wheezy.

Here's an example output, on the bookworm system I'm writing this on:

$ cat backtrace.c
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>

/* Obtain a backtrace and print it to ‘stdout’. */
void
print_trace (void)
{
  void *array[10];
  char **strings;
  int size, i;

  size = backtrace (array, 10);
  strings = backtrace_symbols (array, size);
  if (strings != NULL)
    {
      printf ("Obtained %d stack frames.\n", size);
      for (i = 0; i < size; i++)
        printf ("%s\n", strings[i]);
    }

  free (strings);
}

/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
  print_trace ();
}

int
main (void)
{
  dummy_function ();
  return 0;
}

$ make backtrace CFLAGS=-g
cc -g    backtrace.c   -o backtrace

$ ./backtrace 
Obtained 6 stack frames.
./backtrace(+0x11e9) [0x4fa1e9]
./backtrace(+0x127a) [0x4fa27a]
./backtrace(+0x1292) [0x4fa292]
/lib/i386-linux-gnu/libc.so.6(+0x232d5) [0xb7d932d5]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0x88) [0xb7d93398]
./backtrace(+0x10c7) [0x4fa0c7]

$ addr2line -e backtrace +0x11e9
/tmp/backtrace.c:13

The line appears correct only because there's an assignment after the
call to backtrace.  So the next statement happens on the same line.

$ addr2line -e backtrace +0x127a
/tmp/backtrace.c:30

Should be 29.

$ addr2line -e backtrace +0x1292
/tmp/backtrace.c:36

Wrong, should be 35.

I also tried on a sid system with the test program built with
gcc/4.7.2 (wheezy's compiler); there is no improvement.

Please let me know if you want me to report this upstream.

-- System Information:
Debian Release: 12.12
  APT prefers oldstable-updates
  APT policy: (500, 'oldstable-updates'), (500, 'oldstable-security'), (500, 'oldstable-debug'), (500, 'oldstable')
Architecture: i386 (i686)

Kernel: Linux 6.1.0-40-686-pae (SMP w/1 CPU thread; PREEMPT)
Locale: LANG=bg_BG.UTF-8, LC_CTYPE=bg_BG.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages libc6 depends on:
ii  libgcc-s1  12.2.0-14+deb12u1

Versions of packages libc6 recommends:
ii  libidn2-0  2.3.3-1+b1

Versions of packages libc6 suggests:
ii  debconf [debconf-2.0]  1.5.82
pn  glibc-doc              <none>
ii  libc-l10n              2.36-9+deb12u13
ii  libnss-nis             3.1-4
ii  libnss-nisplus         1.3-4
ii  locales                2.36-9+deb12u13

-- debconf information:
  glibc/disable-screensaver:
  glibc/kernel-too-old:
* libraries/restart-without-asking: false
* glibc/restart-services: spamassassin ssh exim4 cron atd
  glibc/kernel-not-supported:
  glibc/upgrade: true
  glibc/restart-failed:

Reply to: