1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-07-07 15:45:36 +02:00
Commit graph

1812 commits

Author SHA1 Message Date
Tim Deegan 11a7d98e39 Missing header in dist tarball.
Signed-off-by: Tim Deegan <tjd@phlegethon.org>
2014-02-08 19:47:17 -08:00
Ulrich Weigand da0b1a146f Support powerpc64le-linux platform
This patch adds support for the powerpc64le-linux platform.  It consists
of two main features:

- Support little-endian byte order
  This is done via a "big_endian" member of struct unw_addr_space,
  which is evaluated by common code via the dwarf_is_big_endian
  macro, and also in endian-aware code in unw_is_signal_frame.

- Support the ELFv2 ABI
  This is done via an "abi" member of struct unw_addr_space.  This
  is currently only needed in tdep_get_func_addr, since the ELFv2
  ABI does not use function descriptors.

Both new members are initialized in unw_create_addr_space and
ppc64_local_addr_space_init, following the mips precedent.

Since ppc32 and ppc64 now no longer share the unw_create_addr_space
implementation, the file is duplicated from the ppc directory into
ppc32/ppc64.

Tested on powerpc64-linux and powerpc64le-linux.  Support on LE
seems to be as good as existing BE support; I have not attempted to
fix the existing shortcomings of PPC support that already cause a
number to tests to fail due to unimplemented features.

Signed-off-by: Ulrich Weigand <uweigand@de.ibm.com>
2013-12-27 07:09:06 -08:00
Ulrich Weigand 844f1b84cc Pass relocated address to tdep_get_func_addr
The ppc64 implementation of tdep_get_func_addr would crash when
attempting to retrieve the address of a function in a shared
library.  The problem was that it needs to dereference the
function descriptor, but common code was passing the *unrelocated*
adddress of the descriptor to the tdep_get_func_addr routine.

Instead, common code would attempt to relocate the *result* of
tdep_get_func_addr, which is also wrong: the ppc64 implementation
reads the function address from the in-memory copy of the
descriptor, which is already relocation and contains the final
address.

This patch fixes the problem by relocating the descriptor address
before passing it to tdep_get_func_addr, instead of relocating
the result of tdep_get_func_addr.  Since ppc64 is the only
non-trivial implementation of tdep_get_func_addr, this cannot
affect any other platform.

Signed-off-by: Ulrich Weigand <uweigand@de.ibm.com>
2013-12-27 07:08:43 -08:00
Ulrich Weigand 5710c98fbf Fix undefined behavior in dwarf_eval_expr
The dwarf_eval_expr routine uses macros push, pop, and pick to
manipulate the DWARF expression stack.  When these macros are
nested, e.g. in the implementation of DW_OP_dup:
          push (pick (0));
the combination can lead to unfortunate results.

In particular, when substituting into:
do {
  if (tos >= MAX_EXPR_STACK_SIZE)
    {
      Debug (1, "Stack overflow\n");
      return -UNW_EINVAL;
    }
  stack[tos++] = (x);
} while (0)
a value of "x" that makes use of "tos" (as instances of the
pick or pop macros do), the resulting expression will both
use and modify tos without an intervening sequence point,
which is undefined behavior according to the C standard.

And in fact with current GCC on PowerPC, this leads to a
miscompilation of the DW_OP_dup implementation.

This patch fixes the problem by assigning "x" to a
temporary variable before modifying tos.

Signed-off-by: Ulrich Weigand <uweigand@de.ibm.com>
2013-12-27 07:07:48 -08:00
Masatake YAMATO 2c3444d0f4 Remove one of duplicated declarations of `get_proc_name'
Declarations of `get_proc_name' of is duplicated.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2013-09-25 07:39:16 -07:00
Masatake YAMATO dee708f4bc Missing -llzma in libunwind.pc
liblzuma used in decoding MiniDebuginfo is not listed in
libunwind.pc.

Changes in version 2 of patch:

* Don't check HAVE_LZMA. It is redundant.
* Make liblzma as private libraries in use.

Both are suggested by Mike Frysinger <vapier@gentoo.org>.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2013-09-11 00:11:17 -07:00
Luca Clementi af23f0a04b Add Cflags keyword to pkg-config metadata files
pkg-config metadata template files are missing Cflags keyword
which is required to properly compile against libunwind using
PKG_* autoconf macros

Acked-by: Mike Frysinger <vapier@gentoo.org>
2013-08-26 05:40:19 -07:00
Matt Fischer 3b8254d3b9 Fix unwind info freeing code in DWARF parser
The DWARF code allocates its unwind_info objects out of a
memory pool.  The code which frees the object therefore calls
the mempool freeing code.  However, there are cases where the
free code will be run with an unwind_info that was allocated
through a different mechanism (e.g. an ARM exidx table entry).
In these cases, the object should not be freed through the
mempool code.

