Skip to content

NativeAOT: exception.StackTrace() does not show line numbers #68714

@smhmhmd

Description

@smhmhmd

Description

exception.StackTrace() does not show line numbers for the NativeAOT binary, it shows for the dotnet dll

Reproduction Steps

 // The dotnet dll is built as  'dotnet publish -c release --self-contained -r linux-x64'
 // The NativeAOT binary is built as 'dotnet publish -r linux-x64 --self-contained'

  using System;

namespace MyApp
{
	internal class Program
	{
		static double SafeDivision(double x, double y)
		{
			if (y == 0)
				throw new DivideByZeroException();
			return x / y;
		}

		static void func() {
			// Input for test purposes. Change the values to see
			// exception handling behavior.
			double a = 98, b = 0;
			double result;

			try
			{
				result = SafeDivision(a, b);
				Console.WriteLine("{0} divided by {1} = {2}", a, b, result);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.GetType().FullName);
				Console.WriteLine(ex.Message);
				Console.WriteLine(ex.StackTrace);
			}
		}

		public static void Main()
		{
			func();
		}
	}
}

Expected behavior

Line numbers show in this expected exception:

  $ ./exception 
   System.DivideByZeroException
   Attempted to divide by zero.
      at MyApp.Program.SafeDivision(Double x, Double y) in /home/ubuntu/exception/Program.cs:line 10
      at MyApp.Program.func() in /home/ubuntu/exception/Program.cs:line 22

Actual behavior

Line numbers do not show with the NativeAOT binary:

   $ ./exception 
     System.DivideByZeroException
     Attempted to divide by zero.
       at MyApp.Program.SafeDivision(Double, Double) + 0x67
       at MyApp.Program.func() + 0x65

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions