Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

[Linux] Implement generation dwarf debuginfo for types and vars #5542

Merged
merged 3 commits into from
Mar 16, 2018

Conversation

kbaladurin
Copy link
Member

No description provided.

@kbaladurin
Copy link
Member Author

//
// type builder is used to convert .Net types into CodeView descriptors.
//
// Copyright (c) Microsoft. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use our standard license headers on new files?

(I am fixing wrong license headers few existing files in #5544.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@jkotas
Copy link
Member

jkotas commented Mar 13, 2018

The CI tests are failing with:

Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point named 'GetPrimitiveTypeIndex' in DLL 'objwriter'.
at ILCompiler.DependencyAnalysis.ObjectWriter.GetPrimitiveTypeIndex(IntPtr objWriter, Int32 type)

We are going to need a new objectwriter package uploaded to make this work. Do you think you could comment out this call, or ignore this exception, so that we can get the change through and work on unloading objectwriter package as separate step?

@kbaladurin kbaladurin force-pushed the dwarf branch 6 times, most recently from 9975c38 to e319a4d Compare March 15, 2018 10:54
@kbaladurin
Copy link
Member Author

@jkotas I've added commit that fixes CI tests with current objwriter package.

//
// dwarf type builder implementation
//
// Copyright (c) Microsoft. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

std::string Name;
int Size;
DwarfMemberFunctionIdTypeInfo *MethodTypeInfo;
std::vector<EHClauseInfo> EHClauseInfos;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the EHClauseInfo help with debugging - what does the debugger use it for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used to emit DW_TAG_try_block and DW_TAG_catch_block DIEs. They will be used in our lldb to fix stepping though try-catch block (similar approach is used for JITed code now).

@@ -10,6 +10,7 @@ interface IMethodCodeNode : IMethodNode, ISymbolDefinitionNode
{
void SetCode(ObjectNode.ObjectData data);
void InitializeFrameInfos(FrameInfo[] frameInfos);
void InitializeEHClauseInfos(EHClauseInfo[] ehClauseInfos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be rather called DebugEHClauseInfo to make it clear it is just for debugger.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public void EmitEHClause(EHClauseInfo ehClause)
{
try
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to have all places with workarounds for the out-of-sync object writer package to be marked with a easy to search for TODO, with a link to #5177

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jkotas
Copy link
Member

jkotas commented Mar 15, 2018

@davidwrighton @sandreenko Could you please take a look since you have done most work on the debuginfo emission so far?

@sandreenko
Copy link

Could you please insert some examples of variables in gdb after your change? For example enum, struct, 1d/2d array, class with recursion, C# String. Thanks.

Konstantin Baladurin added 3 commits March 16, 2018 16:36
- Ignore exceptions in GetPrimitiveTypeIndex and EmitEHClause methods
- Call EmitDebugVarInfo only for Windows
- Don't call GetMethodFunctionIdTypeIndex in EmitDebugFunctionInfo
@kbaladurin
Copy link
Member Author

@sandreenko
Sample:

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

enum TestEnum
{
    A,
    B,
    C,
    D
}

struct TestStruct
{
    public int Int;
    public float Float;
}

class TestClass
{
    public string String;
    public TestClass Object;
    public TestStruct Struct;

    public TestClass(string Name)
    {
        String = Name;
        Object = this;
        Struct.Int = 10;
        Struct.Float = 5.0F;
    }
}

class Program
{
    static int Main()
    {
        TestClass t = new TestClass("Test");
        TestEnum e = TestEnum.B;
        TestStruct s;
        s.Int = (int)e;
        int[] arr = new int[] {1, 2, 3, 4};
        int[,] arr2 = new int[,] {{1, 2}, {3, 4}};

        Console.WriteLine("Test " + t.String);

        return 0;
    }
}

gdb output:

$ gdb -q /media/kbaladurin/data/dotnet/forked/corert/tests/src/Simple/BasicThreading/bin/Debug/x64/native/BasicThreading
Reading symbols from /media/kbaladurin/data/dotnet/forked/corert/tests/src/Simple/BasicThreading/bin/Debug/x64/native/BasicThreading...done.
(gdb) b BasicThreading.cs:44
Breakpoint 1 at 0x5f7aac: file /media/kbaladurin/data/dotnet/forked/corert/tests/src/Simple/BasicThreading/BasicThreading.cs, line 44.
(gdb) r
Starting program: /media/kbaladurin/data/dotnet/forked/corert/tests/src/Simple/BasicThreading/bin/Debug/x64/native/BasicThreading 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffd9be1700 (LWP 27207)]

Thread 1 "BasicThreading" hit Breakpoint 1, BasicThreading_Program__Main () at /media/kbaladurin/data/dotnet/forked/corert/tests/src/Simple/BasicThreading/BasicThreading.cs:44
44	        TestClass t = new TestClass("Test");
(gdb) n
45	        TestEnum e = TestEnum.B;
(gdb) 
47	        s.Int = (int)e;
(gdb) 
48	        int[] arr = new int[] {1, 2, 3, 4};
(gdb) 
49	        int[,] arr2 = new int[,] {{1, 2}, {3, 4}};
(gdb) 
51	        Console.WriteLine("Test " + t.String);
(gdb) i locals 
e = {value__ = 1}
s = {Int = 1, Float = 0}
arr = @0x7fffd9bf6df0: {<S_P_CoreLib_System_Array> = {<Object> = {m_pEEType = 15076776}, _numComponents = 4}, m_NumComponents = 4, m_Data = 0x7fffd9bf6e00}
t = @0x7fffd9bf6dc8: {<Object> = {m_pEEType = 14698816}, String = @0xda49c8, Object = @0x7fffd9bf6dc8, Struct = {Int = 10, Float = 5}}
arr2 = @0x7fffd9bf6e18: {<S_P_CoreLib_System_Array> = {<Object> = {m_pEEType = 15105816}, _numComponents = 4}, m_NumComponents = 4, m_Bounds = {2, 2}, m_Data = 0x7fffd9bf6e38}
(gdb) p arr.m_Data[0]
$1 = 1
(gdb) p arr.m_Data[1]
$2 = 2
(gdb) p arr.m_Data[2]
$3 = 3
(gdb) p arr.m_Data[3]
$4 = 4
(gdb) p arr2.m_Data[0]
$6 = 1
(gdb) p arr2.m_Data[1]
$7 = 2
(gdb) p arr2.m_Data[2]
$8 = 3
(gdb) p arr2.m_Data[3]
$9 = 4
(gdb) p t.Object
$6 = (BasicThreading_TestClass &) @0x7fffd9bf6dc8: {<Object> = {m_pEEType = 14698816}, String = @0xda49c8, Object = @0x7fffd9bf6dc8, Struct = {Int = 10, Float = 5}}
(gdb) p t.String
$7 = (String &) @0xda49c8: {<Object> = {m_pEEType = 14719112}, _stringLength = 4, _firstChar = 84 u'T', __GCSTATICS = 0xe09888}
(gdb) p &t.String._firstChar
$8 = 0xda49d4 u"Test"

Type for enum vars is fixed in #5550

@sandreenko
Copy link

Thank you.
LGTM,
Does CoreRT has dependency on LLVM headers now?

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jkotas
Copy link
Member

jkotas commented Mar 16, 2018

Does CoreRT has dependency on LLVM headers now?

Just the object writer part. It is not built by default.

@jkotas jkotas merged commit d78cf62 into dotnet:master Mar 16, 2018
This was referenced Mar 22, 2018
A-And added a commit to A-And/corert that referenced this pull request Apr 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants