KEMBAR78
[native] Ensure function_name() is part of log message by jonpryor · Pull Request #10302 · dotnet/android · GitHub
Skip to content

Conversation

@jonpryor
Copy link
Contributor

Context: dotnet/runtime#117733

When a .NET for Android app aborts, the abort message should contain the file name, line number, column, and function name of the function which triggered the abort.

Insteda, we get the filename, line number, and column, but we get %s for the function name:

F monodroid: Abort at mono-log-adapter.cc:46:3 ('%s')

Update the log_fatal() invocation within mono-log-adapter.cc to use {} instead of %s, in accordance with C++ std::format. This should cause sloc.function_name() to be properly part of the abort message.

Context: dotnet/runtime#117733

When a .NET for Android app aborts, the abort message should contain
the file name, line number, column, and function name of the function
which triggered the abort.

Insteda, we get the filename, line number, and column, but we get
`%s` for the function name:

    F monodroid: Abort at mono-log-adapter.cc:46:3 ('%s')

Update the `log_fatal()` invocation within `mono-log-adapter.cc`
to use `{}` instead of `%s`, in accordance with C++ `std::format`.
This should cause `sloc.function_name()` to be properly part of the
abort message.
@jonathanpeppers
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers jonathanpeppers requested a review from Copilot July 16, 2025 20:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a formatting issue in native logging code where function names were not being properly displayed in abort messages. Instead of showing the actual function name, abort messages were displaying the literal string %s.

  • Updates the log format string to use C++ std::format syntax with {} instead of %s
  • Ensures that sloc.function_name() is properly included in abort messages for better debugging

log_fatal (
category,
"Abort at {}:{}:{} ('%s')",
"Abort at {}:{}:{} ('{}')",
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

The format string has been updated to use {} for the function name, but there's no corresponding argument being passed for this placeholder. The diff shows the format string change but doesn't show the function_name argument being added to the log_fatal call.

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

I see std.function_name:

log_fatal (
category,
"Abort at {}:{}:{} ('{}')",
file_name,
sloc.line (),
sloc.column (),
sloc.function_name ()
);

Because this is on multiple lines, I bet the AI didn't actually see the full method...

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

The test failures are due to coming from a fork:

'InstallAndroidDependenciesTestGoogleV2' requires a commercial build of .NET for Android.

We probably want those to just ignore instead of fail.

@jonathanpeppers jonathanpeppers merged commit fa23828 into dotnet:main Jul 17, 2025
54 of 59 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants