Skip to content

[NativeAOT] Add printf gref logging#12218

Open
jonathanpeppers wants to merge 2 commits into
jonathanpeppers-finish-gc-bridge-printffrom
jonathanpeppers-finish-gref-log-formatting
Open

[NativeAOT] Add printf gref logging#12218
jonathanpeppers wants to merge 2 commits into
jonathanpeppers-finish-gc-bridge-printffrom
jonathanpeppers-finish-gref-log-formatting

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Jul 23, 2026

Copy link
Copy Markdown
Member

Dependency

Depends on #12211 and targets its jonathanpeppers-finish-gc-bridge-printf branch.

Part of #12139.

Design

Adds a non-exported printf-style OSBridge::_monodroid_gref_logf() path for the shared CoreCLR/NativeAOT GC bridge. It formats directly to logcat with log_writev() and to the gref file with vfprintf(), using va_copy() so both sinks can consume the arguments without allocating or transferring ownership.

The existing exported _monodroid_gref_log(const char*) entry point, P/Invoke registration, managed callers, and MonoVM implementation remain unchanged.

Scope

Migrates only the three intentionally deferred std::format calls in src/native/clr/host/bridge-processing.cc that feed the gref file/logcat pipeline.

Behavior preservation

  • Retains the existing Logger::gref_log(), Logger::gref_to_logcat(), LOG_GREF, and gc_spew_enabled() gates and surrounding control flow.
  • Preserves message text, punctuation, newlines, source locations, and sink flushing.
  • Uses explicit 0x prefixes with PRIxPTR/uintptr_t so handles retain lowercase pointer-width hexadecimal output, including 0x0 for null handles.
  • Keeps the existing null-message handling on the exported string API; the new internal format argument is also null-safe.
  • Borrows format strings and arguments only for the duration of the call and introduces no returned or transferred ownership.

Non-goals

  • Does not change the managed/native ABI or add a new P/Invoke symbol.
  • Does not modify MonoVM-only gref logging.
  • Does not migrate unrelated formatting outside the NativeAOT-reachable shared GC bridge.

Validation

Prerequisites initialized in the fresh worktree:

  • dotnet build build-tools\xa-prep-tasks\xa-prep-tasks.csproj -v:minimal
  • dotnet build build-tools\Xamarin.Android.Tools.BootstrapTasks\Xamarin.Android.Tools.BootstrapTasks.csproj -v:minimal
  • git submodule update --init -- external/libunwind

Validation run:

  • dotnet build src\native\native-nativeaot.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8a -p:AndroidSupportedTargetAotAbis=arm64 -v:minimal
  • dotnet build src\native\native-clr.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8a -p:AndroidSupportedTargetAotAbis=arm64 -v:minimal
  • rg "std::format" src\native\clr\host\bridge-processing.cc (no matches)
  • git diff --check

No focused existing test target covers this internal OSBridge formatting boundary.

Add an internal printf-style OSBridge path for shared CoreCLR and NativeAOT bridge processing while preserving the existing managed string API and MonoVM behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f05fc3ac-b656-4f49-9b28-4bf39fad49c3
Copilot AI review requested due to automatic review settings July 23, 2026 20:56
Name the internal printf helper _monodroid_gref_logf to match the surrounding gref logging convention.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f05fc3ac-b656-4f49-9b28-4bf39fad49c3

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an internal printf-style gref logging helper for the shared CoreCLR/NativeAOT GC bridge, and migrates the remaining std::format-based gref messages in bridge-processing.cc to avoid libc++ formatting dependencies while preserving existing gref logging behavior.

Changes:

  • Introduce OSBridge::gref_logf(const char* format, ...) which logs to logcat via log_writev() and to the gref file via vfprintf(), using va_copy() for dual-sink consumption.
  • Replace three std::format call sites in src/native/clr/host/bridge-processing.cc with gref_logf() and PRIxPTR-based pointer formatting.
  • Add <cinttypes> include to support PRIxPTR.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/native/clr/include/host/os-bridge.hh Declares new internal OSBridge::gref_logf() printf-style gref logging API.
src/native/clr/host/os-bridge.cc Implements gref_logf() to write to logcat and the gref file without allocating intermediate strings.
src/native/clr/host/bridge-processing.cc Migrates three gref log messages from std::format to gref_logf() with pointer-width hex output.

Comment thread src/native/clr/host/os-bridge.cc
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.

2 participants