Skip to content

NFC: Add fprint variants of internal print functions#54835

Merged
topolarity merged 7 commits intomasterfrom
ct/more-fprint
Sep 19, 2025
Merged

NFC: Add fprint variants of internal print functions#54835
topolarity merged 7 commits intomasterfrom
ct/more-fprint

Conversation

@topolarity
Copy link
Copy Markdown
Member

@topolarity topolarity commented Jun 17, 2024

This adds/changes a number of fprint_* variants to internal debug functions:

  • rename + new ios_t * argument:
    • jl_critical_error -> jl_fprint_critical_error
    • jl_print_native_codeloc -> jl_fprint_native_codeloc
    • jl_print_bt_entry_codeloc -> jl_fprint_bt_entry_codeloc
    • jl_gc_debug_print_status -> jl_gc_debug_fprint_status
    • jl_gc_debug_critical_error -> jl_gc_debug_fprint_critical_error
  • new fprint_* variants:
    • jl_safe_fprintf
    • jl_safe_static_show
    • jl_fprint_backtrace(t)

Note that care needs to be taken w.r.t. what ios_t * value is passed into these functions from within a signal handler on Unix. Memory allocation is not async-signal-safe, so the ios_t needs to wrap a raw fd_t handle.

Immediate motivation is #54836

@topolarity topolarity changed the title Add fprint variants of internal print functions NFC: Add fprint variants of internal print functions Jun 17, 2024
@topolarity topolarity changed the title NFC: Add fprint variants of internal print functions Add fprint variants of internal print functions Jun 17, 2024
@topolarity topolarity changed the title Add fprint variants of internal print functions NFC: Add fprint variants of internal print functions Jun 17, 2024
@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Sep 17, 2025

I started to try to rebase this, but then noticed that it changed jl_safe_printf (to STDERR_FILENO) into jl_unsafe_printf (to ios_stderr), which is very much not NFC.

@vtjnash vtjnash closed this Sep 17, 2025
@topolarity
Copy link
Copy Markdown
Member Author

Is that not covered by:

Note that care needs to be taken w.r.t. what ios_t * value is passed into these functions from within a signal handler on Unix.
Memory allocation is not async-signal-safe, so the ios_t needs to wrap a raw fd_t handle.

@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Sep 17, 2025

Ah, I guess that is true. But you're assuming that ios_t is async-signal-safe, which is only true in bm_none mode or if locally created. Do you want to rebase it then, but use ios_t safe_stderr = ios_fd(&safe_stderr, STDERR_FILENO, 0, 0); safe_stderr->bm = bm_none; ios_close(&safe_stderr), where applicable to make it NFC?

@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Sep 17, 2025

I guess actually bm_line might be a better choice also (should give much faster jl_safe_printf, while still being somewhat robust against crashes)

@topolarity
Copy link
Copy Markdown
Member Author

... use ios_t safe_stderr = ios_fd(&safe_stderr, STDERR_FILENO, 0, 0); safe_stderr->bm = bm_none; ios_close(&safe_stderr), where applicable to make it NFC?

No complaints here, but isn't that how it's already configured?

julia/src/support/ios.c

Lines 1074 to 1076 in f0ece4a

ios_stderr = (ios_t*)malloc_s(sizeof(ios_t));
ios_fd(ios_stderr, STDERR_FILENO, 0, 0);
ios_stderr->bm = bm_none;

@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Sep 18, 2025

It is initialized that way, but that isn't the same as being configured that way arbitrarily later in the program. (and yes, that is where I copied that code from haha)

