termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.3k stars 3.06k forks source link

Mono: enable error logging to console rather than logcat #19479

Closed mnyoshie closed 7 months ago

mnyoshie commented 8 months ago

Problem description

mono does not output an error on stderr when it receives an "Unhandled Exception". (mono $? returns 1). But those "Unhandled Exception" message can be seen on strace.

What steps will reproduce the bug?

~ $ cat t.cs
using System;

public class Test {
  static void Main(string[] args) {
        new System.Net.WebClient().DownloadString("http://blahblah.xxxx");
  }
}
~ $ mcs t.cs
~ $ mono t.exe
~ $ echo $?
1
~ $ strace -v -s 6000 -ff mono --debug -v t.exe 2>&1 | grep "Unhandled Exception"
[pid 21305] writev(3, [{iov_base="\09SU\t\363e\307\343\320\"", iov_len=11}, {iov_base="\6", iov_len=1}, {iov_base="mono\0", iov_len=5}, {iov_base="\nUnhandled Exception:\nSystem.Net.WebException: Error: NameResolutionFailure\n  at System.Net.WebConnection.Connect (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x0002c] in /home/builder/.termux-build/mono/src/mcs/class/System/System.Net/WebConnection.cs:137 \n  at System.Net.WebConnection.InitConnection (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x000cc] in /home/builder/.termux-build/mono/src/mcs/class/System/System.Net/WebConnection.cs:273 \n  at System.Net.WebOperation.Run () [0x00052] in /home/builder/.termux-build/mono/src/mcs/class/System/System.Net/WebOperation.cs:268 \n  at System.Net.WebCompletionSource`1[T].WaitForCompletion () [0x0008e] in /home/builder/.termux-build/mono/src/mcs/class/System/System.Net/WebCompletionSource.cs:111 \n  at System.Net.HttpWebRequest.RunWithTimeoutWorker[T] (System.Threading.Tasks.Task`1[TResult] workerTask, System.Int32 timeout, System.Action abort, System.Func`1[TResult] aborted, System.Threading.CancellationTokenSource cts) [0x000e8] in /home/builder/.termux-build/mono/src/mcs/class/System/System.Net/HttpWebRequest.cs:956 \n  at System.Net.HttpWebRequest.GetResponse () [0x0000f] in /home/builder/.termux-build/mono/src/mcs/class/System/System.Net/HttpWebRequest.cs:1218 \n  at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in /home/builder/.termux-build/mono/src/external/corefx/src/System.Net.WebClient/src/System/Net/WebClient.cs:249 \n  at System.Net.WebClient.DownloadBits (System.Net.WebRequest request, System.IO.Stream writeStream) [0x000e6] in /home/builder/.termux-build/mono/src/external/corefx/src/System.Net.WebClient/src/System/Net/WebClient.cs:850 \n  at System.Net.WebClient.DownloadDataInternal (System.Uri address, System.Net.WebRequest& request) [0x00061] in /home/builder/.termux-build/mono/src/external/corefx/src/System.Net.WebClient/src/System/Net/WebClient.cs:302 \n  at System.Net.WebClient.DownloadString (System.Uri address) [0x00011] in /home/builder/.termux-build/mono/src/external/corefx/src/System.Net.WebClient/src/System/Net/WebClient.cs:684 \n  at System.Net.WebClient.DownloadString (System.String address) [0x00000] in /home/builder/.termux-build/mono/src/external/corefx/src/System.Net.WebClient/src/System/Net/WebClient.cs:674 \n  at Test.Main (System.String[] args) [0x00005] in <256a0ae8ecae4486b06bc73bb1c429a5>:0 \n\0", iov_len=2430}], 4) = 2447
~ $

What is the expected behavior?

mono must explicitly output what got wrong.

System information

termux-info:

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=15421
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://linux.domainesia.com/applications/termux/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://linux.domainesia.com/applications/termux/termux-x11 x11 main
Updatable packages:
apt/stable 2.7.10 aarch64 [upgradable from: 2.7.2]
aria2/stable 1.37.0 aarch64 [upgradable from: 1.36.0-7]
bash-completion/stable 2.12.0 all [upgradable from: 2.11-2]
bash/stable 5.2.26 aarch64 [upgradable from: 5.2.15-1]
binutils-bin/stable 2.42 aarch64 [upgradable from: 2.40]
binutils-gold/stable 2.42 aarch64 [upgradable from: 2.40]
binutils-libs/stable 2.42 aarch64 [upgradable from: 2.40]
binutils/stable 2.42 aarch64 [upgradable from: 2.40]
brotli/stable 1.1.0 aarch64 [upgradable from: 1.0.9-1]
c-ares/stable 1.27.0 aarch64 [upgradable from: 1.19.1]
ca-certificates-java/stable 1:2023.12.12 all [upgradable from: 1:2023.08.22]
ca-certificates/stable 1:2023.12.12 all [upgradable from: 1:2023.08.22]
cmake/stable 3.28.3 aarch64 [upgradable from: 3.26.4-2]
command-not-found/stable 2.4.0-15 aarch64 [upgradable from: 2.2.0-10]
coreutils/stable 9.4 aarch64 [upgradable from: 9.3]
curl/stable 8.6.0-1 aarch64 [upgradable from: 8.5.0]
debianutils/stable 5.17 aarch64 [upgradable from: 5.7-1]
dialog/stable 1.3-20240307-0 aarch64 [upgradable from: 1.3-20230209-0]
dos2unix/stable 7.5.2 aarch64 [upgradable from: 7.5.0]
dpkg/stable 1.22.1-1 aarch64 [upgradable from: 1.21.22]
exiftool/stable 12.78 all [upgradable from: 12.64-1]
ffmpeg/stable 6.1.1-2 aarch64 [upgradable from: 6.0-5]
file/stable 5.45 aarch64 [upgradable from: 5.44]
fontconfig/stable 2.15.0 aarch64 [upgradable from: 2.14.2-2]
freetype/stable 2.13.2 aarch64 [upgradable from: 2.13.1]
gawk/stable 5.3.0 aarch64 [upgradable from: 5.2.2]
gdb/stable 14.1 aarch64 [upgradable from: 13.2-1]
ghostscript/stable 10.02.1 aarch64 [upgradable from: 10.02.0]
giflib/stable 5.2.2 aarch64 [upgradable from: 5.2.1-2]
git/stable 2.44.0 aarch64 [upgradable from: 2.41.0]
glib-networking/stable 2.78.1 aarch64 [upgradable from: 2.78.0]
gnupg/stable 2.4.4 aarch64 [upgradable from: 2.4.3]
gnuplot/stable 6.0.0 aarch64 [upgradable from: 5.4.8]
gpgv/stable 2.4.4 aarch64 [upgradable from: 2.4.3]
gst-plugins-base/stable 1.24.0 aarch64 [upgradable from: 1.22.4-1]
gstreamer/stable 1.24.0 aarch64 [upgradable from: 1.22.4]
gzip/stable 1.13 aarch64 [upgradable from: 1.12-1]
imagemagick/stable 7.1.1.29 aarch64 [upgradable from: 7.1.1.14]
jq/stable 1.7.1 aarch64 [upgradable from: 1.6-3]
ldd/stable 0.3 aarch64 [upgradable from: 0.2]
libaom/stable 3.7.0-1 aarch64 [upgradable from: 3.6.1]
libarchive/stable 3.7.2 aarch64 [upgradable from: 3.7.1]
libblocksruntime/stable 1:5.10 aarch64 [upgradable from: 1:5.8]
libc++/stable 26b aarch64 [upgradable from: 25c]
libcairo/stable 1.18.0 aarch64 [upgradable from: 1.17.8]
libcap-ng/stable 2:0.8.4 aarch64 [upgradable from: 2:0.8.3]
libcurl/stable 8.6.0-1 aarch64 [upgradable from: 8.5.0]
libdav1d/stable 1.4.0 aarch64 [upgradable from: 1.2.1]
libde265/stable 1.0.15 aarch64 [upgradable from: 1.0.12]
libdrm/stable 2.4.120 aarch64 [upgradable from: 2.4.115]
libdw/stable 0.190 aarch64 [upgradable from: 0.189]
libelf/stable 0.190 aarch64 [upgradable from: 0.189]
libexpat/stable 2.6.2 aarch64 [upgradable from: 2.5.0-1]
libgc/stable 8.2.6 aarch64 [upgradable from: 8.2.4]
libgcrypt/stable 1.10.3 aarch64 [upgradable from: 1.10.2]
libglvnd-dev/stable 1.7.0 all [upgradable from: 1.6.0-1]
libglvnd/stable 1.7.0 aarch64 [upgradable from: 1.6.0-1]
libgmp/stable 6.3.0 aarch64 [upgradable from: 6.2.1-2]
libgnutls/stable 3.8.3 aarch64 [upgradable from: 3.8.0-1]
libgrpc/stable 1.62.1 aarch64 [upgradable from: 1.60.0-pre1-0]
libheif/stable 1.17.6 aarch64 [upgradable from: 1.16.2-1]
libicu/stable 74.2-1 aarch64 [upgradable from: 74.1+real74.1]
libjpeg-turbo/stable 3.0.2 aarch64 [upgradable from: 3.0.0]
libjxl/stable 0.10.2 aarch64 [upgradable from: 0.8.2-1]
libksba/stable 1.6.6 aarch64 [upgradable from: 1.6.4]
libltdl/stable 2.4.7-1 aarch64 [upgradable from: 2.4.7]
liblzma/stable 5.6.1 aarch64 [upgradable from: 5.4.3]
libmpfr/stable 4.2.1 aarch64 [upgradable from: 4.2.0-p9-0]
libnfs/stable 5.0.3 aarch64 [upgradable from: 5.0.2]
libnghttp2/stable 1.60.0 aarch64 [upgradable from: 1.58.0]
libnpth/stable 1.6-2 aarch64 [upgradable from: 1.6-1]
liborc/stable 0.4.38 aarch64 [upgradable from: 0.4.34]
libpaper/stable 2.2.5 aarch64 [upgradable from: 2.1.2]
libpng/stable 1.6.43 aarch64 [upgradable from: 1.6.40]
libprotobuf-c/stable 1.5.0 aarch64 [upgradable from: 1.4.1-8]
libprotobuf/stable 2:25.1 aarch64 [upgradable from: 2:22.4-2]
librav1e/stable 0.7.1 aarch64 [upgradable from: 0.6.6]
libre2/stable 2024.03.01 aarch64 [upgradable from: 2023.07.01-1]
librsvg/stable 2.57.2 aarch64 [upgradable from: 2.56.3]
libsmartcols/stable 2.39.3-4 aarch64 [upgradable from: 2.39.1]
libsndfile/stable 1.2.2 aarch64 [upgradable from: 1.2.0]
libsoxr/stable 0.1.3-5 aarch64 [upgradable from: 0.1.3-4]
libsqlite/stable 3.44.2 aarch64 [upgradable from: 3.42.0]
libsrt/stable 1.5.3 aarch64 [upgradable from: 1.5.2]
libssh/stable 0.10.6 aarch64 [upgradable from: 0.10.5]
libtiff/stable 4.6.0 aarch64 [upgradable from: 4.5.1-1]
libtirpc/stable 1.3.4 aarch64 [upgradable from: 1.3.3]
libunbound/stable 1.19.2 aarch64 [upgradable from: 1.17.1-2]
libusb/stable 1.0.27 aarch64 [upgradable from: 1.0.26-1]
libuuid/stable 2.39.3-4 aarch64 [upgradable from: 2.39.1]
libuv/stable 1.48.0 aarch64 [upgradable from: 1.46.0]
libvpx/stable 1:1.14.0-1 aarch64 [upgradable from: 1:1.13.0]
libwayland/stable 1.22.0-1 aarch64 [upgradable from: 1.21.0-2]
libwebp/stable 1.3.2 aarch64 [upgradable from: 1.3.1-2]
libx11/stable 1.8.7 aarch64 [upgradable from: 1.8.6]
libxcb/stable 1.16.1 aarch64 [upgradable from: 1.15]
libxml2/stable 2.12.5 aarch64 [upgradable from: 2.11.4-2]
libxrandr/stable 1.5.4 aarch64 [upgradable from: 1.5.3]
littlecms/stable 2.16 aarch64 [upgradable from: 2.15-1]
lsof/stable 4.99.3 aarch64 [upgradable from: 4.98.0]
mesa-dev/stable 23.3.5 all [upgradable from: 23.1.4]
mesa/stable 23.3.5 aarch64 [upgradable from: 23.1.4]
ncurses-ui-libs/stable 6.4.20231001-3 aarch64 [upgradable from: 6.4.20230527]
ncurses/stable 6.4.20231001-3 aarch64 [upgradable from: 6.4.20230527]
ndk-sysroot/stable 26b-1 aarch64 [upgradable from: 25c]
netcat-openbsd/stable 1.226-1-0 aarch64 [upgradable from: 1.219-1-0]
nginx/stable 1.25.4 aarch64 [upgradable from: 1.25.3]
ngspice/stable 42 aarch64 [upgradable from: 39.3]
ocl-icd/stable 2.3.2 aarch64 [upgradable from: 2.3.1-3]
oniguruma/stable 6.9.9 aarch64 [upgradable from: 6.9.8]
openexr/stable 3.2.1 aarch64 [upgradable from: 3.1.9]
openjdk-17-x/stable 17.0-29 aarch64 [upgradable from: 17.0-27]
openjdk-17/stable 17.0-29 aarch64 [upgradable from: 17.0-27]
openjpeg/stable 2.5.2 aarch64 [upgradable from: 2.5.0-1]
pcre2/stable 10.43 aarch64 [upgradable from: 10.42]
perl/stable 5.38.2 aarch64 [upgradable from: 5.38.0]
poppler/stable 23.10.0-1 aarch64 [upgradable from: 23.07.0]
procps/stable 3.3.17-5 aarch64 [upgradable from: 3.3.17-2]
protobuf-dev/stable 2:25.1 aarch64 [upgradable from: 2:22.4-2]
protobuf/stable 2:25.1 aarch64 [upgradable from: 2:22.4-2]
psmisc/stable 23.6-2 aarch64 [upgradable from: 23.6-1]
pulseaudio/stable 17.0-1 aarch64 [upgradable from: 16.1-4]
python-ensurepip-wheels/stable 3.11.8 all [upgradable from: 3.11.4-2]
python-numpy/stable 1.26.4-1 aarch64 [upgradable from: 1.26.4]
python-pip/stable 24.0-1 all [upgradable from: 23.2.1]
python/stable 3.11.8 aarch64 [upgradable from: 3.11.4-2]
qemu-common/stable 1:8.0.2-1 aarch64 [upgradable from: 1:8.0.2]
qemu-system-x86-64-headless/stable 1:8.0.2-1 aarch64 [upgradable from: 1:8.0.2]
qemu-user-x86-64/stable 1:8.0.2-1 aarch64 [upgradable from: 1:8.0.2]
strace/stable 6.7 aarch64 [upgradable from: 6.4]
termux-am/stable 0.8.0 all [upgradable from: 0.4]
termux-api/stable 0.58.0-1 aarch64 [upgradable from: 0.57]
termux-tools/stable 1.41.1 all [upgradable from: 1.38.3]
texlive-bin/stable 20230313-3 aarch64 [upgradable from: 20230313-2]
unbound/stable 1.19.2 aarch64 [upgradable from: 1.17.1-2]
util-linux/stable 2.39.3-4 aarch64 [upgradable from: 2.39.1]
vim-runtime/stable 9.1.0100 all [upgradable from: 9.0.1650]
vim/stable 9.1.0100 aarch64 [upgradable from: 9.0.1650]
whois/stable 5.5.21 aarch64 [upgradable from: 5.5.20]
xkeyboard-config/x11 2.41 all [upgradable from: 2.39]
xz-utils/stable 5.6.1 aarch64 [upgradable from: 5.4.3]
zbar/stable 0.23.93 aarch64 [upgradable from: 0.23.92-1]
zlib/stable 1.3.1 aarch64 [upgradable from: 1.2.13]
zsh-completions/stable 0.35.0 all [upgradable from: 0.34.0]
zsh/stable 5.9-3 aarch64 [upgradable from: 5.9-2]
zziplib/stable 0.13.74 aarch64 [upgradable from: 0.13.72-1]
termux-tools version:
1.38.3
Android version:
9
Kernel build information:
Linux localhost 4.4.111-21427293 #1 SMP PREEMPT Mon Jul 25 18:15:22 KST 2022 aarch64 Android
Device manufacturer:
samsung
Device model:
SM-G955F
LD Variables:
LD_LIBRARY_PATH=:/data/data/com.termux/files/usr/lib/clang/17/lib/linux
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
mnyoshie commented 8 months ago

Maybe this has something to do:

https://github.com/cydhaselton/mono-android/blob/6cb3b4391788cd71d80a865da925490757a2aea9/README.md?plain=1#L325-L329

Edit: Hmm but the build.sh don't include those. https://github.com/termux/termux-packages/blob/master/packages/mono/build.sh

Maybe a problem in the upstream?

sylirre commented 8 months ago

It sends such information to Android log. Use logcat to see your exception. (marking as not a bug)

Meanwhile I tried to replace http://blahblah.xxxx with http://termux.dev and got an exception that TLS support is not available. So the networking support can be considered as broken or incomplete, but I think this is for another ticket.

sylirre commented 8 months ago

I think default to logcat is specific to Android OS target. This can be changed by patching sources.

mnyoshie commented 8 months ago

Oh I see... Seems like logging with https://github.com/mono/mono/blob/main/mono/utils/mono-log-common.c instead of https://github.com/mono/mono/blob/main/mono/utils/mono-log-android.c should do the trick I believe.

The common logging functions are set in last https://github.com/mono/mono/blob/0cb9dac52f9a3280fe167e3aefd194b1e4dd26c3/mono/utils/mono-logger.c#L181-L184