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

65 commits

Author SHA1 Message Date
Arun Sharma
d7089547e2 Fix a warning message on i386
Without this, we may be accessing data beyond the array bounds.
2009-10-23 22:38:11 -07:00
Arun Sharma
491d576529 Fix compiler warnings on x86_64 2009-10-16 14:01:50 -07:00
Paul Pluzhnikov
b56375e76a Reduce stack use and apply CONFIG_DEBUG_FRAME to more code.
Currently, libunwind allocates several PATH_MAX entries on stack, while
trying to find a binary via /proc/.../maps.

However stack space may be at premium (especially when sigaltstack is used),
and PATH_MAX on Linux is 4096, while SIGSTKSZ is only 8192 on x86.

Attached patch eliminates multiple PATH_MAX stack allocations, and simplifies
code in maps_next, at the cost of being unable to do anything if we can't
mmap one page. It appears to me that under such low-memory conditions,
libunwind will fail shortly elsewhere anyway.

This patch also disables more of debug_frame-handling code when
CONFIG_DEBUG_FRAME is undefined.

Tested on Linux/x86_64 with and without CONFIG_DEBUG_FRAME, no regressions.
2009-10-07 12:51:03 -07:00
Paul Pluzhnikov
fc2934aade Make the remaining sigprocmask calls conditional on --enable-block-signals 2009-09-29 23:14:50 -07:00
Paul Pluzhnikov
839db77b7b Wait if there is contention on the cache
The behavior on wait vs abort unwind depends on the locking primitive
chosen by the user. This makes the API consistent and independent of
the locking primitive.
2009-09-25 09:38:55 -07:00
Paul Pluzhnikov
84d4150668 Allow caller to block signals.
Greetings,

We use libunwind just for stack traces (I suspect many others do as well).

The use pattern is:

