1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-16 21:27:38 +01:00
Commit graph

1850 commits

Author SHA1 Message Date
Doug Moore
38b2bdab33 Add a missing semicolon. 2017-07-05 09:53:46 -07:00
Doug Moore
0e74e583ae arm: Use dwarf_find_proc_info for arm dwarf processing
Rather than using a copy of dwarf_find_proc_info that differs from it slightly.
By using dwarf_find_proc_info, a potential search of the di table is
allowed, where it is omitted now.  Also, for ARM, avoid runtime
checks about which kind of unwind table search to use after dl_iterate_phdr.

A couple of Debug() warnings about ip lookup failure are lost here.
The dwarf callback struct defintion is moved to Gfind_proc_info-lsb.c,
which becomes the only source file that needs it.
2017-06-20 09:47:54 -07:00
Doug Moore
4f14d9714f Don't give up on proc finding if dwarf_callback fails, but
don't bother completing the dwarf search work either.  Move on
to the arm method.
2017-06-16 08:54:48 -07:00
Doug Moore
be06809b5f Arm code uses dwarf before arm for finding proc info, but unlike
dwarf code, ignores error return from dwarf_callback.  Change arm
code to behave like dwarf code in that case.
2017-06-16 08:54:47 -07:00
Doug Moore
0b51f5892d Dwarf cache nodes are allocated in a round-robin fashion, despite the
'lru' prefix used in several data fields.  Drop the unnecessary fields,
and just use a simple counter to track the next cache entry to be recycled.
2017-06-16 08:53:36 -07:00
Doug Moore
27f5f9fa0b Leave ret_addr_column out of the data that gets copied when pushing/popping
data on/off the register state stack.
2017-05-20 14:36:25 -05:00
Doug Moore
c66661f73c Drop reference to dwarf.ret_addr_column. 2017-05-19 19:19:12 -05:00
Doug Moore
afb2491ccb Have dwarf_step return 0 or 1 for success, according to whether the
previous stack frame was the last, just as unw_step does.  For x86_64,
drop the null check for ret_addr_column, since that check is made already
in apply_reg_state.
2017-05-19 18:57:14 -05:00
Doug Moore
f3be411bc8 Use the register_state version of ret_addr_column, rather than the
cursor version, for frame-stashing.  They have the same value in master.
2017-05-19 18:22:08 -05:00
Doug Moore
7634874591 Move the change to c->ret_addr_column to the end of dwarf_step, to make sure
that it gets set in the cache hit case.
2017-05-19 17:59:08 -05:00
Doug Moore
ec1a021243 Move the ret_addr_column field from dwarf_reg_cache_entry to dwarf_reg_state,
so that it will get saved and restored with the register state.  Initialize
the rs_state version of ret_addr_column at the some time the dwarf_cursor
version is initialized, and don't bother copying ret_addr_column explicitly
from cursor to cache since it's copied implicitly as part of reg_state.
Use the reg_state version in apply_reg_state, instead of the cursor version.

Which brings up the question: why do we have ret_addr_column in the dwarf_cursor?
We call find_reg_state before calling apply_reg_state, so the value of ret_addr_column
in the cursor when dwarf_step gets called gets overwritten before it is used.  So
it's initial value doesn't matter.  But some architectures do funky things with
cursor->ret_addr_column, even though I don't see how they matter.

