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

1898 commits

Author SHA1 Message Date
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
Arun Sharma c9c5a40be1 x86_64: unbreak test-ptrace
If dwarf_get returns 0 (indicating the end of call chain), we should
not override the return value to 1. This may result in the caller
continuing to unwind and getting spurious errors.
2012-05-16 07:49:30 -07:00
Konstantin Belousov 1a6ea3da60 freebsd: Fix boundary conditions for non-dwarf walker on x86_64.
In the commit d04dc94cc2, the check for
dwarf.ip == 0 was removed from non-dwarf walker in x86_64 version of
unw_step(). Apparently this broke the detection of the end of frame
chain when NULL %rbp is specified, because the case just marked
dwarf.ip as 0. Explicitly set ret to 0 to indicate the end of
iteration.
2012-05-14 23:18:00 -07:00
Konstantin Belousov 3bb74aae3d freebsd: Account for the possible ERESTART handling of the syscalls. 2012-05-14 23:07:52 -07:00
Konstantin Belousov 5f440b4af2 freebsd: Workaround for old FreeBSD kernels
Older kernels interpret the pid argument of the process information
sysctls as pid only. If libunwind UPT consumer passed tid to _UPT_create,
tdep_get_elf_image() returns error due to sysctls failure. Provide a
slow workaround by searching for a process owning the supplied tid if
sysctl returned ESRCH.
2012-05-14 23:07:52 -07:00
Konstantin Belousov f8858bacca freebsd: Fix logic error
When encountered vm map entry is not backed by a vnode, continue search
for matching entry instead of aborting the loop.
2012-05-14 23:07:51 -07:00
Konstantin Belousov 0fac4c8109 freebsd: Consistently use symbolic name UNW_EUNSPEC for errors 2012-05-14 23:07:51 -07:00
Jiri Olsa 69e300e8f6 dwarf: Get correct return from expression evaluation
Currently the expression evaluation always succeeds,
and possible error is not propagated to the caller.

The ',' operator makes the condition always return 0.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2012-04-16 07:13:54 -07:00
Arun Sharma cbc66b62c0 mips: fix a linker error
Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
2012-04-09 19:48:49 -07:00
Arun Sharma 9507a9b501 ia64: move ia64 specific code out of dwarf
We still need to fixup the callers to pick dwarf_find_unwind_table
vs ia64_find_unwind_table in a target dependent way.
2012-03-29 11:35:26 -07:00
Arun Sharma bc056ffc9f coredump: update license to be the same as rest of libunwind
Per Denys Vlasenko <dvlasenk@redhat.com>:

Sure. It's a trivial file, I don't mind if you use
whatever license you like on it :)
2012-03-26 19:07:58 -07:00
Alexander Larsson edcc521a0e Add helper macros for pointer arithmetics
ALIGN lets you align pointers and STRUCT_MEMBER lets you get
structure members at a specific offset.

These are useful in general, and will be needed for the coredump notes
cleanup work.
2012-03-26 19:04:01 -07:00
Alexander Larsson b1393b7e63 Clean up the elf notes handling in the coredump code
We centralize the elf notes handling code in some macros, thus
simplifying the loops over the notes and avoiding code duplication.
2012-03-26 18:59:49 -07:00
Arun Sharma 49ca8b6a3e ia64: remove references to an out of scope local
This causes problems with gcc-4.7

Signed-off-by: Joel Brobecker <brobecker@adacore.com>
2012-03-26 18:54:53 -07:00
Arun Sharma 5e59e93d04 dwarf: introduce a valid bit for dwarf_reg_state_t
Without this, cache_match() returns true when (ip == 0).
2012-03-25 18:33:40 -07:00
Arun Sharma d04dc94cc2 dwarf: ip == 0 should't terminate unwind 2012-03-25 18:10:10 -07:00
Arun Sharma 43e5ee28c0 Demote the debug level to reduce verbosity 2012-03-25 17:44:53 -07:00
Arun Sharma 0628a9872c Whitespace cleanup 2012-03-23 22:34:42 -07:00
Alexander Larsson 0c0ea23cf2 Add support for multiple threads in core files
_UCD_select_thread() lets you select the active thread from
the core file and _UCD_get_num_threads() tells you how many there are.
2012-03-23 22:07:17 -07:00
Alexander Larsson d627481783 Break out the ifdefs for the UCD_info.prstatus type
This cleans up the code a bit and makes it easier to refer to
the prstatus type in other places.
2012-03-23 22:07:14 -07:00
Alexander Larsson b9ff650a22 Add _UCD_get_pid and _UCD_get_cursig
These let you get the pid and the current signal from the coredump.

