Skip to content

Unable to Read ClrThreadStaticField Values on Linux #1302

@meriffa

Description

@meriffa

Hi,

I am trying to get the value of a ClrThreadStaticField field in .NET Core on Linux using ClrMD. Here are the application details:

Target application:

private static readonly ThreadLocal<string> threadLocal = new();

ClrMD application:

foreach (var field in clrObject.Type.ThreadStaticFields)
  DisplayFieldValues(runtime, field);
...
private void DisplayFieldValues(ClrRuntime runtime, ClrThreadStaticField field)
{
  foreach (var thread in runtime.Threads)
      if (field.IsObjectReference)
      {
        var fieldInitialized = field.IsInitialized(thread);
        var fieldAddress = field.GetAddress(thread);
        var fieldValue = field.ReadObject(thread);
      }
}

The ClrMD application uses a full core dump of the Target application created using createdump -f.

In my case ClrThreadStaticField.GetAddress() returns 0 for all threads. As a result ClrThreadStaticField.ReadObject() returns null object (ClrObject.IsNull) for all threads as well.

Everything in LLDB using SOS works as expected:

(lldb) dumpobj 00007eec268c7468
Name:        System.Threading.ThreadLocal`1[[System.String, System.Private.CoreLib]]
...
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
....
0000000000000000  4000d1e       10              SZARRAY  0 TLstatic  ts_slotArray
    >> Thread:Value 50e0:00007eec268c7aa0 50e2:00007eec268cb868 <<
00007f2c3d8373b0  4000d1f       18 ...Private.CoreLib]]  0 TLstatic  ts_finalizationHelper
    >> Thread:Value 50e0:00007eec268c7ac0 50e2:00007eec268cb888 <<

Here are the environment details:

Is there anything that I am missing?

Thanks,

Marian.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions