Commit Graph

269 Commits

Author SHA1 Message Date
Mark Wielaard 9d29ed2989 libdwfl: Handle LZMA .ko.xz compressed kernel modules.
Linux kernel modules can not just be compressed with gz and bz2, but also
with xz.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-08-15 20:29:20 +02:00
Jan Kratochvil 475849fdb2 Fix report_r_debug for prelinked libraries
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2014-07-28 21:00:13 +02:00
Kurt Roeckx a7a385547b Make the attach code build again on non-Linux hosts.
Signed-off-by: Kurt Roeckx <kurt@roeckx.be>
2014-06-25 09:11:08 +02:00
Mark Wielaard c1c1c06e30 libebl: Add ebl_func_addr_mask plus ARM backend implementation.
The ARM EABI says that the zero bit of function symbol st_value indicates
whether the symbol points to a THUMB or ARM function. Also the return
value address in an unwind will contain the same extra bit to indicate
whether to return to a regular ARM or THUMB function. Add a new ebl
function to mask off such bits and turn a function value into a function
address so that we get the actual value that a function symbol or return
address points to. It isn't easily possible to reuse the existing
ebl_resolve_sym_value for this purpose, so we end up with another hook
that can be used from dwfl_module_getsym, handle_cfi and elflint.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-06-22 13:47:48 +02:00
Mark Wielaard fb86387b18 libdwfl: linux-core-attach.c handle possible unaligned data access.
Use libdw/memory-access.h macros read_4ubyte_unaligned_noncvt and
read_8ubyte_unaligned_noncvt to access possibly unaligned data in
core files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-06-17 16:49:05 +02:00
Mark Wielaard 14beac3b6f libdwfl: Record dwfl_attach_state error and return it on failure.
When dwfl_attach_state fails functions that need the process state should
return the error that caused the attach to fail. Use this in the backtrace
test to signal any attach failure. This makes sure that architectures that
don't provide unwinder support get properly detected (and the tests SKIPs)
Also don't assert when trying to attach a non-core ELF file, but return an
error to indicate failure.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-06-11 15:31:41 +02:00
Mark Wielaard 824f393411 libdwfl: dwfl_standard_argp should not fail when not able to attach Dwfl.
As pointed out in https://bugzilla.redhat.com/show_bug.cgi?id=1107654
commit 191080 introduced a thinko that caused dwfl_standard_argp
to fail if the Dwfl couldn't be attached. Instead of generating a warning
as the comment intended, the failure would be fatal. But even warning
about dwfl_core_file_attach () or dwfl_linux_proc_attach () failing
would be a mistake. The caller/user might not be interested in such
a non-fatal issue. So just ignore if the call failed for whatever reason.
If the caller is interested in warning up front about this issue, then
dwfl_pid () should be called to check the Dwfl is attached. Things should
work just fine for anything that doesn't call any of the dwfl_state related
functions.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-06-11 15:14:00 +02:00
Mark Wielaard 0f5b632a72 libdwfl: Don't leak fd on error in linux-proc-maps.c (grovel_auxv).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-05-15 16:03:59 +02:00
Mark Wielaard bb096d0412 Remove --enable-dwz. dwz alt debug is no longer experimental.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-05-03 00:23:06 +02:00
Mark Wielaard df85bf9902 libdwfl: Move dwz alt multi file searching to find_debuginfo callback.
Don't hard code the Dwarf dwz alt multi file search but allow the user
to override it through the standard Dwfl_Callbacks. Also move ownership
completely to the user of dwarf_setalt by removing free_alt from Dwarf
and adding alt, fd and elf fields to Dwfl_Module. Add a relative .dwz
file test case.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-05-02 17:00:48 +02:00
Mark Wielaard d81d32d2a4 libdwelf: Add dwelf_elf_gnu_build_id.
Move internal function __libdwfl_find_build_id to libdwelf and use it to
add a public dwelf_elf_gnu_build_id function to extract the NT_GNU_BUILD_ID
from an ELF file using either the shdrs or phdrs. Adjust internal callers
and add a testcase.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-05-01 13:51:31 +02:00
Florian Weimer 920f03dcd3 Move .gnu_debugaltlink handling from libdw to libdwfl
Also use dwelf_dwarf_gnu_debugaltlink to locate the alternate debugging
information.