This isn't strictly unwind related, but these are trivial to implement
as we have the info, and you almost always want these when you're
printing a backtrace from a core file.
2012-03-23 22:07:11 -07:00
Alexander Larsson adbeb79155 Fix build with --enable-debug
This just fixes a typo
2012-03-23 22:07:07 -07:00
Kostik Belousov cc7c74e691 On FreeBSD, the structure is called prstatus. 2012-03-13 18:15:39 +02:00
Kostik Belousov dc9be1a97a Implement register read for FreeBSD coredumps.
Rename _UCD_access_reg.c to _UCD_access_reg_linux.c, to have
per-OS coredump register reader.
2012-03-13 14:00:01 +02:00
Kostik Belousov 1e6959a769 Shut down compiler warning about format mismatch. 2012-03-13 13:17:07 +02:00
Kostik Belousov e8eb583450 Handle byteswap.h and endian.h inclusion. 2012-03-13 13:09:25 +02:00
Arun Sharma f0bb806ecb Move the test case to tests dir. 2012-03-12 20:11:49 -07:00
Arun Sharma 0f17b52171 Fixup regnames on x64 2012-03-12 20:11:49 -07:00
Arun Sharma b08ae72d6c Add support for unwinding coredump images
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2012-03-12 20:11:08 -07:00
Arun Sharma d276b7a961 Introduce get_proc_name_in_image()
This is similar to get_proc_name() but takes an already mapped
image.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2012-03-12 20:09:18 -07:00
Arun Sharma 6525714c27 Move some dwarf functionality from ptrace to dwarf
Move ptrace-independent code from src/ptrace/_UPT_find_proc_info.c
to src/dwarf/{G,L}find_unwind_table.c. Name this moved function
dwarf_find_unwind_table().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2012-03-12 20:06:37 -07:00
Arun Sharma 25ee9f8172 Introduce struct elf_dyn_info
This is a common part of struct UPT_info
and struct UCD_info (to be introduced later).
Make _UPTi_find_unwind_table function operate only on this part
of struct UPT_info.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2012-03-12 20:04:19 -07:00
Arun Sharma 3d08506936 Fix undefined symbol: _Uelf64_valid_object
Without this change, we end up building libunwind-${arch}.a with
missing symbols.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2012-02-12 19:53:38 -08:00
Konstantin Belousov 59328832f7 Provide the FreeBSD implementation for _UI_siglongjmp_cont on x86.
On FreeBSD, _NSIG is at least 128, so just pass a pointer to the
signal mask in the register.
Add my copyright.
2012-02-05 11:47:47 +02:00
Konstantin Belousov 1774384098 FreeBSD also supports PT_GNU_STACK. 2012-02-05 11:42:02 +02:00
Konstantin Belousov 29dae2171e Style. 2012-02-05 11:40:17 +02:00
Tommi Rantala 51445f61d3 ARM: fix unwind table search when IP less than first table entry
Properly return error when searching for unwind table entry for an IP
that is less than the first available table entry.
2012-02-01 07:57:15 -08:00
Tommi Rantala ec4b23bf70 ARM: fix off-by-one in exidx VFP pop
The range of VFP registers we need to pop is inclusive.
2012-01-24 20:43:55 -08:00
Tommi Rantala 458c661be7 Fix libunwind-generic.so symbolic link never being created in make install
Commit 7d43108f9c ("No
libunwind-generic.so if configured with --disable-shared") introduced a
check to avoid creating a broken libunwind-generic.so link, but the
result of the commit is that libunwind-generic.so is never created (at
least when installing to a clean directory).

We need to check for the installed libunwind-$(arch).so file,
libunwind-generic.so will be the symbolic link name.
2012-01-23 07:38:59 -08:00
Arun Sharma 52ca68c770 Fix a race condition
There is a window of time between the munmap and the tls_cache being
marked as destroyed, where there could be a bad access to memory that
has been unmapped/freed. Reorder the code a bit to close the window.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-12-16 10:45:51 -08:00
Arun Sharma cf2f3d3b75 Correct the inverted check
Typo when manually applying the previous commit.
2011-12-02 08:35:00 -08:00
Arun Sharma 2f328202ee Fix a compiler warning
Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-12-01 22:08:08 -08:00
Konstantin Belousov 2b606faa21 Fix compilation on non-glibc machines.
Commit 297d9cd07d (Fix for failing test-setjmp)
breaks non glibc systems, since __GLIBC_PREREQ is not defined there.
As a consequence, preprocessor aborts with an error.

Trying to hide __GLIBC_PREREQ under #ifdef __GLIBC would require
either code duplication, or moving the longjmp implementation into
the separate file, which is included twice. In fact, I am not sure
in any use of the __GLIBC_PREREQ at the compile time, because the
compiled code can be run on the later version of glibc.

Below is the patch, tested on FreeBSD x86/x86_64 and Scientific Linux 6.1
x86_64. I compile the code always, but keep it in under unused static
symbol. In principle, the code could be optimized out by linker.

[ Minor formatting edits: asharma@fb.com ]
2011-11-30 21:59:09 -08:00
Arun Sharma 1010880548 Address x86_64 crashes when using sigaltstack
The crashes were tracked down to f->rpb_cfa_offset being incorrect.

The problem is that {rsp,rbp}_cfa_offset only have 15 bits, but for
SIGRETURN frame they are filled with:

// src/x86_64/Gstash_frame.c

   f->cfa_reg_offset = d->cfa - c->sigcontext_addr;
   f->rbp_cfa_offset = DWARF_GET_LOC(d->loc[RBP]) - d->cfa;
   f->rsp_cfa_offset = DWARF_GET_LOC(d->loc[RSP]) - d->cfa;

The problem is that the delta here can be arbitrarily large when
sigaltstack is used, and can easily overflow the 15 and 30-bit fields.

When signal handler starts running, the stack layout is:

 ... higher addresses ...
        ucontext
 CFA->
        __restore_rt (== pretcode in rt_sigframe from
                      linux-2.6/arch/x86/include/asm/sigframe.h)
 SP ->
       ... sighandler runs on this stack.

 ... lower addresses ...

This makes it very convenient to find ucontext from the CFA.

Attached patch re-tested on Linux/x86_64, no new failures.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Reviwed-by: Lassi Tuura <lat@cern.ch>
2011-11-27 18:34:38 -08:00
Paul Pluzhnikov 297d9cd07d Fix for failing test-setjmp
On Mon, Nov 14, 2011 at 5:02 PM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:

> P.S. test-setjmp is failing for me (before or after the patch).
> When I enable assertions (to confirm my new assertions are correct), I see:
>
>  lt-test-setjmp: ../../src/dwarf/Gparser.c:754: apply_reg_state: \
>    Assertion `rs->reg[17].where == DWARF_WHERE_EXPR' failed.
>
> which likely explains that failure.

The problem is actually two-fold:

First, the loops in {sig,}longjmp.c are "do { ... } while (unw_step() >= 0);"

But unw_step() returns 0 on reaching the end of the chain (_start),
and the loop should stop there.

The second problem is that with this commit:
  c67da0b50e
glibc obfuscates value of SP in jmp_buf, so we might as well just give up.

Patch attached.

Thanks,
--
Paul Pluzhnikov
2011-11-19 15:37:35 -08:00
Ken Werner d84e5d5d24 Call dwarf_step only if CONFIG_DEBUG_FRAME is defined
The ARM EABI does not use the .eh_frame and .eh_frame_hdr sections for unwinding. Therefore it doesn't make sense to call dwarf_step if CONFIG_DEBUG_FRAME is not defined.
2011-11-19 15:37:23 -08:00
Arun Sharma 786882ff8c Remove unused variable segbase 2011-11-12 10:02:09 -08:00
Ken Werner 1e644990c9 Only declare the start/end variables in case CONFIG_DEBUG_FRAME is defined.
Prevents compiler warnings about unused variables.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-11-12 09:47:12 -08:00
Ken Werner 25aeae9adf Fix breakage when host != target
Define the sigreturn syscall numbers instead of including on <sys/syscall.h>.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-11-03 08:24:18 -07:00
Arun Sharma d20df8b318 Fix up the breakage when host != target 2011-10-31 22:33:47 -07:00
Arun Sharma 851f14281c Fix some compiler warnings 2011-10-29 17:18:49 -07:00
Ken Werner 0eba2169fb [ARM] Add support for systems that don't support ucontext.h
Define unw_tdep_context rather than using ucontext_t in order to support
systems that lack ucontext.h. Note that POSIX.1-2008 removed getcontext,
makecontext and swapcontext from its specification.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-10-29 17:12:43 -07:00
Ken Werner 059676cb00 Prevent the use of struct dl_phdr_info outside of dl_iterate_phdr
Since the dl_iterate_phdr is required for local unwinding only the use of
struct dl_phdr_info can be eliminated in case libunwind gets compiled for
remote unwinding. This enhances libunwinds portability to targets that
don't provide any dl_iterate_phdr functionality.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-10-29 17:12:43 -07:00
Ken Werner 0fed502a81 UNW_REMOTE_ONLY fixes
Exclude <link.h> because it is only required for local unwinding when
iterating over the program headers.

Have the following DWARF related functions available in case of
UNW_REMOTE_ONLY because they are used by libunwind-ptrace:
  dwarf_find_debug_frame
  locate_debug_info
  find_binary_for_address
  load_debug_frame
  debug_frame_tab_new
  debug_frame_tab_append
  debug_frame_tab_shrink
  debug_frame_tab_compare

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-10-29 17:12:43 -07:00
Arun Sharma 0a26727ea2 Fix TLS destructor ordering problems
Glibc calls thread-specific dtors in the order in which the keys were added,
so the first dtor is the trace_cache_free() one. Then thread-specific
data for some other key is free()d, which calls into unw_backtrace(),
which uses dangling cache and munmapped cache->frames.

[ Minor rename + compiler warning fix: asharma@fb.com ]
Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-10-29 17:12:36 -07:00
Arun Sharma 08077a4962 pthread_once() workaround for FreeBSD and Solaris
On FreeBSD, as well as on the Solaris < 10, weak pthread_once stub is
always exported from libc. But it does nothing, which means that if
threaded library is not loaded, then pthread_once() call do not actually
call the initializer finction. The construct
  if (likely (pthread_once != 0))
  {
    pthread_once(&trace_cache_once, &trace_cache_init_once);
then fails to initialize the trace cache on x86_64.

Work around by checking that the initializer was indeed called.
Note that this can break if libthr is loaded dynamically, but my belief
is that there is no platforms which allow dynamic loading of the threading
library.
2011-10-29 16:53:30 -07:00
Ken Werner 7f41e701e3 Have tdep_get_elf_image available in case of UNW_REMOTE_ONLY
Because it gets used by libunwind-ptrace.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-10-15 23:10:28 -07:00
Ken Werner da4743f52a Exclude arm_find_proc_info and arm_put_unwind_info in case of UNW_REMOTE_ONLY
Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-10-15 23:10:28 -07:00
Ken Werner 197571915c Change _UPTi_find_unwind_table to return an integer.
This keeps the definition on IA64 and all the other architectures in sync with
the declaration of _UPTi_find_unwind_table. This also mimics the behaviour of
what's done for local unwinding and allows the function to provide more than
one way to undwind.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-10-15 23:10:27 -07:00
Arun Sharma c4133e879b undef FORTIFY_SOURCE
It's a bit annoying to undefine at configure or compile time.

Signed-off-by: Arun Sharma <asharma@fb.com>
2011-10-15 23:10:00 -07:00
Arun f89fb17695 Fix incorrect calls to memset.
Found when compiling libunwind with clang.

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
2011-10-02 22:43:28 -07:00
Arun Sharma 962366dace Fixup compile errors on ia64.
Suggested-by: Harald Servat <harald.servat@bsc.es>
2011-09-23 11:11:34 -07:00
Arun Sharma ac0acd06f3 Bump up the library version 2011-09-10 19:57:59 -07:00
Arun Sharma 00abb7c056 Reorder libraries in lib_LTLIBRARIES
This fixes a make install time problem.
2011-09-05 10:46:14 -07:00
Ken Werner 92327a3647 ARM: prefer to unwind using DWARF info
In case the user doesn't specify whether to unwind using the ARM specific
unwind tabler or DWARF info libunwind should prefer the latter. Since DWARF
expressions are more powerful than the ARM specific unwind tables
arm_find_proc_info is changed to check for DWARF first.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-29 17:58:52 +02:00
Ken Werner 912db91b05 ARM: Exit unw_step in case DWARF based unwinding was successful
Prevents unw_step from trying to unwind the stack using the ARM specific
unwind tables in case the DWARF based unwinding was successful.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-29 17:58:52 +02:00
Ken Werner 112c927371 ARM: Ensure unw_step returns whatever find_proc_info() returns
This allows the test-proc-info test case to pass on ARM.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-17 14:32:32 +00:00
Ken Werner 93e64550ac ARM: Fix return value of arm_find_proc_info
Initialize the return value with -1 in order prevent arm_find_proc_info from
returning zero. This could happen in case the environemtn variable
UNW_ARM_UNWIND_METHOD doesn't allow exidx and/or dwarf unwinding.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-17 14:14:48 +00:00
Ken Werner d83846f120 ARM: Initial support for remote unwinding using libunwind-ptrace
Change _UPTi_find_unwind_table to also look for the ARM specific unwind
information. Adjust the ARM unwind code to read memory using the accessor
routines.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-15 20:12:54 +02:00
Ken Werner b317cb4829 Change libunwind-ptrace to also look for .debug_frame if nothing found in .eh_frame.
This changes the behavior of libunwind-ptrace to what we do for local
unwinding.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-15 20:12:54 +02:00
Ken Werner 545023c207 Rework the lookup of the ARM specific unwind info
Implement routines for finding the proc_info and searching the unwind table
for the ARM backend.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-15 20:12:54 +02:00
Ken Werner 0b9f591823 Make the dwarf dl_iterate_phdr callback available within libunwind.
Rename the dwarf dl_iterate_phdr callback routine and the callback_data
structure to dwarf_callback and dwarf_callback_data. Make it available
within libunwind by declaring the two at the dwarf.h header file.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-08-15 20:12:54 +02:00
Ken Werner 25f6b8295d Change address type from void* to unw_word_t.
Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-07-28 11:10:02 +00:00
Ken Werner b28335b5a5 Fix inline assembly.
Remove the third colon if the clobber list is not present.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-06-30 12:36:44 +02:00
Arun Sharma e09f9701ff Handle register nums > 16 on x86_64
gcc generates them when using ms-abi. Support disabled by
default since it increases the cache footprint of the library.
2011-06-18 20:48:49 -07:00
Joel Brobecker 7d43108f9c No libunwind-generic.so if configured with --disable-shared
Installing a libunwind that was configured with --disable-shared
results in a broken libunwind-generic.so link. This patch avoids
this broken link.
2011-06-18 19:50:39 -07:00
Joel Brobecker ea7160a841 Remove unintended semi-colon in os-hpux.c fun definition
Probably a copy/paste error... This showed up on ia64-hpux.
2011-06-18 19:50:35 -07:00
Joel Brobecker 8d991d9258 Fix call to maps_next in _UPT_get_dyn_info_list_addr.c
A previous change reduced the number of arguments that this function
tasks, but one call at least did not get updated, resulting in a build
failure on ia64-linux.  This patch fixes it.
2011-06-18 19:50:31 -07:00
Joel Brobecker e003e44a37 Check for <sys/ptrace.h> before including it
On ia64-hpux version 11.31, <sys/ptrace.h> has been removed.
This patch adds a configure check for this header file, and only
includes <sys/ptrace.h> if it exists.
2011-06-18 19:50:28 -07:00
Lassi Tuura d2525ec936 Use single level hash table for fast trace. 2011-05-06 22:09:07 -07:00
Lassi Tuura 5c2cade264 Inline access to initial register values as it's known to be safe. 2011-05-06 20:19:36 -07:00
Ken Werner 36511d3d1f Add support for handling signal frames on ARM Linux.
This patch add support for resuming at a certain stack frame even if signal
frames are involved. For restoring the registers the trampoline (sigreturn)
is used. RT and non-RT signal frames are handled for both >=2.6.18 and
<2.6.18 kernels.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-05-03 20:18:40 +02:00
Ken Werner 9533ea1a6a Add support for RT signal frame detection on ARM.
This patch adds a few more patterns to the check that detects if the IP
points to a sigreturn sequence.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-05-03 20:18:33 +02:00
Ken Werner 1e10c2931d Add initial support for local unw_resume on ARM Linux.
Provides basic support for resuming execution at a certain stack frame.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-04-21 17:25:42 +02:00
Lassi Tuura ae5c1f2adf Performance optimisations for fast trace.
Insert static branch prediction predicates in useful places and avoid
unnecessary code in the hottest paths. Bypass unnecessary indirect
calls, in particular to access_mem(), when known to be safe.
2011-04-17 20:34:38 -07:00
Arun Sharma e2962af9d3 Implement a cheaper getcontext()
Since the fast unwinding code path doesn't need the full context,
a faster target dependent getcontext is implemented.

Signed-off-by: Lassi Tuura <lat@cern.ch>
2011-04-05 22:07:05 -07:00
Arun Sharma 15f182828d Use __thread instead of pthread_getspecific() 2011-04-05 22:06:51 -07:00
Ken Werner fd21d07fe4 Create a generic and local variant of the extbl parser.
In order to have the DWARF_* macros working properly a generic and a local
variant of the ex_tables.c have been created.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-04-05 20:59:10 -07:00
Lassi Tuura 5f38f35d5d Drop a call frame in tdep_trace and avoid a call to unw_step.
Dropping the extra frame for unw_backtrace itself using unw_step is
approximately 15% slower than skipping the frame in tdep_trace.  So
drop the frame in the latter, and make the function a private
implementation detail for libunwind, not an exported interface.

Also moves unw_getcontext call back into unw_backtrace to avoid an
extra call frame in case slow_backtrace does not get inlined into
unw_backtrace.
2011-04-01 00:00:39 -07:00
Lassi Tuura 50bc12afba Export unw_backtrace() and alias backtrace() to it. 2011-04-01 00:00:33 -07:00
Arun Sharma 2f9b04e9c2 Mark slow_backtrace() ALWAYS_INLINE
Also fix Makefile.am so remote unwinding tests such Gtest-trace
don't link with the local unwind library (libunwind.a).
2011-03-31 22:58:07 -07:00
Lassi Tuura 3b9fd99cb7 Assign copyright as requested by the author. 2011-03-25 00:20:49 -07:00
Lassi Tuura f1ea02be58 Reset 'used' to zero after expanding frame cache hash table. 2011-03-25 00:20:48 -07:00
Arun Sharma 7ff83c051e Fix up compilation and test failures 2011-03-24 23:32:25 -07:00
Lassi Tuura 44a14d1364 Integrate fast trace into backtrace(). 2011-03-24 22:33:55 -07:00
Lassi Tuura 9e98f15e9a Fast back-trace for x86_64 for only collecting the call stack.
Adds new function to perform a pure stack walk without unwinding,
functionally similar to backtrace() but accelerated by an address
attribute cache the caller maintains across calls.
2011-03-24 22:33:17 -07:00
Lassi Tuura 28f33c8ce0 Auto-detect whether to use msync() or mincore() for address validation. 2011-03-24 21:02:28 -07:00
Ken Werner 0f9937485e ARM: Return the dwarf.cfa in case the user requests SP/R13.
Usually we don't have a valid location for the SP but we keep calculating
the value of the CFA. The ARM backend should return this value instead.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-24 20:44:33 -07:00
Ken Werner f053677198 Remove the ARM_EXIDX_TABLE_MALLOC code path.
Using malloc is not an option since unw_init_local and unw_step are supposed
to be async signal safe. Therefore this code path can be removed.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-24 20:44:33 -07:00
Ken Werner 6296ff1fb2 Remove the appname string of the ARM extbl parser.
There is no need for libunwind to set/fake a name of the elf file from which
the program header came from.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-24 20:44:33 -07:00
Ken Werner dcb8d0d90f Prefer to unwind using DWARF info on ARM.
DWARF expressions are more powerful than the ARM specific unwind tables.
Therefore DWARF should be the preferred unwind method.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-24 20:44:33 -07:00
Ken Werner fb325c895e ARM extbl cleanup.
Move code that does not necessarily need to reside in the ex_tables.h header
file into ex_tables.c. Add comments and remove unused code.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-24 20:44:25 -07:00
Ken Werner cf8d5e41af Have the ARM extbtl-parser operate on the DWARF model directly.
This eliminates the arm_stackframe and therefore the need to synchronize the
two models. It also clears the way for unwinding call stacks with mixed
DWARF- and extbl-frames.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-24 20:42:00 -07:00
Konstantin Belousov 04fc88fa31 Fix build and distribution on the FreeBSD.
Signed-off-by: Konstantin Belousov <kostikbel@gmail.com>
2011-03-24 20:41:07 -07:00
Arun Sharma 0613d4c680 Fixup trailing whitespace
Signed-off-by: Arun Sharma <asharma@fb.com>
2011-03-22 08:40:49 -07:00
Zachary T Welch 6a67154674 Use ARM-specific unwinding tables in unw_step
Uses ex_tables routines to provide a new means of unwinding the stack.
Set UNW_ARM_UNWIND_METHOD=4 to use ARM-specific unwinding tables.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-22 08:14:58 -07:00
Zachary T Welch ffc474b8c8 Add module for parsing ARM-specific unwind tables
Handles lookup, extracting unwind entries, and decoding the entry
using a callback mechanism.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-22 08:14:51 -07:00
Zachary T Welch 049e2ba1b9 Add ARM signal frame detection
Implements a check for call to sigreturn that the kernel will have
setup before jumping to the signal handler.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-22 08:14:45 -07:00
Zachary T Welch 6a072982dd Fix file descriptor leakage in maps_init
If mmap fails, be sure to close the maps file before returning an error.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-07 21:24:51 -08:00
Ken Werner 4a89b88fd3 Link libunwind-setjmp against libunwind-elf.
This prevents the linker from complaining about a missing symbol when
building the test-setjmp test case.

Signed-off-by: Ken Werner <ken.werner@linaro.org>
2011-03-07 21:24:51 -08:00
Arun Sharma 516304a557 Revert "Use more convenience libraries"
Breaks make check on both x86 (32 and 64 bit)

This reverts commit af88cab09f.
2011-02-01 20:37:25 -08:00
Arun Sharma a83e96cc1c Some entries in /proc/<pid>/maps are not ELF files, so add check
in elf_map_image() to ensure mapped files have a valid ELF header.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
Signed-off-by: Arun Sharma <asharma@fb.com>
2011-01-23 17:55:55 -08:00
Zachary T Welch 5007f8c794 Improve ELF valid_object() helper
Ensures the ELF header version is valid.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2011-01-23 17:21:04 -08:00
Zachary T Welch af88cab09f Use more convenience libraries
Eliminates obfuscating variables in favor of adding files directly
to library SOURCES.  Eliminates the need for EXTRA_DIST variable.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-29 11:29:01 -08:00
Zachary T Welch ce847afb3b Build ELF convenience libraries
Rather than building the sources directly, create a library that
gets linked statically into libunwind.la and libunwind-$(arch).la.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-29 11:28:57 -08:00
Zachary T Welch 02dd6c468a Use noinst_HEADERS for distributing .h files
Header files should be listed in a HEADERS automake declaration
rather than in the SOURCES.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-29 11:28:54 -08:00
Zachary T Welch 9de666d141 Simplify DWARF source handling
Build DWARF source files into automake convenience libraries to
eliminate duplication in arch-dependent library build rules.
Adds a configure-time check to determine whether to use them.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-29 11:28:51 -08:00
Zachary T Welch b07829bedd Simplify LIBRARIES and LTLIBRARIES automake rules
Use automake's '+=' to eliminate obfuscation.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-29 11:28:47 -08:00
Zachary T Welch 64a827603c Simplify libunwind_setjmp automake rules
Eliminate redundant listing of libunwind_setjmp source files by
using automake's '+=' operator.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-29 11:28:44 -08:00
Zachary T Welch 651e9bb4fd Add MAINTAINERCLEANFILES to Makefile.am files.
Ensures 'make maintainer-clean' removes files generated by autotools.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-08 09:06:09 -08:00
Zachary T Welch cf6a998796 Fix memory leak in ARM unw_create_addr_space()
Frees newly created address space memory in the event of a failure
caused by an endian mismatch.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
2010-11-08 09:03:34 -08:00
Sven Neumann 7909c71e5d [PATCH] Add files to EXTRA_DIST so that 'make dist' works again 2010-08-04 14:26:39 -07:00
Arun Sharma 99e60be5a4 Fix the page boundary crossing bug.
Signed-off-by: Jason Evans <jasone@canonware.com>
2010-06-08 14:44:07 -07:00
Konstantin Belousov b3757e7792 Restore the linking when --enable-debug-frame is not specified 2010-05-29 01:07:40 +03:00
Arun Sharma 00aed9631b Add an experimental and optional frame chain unwinding for ARM
The environment variable UNW_ARM_UNWIND_METHOD controls the unwind method.

1 - debug_frame unwinding
2 - frame chain unwinding,
3 - 1 & 2 (default))

Signed-off-by: Andris Zeila <andris.zeila@accenture.com>
2010-05-26 19:28:44 -07:00
Arun Sharma 46e10c5abe Support .debug_frame based unwinding in _UPTi_find_unwind_table()
Signed-off-by: Andris Zeila <andris.zeila@accenture.com>
2010-05-26 19:25:41 -07:00
Arun Sharma 546463d1e7 Factor out and export dwarf_find_debug_frame() function
Signed-off-by: Andris Zeila <andris.zeila@accenture.com>
2010-05-26 19:21:30 -07:00
Konstantin Belousov 298e575f2c Fix freebsd build 2010-05-17 21:57:59 +03:00
Arun Sharma 8ee7b1762e Add ip argument to _UPTi_find_unwind_table.
Signed-off-by: Andris Zeila <andris.zeila@accenture.com>
2010-05-15 12:15:49 -07:00
Arun Sharma 1787a2fd28 Add path and pathlen arguments to tdep_get_elf_image()
Signed-off-by: Andris Zeila <andris.zeila@accenture.com>
2010-05-15 12:14:09 -07:00
Arun Sharma b115ab645a Ignore separate debug files which contain a .gnu_debuglink section.
Current implementation fails to find separate debug symbols when
.gnu_debuglink is set to the same name of the target ELF basename
(e.g. "libc.so.6" for /lib/libc.so.6). This patch fixes this by ignoring
separate debug files that contain a .gnu_debuglink section.

It also fixes a small typo in a related Debug() line.

Signed-off-by: Andris Zeila <andris.zeila@accenture.com>
2010-05-15 11:57:35 -07:00
Arun Sharma 66b7335ff3 Adds missing register offsets for ARM
Signed-off-by: Andris Zeila <andris.zeila@accenture.com>
2010-05-15 11:56:37 -07:00
Konstantin Belousov e1493dc011 Merge branch 'master' into freebsd 2010-05-03 17:59:50 +03:00
Arun Sharma aa3bb307a3 Fix merge errors 2010-05-03 07:47:41 -07:00
Konstantin Belousov c84005e9c8 Add unwind annotations for freebsd/x86 getcontext.S.
Rearrange the code to put the slow branch out of main body,
and pinch the fixed amount of stack space to be able to annotate
the code.
2010-05-02 17:06:24 +03:00
Konstantin Belousov b73c618a31 Merge branch 'master' into freebsd 2010-05-02 16:29:02 +03:00
Arun Sharma 0176c4f723 Merge commit 'fdc534ccb05d1e6c0438345d292203343a811701' 2010-04-28 17:27:38 -07:00
Arun Sharma fdc534ccb0 Silence a compiler warning 2010-04-28 16:38:27 -07:00
Arun Sharma 215afa30b7 Add unwind descriptors to getcontext.S 2010-04-28 16:32:30 -07:00
Arun Sharma c140d8598d Undo commit f252f5ff4e for now.
Seems to introduce a couple of test breakages.
2010-04-25 09:44:59 -07:00
Arun Sharma d3c4bc4295 Fix a compiler warning 2010-04-25 09:24:40 -07:00
Lassi Tuura 045c55b2a2 Be conservative in all pointer derefrences by default.
Since most people can't completely control their compile or runtime
environment, it becomes hard to ensure that unwind data is perfect.
2010-04-24 19:24:49 -07:00
Lassi Tuura d4fbc8326a Detect end of stack in x86-64 rbp-based walk. 2010-04-24 19:22:08 -07:00
Lassi Tuura 92cc7fd78a Remove obsolete code for 'old way' of handling x86-64 signal frames. 2010-04-24 19:21:52 -07:00
Lassi Tuura f252f5ff4e Recognise and unwind through PLT. 2010-04-24 19:21:26 -07:00
Lassi Tuura a9dce3c06e During the stack unwinding process, the return address points to
the instruction after the call for a normal frame. libunwind uses
IP-1 to lookup unwind information. However, this is not necessary for
interrupted frames such as signal frames (or interrupt frames) in
the kernel context.

This patch handles both cases correctly.

Based on work by Mark Wielaard <mwielaard@redhat.com>
2010-04-24 19:16:09 -07:00
Lassi Tuura 4c553ceb2c Identify end-of-stack by undefined return address location. 2010-04-24 17:18:31 -07:00
Lassi Tuura dac2d001af Identify signal frames by augmentation attribute. 2010-04-24 17:18:26 -07:00
Lassi Tuura 250382c56d Use wider format when printing addresses in debug format. 2010-04-24 17:18:19 -07:00
Konstantin Belousov 58f290e1ce Add config.h. 2010-04-21 15:43:05 +03:00
Konstantin Belousov 2709abc883 msync() also may be called on unaligned address. 2010-04-21 15:33:37 +03:00
Konstantin Belousov 4454413242 Account for possible unaligned access. 2010-04-21 15:18:02 +03:00
Konstantin Belousov ee99dbec87 Use mincore instead of msync when available 2010-04-20 17:45:18 +03:00
Konstantin Belousov 75b76d1f45 Save FPU context for i386. 2010-04-17 00:18:33 +03:00
Konstantin Belousov b1c68e060c Arrange the FreeBSD ucontext offset definitions in ascending order. 2010-04-17 00:17:58 +03:00
Giuseppe Scrivano a67654e86f [PATCH] Reduce scope of the eh_frame_end local variable 2010-04-14 12:11:29 -07:00
Arun Sharma 1d9c5a356d Fix compiler warnings on x86_64 Linux 2010-04-14 12:01:37 -07:00
Arun Sharma 5a70fab451 Fix compiler warnings on x86 Linux 2010-04-14 18:54:20 -07:00
Konstantin Belousov 127acf8e97 Use correct offset name and value for ucontext offset in struct sigframe 2010-04-14 12:15:05 +03:00
Konstantin Belousov 0d311ea161 Add abort() after sigreturn calls 2010-04-14 12:10:34 +03:00
Konstantin Belousov 34b064bf22 Fix typo. 2010-04-14 12:10:14 +03:00
Konstantin Belousov 1e77c66a51 Fix FreeBSD/x86_64 sigcontext restore 2010-04-14 12:04:28 +03:00
Konstantin Belousov 61f4345a9e Fix an issue where len was too short for sysctl to recieve the process
vm map.
2010-04-13 15:33:11 +03:00
Konstantin Belousov 02d0cb6f71 Do not save FPU context on x86 for now; XMM save area must be 16-bytes aligned 2010-04-13 14:20:22 +03:00
Konstantin Belousov ae7eebb839 Separate getcontext implementation for x86 2010-04-13 14:11:39 +03:00
Konstantin Belousov 66e49bdd41 Save %eax for i386 2010-04-13 13:55:23 +03:00
Konstantin Belousov 5a7407dd94 Merge branch 'master' into freebsd 2010-04-12 22:34:24 +03:00
Arun Sharma c2d78041cc GCC compatibility on x86 for C++ exception handling 2010-04-12 12:08:43 -07:00
Giuseppe Scrivano eb8857a324 Silence a compiler warning 2010-04-12 10:45:31 -07:00
Konstantin Belousov 843190597c Remove unneeded include.
Noted by:	Arun Sharma
2010-04-11 22:07:31 +03:00
Konstantin Belousov 21f0e90ce8 Rework 69001646fa, store sigframe address into sigcontext_addr. 2010-04-11 22:01:08 +03:00
Konstantin Belousov 42bc15c72c Provide proper register offsets in the gregset for FreeBSD/i386 2010-04-11 19:18:07 +03:00
Konstantin Belousov f10f851916 Add slightly more debug output 2010-04-11 14:59:36 +03:00
Konstantin Belousov e33fa9f73c Ditch using the libutil, it is not async-signal safe. 2010-04-11 14:36:24 +03:00
Konstantin Belousov 69001646fa Store the ucontext_t pointer to properly handle resume across signal frames. 2010-04-11 13:48:14 +03:00
Konstantin Belousov f01a043712 Convince gcc that x86_64_sigreturn cannot return, as declared. 2010-04-11 13:47:28 +03:00
Konstantin Belousov a688d6c4c9 Remove unused variable. 2010-04-10 18:51:17 +03:00
Konstantin Belousov dd1c7b6c1a Declare mxcsr as XMM 2010-04-10 18:48:35 +03:00
Konstantin Belousov 53f7e650e0 For FreeBSD/i386, add real offset values for FPU context fields. 2010-04-10 18:48:16 +03:00
Konstantin Belousov 6f7b335e89 Add my copyrights to several files that contain essential modifications 2010-04-10 01:42:26 +03:00
Konstantin Belousov 9fe75c7d93 Save FPU state when saving context. For XMM-capable CPUs only (for now). 2010-04-10 00:47:08 +03:00
Konstantin Belousov 117ccd246d Move all XMM offsets into one place. 2010-04-10 00:46:51 +03:00
Konstantin Belousov f6546e27ed Implement the base code to fetch x86/xmm state on x86. Offsets to be filled. 2010-04-10 00:40:39 +03:00
Konstantin Belousov 2c50c95cde Correct arguments for Debug().
Shut up warning by using the cast.
2010-04-10 00:38:54 +03:00
Arun Sharma d1676f192e Fix warnings on 32 bit x86 2010-04-08 03:12:05 -07:00
Arun Sharma caa6095aec Fix compile errors on Linux 2010-04-07 19:59:06 -07:00
Konstantin Belousov 979af4502f Move local_resume to os-specific file. 2010-04-05 23:00:27 +03:00
Konstantin Belousov 0dbeeeb08d Move uc_addr to os-specific file 2010-04-05 22:42:23 +03:00
Konstantin Belousov 79d012348d Move get_scratch_loc() to os-specific file. 2010-04-05 22:22:55 +03:00
Konstantin Belousov aeee03dd74 Reduce diffs to master 2010-04-05 16:28:46 +03:00
Konstantin Belousov ccc0ae665b More move of osdep code. 2010-04-05 16:25:36 +03:00
Konstantin Belousov a40641f326 Trim spaces 2010-04-05 16:25:20 +03:00
Konstantin Belousov fd88f41818 Merge remote branch 'origin/master' into freebsd
Conflicts:
	src/x86/Gis_signal_frame.c
	src/x86/Gstep.c
	src/x86_64/Gis_signal_frame.c
	src/x86_64/Gstep.c
2010-04-05 16:14:50 +03:00
Arun Sharma 8e53e62db9 Refactor os specific code for x86 (both 32 and 64 bit).
Move Linux specific code into ${arch}/Gos-linux.c
2010-04-04 16:46:13 -07:00
Konstantin Belousov 980ccffe9e Merge remote branch 'origin/master' into freebsd
Conflicts:
	src/x86/Gis_signal_frame.c
2010-04-04 12:44:10 +03:00
Arun Sharma 2b7ca45acc Fix handling of SA_SIGINFO frames on 32 bit x86
Submitted by: Arne de Bruijn <mail@arnedebruijn.nl>
2010-04-03 16:49:18 -07:00
Konstantin Belousov bd2798805a Reformat os-freebsd.c. 2010-04-03 23:29:28 +03:00
Konstantin Belousov 5715d912f4 Make setjmp/longjmp work at least on FreeBSD/amd64.
FreeBSD-supplied setjmp() saves incremented stack pointer into jmpbuf.

I have no idea whether siglongjmp ever worked on amd64, since
UNW_NUM_EH_REGS == 2 and abort at siglongjmp.c:81 is firing.
2010-04-03 19:02:43 +03:00
Konstantin Belousov 31ece3eaa1 Fix setcontext for amd64 freebsd 2010-04-03 18:28:31 +03:00
Konstantin Belousov 9bb9c972e6 Merge with origin/master 2010-03-31 16:01:38 +03:00
Arun Sharma 6203f1cd0f Cleanup a mapped elf image.
Without this, we end up with mmap leaks. Thanks to Humberto Abdelnur
for suggesting this.
2010-03-26 15:54:14 -07:00
Arun Sharma 7bd264e292 Fix up what looks like an unintentional semi colon.
Thanks to Lassi Tuura for noticing it.
2010-03-23 10:37:21 -07:00
Konstantin Belousov 8a75ba971a Signal trampoline on amd64 for ia32 is special. 2010-03-13 21:26:50 +02:00
Konstantin Belousov e51429280b Handle error return from is_signal_frame 2010-03-13 20:31:12 +02:00
Konstantin Belousov e9cd30040e Move x86 porting further. 2010-03-13 20:28:12 +02:00
Konstantin Belousov 71c4161247 Remove extra empty line 2010-03-13 18:33:22 +02:00
Arun Sharma f8a15e9679 Fix a couple of test breakages on x86_64
setcontext() now restores the signal mask. Also remove a check
in the test that doesn't seem to be valid.
2010-03-10 22:52:12 -08:00
Konstantin Belousov a6b23dcb0c Add partial implementation for is_signal_frame for i386. 2010-03-11 00:50:40 +02:00
Konstantin Belousov 54f8b2fdbe Fill real offsets for freebsd 2010-03-11 00:02:24 +02:00
Konstantin Belousov 47dcc89457 Remove unneeded braces 2010-03-10 23:51:59 +02:00
Konstantin Belousov bb41eba56c FreeBSD/i386 port. get/setcontext need further work 2010-03-09 18:01:25 +02:00
Konstantin Belousov 9f79621a29 Enough for now for ptrace backend 2010-03-08 20:55:50 +02:00
Konstantin Belousov 752ce15c4f Preliminary version of freebsd syscall unwinder 2010-03-08 19:45:54 +02:00
Konstantin Belousov c1b1c10cfc Fix memory leak on error 2010-03-08 18:48:27 +02:00
Konstantin Belousov 89e1df2d32 Fix _UI_siglongjmp_cont name 2010-03-08 15:55:29 +02:00