private byte[] convert0() throws IOException { ArrayList<PositionList.Entry> sortedPositions = buildSortedPositions(); ArrayList<LocalList.Entry> methodArgs = extractMethodArguments(); emitHeader(sortedPositions, methodArgs); annotate(1, String.format("%04x: prologue end",address)); curLocalIdx = emitLocalsAtAddress(curLocalIdx); curPositionIdx = emitPositionsAtAddress(curPositionIdx, sortedPositions); emitPosition(sortedPositions.get(curPositionIdx++)); } else { emitAdvancePc(next - address); emitEndSequence();
emitAdvanceLine(deltaLines); deltaLines = 0; opcode = computeOpcode (deltaLines, deltaAddress); emitAdvancePc(deltaAddress); deltaAddress = 0; opcode = computeOpcode (deltaLines, deltaAddress); emitAdvanceLine(deltaLines); deltaLines = 0; opcode = computeOpcode (deltaLines, deltaAddress); annotate(1, String.format("%04x: line %d", address, line));
/** * Converts and produces annotations on a stream. Does not write * actual bits to the {@code AnnotatedOutput}. * * @param prefix {@code null-ok;} prefix to attach to each line of output * @param debugPrint {@code null-ok;} if specified, an alternate output for * annotations * @param out {@code null-ok;} if specified, where annotations should go * @param consume whether to claim to have consumed output for * {@code out} * @return {@code non-null;} encoded output */ public byte[] convertAndAnnotate(String prefix, PrintWriter debugPrint, AnnotatedOutput out, boolean consume) { this.prefix = prefix; this.debugPrint = debugPrint; annotateTo = out; shouldConsume = consume; byte[] result = convert(); return result; }
/** * Emits a {@link DebugInfoConstants#DBG_RESTART_LOCAL DBG_RESTART_LOCAL} * sequence. * * @param entry entry associated with this restart * @throws IOException */ private void emitLocalRestart(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_RESTART_LOCAL); emitUnsignedLeb128(entry.getRegister()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: +local restart %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local restart"); } }
/** * Emits a {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED * DBG_START_LOCAL_EXTENDED} sequence. * * @param entry entry to emit * @throws IOException */ private void emitLocalStartExtended(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_START_LOCAL_EXTENDED); emitUnsignedLeb128(entry.getRegister()); emitStringIndex(entry.getName()); emitTypeIndex(entry.getType()); emitStringIndex(entry.getSignature()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: +localx %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local start"); } }
new DebugInfoEncoder(positions, locals, file, codeSize, regSize, isStatic, ref); result = encoder.convert(); } else { result = encoder.convertAndAnnotate(prefix, debugPrint, out, consume);
annotate(output.getCursor() - mark, "line_start: " + line); int curParam = getParamBase(); annotate(output.getCursor() - mark, String.format("parameters_size: %04x", szParamTypes)); emitStringIndex(null); } else { emitStringIndex(arg.getName()); emitStringIndex(null); = (found == null || found.getSignature() != null) ? "<unnamed>" : found.getName().toHuman(); annotate(output.getCursor() - mark, "parameter " + parameterName + " " + RegisterSpec.PREFIX + curParam); emitLocalStartExtended(arg);
/** * Emits a {@link DebugInfoConstants#DBG_END_LOCAL DBG_END_LOCAL} sequence. * * @param entry {@code entry non-null;} entry associated with end. * @throws IOException */ private void emitLocalEnd(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_END_LOCAL); output.writeUleb128(entry.getRegister()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: -local %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local end"); } }
/** * Emits the {@link DebugInfoConstants#DBG_END_SEQUENCE DBG_END_SEQUENCE} * bytecode. */ private void emitEndSequence() { output.writeByte(DBG_END_SEQUENCE); if (annotateTo != null || debugPrint != null) { annotate(1, "end sequence"); } } }
/** * Converts this (PositionList, LocalList) pair into a state machine * sequence. * * @return {@code non-null;} encoded byte sequence without padding and * terminated with a {@code 0x00} byte */ public byte[] convert() { try { byte[] ret; ret = convert0(); if (DEBUG) { for (int i = 0 ; i < ret.length; i++) { System.err.printf("byte %02x\n", (0xff & ret[i])); } } return ret; } catch (IOException ex) { throw ExceptionWithContext .withContext(ex, "...while encoding debug info"); } }
/** * Emits a {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED * DBG_START_LOCAL_EXTENDED} sequence. * * @param entry entry to emit * @throws IOException */ private void emitLocalStartExtended(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_START_LOCAL_EXTENDED); emitUnsignedLeb128(entry.getRegister()); emitStringIndex(entry.getName()); emitTypeIndex(entry.getType()); emitStringIndex(entry.getSignature()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: +localx %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local start"); } }
/** * Emits a {@link DebugInfoConstants#DBG_RESTART_LOCAL DBG_RESTART_LOCAL} * sequence. * * @param entry entry associated with this restart * @throws IOException */ private void emitLocalRestart(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_RESTART_LOCAL); emitUnsignedLeb128(entry.getRegister()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: +local restart %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local restart"); } }
new DebugInfoEncoder(positions, locals, file, codeSize, regSize, isStatic, ref); result = encoder.convert(); } else { result = encoder.convertAndAnnotate(prefix, debugPrint, out, consume);
annotate(output.getCursor() - mark, "line_start: " + line); int curParam = getParamBase(); annotate(output.getCursor() - mark, String.format("parameters_size: %04x", szParamTypes)); emitStringIndex(null); } else { emitStringIndex(arg.getName()); emitStringIndex(null); = (found == null || found.getSignature() != null) ? "<unnamed>" : found.getName().toHuman(); annotate(output.getCursor() - mark, "parameter " + parameterName + " " + RegisterSpec.PREFIX + curParam); emitLocalStartExtended(arg);
/** * Emits a {@link DebugInfoConstants#DBG_END_LOCAL DBG_END_LOCAL} sequence. * * @param entry {@code entry non-null;} entry associated with end. * @throws IOException */ private void emitLocalEnd(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_END_LOCAL); output.writeUleb128(entry.getRegister()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: -local %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local end"); } }
/** * Emits the {@link DebugInfoConstants#DBG_END_SEQUENCE DBG_END_SEQUENCE} * bytecode. */ private void emitEndSequence() { output.writeByte(DBG_END_SEQUENCE); if (annotateTo != null || debugPrint != null) { annotate(1, "end sequence"); } } }
/** * Converts this (PositionList, LocalList) pair into a state machine * sequence. * * @return {@code non-null;} encoded byte sequence without padding and * terminated with a {@code 0x00} byte */ public byte[] convert() { try { byte[] ret; ret = convert0(); if (DEBUG) { for (int i = 0 ; i < ret.length; i++) { System.err.printf("byte %02x\n", (0xff & ret[i])); } } return ret; } catch (IOException ex) { throw ExceptionWithContext .withContext(ex, "...while encoding debug info"); } }
private byte[] convert0() throws IOException { ArrayList<PositionList.Entry> sortedPositions = buildSortedPositions(); ArrayList<LocalList.Entry> methodArgs = extractMethodArguments(); emitHeader(sortedPositions, methodArgs); annotate(1, String.format("%04x: prologue end",address)); curLocalIdx = emitLocalsAtAddress(curLocalIdx); curPositionIdx = emitPositionsAtAddress(curPositionIdx, sortedPositions); emitPosition(sortedPositions.get(curPositionIdx++)); } else { emitAdvancePc(next - address); emitEndSequence();
/** * Emits a {@link DebugInfoConstants#DBG_START_LOCAL_EXTENDED * DBG_START_LOCAL_EXTENDED} sequence. * * @param entry entry to emit * @throws IOException */ private void emitLocalStartExtended(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_START_LOCAL_EXTENDED); emitUnsignedLeb128(entry.getRegister()); emitStringIndex(entry.getName()); emitTypeIndex(entry.getType()); emitStringIndex(entry.getSignature()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: +localx %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local start"); } }
emitAdvanceLine(deltaLines); deltaLines = 0; opcode = computeOpcode (deltaLines, deltaAddress); emitAdvancePc(deltaAddress); deltaAddress = 0; opcode = computeOpcode (deltaLines, deltaAddress); emitAdvanceLine(deltaLines); deltaLines = 0; opcode = computeOpcode (deltaLines, deltaAddress); annotate(1, String.format("%04x: line %d", address, line));