Signed-off-by: Florian Weimer <fweimer@redhat.com>
2014-05-01 13:37:43 +02:00
Mark Wielaard 9380297e13 libdwelf: New DWARF ELF Low-level Functions. Add dwelf_elf_gnu_debuglink.
New public header elfutils/libdwelf.h for low-level DWARF/ELF helper
functions.  The new function dwelf_elf_gnu_debuglink returns the name and
crc as found in the .gnu_debuglink section of an ELF file.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-04-24 13:18:33 +02:00
Mark Wielaard 740d1fe497 libdwfl: __libdwfl_frame_reg_[gs]et use uint64_t when checking bits.
Found by gcc -fsanitize=undefined while running the backtrace-core-ppc test.
runtime error: shift exponent 45 is too large for 32-bit type 'unsigned int'

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-04-24 11:33:54 +02:00
Kurt Roeckx 02cefdaa64 Unwinding is only supported on Linux
Signed-off-by: Kurt Roeckx <kurt@roeckx.be>
2014-04-23 10:56:01 +02:00
Mark Wielaard 3232479483 Remove mudflap build option.
The --enable-mudflap configure build has been broken for 2 years without
anybody apparently noticing. GCC 4.9 removed mudflap support. Before
release we now run make distcheck with valgrind support. Removal of the
mudflap configure option simplifies the build a little.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-04-18 11:46:51 +02:00
Mark Wielaard dd64d4a926 libdwfl: elf_from_remote_memory only trust shdrs of last file-only segment.
If the last PT_LOAD segment that contains the whole shdrs also extends
the segment in memory beyond the end of file the program might be reusing
the memory space that we expect the shdrs to be in. Don't trust the shdrs
are valid in that case.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-03-17 11:08:09 +01:00
Josh Stone 65cefbd079 libdwfl: dwfl_module_getdwarf.c (open_elf) only (re)set mod->e_type once.
As noted in https://sourceware.org/bugzilla/show_bug.cgi?id=16676#c2 for
systemtap, the heuristic used by open_elf to set the kernel Dwfl_Module
type to ET_DYN, even if the underlying ELF file e_type was set to
ET_EXEC, could trigger erroneously for non-kernel/non-main (debug or
aux) files.  Make sure we only set the e_type of the module once when
processing the main file (when the phdrs can be trusted).
2014-03-11 10:19:28 -07:00
Mark Wielaard 4b9e1433d2 libdwfl: dwfl_linux_proc_find_elf use elf_from_remote_memory for (deleted).
If a module has a "(deleted)" main ELF file, then try to read it from
remote memory if the Dwfl has process state attached by reusing the ptrace
mechanism from linux-pid-attach.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-03-10 21:29:00 +01:00
Mark Wielaard f15bcda413 libdwfl: elf_from_remote_memory should use pagesize, not p_align.
elf_from_remote_memory would use the actual p_align of the PT_LOAD segments
to calculate the loadbase, end and start of a segment. But the dynamic
loader aligns the segments using the pagesize and only sanity checks the
p_align values. So we should do the same to get accurate segment addresses.
Also fixes a small memory leak in case the ELF image appears to be bad.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-03-10 21:28:48 +01:00
Mark Wielaard 8f4402f7cd libdwfl: linux-proc-maps.c (proc_maps_report): Don't assert on bad input.
If ino == last_ino && dmajor == last_dmajor && dminor == last_dminor then
we expect the file names to be the same as well. Which is reasonable if
the input came from the /proc file system. But there could be bad user
input if the file was supplied through dwfl_linux_proc_maps_report.
Instead of asserting on the bad input, just signal a bad_report.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-03-03 09:26:10 +01:00
Mark Wielaard 48827ec6cb libdwfl: elf-from-memory.c (elf_from_remote_memory): Check against p64 p_type.
There was a type in the case of parsing ELFCLASS64 phdrs. Check against
p64 p_type, not the p32 p_type which at a different location in the union.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-02-26 17:18:49 +01:00
Petr Machata ced6687b6e robustify: Use gelf_fsize instead of relying on shdr->sh_entsize.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-01-23 11:31:53 +01:00
Mark Wielaard 27aae18ce8 libdwfl: Only skip reset of return register for non-CIE-return regno (ppc64).
For PPC64 we skip resetting the return register if it is already set.
This is because on PPC64 there are two DWARF registers numbers that can
represent the same register. Setting the return address again confuses
the unwinder. But we do want to reset it if the register number
(non-translated by the ppc64 ebl) is equal to the actual register number
as set in the CIE as return address. This happens on older toolchains in
.debug_frame where the return address is set to 108, but the ebl abi_cfi
also sets register number 65.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-01-05 20:49:24 +01:00
Mark Wielaard 68de442d13 libdwfl: linux-pid-attach.c (dwfl_linux_proc_attach): Use and check strtol
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-01-02 21:17:18 +01:00
Mark Wielaard 1910801919 libdwfl: Add dwfl_core_file_attach and dwfl_linux_proc_attach.
Rewrite __libdwfl_attach_state_for_pid and __libdwfl_attach_state_for_core
as public functions and don't call them from dwfl_linux_proc_report and
dwfl_core_file_report anymore. This lets the user attach state explicitly
independ from how the dwfl modules have been reported. Since attaching
state is an explicit action now the error can be returned directly and we
don't need to keep track of process_attach_error. dwfl_linux_proc_attach
lets the user can tell libdwfl whether caller takes care of ptrace
attaching and stopping the threads under inspection, or whether the
callback needs to take care of that and detaching again.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-31 13:59:51 +01:00
Mark Wielaard ac65261cc5 libdwfl: dwfl_linux_proc_find_elf should only return regular files.
When the dwfl_linux_proc_find_elf callback is used together with the
dwfl_linux_proc_report callback that reads /proc/PID/maps files we might
see and try to open special character device files that cannot be normally
read and processed by libelf (and might hang the library on the initial
open or read from the file). Make sure we only try to open and return
regular files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-31 13:58:32 +01:00
Mark Wielaard 05a4412f11 libdwfl: Fix memory leak in linux-core-attach. Allow reiterating threads.
core_next_thread would allocate a new thread_arg each time but never free
it. We only need one active thread_arg to keep the state. Free it when
there are no more threads. It was also not possible to start walking all
threads in the core again. Just reset the note offset at the start.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-31 13:58:32 +01:00
Mark Wielaard b20ca0bd7f libdwfl: Fix build_id memory leak in dwfl_segment_report_module.
We might already have allocated memory to hold the build_id early in
consider_notes when we called consider_phdr for the program headers
we've read from the image. We would leak that memory when we don't use
it then because we return early/fail. This can be because either we
didn't find the correct bias or we skip the module because it would
conflict in address space with any already existing module of DWFL.
In both cases explicitly free the build_id memory.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-31 13:58:32 +01:00
Mark Wielaard 97bbf9b7ca libdwfl: linux-pid-attach.c: Report actual PID (Tgid) to dwfl_attach_state.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-25 22:24:56 +01:00
Mark Wielaard 3e98ab73f3 libdwfl: Make sure to set the CFI return register only once (for ppc64).
On PPC64 there are two DWARF registers numbers that can represent the
same register. If that register is the CIE return register then we only
want to set it once. The second setting will confuse the unwinder.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-25 21:19:35 +01:00
Mark Wielaard e962ec3bcb libdwfl: Add dwfl_getthread_frames.
dwfl_getthread_frames is a convenience function for when the user is only
interested in one specific thread id of a process. It can be implemented by
a simple wrapper function that removes an extra callback layer just to
filter on thread id. But it also provides an optimized path to getting
access to just one particular Dwfl_Thread of the Dwfl process by providing
and (optional) new callback for the state provider. The pid_thread_callbacks
now provide an (optional) pid_getthread that doesn't need to travers all
threads anymore. Which is implemented for the linux-pid-attach provider.

