Hello,

  I'm using libunwind 1.1 in a Linux with ARM processor. I've found that
unw_step seems not to work, or at least not as in x86-64 because it does
not report all the backtrace but only the top of the stack level. I'm
attaching a simple program (derived from the tests  Gtest-bt.c) that
shows this and also the output in a ARM and in a X86/64 machine.

  Do I need to compile something in a special way? I've looked at the
objdump -D output from the ARM version and the subroutines seem to be
there.

  In ARM:
  # gcc -O0 mytest-bt.c -I ../include
-L /gpfs/CEPBATOOLS/libunwind/1.1/lib -lunwind -lunwind-arm -o mytest-bt
  # LD_LIBRARY_PATH=/gpfs/CEPBATOOLS/libunwind/1.1/lib:
$LD_LIBRARY_PATH ./mytest-bt
bar (123)
foo (123)
        explicit backtrace:
0000000000008734 unw_get_proc_name: <do_backtrace+0x3c>
(sp=00000000becce318)
        proc=0x8658-0x8b6b
        handler=0x0 lsda=0x0 gp=0x0

  In X86/64:
  # gcc -O0 mytest-bt.c -I aplic/libunwind/1.1/include -L
aplic/libunwind/1.1/lib -lunwind -lunwind-x86_64 -o mytest-bt
  # LD_LIBRARY_PATH=aplic/libunwind/1.1/lib:$LD_LIBRARY_PATH ./mytest-bt
bar (123)
foo (123)
        explicit backtrace:
000000000040092a unw_get_proc_name: <do_backtrace+0x26>
(sp=00007ffff8c9b150)
        proc=0x400904-0x400b06
        handler=0x0 lsda=0x0 gp=0x6011e0
0000000000400b30 unw_get_proc_name: <foo+0x2a>    (sp=00007ffff8c9b1c0)
        proc=0x400b06-0x400b32
        handler=0x0 lsda=0x0 gp=0x6011e0
0000000000400b63 unw_get_proc_name: <bar+0x31>    (sp=00007ffff8c9b1e0)
        proc=0x400b32-0x400b65
        handler=0x0 lsda=0x0 gp=0x6011e0
0000000000400b7e unw_get_proc_name: <main+0x19>   (sp=00007ffff8c9b200)
        proc=0x400b65-0x400b85
        handler=0x0 lsda=0x0 gp=0x6011e0
0000003c4342169d unw_get_proc_name: <__libc_start_main+0xed>
(sp=00007ffff8c9b220)
        proc=0x3c434215b0-0x3c43421768
        handler=0x0 lsda=0x0 gp=0x3c437b0fe8
0000000000400849 unw_get_proc_name: <_start+0x29> (sp=00007ffff8c9b2e0)
        proc=0x400849-0x40084a
        handler=0x0 lsda=0x0 gp=0x0

Regards


WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer
/* libunwind - a platform-independent unwind library
   Copyright (C) 2001-2004 Hewlett-Packard Co
	Contributed by David Mosberger-Tang <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <errno.h>
#if HAVE_EXECINFO_H
# include <execinfo.h>
#else
  extern int backtrace (void **, int);
#endif
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libunwind.h>

#define panic(args...)				\
	{ fprintf (stderr, args); exit (-1); }

#define SIG_STACK_SIZE 0x100000

int verbose = 1;
int num_errors;

/* These variables are global because they
 * cause the signal stack to overflow */
char buf[512], name[256];
unw_cursor_t cursor;
unw_context_t uc;

static void
do_backtrace (void)
{
  unw_word_t ip, sp, off;
  unw_proc_info_t pi;
  int ret;

  if (verbose)
    printf ("\texplicit backtrace:\n");

  unw_getcontext (&uc);
  if (unw_init_local (&cursor, &uc) < 0)
    panic ("unw_init_local failed!\n");

  do
    {
      unw_get_reg (&cursor, UNW_REG_IP, &ip);
      unw_get_reg (&cursor, UNW_REG_SP, &sp);
      buf[0] = '\0';
      if (unw_get_proc_name (&cursor, name, sizeof (name), &off) == 0)
	{
	  if (off)
	    snprintf (buf, sizeof (buf), "unw_get_proc_name: <%s+0x%lx>", name, (long) off);
	  else
	    snprintf (buf, sizeof (buf), "unw_get_proc_name: <%s>", name);
	}
      if (verbose)
	{
	  printf ("%016lx %-32s (sp=%016lx)\n", (long) ip, buf, (long) sp);

	  if (unw_get_proc_info (&cursor, &pi) == 0)
	    {
	      printf ("\tproc=0x%lx-0x%lx\n\thandler=0x%lx lsda=0x%lx gp=0x%lx",
		  (long) pi.start_ip, (long) pi.end_ip,
		  (long) pi.handler, (long) pi.lsda, (long) pi.gp);
	    }

	  printf ("\n");
	}

      ret = unw_step (&cursor);
      if (ret < 0)
	{
	  unw_get_reg (&cursor, UNW_REG_IP, &ip);
	  printf ("FAILURE: unw_step() returned %d for ip=%lx\n",
		  ret, (long) ip);
	  ++num_errors;
	}
    }
  while (ret > 0);
}


void
foo (long val )
{
  printf ("foo (%ld)\n", val);
  do_backtrace ();
}

void
bar (long v)
{
  printf ("bar (%ld)\n", v);
  foo (v);
}

int
main (int argc, char **argv )
{
  bar(123);
  return 0;
}
_______________________________________________
Libunwind-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/libunwind-devel

Reply via email to