To correct this, a check was added to ensure that the unwind_info
is of the appropriate type before passing the object along to the
mempool to be freed.
2013-05-19 00:10:18 -07:00
Arun Sharma d41a453bbf Fix a build error
<elf.h> needs to be included before the check for ELF_CLASS.
2013-05-19 00:04:15 -07:00
Arun Sharma 5eba0f816d Fixup long lines. 2013-05-18 23:20:03 -07:00
Matt Fischer eac65dc9b8 Add basic support for the QNX operating system
This change adds some special cases to allow libunwind to compile
for QNX.

* QNX's copy of <elf.h> and <link.h> reside in sys/ instead.  To deal
  with this, an AC_CHECK_HEADERS() was added to check for the files
  in both locations.
* Similarly, QNX does not have <endian.h>.  In cases where the file is
  not found, logic was added to refer to QNX-specific macros to determine
  endianness.
* The QCC compiler, which is a wrapper around GCC, cannot handle some
  standard GCC options.  Therefore, logic was added to check for QCC,
  and when it is found, to suppress the use of -lgcc, and to express the
  option -nostartfiles as -Wc,-nostartfiles instead, which is correctly
  passed on to the underlying GCC.
* Finally, the support file os-qnx.c was added, patterned after the existing
  os-*.c files.  Only local image lookup is currently supported (see the
  comments for more information), but this is sufficient for QNX, since
  ptrace is not supported there anyway, and that is the only case where the
  function is required to do remote image lookup.

Change-Id: Ie7934f94a7317bdde59335f2acd4c3a97c0384c1
2013-05-13 10:50:17 -05:00
Yvan Roux ac6c0a6535 [PATCH] AArch64 port. 2013-05-11 09:20:28 -06:00
Matt Fischer 612e1056f6 Fix symlink install hook
During the install, symlinks are added from libunwind-<arch> to
libunwind-generic.  However, on platforms that don't support
symlinking (such as Windows), the $(LN_S) macro is defined
as 'cp -p' instead.  This works fine, except that since the
target of the symlink is a relative path, the copy will only
succeed if the current directory is the directory that contains
the file.