stack now uses this to implement a new '-1' option that shows just one
specific thread of a process.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-23 22:57:22 +01:00
Mark Wielaard 641a4f62f1 libdwfl: Correct nested asprintf result check in report_kernel_archive.
Because of wrongly placed parens the result of only one asprintf call
was checked correctly. Causing dwfl_linux_kernel_report_offline to return
ENOMEM. Rewrite nested if unlikely check into separate if statements to
make clear what is actually being checked and what the actual unlikely
condition is.

Reported against systemtap "build-id difficulties with hand-built kernels"
https://sourceware.org/bugzilla/show_bug.cgi?id=16358

Reported-by: Crestez Dan Leonard <lcrestez@ixiacom.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-21 17:03:11 +01:00
Mark Wielaard 159ac52b06 libdwfl: Introduce dwfl_module_getsym_info and dwfl_module_addrinfo.
Some arches like ppc64 use function descriptor values instead of function
addresses causing matching of names and addresses to fail when using
dwfl_module_getsym or dwfl_module_addrsym.

Add ebl hook to resolve any function descriptor values found in non-ET_REL
modules.

The new function dwfl_module_getsym_info doesn't adjust the symbol value
in any way, but returns the adjusted and/or resolved address associated
with the symbol separately. The new function dwfl_module_addrinfo resolves
against both the address associated with the symbol (which could be the
function entry address) value and the adjusted st_value. So that it is
easy to resolve and match either function descriptors and/or function
entry addresses.

