|
1
|
|
package com.rox.debug.memory; |
|
2
|
|
|
|
3
|
|
import java.util.function.IntUnaryOperator; |
|
4
|
|
|
|
5
|
|
/** Classic hex-dump text: 16 bytes per row, each row prefixed with its address, optionally with an ASCII column. */ |
|
6
|
|
public final class HexDump { |
|
7
|
|
private static final int BYTES_PER_ROW = 16; |
|
8
|
|
private static final int FIRST_PRINTABLE = 0x20; |
|
9
|
|
private static final int LAST_PRINTABLE = 0x7E; |
|
10
|
|
private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); |
|
11
|
|
|
|
12
|
|
private HexDump(){ |
|
13
|
|
} |
|
14
|
|
|
|
15
|
|
/** |
|
16
|
|
* {@code 0010: 00 01 ... 0F} per row, plus {@code |....|} when {@code ascii} (non-printable bytes as |
|
17
|
|
* {@code .}). A last row shorter than 16 bytes is just shorter. |
|
18
|
|
* |
|
19
|
|
* @param end inclusive |
|
20
|
|
*/ |
|
21
|
|
public static String format(final IntUnaryOperator peek, final int start, final int end, final boolean ascii){ |
|
22
|
|
final StringBuilder out = new StringBuilder(); |
|
23
|
|
final StringBuilder characters = new StringBuilder(BYTES_PER_ROW); |
|
24
|
2
1. format : negated conditional → KILLED
2. format : changed conditional boundary → KILLED
|
for (int row = start; row <= end; row += BYTES_PER_ROW){ |
|
25
|
2
1. format : Replaced integer subtraction with addition → KILLED
2. format : Replaced integer addition with subtraction → KILLED
|
final int rowEnd = Math.min(row + BYTES_PER_ROW - 1, end); |
|
26
|
1
1. format : removed call to java/lang/StringBuilder::setLength → KILLED
|
characters.setLength(0); |
|
27
|
2
1. format : Replaced Shift Right with Shift Left → KILLED
2. format : removed call to com/rox/debug/memory/HexDump::appendHex → KILLED
|
appendHex(out, row >> 8); |
|
28
|
1
1. format : removed call to com/rox/debug/memory/HexDump::appendHex → KILLED
|
appendHex(out, row); |
|
29
|
|
out.append(':'); |
|
30
|
2
1. format : changed conditional boundary → KILLED
2. format : negated conditional → KILLED
|
for (int address = row; address <= rowEnd; address++){ |
|
31
|
|
final int value = peek.applyAsInt(address); |
|
32
|
|
out.append(' '); |
|
33
|
1
1. format : removed call to com/rox/debug/memory/HexDump::appendHex → KILLED
|
appendHex(out, value); |
|
34
|
4
1. format : negated conditional → KILLED
2. format : negated conditional → KILLED
3. format : changed conditional boundary → KILLED
4. format : changed conditional boundary → KILLED
|
characters.append(value >= FIRST_PRINTABLE && value <= LAST_PRINTABLE ? (char) value : '.'); |
|
35
|
|
} |
|
36
|
1
1. format : negated conditional → KILLED
|
if (ascii){ |
|
37
|
|
out.append(" |").append(characters).append('|'); |
|
38
|
|
} |
|
39
|
|
out.append('\n'); |
|
40
|
|
} |
|
41
|
1
1. format : replaced return value with "" for com/rox/debug/memory/HexDump::format → KILLED
|
return out.toString(); |
|
42
|
|
} |
|
43
|
|
|
|
44
|
|
/** |
|
45
|
|
* Two uppercase hex digits for {@code value}'s low byte - by table lookup rather than |
|
46
|
|
* {@code String.format}, which is slow enough to matter when a viewer redraws a 32KB region |
|
47
|
|
* (~35,000 bytes) several times a second. |
|
48
|
|
*/ |
|
49
|
|
private static void appendHex(final StringBuilder out, final int value){ |
|
50
|
3
1. appendHex : Replaced bitwise AND with OR → KILLED
2. appendHex : Replaced Shift Right with Shift Left → KILLED
3. appendHex : Replaced bitwise AND with OR → KILLED
|
out.append(HEX_DIGITS[(value >> 4) & 0x0F]).append(HEX_DIGITS[value & 0x0F]); |
|
51
|
|
} |
|
52
|
|
} |
| | Mutations |
| 24 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] negated conditional → KILLED
2.2 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:aSingleByteRangeIsOneShortRow()] changed conditional boundary → KILLED
|
| 25 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] Replaced integer subtraction with addition → KILLED
2.2 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] Replaced integer addition with subtraction → KILLED
|
| 26 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:eachRowHasItsOwnAsciiColumn()] removed call to java/lang/StringBuilder::setLength → KILLED
|
| 27 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] Replaced Shift Right with Shift Left → KILLED
2.2 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] removed call to com/rox/debug/memory/HexDump::appendHex → KILLED
|
| 28 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] removed call to com/rox/debug/memory/HexDump::appendHex → KILLED
|
| 30 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] changed conditional boundary → KILLED
2.2 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] negated conditional → KILLED
|
| 33 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] removed call to com/rox/debug/memory/HexDump::appendHex → KILLED
|
| 34 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:asciiColumnShowsPrintableBytesAndDotsForTheRest()] negated conditional → KILLED
2.2 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:asciiColumnShowsPrintableBytesAndDotsForTheRest()] negated conditional → KILLED
3.3 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:asciiColumnShowsPrintableBytesAndDotsForTheRest()] changed conditional boundary → KILLED
4.4 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:asciiColumnShowsPrintableBytesAndDotsForTheRest()] changed conditional boundary → KILLED
|
| 36 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] negated conditional → KILLED
|
| 41 |
|
1.1 Location : format Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] replaced return value with "" for com/rox/debug/memory/HexDump::format → KILLED
|
| 50 |
|
1.1 Location : appendHex Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] Replaced bitwise AND with OR → KILLED
2.2 Location : appendHex Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] Replaced Shift Right with Shift Left → KILLED
3.3 Location : appendHex Killed by : com.rox.debug.memory.HexDumpTest.[engine:junit-jupiter]/[class:com.rox.debug.memory.HexDumpTest]/[method:rowsAreLabelledWithAbsoluteAddresses()] Replaced bitwise AND with OR → KILLED
|