The solution to this problem suggested in the Autotools manual
(see http://www.gnu.org/software/automake/manual/automake.html#Extending)
is to simply cd into the correct directory first.  This patch
makes that change for the symlinks that are being made during install.

[ edit: use relative path for the link name as well ]
2013-04-19 20:07:02 -07:00
Matt Fischer 563b0ff314 Added --enable-setjmp
Currently, libunwind-setjmp is built whenever local unwinding is
built.  This patch adds an explicit flag to control it instead.
The default if not specified is to follow the old behavior.
2013-04-19 17:08:03 -05:00
Matt Fischer abb0957198 Added --enable-ptrace
This change adds a manual override to control building of the ptrace
library, similar to the existing --enable-coredump option.  The
default is set based on the existence of sys/ptrace.h, allowing it
to be automatically disabled for platforms that do not have ptrace.
2013-04-19 16:46:24 -05:00
Arun Sharma f92ecb6127 dwarf: Fix memory leak
Need to clean up by calling put_unwind_info() on code paths where fetch_proc_info() fails.

Signed-off-by: Arun Sharma <asharma@fb.com>
2013-04-02 21:19:56 -07:00
dave lerner 8028a537dd unw_is_signal_frame should return false/0 for bad addresses
access_mem() could fail and return a non-zero value, which callers
interpret as boolean true.

Signed-off-by: Dave Lerner <dave.lerner@windriver.com>
2013-03-10 14:59:44 -07:00
Chris January 679b65cd22 dwarf: Fix the order of the operands to the relational operators
dwarf_eval_expr are reversed compared with the DWARF spec.
2013-02-04 19:36:33 -08:00
Ladislav Michl 10b064ffe9 Support building with older compilers.
Add a check for __builtin_unreachable.
2012-11-24 21:37:07 -08:00
Arun Sharma d7322f0f64 Update to v1.1 2012-10-05 21:54:17 -07:00
Tommi Rantala adae66d2e2 Fix x86-64 debug build -Wformat warning
src/x86_64/Gstep.c: In function '_ULx86_64_step':
src/x86_64/Gstep.c:204:4: warning: unknown conversion type character 'r' in format [-Wformat]
2012-10-05 21:24:36 -07:00
Tommi Rantala 96c1bca2b0 Fix header inclusion order in `src/elfxx.c'
Make sure that we have included `config.h' before checking HAVE_LZMA.
This makes a difference at least on MIPS, where we include `elfxx.c'
directly. For other platforms this does not make much difference, as we
are already indirectly including `config.h' from other headers.
2012-10-05 21:24:30 -07:00
Arun Sharma cb3fbbb172 Reduce the number of ifdefs in machine independent code
Hopefully we don't have too many GNUC users who don't have
fetch and add.
2012-09-29 12:22:47 -07:00
Tommi Rantala 890e23eb9d Prefer NULL over zero 2012-09-28 14:51:21 +03:00
Tommi Rantala aebba1f8a7 Apply `define_lock()'
We have a nice macro for defining pthread mutexes, use it.
2012-09-28 14:51:21 +03:00
Tommi Rantala 22aff2cc1f Fix second operand read in dwarf_eval_expr()
Due to bad bracketing, the second operand was never read for dwarf
expressions that take two operands.

Caught with sparse.
2012-09-28 14:51:21 +03:00
Tommi Rantala 65bdcc6f9d Teach autotools current ARM `ex_tables.h' location 2012-09-28 14:51:21 +03:00
Tommi Rantala 5e7e890a0b Plug in `ALIAS' attribute 2012-09-28 14:51:21 +03:00
Tommi Rantala 7d471b1440 Define and use `CONST_ATTR' 2012-09-28 14:51:21 +03:00
Tommi Rantala e0653f9e3a Define and use `WEAK' 2012-09-28 14:51:21 +03:00
Tommi Rantala 397f32a378 Plug in `ARRAY_SIZE' in ptrace code 2012-09-28 14:50:03 +03:00
Tommi Rantala dcbe6836eb IA64: constify read only arrays in `tdep_init()' 2012-09-28 14:50:03 +03:00
Tommi Rantala 088ac53775 Constify `operands' in src/dwarf/Gexpr.c 2012-09-28 14:50:03 +03:00
Tommi Rantala ee8df26288 Constify `dwarf_to_unw_regnum_map' 2012-09-28 14:50:03 +03:00
Tommi Rantala a9b5b10f23 Set `_UPT_reg_offset' read only
We do not modify `_UPT_reg_offset', so let's set it `const'. Given that
the array is exported, it's technically possible that some library user
is actually modifying the content, but does not seem really all that
likely.
2012-09-28 14:50:03 +03:00
Tommi Rantala e2d5cdd22d ppc32: include `compiler.h' for UNUSED in ucontext_i.h 2012-09-28 14:50:03 +03:00
Tommi Rantala 8d5b1aeeff SuperH port
Add support for the 32bit SuperH architecture running Linux.
Specifically, support is added for SH4, and support for earlier SH
versions and to the 64bit SH5 are left out. This was tested in qemu with
a little-endian SH4 debian image & GCC 4.7 cross compiler.
2012-09-28 14:50:03 +03:00
Tommi Rantala 79c2c254a7 MIPS coredump support
Add MIPS support to the coredump library. Explicit support for the MIPS
program counter register is added so that we can start backtracing from
the program counter value we read from a core dump. The PC register
support was not strictly required for local backtracing, and we will in
fact just plug the return address to the PC register in getcontext().

I have only tested the 32bit "OABI" paths.
2012-09-28 14:50:03 +03:00
Tommi Rantala ded94b98ff Stop including `memory.h'
I am unable to find any reference to `memory.h' in the C99 and C11
committee drafts, so include `string.h' instead when we need memset() or
similar.
2012-09-28 14:50:03 +03:00
Tommi Rantala cc6cd621ea HPPA: kludge out unused variable in unw_get_save_loc() stub 2012-09-28 14:06:07 +03:00
Tommi Rantala fc38a5339d HPPA: properly check dwarf_get() return value in unw_step() 2012-09-28 14:06:07 +03:00
Tommi Rantala 6023ccf667 PPC: remove unused `PAGE_START' macro from Ginit.c 2012-09-28 14:06:07 +03:00
Tommi Rantala 0941dedb70 Remove unused src/x86_64/Lis_signal_frame.c 2012-09-28 14:06:07 +03:00
Tommi Rantala 23ecb97906 IA64: avoid -Wunused-but-set-variable in src/ia64/init.h
In file included from src/ia64/Ginit_remote.c:26:0:
src/ia64/init.h: In function 'common_init':
src/ia64/init.h:32:12: warning: variable 'natp' set but not used [-Wunused-but-set-variable]
2012-09-28 14:06:07 +03:00
Tommi Rantala b4bde18112 Apply UNW_ALIGN more in src/mi/mempool.c
Apply UNW_ALIGN in a few places in src/mi/mempool.c that I missed in
commit c2f757418 ("Rename and share `ALIGN' macro from
_UCD_internal.h").
2012-09-28 14:06:07 +03:00
Tommi Rantala 5d0f376b08 Invert tdep_init() flag logic
Invert the flag that signals that tdep_init() was called, to move the
symbol from data to BSS.
2012-09-28 14:06:07 +03:00
Tommi Rantala 9a3565ddc1 Simplify `sos_alloc()' implementation
Instead of maintaining a pointer to the `sos_memory' array, maintain an
index that tells the next free position. When atomic operations are
available, the allocation boils down to a single fetch-and-add
operation.
2012-09-28 13:52:22 +03:00
Tommi Rantala 26fc1563fb Align `sos_memory' to MAX_ALIGN
We give aligned pointers from the `sos_memory' array, so any non-aligned
bytes are only wasted.
2012-09-28 13:52:22 +03:00
Tommi Rantala c36a14f245 Workaround non-power-of-two i386 sizeof(long double) in src/mi/mempool.c
To ensure that we return properly aligned pointers from sos_alloc(),
MAX_ALIGN must be a power-of-two. On i386 the power-of-two assumption
fails as sizeof(long double) = 12. Fix this by rounding up to 16.
2012-09-28 13:52:22 +03:00
Tommi Rantala e6edad069c Use GCC __BIGGEST_ALIGNMENT__ for sos-pool MAX_ALIGN
Use the __BIGGEST_ALIGNMENT__ macro provided by GCC for sos_alloc()
allocation alignment. The macro gives ``the largest alignment ever used
for any data type on the target machine you are compiling for.''

__BIGGEST_ALIGNMENT__ also has some other nice properties, e.g. it is
power-of-two on all architectures (note that on i386, sizeof(long
double) = 12), and on some architectures (e.g. SuperH) the alignment
requirement can be lower than sizeof(long double).
2012-09-28 13:52:21 +03:00
Konstantin Belousov d0cbc51955 x86_64: stop unwinding when %rbp location is NULL 2012-09-21 23:06:17 -07:00
Tommi Rantala e891591bcb ppc32: fixup cross build failure 2012-09-21 22:52:28 -07:00
Arun Sharma e4b24be9c2 pkg-config file fixups
Suggested-by: Alexander Toresson <alexander.toresson@gmail.com>
2012-09-21 22:46:01 -07:00
Alexander Toresson ea5e90fd9f Create and install pkg-config .pc files
[Edit: renamed to libunwind-generic.pc and some .pc files
 created only when needed -- asharma@fb.com]
2012-09-15 11:34:43 -07:00
Cody P Schafer 9184535486 ptrace: add more Debug to access_reg
This was useful in debugging issues with the libunwind-ptrace code on
ppc64.
2012-09-15 10:50:32 -07:00
Cody P Schafer 3d6f7479b0 ptrace: check for NULL arg.
tdep_get_func_addr in ppc64 passes NULL for the last argument of
as->access_mem.  tdep_get_func_addr is called by elf_w(lookup_symbol),
which in turn is called by elf_w(get_proc_name_in_image).

elf_w(get_proc_name_in_image) is part of the API, and is only passed an
unw_addr_space_t, not a unw_cursor_t, meaning that we cannot recover the
UPT_info on the PPC64 platform.

This could be fixed by giving libunwind the knowledge to perform
relocations itself, thus not needing to look at the running image to
determine function addresses.
2012-09-15 10:47:43 -07:00
Cody P Schafer 10abb25af4 ptrace/access_reg: print out register name on "bad register"
When we have a "bad register", print out the name of that register (if
possible) to aid in debugging.
2012-09-15 10:47:43 -07:00
Cody P Schafer f796a6dfe9 ppc64: add FRAME_POINTER & NIP to regname. 2012-09-15 10:47:43 -07:00
Cody P Schafer 0abc36eb18 ppc64: be explicit in access_reg range check 2012-09-15 10:47:42 -07:00
Cody P Schafer 64e8a3d909 UPT: Add reg offsets for ppc32/64 2012-09-15 10:47:42 -07:00
Cody P Schafer 3a5d7ff694 build: make libunwind-coredump build optional
Disable the building of libunwind-coredump except on x86_64 and x86
(where implimentations exsist).

Allow overriding of this autodetection via --enable-coredump and
--disable-coredump.
2012-09-15 10:47:42 -07:00
Cody P Schafer fa56db394d ppc32: add UNUSED attribute to dmy_ctxt 2012-09-15 10:47:42 -07:00
Cody P Schafer 4ddca1acf1 ppc32: remove unused dmy_vrregset 2012-09-15 10:47:42 -07:00
ariel.burton@roguewave.com d00b621090 PATCH: fix build with --enable-msabi-support
This attached patch, relative to libuninwd-1.0.1,
will fix building with --enable-msabi-support on linux x86_64.

Ariel Burton
2012-09-15 10:47:34 -07:00
Arun Sharma 58db35eceb Silence a compiler error. 2012-09-08 21:41:52 -07:00
Tommi Rantala c2f7574187 Rename and share `ALIGN' macro from _UCD_internal.h
Rename the `ALIGN' macro to `UNW_ALIGN', and move it from
`_UCD_internal.h' to `libunwind_i.h' so that we can share it with the
mempool code. `ALIGN' was clashing with system headers on FreeBSD:

In file included from src/coredump/_UCD_access_reg_freebsd.c:26:
src/coredump/_UCD_internal.h:102:1: warning: "ALIGN" redefined
In file included from /usr/include/sys/param.h:115,
                 from src/coredump/_UCD_lib.h:52,
                 from src/coredump/_UCD_access_reg_freebsd.c:24:
/usr/include/machine/param.h:79:1: warning: this is the location of the previous definition
2012-09-05 14:02:36 +03:00
Tommi Rantala ee06b32975 Fix IA64 separate builddir cursor generation
IA64 build was failing when using a separate build directory. Refer to
the source files with `$srcdir' to fix the build.
2012-09-04 14:58:38 +03:00
Tommi Rantala a6f2a7a2a8 Fix incorrect .debug_frame lookup with non-zero text segment vaddr
Unwinding over ptrace and unwinding coredump fail to lookup the
.debug_frame dwarf data when the ELF file text segment virtual address
is non-zero. Looking at some binaries, the virtual address is non-zero
for non-pie binaries, and zero for PIC shared libraries and PIE
executables.

The core dump unwinder can be used for demonstrating the bug. Without
this patch, the unwinding fails badly (testing with a ARM qemu image):

 $ UNW_ARM_UNWIND_METHOD=1 ./test-coredump-unwind core `cat backing_files`
 test-coredump-unwind: unw_get_proc_info(ip=0x86d8) failed: ret=-10

After applying this patch, we can unwind all the way until running out
of dwarf data:

 $ UNW_ARM_UNWIND_METHOD=1 ./test-coredump-unwind core `cat backing_files`
     ip=0x000086d8 proc=000086d4-000086dc handler=0x00000000 lsda=0x00000000
 test-coredump-unwind: step
 test-coredump-unwind: step done:1
     ip=0x000086ef proc=000086dc-000086f2 handler=0x00000000 lsda=0x00000000
 test-coredump-unwind: step
 test-coredump-unwind: step done:1
     ip=0x000086e7 proc=000086dc-000086f2 handler=0x00000000 lsda=0x00000000
 test-coredump-unwind: step
 test-coredump-unwind: step done:1
     ip=0x00008597 proc=00008584-0000859a handler=0x00000000 lsda=0x00000000
 test-coredump-unwind: step
 test-coredump-unwind: step done:1
     ip=0x76eacc3b proc=76eacba0-76eaccec handler=0x00000000 lsda=0x00000000
 test-coredump-unwind: step
 test-coredump-unwind: step done:1
 test-coredump-unwind: unw_get_proc_info(ip=0x85c3) failed: ret=-10

Note how the binary itself is mapped to address 0x8000, the virtual
address for the text segment is 0x8000, and the .debug_frame program
counter values are relative to 0:

$ tr ' ' '\n' < backing_files
0x8000:/home/user/tests/crasher
0x76e96000:/lib/arm-linux-gnueabi/libc-2.13.so
0x76f77000:/lib/arm-linux-gnueabi/libgcc_s.so.1
0x76f88000:/lib/arm-linux-gnueabi/ld-2.13.so

$ readelf -l crasher
Elf file type is EXEC (Executable file)
Entry point 0x859d
There are 9 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  EXIDX          0x0007b0 0x000087b0 0x000087b0 0x00030 0x00030 R   0x4
  PHDR           0x000034 0x00008034 0x00008034 0x00120 0x00120 R E 0x4
  INTERP         0x000154 0x00008154 0x00008154 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.3]
  LOAD           0x000000 0x00008000 0x00008000 0x007e4 0x007e4 R E 0x8000
  LOAD           0x000efc 0x00010efc 0x00010efc 0x00148 0x00154 RW 0x8000
  DYNAMIC        0x000f08 0x00010f08 0x00010f08 0x000f8 0x000f8 RW  0x4
  NOTE           0x000168 0x00008168 0x00008168 0x00044 0x00044 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4
  GNU_RELRO      0x000efc 0x00010efc 0x00010efc 0x00104 0x00104 R   0x1