Since these new functions also return more information they replace the
dwfl_module_getsym_elf and dwfl_module_addrsym_elf functions that never
made it into a released elfutils version.

addr2line and readelf now use the new functions when looking up functions
names. addr2line will now also display the section the address was found
in when given -x.

Extra testcases were added for both addr2line and the dwflsyms testscase.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-20 10:09:49 +01:00
Jan Kratochvil c530946345 Use executable_for_core in dwfl_build_id_find_elf.
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-12-18 15:02:19 +01:00
Jan Kratochvil c6a41483f2 unwinder: s390 and s390x
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-12-18 13:01:05 +01:00
Jan Kratochvil 6cd283c920 Fix forgotten call of ebl_dwarf_to_regno.
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-12-17 18:17:32 +01:00
Mark Wielaard c76b2ff3ee libdwfl: linux-pid-attach.c (pid_next_thread): Use rewinddir on first call.
dwfl_getthreads would otherwise fail to report any threads after it was
called once.

Reported-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-17 10:37:29 +01:00
Mark Wielaard 14c2d9e614 libdwfl: Add dwfl_module_getsymtab_first_global.
New function that provides the index after the last non-local symbol as
returned by dwfl_module_getsym and dwfl_module_getsym_info. Allows users to
first search through all global symbols before searching the local symbols
in the table like dwfl_module_addrsym and dwfl_module_addrsym_info do as
optimization.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-16 15:27:27 +01:00
Mark Wielaard e6e6cc83ea libdwfl: Fix various frame related memory leaks.
The result of dwarf_cfi_addrframe should have been freed when done.
Dwfl_Module cached the reloc_info and the eh_cfi it which also should
have been released when disposing of the module.

Reported-by: Masatake YAMATO <yamato@redhat.com>
Tested-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-12-16 09:03:22 +01:00
Jan Kratochvil 5cbf42aaf4 unwinder: ppc and ppc64
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-12-15 18:56:17 +01:00
Jan Kratochvil 5ef96c979c Introduce process_attach_error.
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-11-30 21:40:29 +01:00
Mark Wielaard 819c349f63 libdwfl: Add dwfl_module_addrsym_elf and dwfl_module_getsym_elf.
Introduce two new functions that also return the elf associated with a
symbol to make symbol section indexing work for non-special sections.
Simplify code by removing dwfl_file where appropriate and just track Elf
directly. Document limitations of shndx with existing dwfl_module_addrsym
and dwfl_module_getsym. Extend dwflsyms testcase to check some more symbol
and section (index) properties.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2013-11-27 16:45:44 +01:00
Jan Kratochvil 99a29497c6 Fix non-build-id core files on build-id system
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-11-21 15:33:22 +01:00
Jan Kratochvil b301c2efea Verify file vs. core build-id, when both available
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-11-21 15:31:04 +01:00
Jan Kratochvil 463e983e20 link_map: Use proper bias, not l_addr
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-11-21 15:28:02 +01:00
Jan Kratochvil 10d7a39aa2 Compatibility with older kernels such as RHEL-6.
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-11-19 15:00:15 +01:00
Josh Stone db35c87a85 libdwfl: Fix and test aux_sym address_sync with relocated ELF
The aux_sym address_sync already worked with a full prelink, which has
.gnu.prelink_undo, but it failed on plain relocations with prelink -r.

Now it uses the difference in ehdr.e_entry as a first offset guess, and
the tests confirm this seems to work fine.

Signed-off-by: Josh Stone <jistone@redhat.com>
2013-11-18 14:29:35 -08:00
Jan Kratochvil 1c1a53b657 Code cleanup: Remove const in prototype
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-11-14 20:55:41 +01:00
Jan Kratochvil ed78237ef7 Fix dwfl_attach_state machine->elf
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
2013-11-14 20:53:20 +01:00