3714 Commits

Author SHA1 Message Date
Kent Cheung
02006007bd Further improvements to unw_step fallback method on AArch64.
Frame pointer (FP) cannot always be relied upon if DWARF unwinding
fails. Depending on position in the function prologue/epilogue, the
frame record may be pointed to by the FP, SP, or at an offset to SP.
Detect which case it is by inspecting the function disassembly and
matching to known frame record store/load instructions.

Unittest added to verify different frame record store/load methods are
detected when given real function examples from a python2.7 binary.
2023-11-24 15:29:15 -05:00
Stephen Webb
5f24bd6d9e Remove include/x86/jmpbuf.h
This file had been superceded by include/tdep-x86/jmpbuf.h, wasn't used
anywhere, and not even distributed.
2023-11-21 12:50:35 -05:00
Stephen Webb
a9a110f768 Fixed local variable hiding a global variable
This issue was found by static analysis. It makes comprehending what the
tests do a little more difficult. There is no functional change.

Verified on Ubuntu 20.04 x86_64.
2023-11-13 10:16:26 -05:00
Stephen Webb
65c2bce6d2 Fix scan_hex() logic error
This was dertected by static analysis. The function scan_hex() had a
logic error. It was unlikely to be encountered in real life but fixing
it guarantees it won;t have any effect.

Built and tested Ubunbtu 20.04 x86_64. No regressions.
2023-11-06 14:19:33 -05:00
Bert Wesarg
1b783a8e68 Ensure that structs are not empty
Closes #434

Signed-off-by: Bert Wesarg <bert.wesarg@tu-dresden.de>
2023-11-01 09:22:32 -04:00
Po-Chuan Hsieh
24dc3b0880 Fix build on FreeBSD i386
The error message is as follows:
```
--- x86/Gos-freebsd.lo ---
x86/Gos-freebsd.c:127:10: error: use of undeclared identifier 'i'
    for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
         ^
x86/Gos-freebsd.c:127:17: error: use of undeclared identifier 'i'
    for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
                ^
x86/Gos-freebsd.c:127:49: error: use of undeclared identifier 'i'
    for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
                                                ^
x86/Gos-freebsd.c:128:20: error: use of undeclared identifier 'i'
      c->dwarf.loc[i] = DWARF_NULL_LOC;
                   ^
4 errors generated.
*** [x86/Gos-freebsd.lo] Error code 1
```
2023-10-14 19:41:51 -04:00
Stephen Webb
d2d34f81a5 Add more automation.
Added GitHub workflows for CodeQL static analysis and stale issue
grooming.
2023-10-12 09:07:48 -04:00
Stephen Webb
108a02365d Bump SONAME to 8.1.0
New public API calls were added.
2023-09-20 12:08:54 -04:00
Stephen Webb
665a0397cb Fix segfault on QNX x86_64
Various backtraces were failing on QNX x86_64 (including the
x64-unwind-badjmp-signal-frame unit test) with a segfault. Turns out
checking the 'validate memory' flag was not being done when checking for
a signal trampoline in the OS-specific code.
2023-09-20 11:35:03 -04:00
Giovanni Mascellani
b65d0b3af7 Import config.h before dwarf-config.h.
Header tdep-x86_64/dwarf-config.h depends on config.h because it uses
CONFIG_MSABI_SUPPORT.
2023-09-20 10:56:54 -04:00
Xiang.Lin
7e4edd3b13 Fix crash in elf_w(valid_object) on QNX
If ip is invalid, _get_remote_elf_image should return negative value,
otherwise elf_w(get_proc_name) will think elf image is loaded, then
crash in elf_w(valid_object) when want to access elf image buffer.
2023-09-20 10:42:24 -04:00
Stephen M. Webb
7c29dd5832 Adjust DYNAMIC addrs in loaded image
In ELF lookup_symbol_from_dynamic() the DYNAMIC segment was using the raw
virtual address of various sections rather than the offset within the mapped
file. They needed to be adjusted by the virtual address offset withing the ELF
file itself.

Fixes some CI FAILS on x86_64.
2023-09-20 08:49:41 -04:00
Xiang.Lin
1769de8902 Fix maps leak if caller's pathlen is too small 2023-09-18 09:01:26 -04:00
Xiang.Lin
536e9d51db Add unw_get_elf_filename manual 2023-09-15 13:43:35 -04:00
Xiang.Lin
8563227423 Add tests for unw_get_elf_filename 2023-09-15 13:43:35 -04:00
Xiang.Lin
d7e59261fe Get elf filename and fileoffset from ip
For the case that can't get symbol info on board, it's a benefit
if can get filename and offset, then use addr2line to decode on host.
2023-09-15 13:43:35 -04:00
Xiang.Lin
6abbc122d1 Try lookup symbol from DYNAMIC segment
if no symtab and dynsym section, DYNAMIC segment
should have some symtab info, give it a try.
2023-09-11 08:59:02 -04:00
Stephen Webb
e1964a6a2c Move man pages into section 3libunwind
It's a convention that unadorned section 3 man pages are libc functions
and other libraries adorn the section name.

Also added example code to the ptrace and nto remotes and fixed some
unusual Engish-language constructs.

Regenerated all man pages from their LaTEX sources.
2023-09-07 11:20:20 -04:00
Stephen Webb
b8bcb5342c Fix FTBFS on PPC
A PPC-specific macros caused a failure to build from source in some
recent changes due to a missing argument.
2023-09-07 11:19:38 -04:00
Simon Giesecke
8c1333ef8c Cast addr to void*. 2023-09-05 09:50:02 -04:00
Simon Giesecke
5912e84303 Fix unaligned memory accesses in */Ginit.c 2023-09-05 09:50:02 -04:00
Xiang.Lin
a35ff787bf Fix lose caller frame of kernel call on QNX aarch64
QNX aarch64 kernel call without frame pointer and cfi directives,
this will fallback to use frame pointer unwinder, but the frame pointer
is caller's frame pointer, causing caller frame be skipped.

Try to sniff kernel call pattern, get procedure's ip range by symtab
and do the matchup from the beginning of procedure. If matched, then
fallback to use link register unwinder.
2023-09-04 09:32:19 -04:00
Robert Whitton
c1c88dacbb Fix missing fn rename.
Changed files:

src/dwarf/Gfind_proc_info-lsb.c:

I really don't know how this got missed but fix the call to match the remaining instances.
2023-09-01 11:55:20 -04:00
Robert Whitton
3f77a77e63 Address pull request review comments in order to add build-id support. Modified files:
src/coredump/_UCD_get_proc_name.c:
src/elfxx.c:
src/elfxx.h:

Rename load_debuglib to the more generic/agnostic load_debuginfo.

Fix minor pointer infelicity.

ELF_NOTE_GNU and NT_GNU_BUILD_ID will not be defined for non-gnu platforms resulting in compilation failure. Via conditional compilation ensure that find_build_id_path simply returns fail for such platforms - the code will then fall through to the next option. Note that NT_GNU_BUILD_ID doesn't appear in glibc header files until version 2.7 (2007 vintage).

Section headers might be stripped so switch to look for the notes in the PT_NOTE segment in the program headers.
2023-09-01 11:55:20 -04:00
Robert Whitton
ca855cb435 Add support to look for debug libraries via the build-id 2023-09-01 11:55:20 -04:00
happyCoder92
6e6c0713ec Fallback to direct access instead of through /proc/[pid]/root/
In some namespace setups the binary might not even be present in the mnt_ns.
This is the case if it's launched from an fd in a specially prepared empty mnt_ns via a execveat (sandboxing usecase).

Therefore it makes sense to fallback to the original path.
2023-08-25 09:18:04 -04:00
Xiang.Lin
f0645ecb8c Try debuglink if get proc name fail on coredump
Coredump remote use ucd_file to get proc name directly, the backing elf image
file maybe stripped and without symtab, try to get proc name use debug file referred
by debuglink if it can, and elfxx always use debuglink to get proc name.

Signed-off-by: Xiang.Lin <myd.xia@gmail.com>
2023-08-24 10:20:10 -04:00
Kent Cheung
90e3e53f01 Improved AArch64 is_plt_entry implementation
Previous implementation could only handle cases where IP was at the
first instruction in the PLT. This change implements detecting PLT
entries regardless of where the current IP is within the entry.

Added AArch64-only unittest for is_plt_entry. Mock instructions are set
up for testing, using different offsets and non-PLT replacements.
2023-08-22 10:58:22 -04:00
Joyce
358d8390be Create SECURITY.md
Signed-off-by: Joyce <joycebrum@google.com>
2023-08-14 16:09:28 -04:00
Kent Cheung
70f4f920e7 Use pthread_sigmask instead of sigprocmask
pthread_sigmask use in multithreaded programs is explicitly specified by POSIX.1.
2023-08-14 10:37:45 -04:00
Stephen M. Webb
4ffcf81c53 Fix bad git merge in src/Makefile.am
Closes #595
2023-08-06 07:46:53 -04:00
kasperk81 k
5c0f5237f7 typos 2023-08-06 07:05:56 -04:00
Stephen M. Webb
4360a90d7a Fix failing make install
The order in which the libraries are installed is significant so that
dependendies can be properly linked in. Made that depepdency order manifest in
src/Makefile.am.

Took the opportunity to modify the style of src/Makefile.am for consistency,
inclusing alphabetizing all source file lists.
2023-08-04 11:50:14 -04:00
Stephen Webb
22f586d099 Add direct dependent libraries to remotes
The ptrace and coredump remote libraries were underlinked -- they did
not have DT_NEEDED entries for their direct depdendencies. This is bad
practice and is only alleviated by developers guessing what needs to be
linked where and when when using these libraries.

This change adds those dependencies.
2023-07-25 20:16:16 -04:00
Stephen M. Webb
7a032234dd Changes for FreeBSD/Aarch64 resume
Splits `aarch64_local_resume()` into OS-specific source files for aarch64 and adds a FreeBSD implementation.
2023-07-13 08:42:47 -04:00
Dmitry Chagin
b64a553385 Fix QNX build 2023-07-12 14:36:14 +03:00
Ben Hannel
8cd667c654 Fix array indexing bug in dwarf_search_unwind_table 2023-07-10 19:49:39 -04:00
hubin
4a542a787f tests/mapper: avoid calling printf between SIGUSR1 and SIGUSR2
glibc printf() needs using atomic instruction to acquire the stdout lock.
Under ARMv8.0 ISA, atomic instruction is realized using LL-SC routine, which
will keep retrying if other cpu accesses the target memory during the atomic
instruction.
In mapper testcase, parent process uses ptrace to single step mapper program,
thus if calling printf between SIGUSR1 and SIGUSR2, printf will be single-
step executed, and the atomic instruction will be stuck in deadloop.
2023-07-07 11:55:46 -04:00
Dmitry Chagin
e080115299 Add a comment explaining bug of the signal trampolines detecting. 2023-07-07 00:18:44 +03:00
Dmitry Chagin
032abaaac2 Implement unw_resume for FreeBSD/Aarch64. 2023-07-07 00:10:16 +03:00
Dmitry Chagin
de7dcc5104 In preparation to implement resume for FreeBSD/Aarch64 fixed the way
how it check the signal mask is saved.
2023-07-07 00:08:44 +03:00
Dmitry Chagin
599e2db62a Unify the way we search for a frame by stack pointer
Due to the fact that it highly depends on the platform and OS adding
the opportunity to specify stack shift for all ports independently.
2023-07-07 00:08:34 +03:00
Dmitry Chagin
facd089140 Reset sigcontext_format before dwarf_step try.
Otherwise all subsequent frames after the signal trampoline will be marked.
2023-07-07 00:08:19 +03:00
Dmitry Chagin
7c601203ee Move aarch64_local_resume to OS-specific file 2023-07-07 00:08:12 +03:00
Ziyang Chen
634206d8fe Fix run-ptrace-mapper test case failed by allowing unw_get_proc_info() return unsuccessful result. 2023-07-06 14:23:13 -04:00
Kent Cheung
ae6f1d4b9f Corrected restriction for plt check and test to little endian. 2023-07-06 13:57:03 -04:00
Kent Cheung
0d6d11326f Limited plt check to big endian only. 2023-07-06 13:57:03 -04:00
Kent Cheung
78066de654 Addressed static linking failure in unittest. 2023-07-06 13:57:03 -04:00
Kent Cheung
00376d19ab Added support for unwinding through PPC64 PLT entries.
Added function to detect when specified IP is within a PLT entry. This
is determined by reading surrounding instructions and matching them to
known PPC64 PLT procedure instructions.

Added PPC64-only unittest for is_plt_entry. Mock instructions are set up
for testing, using different offsets and non-PLT replacements.
2023-07-06 13:57:03 -04:00
Stephen Webb
2c1613b7ad Remove tilegx as a target
This target is no longer supported by common toolchains or operating
systems. If support is required, it can still be found in libunwind
version 1.7 and earlier.
2023-07-05 14:03:58 -04:00