GetStackTrace(void** result, int max_depth)
{
...
  unw_getcontext(&uc);
  unw_init_local(&cursor, &uc);

  while (n < max_depth) {
    if (unw_get_reg(&cursor, UNW_REG_IP, (unw_word_t *) &ip) < 0) {
      break;
    }
    result[n++] = ip;
    if (unw_step(&cursor) <= 0) {
      break;
    }
  }

Given this usage, it is quite convenient for us to block signals (or
prevent signal handlers from re-entering libunwind by other means) at the
"top level", which makes most of the sigprocmask calls performed by
libunwind itself unneccessary.

The second patch in this series adds a configure option which removes most
of the sigprocmask calls.

Attached patch is a preliminary for it -- consolidating all of the
"sigprocmask; mutex_lock;" sequences into lock_acquire and "mutex_unlock;
sigprocmask;" sequences into lock_release.

Thanks,
--
Paul Pluzhnikov

commit 402d15b123d54a7669db7cf17a76dd315094e472
Author: Paul Pluzhnikov <ppluzhnikov@google.com>
Date:   Mon Sep 21 10:18:28 2009 -0700

    Replace "sigprocmask + mutext_lock" with a single lock_acquire.
    Likewise, replace "mutext_unlock + sigprocmask" with lock_release.
2009-09-25 09:35:31 -07:00
Arun Sharma
9607c6407c Fixup CONFIG_DEBUG_FRAME support. 2009-03-17 19:08:58 -07:00
Arun Sharma
ec53de82ec [PATCH] Avoiding name conflict with the GNU-specific dprintf in stdio.h
Signed-off-by: Yang Zhang <yaaang@gmail.com>
2009-03-16 21:37:11 -07:00
Arun Sharma
a2c27a4ab7 Make .debug_frame support optional.
Because these code paths use malloc and stdio, they could
cause deadlocks when we try to unwind stack from inside malloc.
2009-03-16 21:21:58 -07:00
Daniel Jacobowitz
3842dac733 Add initial ARM and MIPS support. To support this, also enable the
reading of .debug_frame sections (used in lieu of .eh_frame sections
when they're not available).
2008-02-04 17:16:37 -07:00
Mark Wielaard
5ed2da2a40 [DWARF] Fix error return.
* src/dwarf/Gfde.c (dwarf_extract_proc_info_from_fde):
	  Return -UNW_ENOMEM.
2008-02-04 16:31:34 -07:00
Arun Sharma
55fe524775 Cleanup the hash() function copied from ia64
Fixes the compiler warning on x86-32.

Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-08-16 15:43:49 -06:00
Arun Sharma
a5d0c1f8b7 Remove HAVE___THREAD. This was never tested.
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-08-16 15:41:32 -06:00
Arun Sharma
11ea1275bd [dwarf] The sword() function in Gexpr.c doesn't do what's intended.
Yes, it casts to signed, but then converts right back to
unsigned via the return type.  Fixed thus.

Signed-off-by: Richard Henderson <rth@redhat.com>
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-07-26 22:12:10 -06:00
Arun Sharma
58888a5060 (dwarf_find_save_locs): Also apply register-state after parsing the FDE 2006-07-26 21:55:09 -06:00
Arun Sharma
4312719cbc [dwarf] Need to guard against multiple threads accessing the rs cache.
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-07-26 21:44:38 -06:00
Arun Sharma
c5dc3c150a [dwarf] Allow return address column to differ from function to function.
Signed-off-by: Andrey Veskov <Andrey.Veskov@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-07-26 21:29:50 -06:00
Arun Sharma
60b7af702a (dwarf_find_save_locs): Add a comment.
Now that dwarf_find_save_locs() not just finds the save-locations but
also updates the cursor-state, document this fact (the function really
is misnamed now).
2006-07-26 21:25:37 -06:00
Arun Sharma
3dfde7a3f0 (dwarf_find_save_locs): put_unwind_info() is not needed in the cached case. 2006-07-26 21:23:30 -06:00
Arun Sharma
00db7f752a Implement a ip -> dwarf_reg_state cache.
Signed-off-by: Arun Sharma <arun.sharma@google.com>
2006-07-26 21:18:49 -06:00
hp.com!davidm
d9e100753f Include "libunwind_i.h" instead of "tdep.h".
(Logical change 1.294)
2005-05-20 09:48:08 +00:00
hp.com!davidm
b7adf160ee Include "dwarf_i.h" instead of "dwarf.h".
(Logical change 1.294)
2005-05-20 09:48:08 +00:00
hp.com!davidm
df3d6af467 Don't include <string.h>.
Include "libunwind_i.h" instead of "tdep.h".

(Logical change 1.294)
2005-05-20 09:48:08 +00:00
hp.com!davidm
9fac7579ee Don't include <string.h> and "tdep.h".
(Logical change 1.294)
2005-05-20 09:48:08 +00:00
hp.com!davidm
03ba50ccaa Don't include <stdlib.h> and <string.h>.
Include "libunwind_i.h" instead of "tdep.h".

(Logical change 1.294)
2005-05-20 09:48:08 +00:00
mostang.com!davidm
9bc79a618b Rename: src/dwarf/dwarf-eh.h -> include/dwarf-eh.h
}(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm
1f5ac0f5bd Adjust for sigset_t to intrmask_t renaming.
2004/11/17 02:43:39-08:00 mostang.com!davidm
(struct callback_data): New structure.
(linear_search): New function.
(callback): Convert to getting auxiliary info passed via a pointer to
	a callback_data structure, rather than an unw_dyn_info_t
	structure.
	Keep track of the maximum load address in max_load_addr.
	If an object doesn't have a binary search-table, fall back
	on a linear search.
(dwarf_find_proc_info): Fill in callback-data structure before calling
	dl_iterate_phdr().  Upon returning, check whether
	cb_data.single_fde is set and, if so, return directly, without
	searching the DWARF unwind-table.
(dwarf_search_unwind_table): Adjust for renaming of
	dwarf_parse_fde() to dwarf_extract_proc_info_from_fde().
	If IP doesn't fall into the IP-range of the FDE-entry found
	by the search, return UNW_ENOINFO.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm
46b7b8196c (is_cie_id): New function.
(parse_cie): Adjust for moving DWARF2 extra-info from
	unw_dyn_dwarf_fde_info_t to dwarf_cie_info.
	Add support for `S' augmentation ("special frames").
(dwarf_extract_proc_info_from_fde): Rename frm dwarf_parse_fde().
	Convert to returning data via dwarf_cie_info rather than
	unw_dyn-dwarf_fde_info_t.  Allow 0-length FDE since those
	can be used to indicate the end of the FDE-table.  Return
	the end of the FDE via *ADDRP.  Ignore CIEs (we may pick them
	up during linear searches through the FDE-table).
	Fill in the unwind-info only if really needed.  When needed,
	return the info via a dynamically allocated dwarf_cie_info
	structure.  Add support for `S' augmentation (ABI/tag pairs).

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm
c14371409a (fetch_proc_info): Decrement IP before searching for dynamic/static
unwind-info, since DWARF expects us to do so (unlikey for ia64,
	where we are guaranteed that the (return) IP points to the
	correct unwind-info).

2004/11/17 02:43:39-08:00 mostang.com!davidm
(run_cfi_program): Switch over to using dwarf_cie_info instead of
	unw_dyn_dwarf_fde_info_t.
(fetch_proc_info): Clear c->pi before filling it in.
(put_unwind_info): If we got non-dynamic unwind-info, free it
	via a call to mempool_free().
(parse_fde): Switch over to using dwarf_cie_info instead of
	unw_dyn_dwarf_fde_info_t.
(apply_reg_state): Drop accessees to c->cfa_is_sp.

2004/10/25 17:38:51+02:00 homeip.net!davidm
Fix typo: DW_CFA_CFA_expression -> DW_CFA_expression.

2004/10/21 11:15:44+02:00 homeip.net!davidm
Auto merged

2004/10/21 11:15:12+02:00 homeip.net!davidm
(run_cfi_program): Add missing newline in Debug statement.
(apply_reg_state): It was wrong to do a dwarf_get() on the CFA-location
	returned by eval_location_expr().  Instead, we must make sure
	we're dealing with a memory-location and, if so, just extract
	the memory address as the CFA.
	Also, update c->cfa only _after_ the other frame-state has
	been updated.  This seems to be necessary for correct parsing
	of the sigtramp unwind info.  Not sure yet this is 100% correct,
	but it gets us through Gtest-resume-sig.

2004/10/19 23:24:56-07:00 mostang.com!davidm
(run_cfi_program): Fix typos in Debug statements.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm
4502aa0ff2 (dwarf_read_encoded_pointer): Implement simply by calling
dwarf_read_encoded_pointer_inlined().

2004/11/17 02:43:39-08:00 mostang.com!davidm
(dwarf_read_encoded_pointer): Declare proc-info-pointer argument
	as "const".

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
mostang.com!davidm
3239e7db60 (dwarf_cie_info_pool): New variable.
(dwarf_init): Initialize dwarf_cie_info_pool.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
homeip.net!davidm
bb03dca33e Add Debug statement for return-value.
2004/10/19 23:15:02-07:00 mostang.com!davidm
(update_frame_state): Take additional argument "prev_cfa".
	When we detect a NULL-frame, debug-print the IP and the CFA
	so we know where things went wrong.
(dwarf_step): Get "prev_cfa" before we call dwarf_find_save_locs(),
	since update_frame_state() doesn't actually update
	the CFA.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
homeip.net!davidm
670399d357 (pop): Returning the right element does help...
(pick): Likewise.
(dwarf_eval_expr): Fix "while" conditional so we see all operators.
	Fix DW_OP_litN typo: "opcode = DW_OP_lit0" to
	"opcode - DW_OP_lit0".
	Add lots of Debug() statements so we can see what's going
	on.  Debug level 15 will show just entry/return values.
	Debug level 16 shows all operators.

(Logical change 1.290)
2005-05-03 09:13:17 +00:00
com[davidm]!marky
271f706944 dwarf: fix local & remote table lookup
(Logical change 1.256)
2004-08-24 08:19:00 +00:00
homeip.net!davidm
642607dbaa Cast register indices of type unw_word_t to (unsigned int) before
printing them.  Avoids compiler-warning for 64-bit targets.

(apply_reg_state): Handle the special case where the stack-pointer
	plays the role of the CFA and the stack-pointer hasn't
	been saved.  This is based on a patch by Max Asbock.

(Logical change 1.253)
2004-08-20 11:23:15 +00:00
homeip.net!davidm
9ac7a860d1 (parse_cie): Clarify the comment about the default FDE-encoding a bit.
(Logical change 1.253)
2004-08-20 11:23:15 +00:00
homeip.net!davidm
077322d414 Drop DWARF-parsing debug prints from level 16 to 15.
(parse_cie): Pick correct default for FDE-encoding, not just DW_EH_PE_omit.

(Logical change 1.248)
2004-08-19 12:26:11 +00:00
homeip.net!davidm
aae368ace2 Drop DWARF-parsing debug prints from level 16 to 15.
(Logical change 1.248)
2004-08-19 12:26:11 +00:00
homeip.net!davidm
e9045e3cca Add include of dwarf_i.h now that we need dwarf_reads32().
Drop DWARF-parsing debug prints from level 16 to 15.
(struct table_entry): Change member types from unw_word_t to int32_t.  The members
	need to be of a signed type and forcing them to 32 bits makes the type
	work for both 32-bit and 64-bit executables (up to 4GB of text-size).
(callback): Only allow search tables which have 32-bit members.
	Fix initialization of di->u.rti.table_len to express table-length as a count
	of unw_word_t, as it's defined to be (we get lucky here: even with 32-bit
	members, each table-entry contains two members so we're guaranteed that the
	table has a size that is an integer-multiple of unw_word_t even on 64-bit
	platforms).
(lookup): Change type of "rel_ip" from unw_word_t to int32_t.  Simplify the
	code a bit.
(remote_read): Delete.
(remote_lookup): Use dwarf_reads32() instead of remote_read() to read out table
	members.  Simplify code a bit.

(Logical change 1.248)
2004-08-19 12:26:11 +00:00
homeip.net!davidm
02d4112138 Rename: src/dwarf/global-dwarf.c -> src/dwarf/global.c
}(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
08d29fd0ab Rename: src/dwarf/global-dwarf.c -> src/dwarf/global.c
(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
16213e9846 Rename: src/dwarf/Gstep-dwarf.c -> src/dwarf/Gstep.c
}(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
6037c78f41 Rename: src/dwarf/Gstep-dwarf.c -> src/dwarf/Gstep.c
(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
e3066cb69a Rename: src/dwarf/Gpe-dwarf.c -> src/dwarf/Gpe.c
}(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
fa5c508536 Rename: src/dwarf/Gpe-dwarf.c -> src/dwarf/Gpe.c
(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
9636cfef38 Rename: src/dwarf/Gparser-dwarf.c -> src/dwarf/Gparser.c
}(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
88160e0f66 Rename: src/dwarf/Gparser-dwarf.c -> src/dwarf/Gparser.c
(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
91c9e6a384 Rename: src/dwarf/Gfde-dwarf.c -> src/dwarf/Gfde.c
}(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
32f3a1e58f Rename: src/dwarf/Gfde-dwarf.c -> src/dwarf/Gfde.c
(Logical change 1.241)
2004-08-17 15:34:28 +00:00
homeip.net!davidm
c7d65772a7 Rename: src/dwarf/Gexpr-dwarf.c -> src/dwarf/Gexpr.c
}(Logical change 1.241)
2004-08-17 15:34:28 +00:00