$ readelf --debug-dump=frames crasher | grep FDE
00000010 00000024 00000000 FDE cie=00000000 pc=00008614..000086d4
00000038 0000000c 00000000 FDE cie=00000000 pc=000086d4..000086dc
00000048 00000014 00000000 FDE cie=00000000 pc=000086dc..000086f2
00000060 00000014 00000000 FDE cie=00000000 pc=00008584..0000859a
2012-09-04 14:58:38 +03:00
Tommi Rantala 2aea391d6a ARM: invalidate proc info after non-dwarf unw_step()
After successfully stepping the cursor on ARM, the proc info is
invalidated only in dwarf_step(). Invalidate the proc info also when
stepping with the non-dwarf based methods. This fixes
unw_get_proc_info() returning stale data.

The core dump unwinder can be used for demonstrating the bug. When
unwinding based only on DWARF data, the proc info is correct:

$ UNW_ARM_UNWIND_METHOD=1 ./test-coredump-unwind core `cat backing_files` 2>/dev/null
    ip=0x000086d8 proc=000086d4-000086dc handler=0x00000000 lsda=0x00000000
    ip=0x000086ef proc=000086dc-000086f2 handler=0x00000000 lsda=0x00000000
    ip=0x000086e7 proc=000086dc-000086f2 handler=0x00000000 lsda=0x00000000
    ip=0x00008597 proc=00008584-0000859a handler=0x00000000 lsda=0x00000000
    ip=0x76e3ac3b proc=76e3aba0-76e3acec handler=0x00000000 lsda=0x00000000

