2626
2727package com .oracle .objectfile .elf .dwarf ;
2828
29- import com .oracle .objectfile .LayoutDecision ;
3029import com .oracle .objectfile .debugentry .CompiledMethodEntry ;
3130import com .oracle .objectfile .debugentry .range .Range ;
3231import com .oracle .objectfile .debuginfo .DebugInfoProvider ;
33- import com .oracle .objectfile .elf .dwarf .constants .DwarfFrameValues ;
34- import com .oracle .objectfile .elf .dwarf .constants .DwarfSectionNames ;
32+ import com .oracle .objectfile .elf .dwarf .constants .DwarfFrameValue ;
3533import org .graalvm .compiler .debug .DebugContext ;
3634
3735import java .util .List ;
3836
37+ import static com .oracle .objectfile .elf .dwarf .constants .DwarfSectionName .DW_FRAME_SECTION ;
38+ import static com .oracle .objectfile .elf .dwarf .constants .DwarfSectionName .DW_LINE_SECTION ;
39+
3940/**
4041 * Section generic generator for debug_frame section.
4142 */
@@ -46,12 +47,8 @@ public abstract class DwarfFrameSectionImpl extends DwarfSectionImpl {
4647 private static final int CFA_CIE_id_default = -1 ;
4748
4849 public DwarfFrameSectionImpl (DwarfDebugInfo dwarfSections ) {
49- super (dwarfSections );
50- }
51-
52- @ Override
53- public String getSectionName () {
54- return DwarfSectionNames .DW_FRAME_SECTION_NAME ;
50+ // debug_frame section depends on debug_line section
51+ super (dwarfSections , DW_FRAME_SECTION , DW_LINE_SECTION );
5552 }
5653
5754 @ Override
@@ -124,7 +121,7 @@ private int writeCIE(byte[] buffer, int p) {
124121 int lengthPos = pos ;
125122 pos = writeInt (0 , buffer , pos );
126123 pos = writeInt (CFA_CIE_id_default , buffer , pos );
127- pos = writeByte ( DwarfFrameValues . DW_CFA_CIE_version , buffer , pos );
124+ pos = writeCIEVersion ( buffer , pos );
128125 pos = writeByte ((byte ) 0 , buffer , pos );
129126 pos = writeULEB (1 , buffer , pos );
130127 pos = writeSLEB (-8 , buffer , pos );
@@ -141,6 +138,10 @@ private int writeCIE(byte[] buffer, int p) {
141138 return pos ;
142139 }
143140
141+ private int writeCIEVersion (byte [] buffer , int pos ) {
142+ return writeByte (DwarfFrameValue .DW_CFA_CIE_version .value (), buffer , pos );
143+ }
144+
144145 private int writeMethodFrame (CompiledMethodEntry compiledEntry , byte [] buffer , int p ) {
145146 int pos = p ;
146147 int lengthPos = pos ;
@@ -198,21 +199,22 @@ private int writeFDEHeader(int lo, int hi, byte[] buffer, int p) {
198199 private int writePaddingNops (byte [] buffer , int p ) {
199200 int pos = p ;
200201 while ((pos & (PADDING_NOPS_ALIGNMENT - 1 )) != 0 ) {
201- pos = writeByte (DwarfFrameValues .DW_CFA_nop , buffer , pos );
202+ pos = writeByte (DwarfFrameValue .DW_CFA_nop . value () , buffer , pos );
202203 }
203204 return pos ;
204205 }
205206
206207 protected int writeDefCFA (int register , int offset , byte [] buffer , int p ) {
207208 int pos = p ;
208- pos = writeByte (DwarfFrameValues .DW_CFA_def_cfa , buffer , pos );
209+ pos = writeByte (DwarfFrameValue .DW_CFA_def_cfa . value () , buffer , pos );
209210 pos = writeULEB (register , buffer , pos );
210211 return writeULEB (offset , buffer , pos );
211212 }
212213
213214 protected int writeDefCFAOffset (int offset , byte [] buffer , int p ) {
214215 int pos = p ;
215- pos = writeByte (DwarfFrameValues .DW_CFA_def_cfa_offset , buffer , pos );
216+ byte op = DwarfFrameValue .DW_CFA_def_cfa_offset .value ();
217+ pos = writeByte (op , buffer , pos );
216218 return writeULEB (offset , buffer , pos );
217219 }
218220
@@ -235,20 +237,20 @@ protected int writeAdvanceLoc0(byte offset, byte[] buffer, int pos) {
235237
236238 protected int writeAdvanceLoc1 (byte offset , byte [] buffer , int p ) {
237239 int pos = p ;
238- byte op = DwarfFrameValues .DW_CFA_advance_loc1 ;
240+ byte op = DwarfFrameValue .DW_CFA_advance_loc1 . value () ;
239241 pos = writeByte (op , buffer , pos );
240242 return writeByte (offset , buffer , pos );
241243 }
242244
243245 protected int writeAdvanceLoc2 (short offset , byte [] buffer , int p ) {
244- byte op = DwarfFrameValues .DW_CFA_advance_loc2 ;
246+ byte op = DwarfFrameValue .DW_CFA_advance_loc2 . value () ;
245247 int pos = p ;
246248 pos = writeByte (op , buffer , pos );
247249 return writeShort (offset , buffer , pos );
248250 }
249251
250252 protected int writeAdvanceLoc4 (int offset , byte [] buffer , int p ) {
251- byte op = DwarfFrameValues .DW_CFA_advance_loc4 ;
253+ byte op = DwarfFrameValue .DW_CFA_advance_loc4 . value () ;
252254 int pos = p ;
253255 pos = writeByte (op , buffer , pos );
254256 return writeInt (offset , buffer , pos );
@@ -270,7 +272,8 @@ protected int writeRestore(int register, byte[] buffer, int p) {
270272 @ SuppressWarnings ("unused" )
271273 protected int writeRegister (int savedReg , int savedToReg , byte [] buffer , int p ) {
272274 int pos = p ;
273- pos = writeByte (DwarfFrameValues .DW_CFA_register , buffer , pos );
275+ byte op = DwarfFrameValue .DW_CFA_register .value ();
276+ pos = writeByte (op , buffer , pos );
274277 pos = writeULEB (savedReg , buffer , pos );
275278 return writeULEB (savedToReg , buffer , pos );
276279 }
@@ -282,38 +285,23 @@ protected int writeRegister(int savedReg, int savedToReg, byte[] buffer, int p)
282285
283286 protected abstract int writeInitialInstructions (byte [] buffer , int pos );
284287
285- /**
286- * The debug_frame section depends on debug_line section.
287- */
288- private static final String TARGET_SECTION_NAME = DwarfSectionNames .DW_LINE_SECTION_NAME ;
289-
290- @ Override
291- public String targetSectionName () {
292- return TARGET_SECTION_NAME ;
293- }
294-
295- private final LayoutDecision .Kind [] targetSectionKinds = {
296- LayoutDecision .Kind .CONTENT ,
297- LayoutDecision .Kind .SIZE
298- };
299-
300- @ Override
301- public LayoutDecision .Kind [] targetSectionKinds () {
302- return targetSectionKinds ;
303- }
304-
305288 private static byte offsetOp (int register ) {
306- assert ( register >> 6 ) == 0 ;
307- return ( byte ) (( DwarfFrameValues . DW_CFA_offset << 6 ) | register );
289+ byte op = DwarfFrameValue . DW_CFA_offset . value () ;
290+ return encodeOp ( op , register );
308291 }
309292
310293 private static byte restoreOp (int register ) {
311- assert ( register >> 6 ) == 0 ;
312- return ( byte ) (( DwarfFrameValues . DW_CFA_restore << 6 ) | register );
294+ byte op = DwarfFrameValue . DW_CFA_restore . value () ;
295+ return encodeOp ( op , register );
313296 }
314297
315298 private static byte advanceLoc0Op (int offset ) {
316- assert (offset >= 0 && offset <= 0x3f );
317- return (byte ) ((DwarfFrameValues .DW_CFA_advance_loc << 6 ) | offset );
299+ byte op = DwarfFrameValue .DW_CFA_advance_loc .value ();
300+ return encodeOp (op , offset );
301+ }
302+
303+ private static byte encodeOp (byte op , int value ) {
304+ assert (value >> 6 ) == 0 ;
305+ return (byte ) ((op << 6 ) | value );
318306 }
319307}
0 commit comments