1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-05-20 20:05:18 +02:00
Commit graph

1743 commits

Author SHA1 Message Date
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