So I'm not deleting dwarf_cursor->ret_addr_column, even though I suspect this
patch makes it useless.
2017-05-16 22:00:38 -05:00
Doug Moore
028a60f064 Change dwarf_reg_state from an array of pairs of differently-sized objects
to a pair of arrays, to reduce internal fragmentation.  Reduces storage
use by 37.5% on x86_64.
2017-05-16 17:40:58 -05:00
Doug Moore
2b692db23f In dwarf_reg_states_table_iterate, the rs stack has to persist from
one run_cfi_program call to the next, so pull the stack out of run_cfi_program
and make the caller responsible for cleanup at the end.
2017-05-16 01:04:49 -05:00
Doug Moore
bb61e0bc2b Bury the last_ip field until it can reappear in version 2.0. 2017-05-12 23:45:56 -05:00
Doug Moore
fef5de6c45 Move ret_addr_column and signal_frame from dwarf_reg_state to
dwarf_reg_cache_entry, leaving in dwarf_reg_state only what
apply_reg_state needs.
2017-05-12 22:24:00 -05:00
Doug Moore
a7c65f5c3e Remove next field from dwarf_reg_state. Create new struct
that includes next field and dwarf_reg_state, and use that
strictly for stack push/pop in run_cfi_program.
2017-05-12 22:24:00 -05:00
Doug Moore
4184bb478a Restore a dwarf-free "apply_reg_state" function. 2017-05-12 22:24:00 -05:00
Doug Moore
3888b2bbcb In dwarf_apply_reg_state change from dewarf_reg_state_t back to struct dwarf_reg_state. 2017-05-12 22:24:00 -05:00
Doug Moore
502ba27753 Add a function to capture the dwarf_reg_states that occur in processing
the dwarf code for a procedure, and a function to apply a captured
dwarf_reg_state later.
2017-05-12 22:24:00 -05:00
Doug Moore
bbdc4b12da Capture the address of the first byte after the instructionless gap
that follows the procedure.
2017-05-12 22:24:00 -05:00
Doug Moore
06d230d732 Merge dwarf_find_save_locs into dwarf_step. 2017-05-12 22:24:00 -05:00
Doug Moore
1602987b5f Extract 'find_reg_state' from dwarf_find_save_locs. 2017-05-12 22:23:59 -05:00
Doug Moore
04db2b7cea The call to put_unwind_info is what makes pi invalid, so clear the
valid bit here, and soon stop bothering to clear it in other places.
2017-05-12 22:23:59 -05:00
Doug Moore
1c76d41939 Pass in a pointer to the address where run_cfi_program will start,
or resume, its decoding, rather than always starting at the procedure
start, so that resuming a cfi_program becomes possible.
2017-05-12 22:23:59 -05:00
Doug Moore
7a962b951b Create setup_fde, and put all the one-time parts of fde processing there. 2017-05-12 22:23:59 -05:00
Doug Moore
50a457abb0 Pull cache-related fields out of reg_state, and put them into reg_cache struct. 2017-05-12 22:23:59 -05:00
Doug Moore
59ecb24ca2 dwarf:Drop dwarf_create_state_record.
In dwarf_make_proc_info, fix a leak in the case that create_state_record fails.
2017-04-28 09:59:22 -07:00
Doug Moore
3775cdd997 dwarf: Avoid a leak for a no-cache failure in create_state_record_for.
Avoid a duplicate copy for a cache miss.
2017-04-28 09:58:40 -07:00
Doug Moore
24ac32b480 run_cfi patch for libunwind
dwarf: If the dwarf_readu8 call to set op fails, and if there are register
states pushed onto the stack, the stack is not emptied before the function
returns. This change addresses that.

Most of the rest is eliminating ‘goto fail’ from the code.
2017-04-26 08:11:34 -07:00
Doug Moore
24f27f02ac dwarf: error in unmap size arguments
This patch fixes an error in the unmapping of
hash table memory when the dwarf hash table is resized.
2017-04-17 10:28:48 -07:00
Doug Moore
0f24c6dec8 dwarf: Cleanup dwarf cache hint
0-valued hints are used when they are just initial values with no use as
hints. And I think there were some other problems as well.
This patch cleans up and stores hint values with 1 added, so that 0-valued
hints can be ignored.
2017-04-14 08:02:10 -07:00
Dave Watson
aee8bbe795 dwarf: fix unw_get_proc_info
unw_get_proc_info must always load the unwind info so that unw_resume
works with GNU_args_size expressions, but must not update
use_prev_expr unless we are unw_step()ing.

blame rev: 4b63a536ee

reported-by: Doug Moore <dougm@rice.edu>
2017-04-04 11:15:23 -07:00
Doug Moore
14c48b3d51 unw_init_local_signal
init_local, but *not* setting use_prev_instr.
This is necessary to correctly unwind using ucontext argument to signal handlers.
2017-04-03 14:44:40 -07:00
Rene Nielsen
2a5d1a6296 mips: remote unwind support
libunwind already had support for local unwind on a MIPS. This patch makes
support for remote unwinding on a MIPS.

I should add a few words to the changes to _UPT_access_mem.c: On MIPS, an
unw_word_t is defined as a 64-bit integer whether it's compiled for a 32- or a
64-bit MIPS.

When doing remote unwinding using the default _UPT_accessors, dwarf_readu8()
therefore expects _UPT_access_mem() to return a 64-bit integer. However, if
compiled on a 32-bit MIPS, only 32 bits are valid upon return from
_UPT_access_mem(). The patch detects this and will in this case perform two
calls to ptrace(PTRACE_POKE/PEEK_DATA) and organize the return value according
to endianness.
2017-03-02 08:02:41 -08:00
Dave Watson
54a970079d elf: Follow .gnu_debuglink when resolving function names
Centralize gnu_debuglink logic in elfxx.  Remove previous duplicated logic
from Gfind_proc_info and os-linux.

Logic is roughly the same as previous load_debug_frame, but uses VLAs
instead of malloc.
2017-03-02 08:02:14 -08:00
Mike Frysinger
f3f456c0d1 coredump: simplify bad regnum checks a little
We always want to reject negative regnums since we use it as an index,
so make it a common check at the top for all arches.
2017-02-14 08:23:38 -08:00
Королев Сергей
00cca00716 mips/Gstep.c: unw_handle_signal_frame: remove unused 'sp' variable
This fixes GCC 4.9.3 warnings (Linux/mipsel):

mips/Gstep.c: In function '_Umips_handle_signal_frame':
mips/Gstep.c:33:23: warning: unused variable 'sp' [-Wunused-variable]
   unw_word_t sc_addr, sp, sp_addr = c->dwarf.cfa;
                       ^
2017-02-14 08:22:00 -08:00
Королев Сергей
b5de17183c mips[el]: fix cast from pointer to integer of different size
This fixes GCC 4.9.3 warnings (Linux/mipsel):

In file included from dwarf/Lfind_unwind_table.c:4:0:
dwarf/Gfind_unwind_table.c: In function '_ULmips_dwarf_find_unwind_table':
dwarf/Gfind_unwind_table.c:140:14: warning: cast from pointer to integer of
different size [-Wpointer-to-int-cast]
       addr = (unw_word_t) (hdr + 1);
              ^