Comment thread src/support/ios.c Outdated
Comment thread src/support/ios.c Outdated
This is not exposed to flisp and is intended for safe printing
in an async-signal context. Accordingly, it must be configured
to write to an `fd` with `bm_none`.
This allows backtraces to be printed somewhere other than stderr
This is similar to `jl_static_show` but is wrapped in a setjmp() for
error tolerance.
@topolarity topolarity requested a review from vtjnash September 18, 2025 20:16
@topolarity topolarity merged commit d975206 into master Sep 19, 2025
7 checks passed
@topolarity topolarity deleted the ct/more-fprint branch September 19, 2025 13:06
@topolarity topolarity restored the ct/more-fprint branch September 19, 2025 13:08
@topolarity topolarity deleted the ct/more-fprint branch September 19, 2025 13:09
topolarity added a commit that referenced this pull request Sep 22, 2025
This change adds a small dialog (disabled by default) for fatal errors on Windows
with a corresponding entry in the `Application` log (in Event Viewer, enabled by default)

This is intended primarily for users of PackageCompiler.jl, who might be
using Julia in a GUI application.

If a Julia-compiled library fails in a GUI application, users currently
have no good way to know why/how their application crashed if, e.g., an
exception was accidentally left unhandled in their Julia code.

Depends on #54835
@fingolfin
Copy link
Copy Markdown
Member

@topolarity I am now seeing this in "build x86_64-linux-gnummtk
" CI tests
, not sure if related to this PR:

/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: ./builtins.o: in function `jl_f_intrinsic_call':
[buildroot]/src/builtins.c:2459: undefined reference to `jl_gc_debug_fprint_critical_error'
/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: ./signal-handling.o: in function `jl_fprint_critical_error':
[buildroot]/src/signal-handling.c:652: undefined reference to `jl_gc_debug_fprint_status'
/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: [buildroot]/src/signal-handling.c:653: undefined reference to `jl_gc_debug_fprint_critical_error'
/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: ./task.o: in function `jl_finish_task':
[buildroot]/src/task.c:355: undefined reference to `jl_gc_debug_fprint_critical_error'
/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: ./safepoint.o: in function `jl_safepoint_init':
[buildroot]/src/safepoint.c:109: undefined reference to `jl_gc_debug_fprint_critical_error'
/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: ./rtutils.o: in function `__stack_chk_fail':
[buildroot]/src/rtutils.c:246: undefined reference to `jl_gc_debug_fprint_critical_error'
/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: [buildroot]/usr/lib/libjulia-internal.so.1.13.0: hidden symbol `jl_gc_debug_fprint_status' isn't defined
/usr/local/bin/../lib/gcc/x86_64-linux-gnu/9.1.0/../../../../x86_64-linux-gnu/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:449: [buildroot]/usr/lib/libjulia-internal.so.1.13.0] Error 1

xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
This adds/changes a number of `fprint_*` variants to internal debug
functions:
  - rename + new `ios_t *` argument:
    - `jl_critical_error` -> `jl_fprint_critical_error`
    - `jl_print_native_codeloc` -> `jl_fprint_native_codeloc`
    - `jl_print_bt_entry_codeloc` -> `jl_fprint_bt_entry_codeloc`
    - `jl_gc_debug_print_status` -> `jl_gc_debug_fprint_status`
- `jl_gc_debug_critical_error` -> `jl_gc_debug_fprint_critical_error`
 - new `fprint_*` variants:
    - `jl_safe_fprintf`
    - `jl_safe_static_show`
    - `jl_fprint_backtrace(t)`

Note that care needs to be taken w.r.t. what `ios_t *` value is passed
into these functions from within a signal handler on Unix. Memory
allocation is not async-signal-safe, so the ios_t needs to wrap a raw
`fd_t` handle.

Immediate motivation is JuliaLang#54836
xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
This change adds a small dialog (disabled by default) for fatal errors on Windows
with a corresponding entry in the `Application` log (in Event Viewer, enabled by default)

This is intended primarily for users of PackageCompiler.jl, who might be
using Julia in a GUI application.

If a Julia-compiled library fails in a GUI application, users currently
have no good way to know why/how their application crashed if, e.g., an
exception was accidentally left unhandled in their Julia code.

Depends on JuliaLang#54835
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants