Bug 23781 - Exception stack trace does not include line numbers in debug build when no debugger is attached
Summary: Exception stack trace does not include line numbers in debug build when no de...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.20.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: master
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-10-13 12:47 UTC by Jiri Banas
Modified: 2017-08-22 11:44 UTC (History)
7 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jiri Banas 2014-10-13 12:47:44 UTC
When I run this obviously wrong code in order to trigger an exception (Logger is my helper class writing to a log file):

  string a = null;
  var b = a.Split ('a');
catch (Exception ex)
  Logger.Write (ex.StackTrace);

I get in my log file:

Exception: Object reference not set to an instance of an object
StackTrace: at TestApp.TestActivity.TestMethod() [0x0000f] in /testapp/TestActivity.cs:4

Clearly showing the filename and the line where the exception has occurred. 

This works when I compile the app in Debug mode and run from Xamarin Studio with the debugger attached on a physical device (not tested in emulator).

However, when I disconnect the device and run the app without the debugger attached, I get in my log file:

Exception: Object reference not set to an instance of an object
StackTrace: at TestApp.TestActivity.TestMethod() () <0x00068>

The filename and line number is missing.

Compiler Debug Information for the project I've set to Full, the APK is compiled in DEBUG mode (assuming MDB files are copied into the APK if this works with the debugger attached). I've read about MONO_ENV_OPTIONS flag which should perhaps invokes the debugging of the app even if no debugger is attached but couldn't get this to work with:

System.Environment.SetEnvironmentVariable ("MONO_ENV_OPTIONS", "--debug");

So why the line numbers are stripped out when no debugger is attached to the same DEBUG compiled APK running on a physical device? This makes and exception logging within the app and therefore debugging away from the development machine useless.
Comment 1 Rodrigo Kumpera 2014-11-12 11:16:13 UTC
You need to ship the debug files in your app to have line information available on backtraces otherwise there's no way for the runtime to figure out what they are.
Comment 2 Jiri Banas 2014-11-12 11:36:03 UTC
I believe the debug files are included in the APK because when I attach a debugger to my device and run the app, I can see the line information. It's just without the debugger attach, the line information doesn't come up. The APK however is still the same. I'm guessing the APK includes the debug files otherwise how else it would have worked with the debugger attached.
Comment 3 Rodrigo Kumpera 2014-11-12 11:42:05 UTC
That looks like a packaging problem on Android.
Comment 4 Jonathan Pryor 2014-11-24 12:16:51 UTC
For now, you can set the `debug.mono.debug` system property:

    adb shell setprop debug.mono.debug 1

This is akin to running with `mono --debug`, which enables line numbers in stack traces (if available).

This does raise an interesting question: should the default Debug runtime behavior be to enable `mono --debug`, which (historically?) increases app memory use and possibly inhibits certain optimizations, or should `mono --debug` be opt-in as it is now?
Comment 5 Jon Douglas [MSFT] 2017-08-08 17:11:08 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
Comment 6 softlion 2017-08-22 11:44:39 UTC
the bug is still there.

Creating a texte file with AndroidEnvironment action does nothing.

   adb shell setprop debug.mono.debug 1
on the device does fix the issue.

So by default no line numbers.
Using Xamarin Android SDK on VS2017.