dwarf/Gfind_unwind_table.c:196:50: warning: cast from pointer to integer of
different size [-Wpointer-to-int-cast]
                                        + (addr - (unw_word_t) edi->ei.image
                                                  ^
dwarf/Gfind_unwind_table.c:202:40: warning: cast from pointer to integer of
different size [-Wpointer-to-int-cast]
                                     + ((unw_word_t) hdr - (unw_word_t)
edi->ei.image
                                        ^
dwarf/Gfind_unwind_table.c:202:59: warning: cast from pointer to integer of
different size [-Wpointer-to-int-cast]
                                     + ((unw_word_t) hdr - (unw_word_t)
edi->ei.image
                                                           ^
2017-02-14 08:21:49 -08:00
Rene Nielsen
cfd4306cc7 mips: fix compiler warnings
This fixes a number of compiler warnings I got when compiling for mips32el with
gcc 5.3.0.
2017-02-14 08:18:49 -08:00
Bert Wesarg
b15e74a884 dwarf: Utilize ELFs find_section to find the eh_frame.
Makes it thread-safe.
2017-02-02 08:29:17 -08:00
Bert Wesarg
1b960e54e9 elfxx: Add helper to find a section in ELF image. 2017-02-02 08:29:17 -08:00
Dave Watson
316a34a36e mips/tilegx: Add missing unwind_i.h header file
reported-by: John Knight <John.Knight@belkin.com>
2017-01-25 16:23:59 -08:00
Bert Wesarg
2e60ca34d2 dwarf: Fix warning about -Wmaybe-uninitialized.
```
src/dwarf/Gfind_proc_info-lsb.c:536:16: warning: 'eh_frame' may be used uninitialized in this function [-Wmaybe-uninitialized]
   Elf_W (Addr) eh_frame;
                ^
```

Introduced-in: 25413c729a
2017-01-24 11:09:25 -08:00
Bert Wesarg
4dea379ad9 x84_64: It's only 'mcontext_t'.
Fixes warning:
```
src/x86_64/Gos-linux.c:141:36: warning: initialization from incompatible pointer type
   struct mcontext_t *sc_mcontext = &((struct ucontext*)sc)->uc_mcontext;
                                    ^
```

Introduced-in: 29483327be
2017-01-24 11:09:14 -08:00
Saleem Abdulrasool
e9e8ed73e3 dwarf: Account for multiple CFA for args_size
It is possible to have multiple CFA_args_size adjustments for a single
frame.  If the CFA_args_size adjustment is immediately following the
return from a function which can raise an exception, it is possible to
incorrectly adjust the stack pointer.  Consider the following:

  ...
  .cfi_escape 0x2e, 0x00
  call f
.Ltmp:
  .cfi_escape 0x2e, 0x10
  lea label@GOTOFF(%ebx), %eax
  ...

Because we process the CFI program up to and *INCLUDING* IP, where the
IP is the RA, we would process the associated DW_CFA_GNU_args_size for
the post-call instruction.  The result would be a DW_CFA_GNU_args_size
of 0x10 rather than 0x00, resulting in an incorrect stack adjustment.
Handle this by processing the CFI operation but not adjusting the state
record unless we are below the current IP.
2017-01-19 10:07:53 -08:00
Konstantin Belousov
9e97c9b17a dwarf: Make binary path calculation os-specific.
/proc/self/exe only works on Linux, move path computation to os-* files
2017-01-19 10:07:13 -08:00
Vitaly Kuzmichev
7885596b9c arm: ptrace: Fix order of probing unwind tables
Commit 92327a3 "ARM: prefer to unwind using DWARF info"
changes order of unwind info searching to prefer DWARF (.debug_frame)
section in prior to ARM specific (.ARM.exidx). This patch only affects
local process unwinding. Now the same is done for remote unwinding.

Sometimes probing .ARM.exidx first causes backtrace truncation
after __aeabi_ldiv0 (division by 0 handler that generates SIGFPE),
because it hits [cantunwind] generated by cross-gcc for __divsi3
function copied with __aeabi_ldiv0 from libgcc.a. Perhaps, lack of
debug info for __divsi3 causes [cantunwind], or there is a problem
converting DWARF to ARM unwind tables, but when unwinding using
DWARF, it hits proper entry, and backtrace is shown correctly.

Reported-by: Frederic Berat <fberat@de.adit-jv.com>
Signed-off-by: Vitaly Kuzmichev <Vitaly_Kuzmichev@mentor.com>
2017-01-19 10:06:24 -08:00
Saleem Abdulrasool
11a053f5ca use target dependent names for stack registers
When adjusting the stack for a DW_CFA_arg_size adjustment, ensure that
we use the target dependent register name as the generic name does not
necessarily map to the same register.  For example, on x86, ESP maps to
the eip register, which results in the wrong stack adjustment being
applied.
2017-01-18 10:17:15 -08:00
Konstantin Belousov
09a598a3da Make the code compile on FreeBSD. 2017-01-18 09:18:29 -08:00
Guy Menanteau
7c079200d0 ppc64: Make access_fpreg function accept fp and v registers 2017-01-13 08:41:45 -08:00