When unwinding based only on the exidx method, we see the proc info
lagging behind:

$ UNW_ARM_UNWIND_METHOD=4 ./test-coredump-unwind core `cat backing_files` 2>/dev/null
    ip=0x000086d8 proc=000086d4-000086db handler=0x00000000 lsda=0x00000000
    ip=0x000086ef proc=000086d4-000086db handler=0x00000000 lsda=0x00000000
    ip=0x000086e7 proc=000086dc-000086f3 handler=0x00000000 lsda=0x00000000
    ip=0x00008597 proc=000086dc-000086f3 handler=0x00000000 lsda=0x00000000
    ip=0x76e3ac3b proc=00008584-0000859b handler=0x00000000 lsda=0x00000000
    ip=0x000085c3 proc=76e3aba0-76e3ae4b handler=0x00000000 lsda=0x00000000

Finally, with this patch applied, we get the desired proc info also with
the exidx unwinder:

$ UNW_ARM_UNWIND_METHOD=4 ./test-coredump-unwind core `cat backing_files` 2>/dev/null
    ip=0x000086d8 proc=000086d4-000086db handler=0x00000000 lsda=0x00000000
    ip=0x000086ef proc=000086dc-000086f3 handler=0x00000000 lsda=0x00000000
    ip=0x000086e7 proc=000086dc-000086f3 handler=0x00000000 lsda=0x00000000
    ip=0x00008597 proc=00008584-0000859b handler=0x00000000 lsda=0x00000000
    ip=0x76e3ac3b proc=76e3aba0-76e3ae4b handler=0x00000000 lsda=0x00000000
    ip=0x000085c3 proc=0000859c-00008613 handler=0x00000000 lsda=0x00000000
