summaryrefslogtreecommitdiffstats
path: root/dexlib/src/main/java/org/jf/dexlib/DebugInfoItem.java
blob: 81e023de3f37097f40f68851b01bf2f9569879ff (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*
 * [The "BSD licence"]
 * Copyright (c) 2010 Ben Gruver (JesusFreke)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.jf.dexlib;

import org.jf.dexlib.Debug.DebugInstructionIterator;
import org.jf.dexlib.Debug.DebugOpcode;
import org.jf.dexlib.Util.AnnotatedOutput;
import org.jf.dexlib.Util.ByteArrayInput;
import org.jf.dexlib.Util.Input;
import org.jf.dexlib.Util.Leb128Utils;

import java.util.ArrayList;
import java.util.List;

public class DebugInfoItem extends Item<DebugInfoItem> {
    private int lineStart;
    private StringIdItem[] parameterNames;
    private byte[] encodedDebugInfo;
    private Item[] referencedItems;

    private CodeItem parent = null;

    /**
     * Creates a new uninitialized <code>DebugInfoInfo</code>
     * @param dexFile The <code>DexFile</code> that this item belongs to
     */
    public DebugInfoItem(DexFile dexFile) {
        super(dexFile);
    }

    /**
     * Creates a new <code>DebugInfoItem</code> with the given values
     * @param dexFile The <code>DexFile</code> that this item belongs to
     * @param lineStart the initial value for the line number register for the debug info machine
     * @param parameterNames an array of the names of the associated method's parameters. The entire parameter
     * can be null if no parameter info is available, or any element can be null to indicate no info for that parameter
     * @param encodedDebugInfo the debug info, encoded as a byte array
     * @param referencedItems an array of the items referenced by instructions, in order of occurance in the encoded
     * debug info
     */
    private DebugInfoItem(DexFile dexFile,
                         int lineStart,
                         StringIdItem[] parameterNames,
                         byte[] encodedDebugInfo,
                         Item[] referencedItems) {
        super(dexFile);
        this.lineStart = lineStart;
        this.parameterNames = parameterNames;
        this.encodedDebugInfo = encodedDebugInfo;
        this.referencedItems = referencedItems;
    }

    /**
     * Returns a new <code>DebugInfoItem</code> with the given values
     * @param dexFile The <code>DexFile</code> that this item belongs to
     * @param lineStart the initial value for the line number register for the debug info machine
     * @param parameterNames an array of the names of the associated method's parameters. The entire parameter
     * can be null if no parameter info is available, or any element can be null to indicate no info for that parameter
     * @param encodedDebugInfo the debug info, encoded as a byte array
     * @param referencedItems an array of the items referenced by instructions, in order of occurance in the encoded
     * debug info
     * @return a new <code>DebugInfoItem</code> with the given values
     */
    public static DebugInfoItem internDebugInfoItem(DexFile dexFile,
                         int lineStart,
                         StringIdItem[] parameterNames,
                         byte[] encodedDebugInfo,
                         Item[] referencedItems) {
        DebugInfoItem debugInfoItem = new DebugInfoItem(dexFile, lineStart, parameterNames, encodedDebugInfo,
                referencedItems);
        return dexFile.DebugInfoItemsSection.intern(debugInfoItem);
    }

    /** {@inheritDoc} */
    protected void readItem(Input in, ReadContext readContext) {
        lineStart = in.readUnsignedLeb128();
        parameterNames = new StringIdItem[in.readUnsignedLeb128()];
        IndexedSection<StringIdItem> stringIdSection = dexFile.StringIdsSection;
        for (int i=0; i<parameterNames.length; i++) {
            parameterNames[i] = stringIdSection.getOptionalItemByIndex(in.readUnsignedLeb128() - 1);
        }

        int start = in.getCursor();
        final List<Item> referencedItemsList = new ArrayList<Item>(50);
        DebugInstructionIterator.IterateInstructions(in,
                new DebugInstructionIterator.ProcessRawDebugInstructionDelegate() {
                    @Override
                    public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex,
                                                  int typeIndex, boolean registerIsSigned) {
                        if (nameIndex != -1) {
                            referencedItemsList.add(dexFile.StringIdsSection.getItemByIndex(nameIndex));
                        }
                        if (typeIndex != -1) {
                            referencedItemsList.add(dexFile.TypeIdsSection.getItemByIndex(typeIndex));
                        }
                    }

                    @Override
                    public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNume,
                                                          int nameIndex, int typeIndex, int signatureIndex,
                                                          boolean registerIsSigned) {
                        if (nameIndex != -1) {
                            referencedItemsList.add(dexFile.StringIdsSection.getItemByIndex(nameIndex));
                        }
                        if (typeIndex != -1) {
                            referencedItemsList.add(dexFile.TypeIdsSection.getItemByIndex(typeIndex));
                        }
                        if (signatureIndex != -1) {
                            referencedItemsList.add(dexFile.StringIdsSection.getItemByIndex(signatureIndex));
                        }
                    }

                    @Override
                    public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) {
                        if (nameIndex != -1) {
                            referencedItemsList.add(dexFile.StringIdsSection.getItemByIndex(nameIndex));
                        }
                    }
                });

        referencedItems = new Item[referencedItemsList.size()];
        referencedItemsList.toArray(referencedItems);

        int length = in.getCursor() - start;
        in.setCursor(start);
        encodedDebugInfo = in.readBytes(length);
    }



    /** {@inheritDoc} */
    protected int placeItem(int offset) {
        offset += Leb128Utils.unsignedLeb128Size(lineStart);
        offset += Leb128Utils.unsignedLeb128Size(parameterNames.length);
        for (StringIdItem parameterName: parameterNames) {
            int indexp1;
            if (parameterName == null) {
                indexp1 = 0;
            } else {
                indexp1 = parameterName.getIndex() + 1;
            }
            offset += Leb128Utils.unsignedLeb128Size(indexp1);
        }

        //make a subclass so we can keep track of and access the computed length
        class ProcessDebugInstructionDelegateWithLength extends
                DebugInstructionIterator.ProcessRawDebugInstructionDelegate {
            public int length = 0;
        }
        ProcessDebugInstructionDelegateWithLength pdidwl;

        //final referencedItems = this.referencedItems;

        DebugInstructionIterator.IterateInstructions(new ByteArrayInput(encodedDebugInfo),
                pdidwl = new ProcessDebugInstructionDelegateWithLength() {
                    private int referencedItemsPosition = 0;

                    @Override
                    public void ProcessStaticOpcode(DebugOpcode opcode, int startDebugOffset, int length) {
                        this.length+=length;
                    }

                    @Override
                    public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex,
                                                  int typeIndex, boolean registerIsSigned) {
                        this.length++;
                        if (dexFile.getPreserveSignedRegisters() && registerIsSigned) {
                            this.length += Leb128Utils.signedLeb128Size(registerNum);
                        } else {
                            this.length+=Leb128Utils.unsignedLeb128Size(registerNum);
                        }
                        if (nameIndex != -1) {
                            this.length+=
                               Leb128Utils.unsignedLeb128Size(referencedItems[referencedItemsPosition++].getIndex()+1);
                        } else {
                            this.length++;
                        }
                        if (typeIndex != -1) {
                            this.length+=
                                Leb128Utils.unsignedLeb128Size(referencedItems[referencedItemsPosition++].getIndex()+1);
                        } else {
                            this.length++;
                        }

                    }

                    @Override
                    public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNum, int nameIndex,
                                                          int typeIndex, int signatureIndex,
                                                          boolean registerIsSigned) {
                        this.length++;
                        if (dexFile.getPreserveSignedRegisters() && registerIsSigned) {
                            this.length += Leb128Utils.signedLeb128Size(registerNum);
                        } else {
                            this.length+=Leb128Utils.unsignedLeb128Size(registerNum);
                        }
                        if (nameIndex != -1) {
                            this.length+=
                               Leb128Utils.unsignedLeb128Size(referencedItems[referencedItemsPosition++].getIndex()+1);
                        } else {
                            this.length++;
                        }
                        if (typeIndex != -1) {
                            this.length+=
                               Leb128Utils.unsignedLeb128Size(referencedItems[referencedItemsPosition++].getIndex()+1);
                        } else {
                            this.length++;
                        }
                        if (signatureIndex != -1) {
                            this.length+=
                               Leb128Utils.unsignedLeb128Size(referencedItems[referencedItemsPosition++].getIndex()+1);
                        } else {
                            this.length++;
                        }
                    }

                    @Override
                    public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) {
                        this.length++;
                        if (nameIndex != -1) {
                            this.length+=
                               Leb128Utils.unsignedLeb128Size(referencedItems[referencedItemsPosition++].getIndex()+1);
                        } else {
                            this.length++;
                        }
                    }
                });
        return offset + pdidwl.length;
    }

    /** {@inheritDoc} */
    protected void writeItem(final AnnotatedOutput out) {
        if (out.annotates()) {
            writeItemWithAnnotations(out);
        } else {
            writeItemWithNoAnnotations(out);
        }
    }

    /**
     * Replaces the encoded debug info for this DebugInfoItem. It is expected that the new debug info is compatible
     * with the existing information, i.e. lineStart, referencedItems, parameterNames
     * @param encodedDebugInfo the new encoded debug info
     */
    protected void setEncodedDebugInfo(byte[] encodedDebugInfo) {
        //TODO: I would rather replace this method with some way of saying "The (code) instruction at address changed from A bytes to B bytes. Fixup the debug info accordingly"

        this.encodedDebugInfo = encodedDebugInfo;
    }

    /**
     * Helper method that writes the item, without writing annotations
     * @param out the AnnotatedOutput object
     */
    private void writeItemWithNoAnnotations(final AnnotatedOutput out) {
        out.writeUnsignedLeb128(lineStart);
        out.writeUnsignedLeb128(parameterNames.length);
        for (StringIdItem parameterName: parameterNames) {
            int indexp1;
            if (parameterName == null) {
                indexp1 = 0;
            } else {
                indexp1 = parameterName.getIndex() + 1;
            }
            out.writeUnsignedLeb128(indexp1);
        }

        DebugInstructionIterator.IterateInstructions(new ByteArrayInput(encodedDebugInfo),
                new DebugInstructionIterator.ProcessRawDebugInstructionDelegate() {
                    private int referencedItemsPosition = 0;

                    @Override
                    public void ProcessStaticOpcode(DebugOpcode opcode, int startDebugOffset, int length) {
                        out.write(encodedDebugInfo, startDebugOffset, length);
                    }

                    @Override
                    public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex,
                                                  int typeIndex, boolean registerIsSigned) {
                        out.writeByte(DebugOpcode.DBG_START_LOCAL.value);
                        if (dexFile.getPreserveSignedRegisters() && registerIsSigned) {
                            out.writeSignedLeb128(registerNum);
                        } else {
                            out.writeUnsignedLeb128(registerNum);
                        }
                        if (nameIndex != -1) {
                            out.writeUnsignedLeb128(referencedItems[referencedItemsPosition++].getIndex() + 1);
                        } else {
                            out.writeByte(0);
                        }
                        if (typeIndex != -1) {
                            out.writeUnsignedLeb128(referencedItems[referencedItemsPosition++].getIndex() + 1);
                        } else {
                            out.writeByte(0);
                        }
                    }

                    @Override
                    public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNum, int nameIndex,
                                                          int typeIndex, int signatureIndex,
                                                          boolean registerIsSigned) {
                        out.writeByte(DebugOpcode.DBG_START_LOCAL_EXTENDED.value);
                        if (dexFile.getPreserveSignedRegisters() && registerIsSigned) {
                            out.writeSignedLeb128(registerNum);
                        } else {
                            out.writeUnsignedLeb128(registerNum);
                        }
                        if (nameIndex != -1) {
                            out.writeUnsignedLeb128(referencedItems[referencedItemsPosition++].getIndex() + 1);
                        } else {
                            out.writeByte(0);
                        }
                        if (typeIndex != -1) {
                            out.writeUnsignedLeb128(referencedItems[referencedItemsPosition++].getIndex() + 1);
                        } else {
                            out.writeByte(0);
                        }
                        if (signatureIndex != -1) {
                            out.writeUnsignedLeb128(referencedItems[referencedItemsPosition++].getIndex() + 1);
                        } else {
                            out.writeByte(0);
                        }
                    }

                    @Override
                    public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) {
                        out.writeByte(DebugOpcode.DBG_SET_FILE.value);
                        if (nameIndex != -1) {
                            out.writeUnsignedLeb128(referencedItems[referencedItemsPosition++].getIndex() + 1);
                        } else {
                            out.writeByte(0);
                        }
                    }
                });
    }

    /**
     * Helper method that writes and annotates the item
     * @param out the AnnotatedOutput object
     */
    private void writeItemWithAnnotations(final AnnotatedOutput out) {
        out.annotate(0, parent.getParent().method.getMethodString());
        out.annotate("line_start: 0x" + Integer.toHexString(lineStart) + " (" + lineStart + ")");
        out.writeUnsignedLeb128(lineStart);
        out.annotate("parameters_size: 0x" + Integer.toHexString(parameterNames.length) + " (" + parameterNames.length
                + ")");
        out.writeUnsignedLeb128(parameterNames.length);
        int index = 0;
        for (StringIdItem parameterName: parameterNames) {
            int indexp1;
            if (parameterName == null) {
                out.annotate("[" + index++ +"] parameterName: ");
                indexp1 = 0;
            } else {
                out.annotate("[" + index++ +"] parameterName: " + parameterName.getStringValue());
                indexp1 = parameterName.getIndex() + 1;
            }
            out.writeUnsignedLeb128(indexp1);
        }

        DebugInstructionIterator.IterateInstructions(new ByteArrayInput(encodedDebugInfo),
                new DebugInstructionIterator.ProcessRawDebugInstructionDelegate() {
                    private int referencedItemsPosition = 0;

                    @Override
                    public void ProcessEndSequence(int startDebugOffset) {
                        out.annotate("DBG_END_SEQUENCE");
                        out.writeByte(DebugOpcode.DBG_END_SEQUENCE.value);
                    }

                    @Override
                    public void ProcessAdvancePC(int startDebugOffset, int length, int addressDiff) {
                        out.annotate("DBG_ADVANCE_PC");
                        out.writeByte(DebugOpcode.DBG_ADVANCE_PC.value);
                        out.indent();
                        out.annotate("addr_diff: 0x" + Integer.toHexString(addressDiff) + " (" + addressDiff + ")");
                        out.writeUnsignedLeb128(addressDiff);
                        out.deindent();
                    }

                    @Override
                    public void ProcessAdvanceLine(int startDebugOffset, int length, int lineDiff) {
                        out.annotate("DBG_ADVANCE_LINE");
                        out.writeByte(DebugOpcode.DBG_ADVANCE_LINE.value);
                        out.indent();
                        out.annotate("line_diff: 0x" + Integer.toHexString(lineDiff) + " (" + lineDiff + ")");
                        out.writeSignedLeb128(lineDiff);
                        out.deindent();
                    }

                    @Override
                    public void ProcessStartLocal(int startDebugOffset, int length, int registerNum, int nameIndex,
                                                  int typeIndex, boolean registerIsSigned) {
                        out.annotate("DBG_START_LOCAL");
                        out.writeByte(DebugOpcode.DBG_START_LOCAL.value);
                        out.indent();
                        out.annotate("register_num: 0x" + Integer.toHexString(registerNum) + " (" + registerNum + ")");
                        if (dexFile.getPreserveSignedRegisters() && registerIsSigned) {
                            out.writeSignedLeb128(registerNum);
                        } else {
                            out.writeUnsignedLeb128(registerNum);
                        }
                        if (nameIndex != -1) {
                            Item nameItem = referencedItems[referencedItemsPosition++];
                            assert nameItem instanceof StringIdItem;
                            out.annotate("name: " + ((StringIdItem)nameItem).getStringValue());
                            out.writeUnsignedLeb128(nameItem.getIndex() + 1);
                        } else {
                            out.annotate("name: ");
                            out.writeByte(0);
                        }
                        if (typeIndex != -1) {
                            Item typeItem = referencedItems[referencedItemsPosition++];
                            assert typeItem instanceof TypeIdItem;
                            out.annotate("type: " + ((TypeIdItem)typeItem).getTypeDescriptor());
                            out.writeUnsignedLeb128(typeItem.getIndex() + 1);
                        } else {
                            out.annotate("type: ");
                            out.writeByte(0);
                        }
                        out.deindent();
                    }

                    @Override
                    public void ProcessStartLocalExtended(int startDebugOffset, int length, int registerNum,
                                                          int nameIndex, int typeIndex, int signatureIndex,
                                                          boolean registerIsSigned) {
                        out.annotate("DBG_START_LOCAL_EXTENDED");
                        out.writeByte(DebugOpcode.DBG_START_LOCAL_EXTENDED.value);
                        out.indent();
                        out.annotate("register_num: 0x" + Integer.toHexString(registerNum) + " (" + registerNum + ")");
                        if (dexFile.getPreserveSignedRegisters() && registerIsSigned) {
                            out.writeSignedLeb128(registerNum);
                        } else {
                            out.writeUnsignedLeb128(registerNum);
                        }
                        if (nameIndex != -1) {
                            Item nameItem = referencedItems[referencedItemsPosition++];
                            assert nameItem instanceof StringIdItem;
                            out.annotate("name: " + ((StringIdItem)nameItem).getStringValue());
                            out.writeUnsignedLeb128(nameItem.getIndex() + 1);
                        } else {
                            out.annotate("name: ");
                            out.writeByte(0);
                        }
                        if (typeIndex != -1) {
                            Item typeItem = referencedItems[referencedItemsPosition++];
                            assert typeItem instanceof TypeIdItem;
                            out.annotate("type: " + ((TypeIdItem)typeItem).getTypeDescriptor());
                            out.writeUnsignedLeb128(typeItem.getIndex() + 1);
                        } else {
                            out.annotate("type: ");
                            out.writeByte(0);
                        }
                        if (signatureIndex != -1) {
                            Item signatureItem = referencedItems[referencedItemsPosition++];
                            assert signatureItem instanceof StringIdItem;
                            out.annotate("signature: " + ((StringIdItem)signatureItem).getStringValue());
                            out.writeUnsignedLeb128(signatureItem.getIndex() + 1);
                        } else {
                            out.annotate("signature: ");
                            out.writeByte(0);
                        }
                        out.deindent();
                    }

                    @Override
                    public void ProcessEndLocal(int startDebugOffset, int length, int registerNum,
                                                boolean registerIsSigned) {
                        out.annotate("DBG_END_LOCAL");
                        out.writeByte(DebugOpcode.DBG_END_LOCAL.value);
                        out.annotate("register_num: 0x" + Integer.toHexString(registerNum) + " (" + registerNum + ")");
                        if (registerIsSigned) {
                            out.writeSignedLeb128(registerNum);
                        } else {
                            out.writeUnsignedLeb128(registerNum);
                        }
                    }

                    @Override
                    public void ProcessRestartLocal(int startDebugOffset, int length, int registerNum,
                                                    boolean registerIsSigned) {
                        out.annotate("DBG_RESTART_LOCAL");
                        out.writeByte(DebugOpcode.DBG_RESTART_LOCAL.value);
                        out.annotate("register_num: 0x" + Integer.toHexString(registerNum) + " (" + registerNum + ")");
                        if (registerIsSigned) {
                            out.writeSignedLeb128(registerNum);
                        } else {
                            out.writeUnsignedLeb128(registerNum);
                        }
                    }

                    @Override
                    public void ProcessSetPrologueEnd(int startDebugOffset) {
                        out.annotate("DBG_SET_PROLOGUE_END");
                        out.writeByte(DebugOpcode.DBG_SET_PROLOGUE_END.value);
                    }

                    @Override
                    public void ProcessSetEpilogueBegin(int startDebugOffset) {
                        out.annotate("DBG_SET_EPILOGUE_BEGIN");
                        out.writeByte(DebugOpcode.DBG_SET_EPILOGUE_BEGIN.value);
                    }

                    @Override
                    public void ProcessSetFile(int startDebugOffset, int length, int nameIndex) {
                        out.annotate("DBG_SET_FILE");
                        out.writeByte(DebugOpcode.DBG_SET_FILE.value);
                        if (nameIndex != -1) {
                            Item sourceItem = referencedItems[referencedItemsPosition++];
                            assert sourceItem instanceof StringIdItem;
                            out.annotate("source_file: \"" + ((StringIdItem)sourceItem).getStringValue() + "\"");
                            out.writeUnsignedLeb128(sourceItem.getIndex() + 1);
                        } else {
                            out.annotate("source_file: ");
                            out.writeByte(0);
                        }
                    }

                    @Override
                    public void ProcessSpecialOpcode(int startDebugOffset, int debugOpcode, int lineDiff,
                                                     int addressDiff) {
                        out.annotate("DBG_SPECIAL_OPCODE: line_diff=0x" + Integer.toHexString(lineDiff) + "(" +
                                lineDiff +"),addressDiff=0x" + Integer.toHexString(addressDiff) + "(" + addressDiff +
                                ")");
                        out.writeByte(debugOpcode);
                    }
                });
    }




    /** {@inheritDoc} */
    public ItemType getItemType() {
        return ItemType.TYPE_DEBUG_INFO_ITEM;
    }

    /** {@inheritDoc} */
    public String getConciseIdentity() {
        return "debug_info_item @0x" + Integer.toHexString(getOffset());
    }

    /** {@inheritDoc} */
    public int compareTo(DebugInfoItem other) {
        if (parent == null) {
            if (other.parent == null) {
                return 0;
            }
            return -1;
        }
        if (other.parent == null) {
            return 1;
        }
        return parent.compareTo(other.parent);
    }

    /**
     * Set the <code>CodeItem</code> that this <code>DebugInfoItem</code> is associated with
     * @param codeItem the <code>CodeItem</code> that this <code>DebugInfoItem</code> is associated with
     */
    protected void setParent(CodeItem codeItem) {
        this.parent = codeItem;
    }

    /**
     * @return the initial value for the line number register for the debug info machine
     */
    public int getLineStart() {
        return lineStart;
    }

    /**
     * @return the debug info, encoded as a byte array
     */
    public byte[] getEncodedDebugInfo() {
        return encodedDebugInfo;
    }

    /**
     * @return an array of the items referenced by instructions, in order of occurance in the encoded debug info
     */
    public Item[] getReferencedItems() {
        return referencedItems;
    }

    /**
     * @return an array of the names of the associated method's parameters. The array can be null if no parameter info
     * is available, or any element can be null to indicate no info for that parameter
     */
    public StringIdItem[] getParameterNames() {
        return parameterNames;
    }
}