summaryrefslogtreecommitdiff
path: root/src/vm/debuginfostore.h
blob: 1313b09161c990b1a1f2b500147690490fc4e616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// DebugInfoStore




#ifndef __DebugInfoStore_H_
#define __DebugInfoStore_H_

// Debugging information is described in CorInfo.h
#include "corinfo.h"

#include "nibblestream.h"

//-----------------------------------------------------------------------------
// Information to request Debug info.
//-----------------------------------------------------------------------------
class DebugInfoRequest
{
public:
#ifdef _DEBUG
    // Must initialize via an Init*() function, not just a ctor.
    // In debug, ctor sets fields to values that will cause asserts if not initialized.
    DebugInfoRequest() 
    { 
        SUPPORTS_DAC;
        m_pMD = NULL; 
        m_addrStart = NULL; 
    }
#endif
    // Eventually we may have many ways to initialize a request.
    
    // Init given a method desc and starting address for a native code blob.
    void InitFromStartingAddr(MethodDesc * pDesc, PCODE addrCode);
    

    MethodDesc * GetMD() const { LIMITED_METHOD_DAC_CONTRACT; return m_pMD; }
    PCODE GetStartAddress() const { LIMITED_METHOD_DAC_CONTRACT; return m_addrStart; }

protected:    
    MethodDesc * m_pMD;
    PCODE        m_addrStart;
    
};

//-----------------------------------------------------------------------------
// A Debug-Info Store abstracts the storage of debugging information
//-----------------------------------------------------------------------------


// We pass the IDS an allocator which it uses to hand the data back.
// pData is data the allocator may use for 'new'. 
// Eg, perhaps we have multiple heaps (eg, loader-heaps per appdomain).
typedef BYTE* (*FP_IDS_NEW)(void * pData, size_t cBytes);   


//-----------------------------------------------------------------------------
// Utility routines used for compression
// Note that the compression is just an implementation detail of the stores,
// and so these are just utility routines exposed to the stores.
//-----------------------------------------------------------------------------
class CompressDebugInfo
{
public:
    // Compress incoming data and write it to the provided NibbleWriter.
    static void CompressBoundaries(
        IN ULONG32                       cMap,
        IN ICorDebugInfo::OffsetMapping *pMap,
        IN OUT NibbleWriter * pWriter
    );

    static void CompressVars(
        IN ULONG32                         cVars,
        IN ICorDebugInfo::NativeVarInfo    *vars,
        IN OUT NibbleWriter * pBuffer
    );

    // Stores the result into SBuffer (used by NGen), or in LoaderHeap (used by JIT)
    static PTR_BYTE CompressBoundariesAndVars(
        IN ICorDebugInfo::OffsetMapping * pOffsetMapping,
        IN ULONG            iOffsetMapping,
        IN ICorDebugInfo::NativeVarInfo * pNativeVarInfo,
        IN ULONG            iNativeVarInfo,
        IN OUT SBuffer    * pDebugInfoBuffer,
        IN LoaderHeap     * pLoaderHeap
    );

public:
    // Uncompress data supplied by Compress functions.
    static void RestoreBoundariesAndVars(
        IN FP_IDS_NEW fpNew, IN void * pNewData,
        IN PTR_BYTE                         pDebugInfo,
        OUT ULONG32                       * pcMap, // number of entries in ppMap
        OUT ICorDebugInfo::OffsetMapping **ppMap, // pointer to newly allocated array
        OUT ULONG32                         *pcVars,
        OUT ICorDebugInfo::NativeVarInfo    **ppVars
    ); 

#ifdef DACCESS_COMPILE
    static void EnumMemoryRegions(CLRDataEnumMemoryFlags flags, PTR_BYTE pDebugInfo);
#endif
};

//-----------------------------------------------------------------------------
// Debug-Info-manager. This is like a process-wide store.
// There should be only 1 instance of this and it's process-wide.
// It will delegate to sub-stores as needed
//-----------------------------------------------------------------------------
class DebugInfoManager
{
public:
    static BOOL GetBoundariesAndVars(
        const DebugInfoRequest & request,
        IN FP_IDS_NEW fpNew, IN void * pNewData,
        OUT ULONG32 * pcMap, 
        OUT ICorDebugInfo::OffsetMapping ** ppMap,
        OUT ULONG32 * pcVars, 
        OUT ICorDebugInfo::NativeVarInfo ** ppVars);

#ifdef DACCESS_COMPILE
    static void EnumMemoryRegionsForMethodDebugInfo(CLRDataEnumMemoryFlags flags, MethodDesc * pMD);
#endif
};



#endif // __DebugInfoStore_H_