2012-09-04 14:58:38 +03:00
Tommi Rantala 21ad2c19ea Implement _UCD_access_reg() for ARM
Implement the Linux version of _UCD_access_reg() for ARM. We can
sidestep the register number remapping, as the libunwind register
numbers match one-to-one to the ELF core file register numbers.
2012-09-04 14:58:38 +03:00
Tommi Rantala f93e1e93be Avoid LLVM -Wunused-value warning in src/dwarf/Gexpr.c
src/dwarf/Gexpr.c:434:4: warning: expression result unused [-Wunused-value]
          pop ();
          ^~~~~~
src/dwarf/Gexpr.c:211:14: note: expanded from:
  stack[--tos];                                 \
  ~~~~~ ~~~~~^
2012-09-04 14:58:38 +03:00
Tommi Rantala fce25d74c9 Eliminate one heap allocation in dwarf_find_debug_frame()
Allocate `tab' from stack in dwarf_find_debug_frame(), as it's only a
few members and we only need it locally in the function.
2012-09-04 14:58:37 +03:00
Tommi Rantala 90d7baea35 Remove free() NULL pointer checks in load_debug_frame() error path
Just pass potentially NULL pointers to free() in the error path in
load_debug_frame(). Saved 40 bytes of code in libunwind.so on ARM -O2
thumb build at the expense of slightly slower execution.
2012-09-04 14:58:24 +03:00
Tommi Rantala a745ac2f60 PPC: return failure from the unw_get_proc_info() stub
Stop pretending that unw_get_proc_info() works on PPC, and instead give
an error back to the caller. As far as I can tell, none of the libunwind
tests clear out the `unw_proc_info_t' before passing it to
unw_get_proc_info(), so they would end up working on garbage data.
2012-09-04 13:26:13 +03:00
Tommi Rantala 8f94f1e6c0 PPC: add missing debug level in Debug() calls in Gstep.c
ppc32/Gstep.c:116: warning: comparison between pointer and integer
ppc32/Gstep.c:116: warning: comparison with string literal results in unspecified behavior
ppc32/Gstep.c:116: warning: initialization makes integer from pointer without a cast
ppc32/Gstep.c:116: warning: passing argument 2 of 'fprintf' makes pointer from integer without a cast
/usr/powerpc-linux-gnu/include/stdio.h:333: note: expected 'const char *__restrict__' but argument is of type 'int'
2012-09-04 13:26:13 +03:00
Tommi Rantala 7feb6b8575 HPPA: fix common_init() bitrot
Fix bitrot in HPPA common_init(). This has only been compile tested.

