259 Commits

Author SHA1 Message Date
Jean Boussier
e042e10644 vm_dump.c: avoid USE_MN_THREADS is not defined warning 2025-05-05 15:55:42 +02:00
Jean Boussier
3a2e56e685 Fix USE_MN_THREADS=0 builds on macOS
This was recently broken.
2025-05-05 15:34:32 +02:00
Nobuyoshi Nakada
229784d160
[Bug #21150] macOS: unwinding coroutine workaround is only for arm64 2025-04-05 10:31:20 +09:00
Nobuyoshi Nakada
1bc57b5e0e
[Bug #21150] macOS: Temporary workaround at unwinding coroutine
On arm64 macOS, libunwind (both of system library and homebrew
llvm-18) seems not to handle our coroutine switching code.
2025-02-21 17:53:16 +09:00
Hiroshi SHIBATA
9bbcbc3f36 glibc and musl didn't provide A1-A7, FP and S3-S8 constants.
* https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
* https://git.musl-libc.org/cgit/musl/tree/arch/loongarch64/bits/signal.h
2025-01-07 08:00:22 +09:00
Nobuyoshi Nakada
e4a4dea2c0
Win32: Fix the macro for arm64 on mswin
Visual C defines `_M_`-prefixed macros for the target architectures.
2024-12-17 20:25:06 +09:00
Peter Zhu
2da70aac25 Don't output memory map in crash report for ASAN
ASAN maps a large amount of memory, which makes the memory map section
massive.
2024-12-12 14:07:56 -05:00
Yusuke Endoh
6c5a808b86 Use rb_fiber_scheduler_get() instead of rb_fiber_scheduler_current()
rb_fiber_scheduler_current() may return nil depending on whether the
scheduler is being prevented for some reason, e.g., Fiber.blocking{}.

Co-Authored-By: Samuel Williams <samuel.williams@oriontransfer.co.nz>
2024-11-05 19:48:00 +09:00
Yusuke Endoh
2d2d363012 Let vm_dump show whether the fiber scheduler is enabled or not
... just for the case.
2024-11-05 17:48:01 +09:00
Hiroshi SHIBATA
71b253cdf3 Added LARCH_REG_FP to dump results 2024-09-26 17:53:21 +09:00
Hiroshi SHIBATA
a07bf6d5ff Use constants for register numbers 2024-09-26 17:53:21 +09:00
Hiroshi SHIBATA
bdee1772b2 Removed duplicated dumps 2024-09-26 17:53:21 +09:00
Nobuyoshi Nakada
8350b48cfa
Import patches for old macOS from MacPorts 2024-09-26 10:32:30 +09:00
Pierrick Bouvier
784fdecc4c
windows-arm64 support (#8995)
* [win32] fix compilation for windows-arm64

Credits to MSYS2 Ruby package using this patch.

* [win32] nm use full options

Fix compilation error when using MSYS2 environment.
Credits to MSYS2 Ruby package using this patch.

* [win32] detect llvm-windres (used for windows-arm64)

When adding preprocessor option for llvm-windres (using clang as
parameter), it fails. Thus, do not add this.

It's needed to be able to compile windows-arm64 version, because MSYS2
toolchain is LLVM based (instead of GCC/binutils).

* [win32] pioinfo detection for windows-arm64

This fixes "unexpected ucrtbase.dll" for native windows-arm64 ruby
binary. It does not solve issue with x64 version emulated on this
platform.

Value of pioinfo pointer can be found in ucrtbase.dll at latest adrp/add
sequence before return of _isatty function. This works for both release
and debug ucrt.

Due to the nature of aarch64 ISA (vs x86 or x64), it's needed to
disassemble instructions to retrieve offset value, which is a bit more
complicated than matching specific string patterns.

Details about adrp/add usage can be found in this blog post:
https://devblogs.microsoft.com/oldnewthing/20220809-00/?p=106955
For instruction decoding, the Arm documentation was used as a reference.
2023-11-23 17:17:28 +09:00
Nobuyoshi Nakada
9859dbc7fd
Fix leaked symbols on FreeBSD [ci skip] 2023-10-12 15:07:42 +09:00
Nobuyoshi Nakada
5eef125afe
Dump backtraces to an arbitrary stream when using libprocstat 2023-09-26 09:02:37 +09:00
Nobuyoshi Nakada
d2cc4437a1
Labels cannot at the end of block 2023-09-26 08:31:51 +09:00
Nobuyoshi Nakada
ca2594535d
Add a missing label 2023-09-26 02:15:38 +09:00
Nobuyoshi Nakada
85984a53e8 Abort dumping when output failed 2023-09-25 22:57:28 +09:00
Nobuyoshi Nakada
ac244938e8 Dump backtraces to an arbitrary stream 2023-09-25 22:57:28 +09:00
Takashi Kokubun
38be9a9b72
Clean up OPT_STACK_CACHING (#8132) 2023-07-27 17:27:05 -07:00
Alan Wu
f302e725e1
Remove __bp__ and speed-up bmethod calls (#8060)
Remove rb_control_frame_t::__bp__ and optimize bmethod calls

This commit removes the __bp__ field from rb_control_frame_t. It was
introduced to help MJIT, but since MJIT was replaced by RJIT, we can use
vm_base_ptr() to compute it from the SP of the previous control frame
instead. Removing the field avoids needing to set it up when pushing new
frames.

Simply removing __bp__ would cause crashes since RJIT and YJIT used a
slightly different stack layout for bmethod calls than the interpreter.
At the moment of the call, the two layouts looked as follows:

                   ┌────────────┐    ┌────────────┐
                   │ frame_base │    │ frame_base │
                   ├────────────┤    ├────────────┤
                   │    ...     │    │    ...     │
                   ├────────────┤    ├────────────┤
                   │    args    │    │    args    │
                   ├────────────┤    └────────────┘<─prev_frame_sp
                   │  receiver  │
    prev_frame_sp─>└────────────┘
                     RJIT & YJIT      interpreter

Essentially, vm_base_ptr() needs to compute the address to frame_base
given prev_frame_sp in the diagrams. The presence of the receiver
created an off-by-one situation.

Make the interpreter use the layout the JITs use for iseq-to-iseq
bmethod calls. Doing so removes unnecessary argument shifting and
vm_exec_core() re-entry from the interpreter, yielding a speed
improvement visible through `benchmark/vm_defined_method.yml`:

     patched:   7578743.1 i/s
      master:   4796596.3 i/s - 1.58x  slower

C-to-iseq bmethod calls now store one more VALUE than before, but that
should have negligible impact on overall performance.

Note that re-entering vm_exec_core() used to be necessary for firing
TracePoint events, but that's no longer the case since
9121e57a5f50bc91bae48b3b91edb283bf96cb6b.

Closes ruby/ruby#6428
2023-07-17 13:57:58 -04:00
Alan Wu
2f81bb793f Add thread and ractor counts to bug reports
This is useful for crash triaging. It also helps to hint extension
developers about the misuse of `rb_thread_call_without_gvl()`.

Example:

    $ ./miniruby -e 'Ractor.new{Ractor.receive};
        Thread.new{sleep}; Process.kill:SEGV,Process.pid'
    <snip>
    -- Threading information ---------------------------------------------------
    Total ractor count: 2
    Ruby thread count for this ractor: 2
2023-03-16 10:46:30 -04:00
Nobuyoshi Nakada
da0e6b99c7 Move dump_machine_register definitions 2023-02-23 11:25:56 +09:00
小MAO钓鱼
65ef20d2a7
Add support for LoongArch (#7343)
* vm_dump.c: Dump machine registers on loongarch64 Linux.

* coroutines: Support for native loongarch64 coroutines.

---------

Co-authored-by: zangruochen <zangruochen@loongson.cn>
2023-02-22 13:11:33 +09:00
Matt Valentine-House
72aba64fff Merge gc.h and internal/gc.h
[Feature #19425]
2023-02-09 10:32:29 -05:00
NARUSE, Yui
ee60756495
Fix backtrace beyond _singtramp on macOS arm64 (#7015)
* move ptrauth_strip logic into vm_dump.c
* don't use _sigtramp special logic on arm64
2022-12-24 02:24:55 +09:00
Koichi Sasada
e35c528d72 push dummy frame for loading process
This patch pushes dummy frames when loading code for the
profiling purpose.

The following methods push a dummy frame:
* `Kernel#require`
* `Kernel#load`
* `RubyVM::InstructionSequence.compile_file`
* `RubyVM::InstructionSequence.load_from_binary`

https://bugs.ruby-lang.org/issues/18559
2022-10-20 17:38:28 +09:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Alan Wu
e4fe347302 Prevent printing crash report in a loop
In the event that we are crashing due to a corrupt Ruby stack, we might
re-enter rb_vm_bugreport() due to failed assertions in
rb_backtrace_print_as_bugreport() or SDR(). In these cases we were
printing the bug report ad infinitum with unbounded recusion.

I seem to run into this every once in a while and the amount of log it
prints out is pretty distracting. On CI environments it makes the log
output unnecessarily big. Let's fix this.
2022-06-03 13:50:32 -04:00
Koichi Sasada
d9984f39d3 remove NON_SCALAR_THREAD_ID support
`NON_SCALAR_THREAD_ID` shows `pthread_t` is non-scalar (non-pointer)
and only s390x is known platform. However, the supporting code is
very complex and it is only used for deubg print information.

So this patch removes the support of `NON_SCALAR_THREAD_ID`
and make the code simple.
2022-05-24 10:06:51 +09:00
Koichi Sasada
03d21a4fb0 introduce struct rb_native_thread
`rb_thread_t` contained `native_thread_data_t` to represent
thread implementation dependent data. This patch separates
them and rename it `rb_native_thread` and point it from
`rb_thraed_t`.

Now, 1 Ruby thread (`rb_thread_t`) has 1 native thread (`rb_native_thread`).
2022-04-23 03:08:27 +09:00
Jean byroot Boussier
fa2df520bc
Enable C backtraces on Apple silicon (#5770)
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2022-04-20 11:52:47 +09:00
S-H-GAMELINKS
5b467400d2 [DOC]Some link prefix replace 2022-04-09 17:43:46 +09:00
Nobuyoshi Nakada
42a0bed351
Prefix ccan headers (#4568)
* Prefixed ccan headers

* Remove unprefixed names in ccan/build_assert

* Remove unprefixed names in ccan/check_type

* Remove unprefixed names in ccan/container_of

* Remove unprefixed names in ccan/list

Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
2022-03-30 20:36:31 +13:00
Peter Zhu
5f10bd634f Add ISEQ_BODY macro
Use ISEQ_BODY macro to get the rb_iseq_constant_body of the ISeq. Using
this macro will make it easier for us to change the allocation strategy
of rb_iseq_constant_body when using Variable Width Allocation.
2022-03-24 10:03:51 -04:00
Koichi Sasada
a51e1cd682 enable RUBY_ON_BUG on release build
[Feature #18483]
2022-01-25 16:43:57 +09:00
Nobuyoshi Nakada
ef352c5865
Shorten register names on arm64-darwin not to be truncated 2021-10-10 21:58:56 +09:00
Aaron Patterson
d74e5d5b4f
Crash more nicely when the VM isn't fully set up
If we crash but the VM isn't fully alive, we can get an infinite loop.
2021-06-10 16:31:29 -07:00
Aaron Patterson
459a9f82c9
Don't create objects during GC
If we crash during GC, allocating new objects in the segv handler can
cause an infinite loop.  This commit is to avoid creating new objects in
the crash handler
2021-06-07 11:47:16 -07:00
Takashi Kokubun
007e439fe9
Do not expect ec on rb_vm_bugreport
because a SEGV might happen on an MJIT worker. As you can clearly see
from `if (vm && ec) {`, ec is not guaranteed to exist here.
2021-06-02 21:50:40 -07:00
Benoit Daloze
9e2483ee0b vm_dump.c: rename HAVE_BACKTRACE to USE_BACKTRACE
* HAVE_ macros should only be defined or undefined, not used for their value.
* See [Feature #17752]

Co-authored-by: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
2021-05-04 14:56:55 +02:00
Nobuyoshi Nakada
3cd3d25dde
Unify code by word sizes 2021-04-04 23:29:16 +09:00
David CARLIER
35d30c6ac5 vm dump display return address in the abscence of X30 in Mac ARM64. 2021-03-22 23:32:07 +09:00
Yusuke Endoh
66394aec98 vm_dump.c: Dump machine registers on RISC-V Linux
Fixes [Bug #17615]

Co-Authored-By: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
2021-02-10 04:39:41 +09:00
Yusuke Endoh
f71659d47b Revert "vm_dump.c: Do not show C backtrace on riscv"
This reverts commit 6985bfb72c8d7e7d94f1aad1f0902b602bbfa6da.

Now it should work on riscv by the previous commit. [Bug #17609]
2021-02-04 17:47:12 +09:00
David CARLIER
3813bb4152 vm_dump: dump registers for Mac M1 2021-01-31 09:53:03 +09:00
Nobuyoshi Nakada
d8fb0bca54
Removed excess stringizations on regstr [Bug #17532] 2021-01-13 12:47:42 +09:00
David CARLIER
19157a3c00
vm debug: dump registers on ARM too. (#3900)
* vm debug: dump registers on ARM too.
2020-12-16 15:32:11 +09:00
Takashi Kokubun
885135f84c
Allow an MJIT worker to show a backtrace on SEGV
An MJIT worker thread doesn't have ec, and it's required for SDR() and
rb_backtrace_print_as_bugreport(). Therefore it must be checked.
2020-12-10 21:56:49 -08:00