dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.28k stars 4.74k forks source link

[NativeAOT] REGNUM_AMBIENT_SP not properly handled in debugging information #77089

Open filipnavara opened 2 years ago

filipnavara commented 2 years ago

Neither DWARF nor CodeView debugging information seems to represent REGNUM_AMBIENT_SP variable location correctly. For CodeView there's a TODO in the code. For DWARF it just generates garbage register references (takes a code branch that assumes it's a floating point register):

0x00108d61:     DW_TAG_formal_parameter
                  DW_AT_name [DW_FORM_strp] ("fHasThreadStatics")
                  DW_AT_decl_file [DW_FORM_data1]   ("/Users/filipnavara/Projects/runtime/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs")
                  DW_AT_decl_line [DW_FORM_data1]   (1)
                  DW_AT_type [DW_FORM_ref4] (0x000000c8 "bool")
                  DW_AT_location [DW_FORM_sec_offset]   (0x000bcd2c: 
                     [0x00000000001c5ee0, 0x00000000001c5f24): DW_OP_bregx B31+168
                     [0x00000000001c5f24, 0x00000000001c6164): DW_OP_breg29 W29+176)
filipnavara commented 2 years ago

I believe the proper way to express it in DWARF is to use DW_OP_call_frame_cfa (possibly with some architecture specific offset).