hppa/init.h: In function 'common_init':
hppa/init.h:33: error: 'struct cursor' has no member named 'ip_loc'
hppa/init.h:33: warning: implicit declaration of function 'HPPA_REG_LOC'
hppa/init.h:34: error: 'struct cursor' has no member named 'sp_loc'
hppa/init.h:36: warning: implicit declaration of function 'hppa_get'
hppa/init.h:36: error: 'struct cursor' has no member named 'ip_loc'
hppa/init.h:36: error: 'struct cursor' has no member named 'ip'
hppa/init.h:40: error: 'struct cursor' has no member named 'sp'
2012-09-04 13:26:13 +03:00
Tommi Rantala 7e5cab6dac Add missing newline to debug message in _UCD_access_reg_linux.c 2012-08-21 23:04:07 +03:00
Tommi Rantala e61c6f69c3 Fix function name duplication in Debug() output
Fix function name duplication in Debug() output that was caused by
manually prepending the debug message with the function name.
2012-08-21 23:04:07 +03:00
Tommi Rantala 5738bac171 ARM: fix with-signal-frame local unw_resume()
Make sure that the `sigcontext_addr' cursor member is pointing to the
`struct sigcontext' as expected in arm_local_resume().
2012-08-21 22:33:56 +03:00
Tommi Rantala 14fc15928b ARM: fix non-signal-frame local unw_resume() due to compiler optimization cleverness
When cross-compiling libunwind with optimizations (-O1 or higher),
gcc-4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) optimizes away the memory
writes prior to the inline asm() statement in arm_local_resume() in the
non-signal-frame path, causing the `regs' array to be only allocated on
the stack, but not populated. This means that we are restoring garbage
to the registers.

As suggested in the GCC docs, add a fixed size input memory constraint
for the array content. This is enough to get the desired code to be
generated.

Adding __builtin_unreachable() to the point that we should never reach
was also in itself enough to inhibit the optimization. It also reduces
the function size by a few instructions.
2012-08-21 22:33:56 +03:00
Tommi Rantala 5fef17c05d Fix memory leaks in unw_create_addr_space() wrong-endian error paths
Check the endianness earlier in unw_create_addr_space() on all
architectures to avoid leaking the dynamically allocated address space
struct.

This was already fixed for ARM in commit cf6a998796 ("Fix memory leak
in ARM unw_create_addr_space()"). Move the endianness check also on ARM
to avoid malloc() & free() in the error case.
2012-08-21 22:33:29 +03:00
Tommi Rantala 2d750952a5 Use constants for ELF magic bytes in _UCD_create.c 2012-08-21 22:30:47 +03:00
Tommi Rantala 7b81113721 MIPS: implement dwarf_to_unw_regnum() macro without table 2012-08-21 22:30:46 +03:00
Tommi Rantala 1dc66bd181 ARM: implement dwarf_to_unw_regnum() macro without table 2012-08-21 22:30:46 +03:00
Tommi Rantala 54a096a5af PPC: do not export dwarf_to_unw_regnum_map
dwarf_to_unw_regnum_map is internal to libunwind, and should not be
exported.
2012-08-21 22:30:46 +03:00
Tommi Rantala 80fc285599 MIPS: fix symbol naming for mips_lock', mips_local_resume', and `mips_local_addr_space_init'
Properly export the symbol names also on MIPS. `make check' was
complaining:

src/.libs/libunwind.a(Linit.o): In function `mips_local_addr_space_init':
src/mips/Ginit.c:183: multiple definition of `mips_local_addr_space_init'
../src/.libs/libunwind-mips.a(Ginit.o):src/mips/Ginit.c:183: first defined here

src/.libs/libunwind.a(Lglobal.o): In function `_ULmips_init':
src/mips/Gglobal.c:42: multiple definition of `mips_lock'
../src/.libs/libunwind-mips.a(Gglobal.o):src/mips/Gglobal.c:42: first defined here

collect2: ld returned 1 exit status
2012-08-21 22:30:46 +03:00
Arun Sharma 201bb8733d Use libtool to build libunwind-ptrace 2012-08-18 12:41:21 -07:00
Martin Milata 3d5e6c1ddd Search MiniDebugInfo for procedure names
After searching the normal symbol table, look if the binary contains
.gnu_debugdata section. If it does, run LZMA decompression on it, load
the resulting ELF image into memory and call lookup_symbol() on it
again.

lookup_symbol() is modified so that it takes min_dist as a parameter and
only returns a symbol when it finds one that is closer than indicated by
the parameter.

Signed-off-by: Martin Milata <mmilata@redhat.com>
2012-08-10 15:29:07 +02:00
Martin Milata 71c1fffc35 Refactor parts of elfxx.c to allow reusing code
Signed-off-by: Martin Milata <mmilata@redhat.com>
2012-08-10 15:29:07 +02:00
Martin Milata 7d5a197021 Add liblzma detection to configure script
Signed-off-by: Martin Milata <mmilata@redhat.com>
2012-08-10 15:07:49 +02:00
Martin Milata e11a6a4fdf Fix incorrect return code of unw_get_proc_name
The code for symbol lookup (elfxx.c:lookup_symbol) works by iterating
over symbol tables while maintaing the symbol closest to the supplied
instruction pointer. Whenever this search encountered symbol that was
longer than result buffer, the function returned -UNW_ENOMEM even though
the final symbol wasn't too long.

Signed-off-by: Martin Milata <mmilata@redhat.com>
2012-08-06 20:12:38 +02:00
Arun Sharma 814bd79fb1 Fix some compiler warnings 2012-08-04 12:48:56 -07:00
Tommi Rantala a26f1eac22 IA64: `ent' needed conditionally in Gtables.c
ia64/Gtables.c: In function '_ULia64_search_unwind_table':
ia64/Gtables.c:258: warning: unused variable 'ent'
2012-07-31 16:21:15 +03:00
Tommi Rantala 0fecf13d10 Fix --enable-debug-frame build
dwarf/Gfind_unwind_table.c: In function '_Ux86_dwarf_find_unwind_table':
dwarf/Gfind_unwind_table.c:223:46: error: 'struct elf_dyn_info' has no member named 'edi'
2012-07-31 16:21:15 +03:00
Tommi Rantala 5d36914c9b IA64: use tdep_find_unwind_table() in coredump lib
Fixup commit d93d96ad83 ("Fix compilation
on IA64"), and replace the dwarf_find_unwind_table() call with
tdep_find_unwind_table().

Fixes linkage error on IA64:
../src/.libs/libunwind-coredump.so: undefined reference to `dwarf_find_unwind_table'
2012-07-31 16:21:15 +03:00
Tommi Rantala 354b3fd45b Allow IA64 cross-compilation
Change the way we generate the cursor header files, so that we do not
need to invoke IA64 binaries, which would fail when cross-compiling
libunwind.

Adopt the strategy used in the Linux kernel build system, and parse our
annotated offset information from the assembler file produced by the
compiler.
2012-07-31 16:03:53 +03:00
Martin Milata de28c51e63 Build libunwind-coredump using libtool
So that it builds shared/pic library that can be linked with other
libraries.

Signed-off-by: Martin Milata <mmilata@redhat.com>
2012-07-04 17:01:44 -07:00
Martin Milata d93d96ad83 Fix compilation on IA64
- Add tdep macro for {dwarf,ia64}_find_unwind_table so that ia64
   doesn't try to use dwarf code.
 - Fix extraneous #if.
 - Fix mistyped filename in Makefile.am.
 - Link ia64-specific tests with correct libraries.

Signed-off-by: Martin Milata <mmilata@redhat.com>
2012-05-23 20:52:28 -07:00
Arun Sharma fa5409387c Merge branch 'coredump2' of https://github.com/adsharma/libunwind
Conflicts:
	src/ptrace/_UPT_find_proc_info.c
2012-05-23 20:51:50 -07:00
Arun Sharma dd297ea92e Revert "x86_64: unbreak test-ptrace"
This reverts commit c9c5a40be1.
dwarf_get() returns 0 on success. We should continue unwinding
in that case.

TBD: investigate test-ptrace failure on some platforms.
2012-05-18 15:24:02 -07:00