2626
2727package com .oracle .objectfile .pecoff .cv ;
2828
29+ import com .oracle .objectfile .ObjectFile ;
30+ import com .oracle .objectfile .SectionName ;
2931import com .oracle .objectfile .debugentry .ClassEntry ;
3032import com .oracle .objectfile .debugentry .FieldEntry ;
3133import com .oracle .objectfile .debugentry .PrimaryEntry ;
3234import com .oracle .objectfile .debugentry .Range ;
3335import com .oracle .objectfile .debugentry .TypeEntry ;
36+ import com .oracle .objectfile .pecoff .PECoffObjectFile ;
3437import org .graalvm .compiler .debug .DebugContext ;
3538
3639import java .lang .reflect .Modifier ;
3740
41+ import static com .oracle .objectfile .elf .dwarf .DwarfDebugInfo .HEAP_BEGIN_NAME ;
42+
3843final class CVSymbolSubsectionBuilder {
3944
4045 private final CVDebugInfo cvDebugInfo ;
4146 private final CVSymbolSubsection cvSymbolSubsection ;
4247 private CVLineRecordBuilder lineRecordBuilder ;
43- private DebugContext debugContext = null ;
48+ private ObjectFile . Section rwSection ;
4449
4550 private boolean noMainFound = true ;
4651
@@ -53,13 +58,24 @@ final class CVSymbolSubsectionBuilder {
5358 * Build DEBUG_S_SYMBOLS record from all classEntries. (CodeView 4 format allows us to build one
5459 * per class or one per function or one big record - which is what we do here).
5560 *
56- * The CodeView symbol section Prolog is also a CVSymbolSubsection, but it is not build in this
61+ * The CodeView symbol section Prolog is also a CVSymbolSubsection, but it is not built in this
5762 * class.
5863 */
5964 void build (DebugContext theDebugContext ) {
60- this .debugContext = theDebugContext ;
61- this .lineRecordBuilder = new CVLineRecordBuilder (debugContext , cvDebugInfo );
62- /* loop over all classes defined in this module. */
65+ this .lineRecordBuilder = new CVLineRecordBuilder (theDebugContext , cvDebugInfo );
66+
67+ /* Find the heap section; static member variables are offset from __svm_heap_begin */
68+ ObjectFile objectFile = cvDebugInfo .getCVTypeSection ().getOwner ();
69+ String rwSectionName = SectionName .SVM_HEAP .getFormatDependentName (objectFile .getFormat ());
70+ rwSection = null ;
71+ for (ObjectFile .Section s : objectFile .getSections ()) {
72+ if (s .getName ().equals (rwSectionName )) {
73+ rwSection = s ;
74+ break ;
75+ }
76+ }
77+
78+ /* Loop over all classes defined in this module. */
6379 for (TypeEntry typeEntry : cvDebugInfo .getTypes ()) {
6480 /* add type records for the class, it's superclass, and instance variables */
6581 addTypeRecords (typeEntry );
@@ -71,7 +87,7 @@ void build(DebugContext theDebugContext) {
7187 }
7288
7389 /**
74- * Build all debug info for a classEntry. (does not yet handle member variables).
90+ * Build all debug info for a classEntry.
7591 *
7692 * @param classEntry current class
7793 */
@@ -80,14 +96,17 @@ private void build(ClassEntry classEntry) {
8096 for (PrimaryEntry primaryEntry : classEntry .getPrimaryEntries ()) {
8197 build (primaryEntry );
8298 }
83- /* Add manifested static fields. */
99+ /* Add manifested static fields as S_GDATA32 records. */
100+ final short sectionId = (short ) ((PECoffObjectFile .PECoffSection ) rwSection ).getSectionID ();
84101 classEntry .fields ().filter (CVSymbolSubsectionBuilder ::isManifestedStaticField ).forEach (f -> {
85102 int typeIndex = cvDebugInfo .getCVTypeSection ().getIndexForPointer (f .getValueType ());
103+ String externName = "static$" + classEntry .getTypeName ().replace ("." , "_" ) + "_" + f .fieldName ();
86104 if (cvDebugInfo .useHeapBase ()) {
87105 /* REL32 offset from heap base register. */
88- addToSymbolSubsection (new CVSymbolSubrecord .CVSymbolRegRel32Record (cvDebugInfo , f . fieldName () , typeIndex , f .getOffset (), cvDebugInfo .getHeapbaseRegister ()));
106+ addToSymbolSubsection (new CVSymbolSubrecord .CVSymbolRegRel32Record (cvDebugInfo , externName , typeIndex , f .getOffset (), cvDebugInfo .getHeapbaseRegister ()));
89107 } else {
90- addToSymbolSubsection (new CVSymbolSubrecord .CVSymbolGData32Record (cvDebugInfo , f .fieldName (), typeIndex , f .getOffset (), (short ) 0 ));
108+ /* Offset from heap begin. */
109+ addToSymbolSubsection (new CVSymbolSubrecord .CVSymbolGData32Record (cvDebugInfo , externName , HEAP_BEGIN_NAME , typeIndex , f .getOffset (), sectionId ));
91110 }
92111 });
93112 }
0 commit comments