Skip to content

Commit

Permalink
chore: include details on the used ArtAdapter in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jpstotz committed Aug 16, 2023
1 parent 4a1a0f6 commit fc46c22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

public class ArtAdapter {

public interface Debugger {
public interface IArtAdapter {
int getRuntimeRegNum(int smaliNum, int regCount, int paramStart);

boolean readNullObject();

String typeForNull();
}

public static Debugger getAdapter(int androidReleaseVer) {
public static IArtAdapter getAdapter(int androidReleaseVer) {
if (androidReleaseVer <= 8) {
return new AndroidOreoAndBelow();
} else {
return new AndroidPieAndAbove();
}
}

public static class AndroidOreoAndBelow implements Debugger {
public static class AndroidOreoAndBelow implements IArtAdapter {
@Override
public int getRuntimeRegNum(int smaliNum, int regCount, int paramStart) {
int localRegCount = regCount - paramStart;
Expand All @@ -36,7 +36,7 @@ public String typeForNull() {
}
}

public static class AndroidPieAndAbove implements Debugger {
public static class AndroidPieAndAbove implements IArtAdapter {
@Override
public int getRuntimeRegNum(int smaliNum, int regCount, int paramStart) {
return smaliNum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class DebugController implements SmaliDebugger.SuspendListener, IDe

private JDebuggerPanel debuggerPanel;
private SmaliDebugger debugger;
private ArtAdapter.Debugger art;
private ArtAdapter.IArtAdapter art;
private final CurrentInfo cur = new CurrentInfo();

private BreakpointStore bpStore;
Expand Down Expand Up @@ -881,7 +881,7 @@ private void updateAllInfo(long threadID, long codeOffset) {
cur.regAdapter = regAdaMap.computeIfAbsent(cur.mthFullID,
k -> RegisterObserver.merge(
getRuntimeDebugInfo(cur.frame),
getRegisterList()));
getSmaliRegisterList(), art));

if (cur.smali.getRegCount(cur.mthFullID) > 0) {
updateAllRegisters(cur.frame);
Expand All @@ -893,7 +893,7 @@ private void updateAllInfo(long threadID, long codeOffset) {
});
}

private List<SmaliRegister> getRegisterList() {
private List<SmaliRegister> getSmaliRegisterList() {
int regCount = cur.smali.getRegCount(cur.mthFullID);
int paramStart = cur.smali.getParamRegStart(cur.mthFullID);
List<SmaliRegister> srs = cur.smali.getRegisterList(cur.mthFullID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ public class RegisterObserver {

private Map<Long, List<Info>> infoMap;
private final List<SmaliRegisterMapping> regList;
private final ArtAdapter.IArtAdapter art;
private boolean hasDbgInfo = false;

private RegisterObserver() {
private RegisterObserver(ArtAdapter.IArtAdapter art) {
regList = new ArrayList<>();
infoMap = Collections.emptyMap();
this.art = art;
}

@NotNull
public static RegisterObserver merge(List<RuntimeVarInfo> rtRegs, List<SmaliRegister> smaliRegs) {
RegisterObserver adapter = new RegisterObserver();
public static RegisterObserver merge(List<RuntimeVarInfo> rtRegs, List<SmaliRegister> smaliRegs, ArtAdapter.IArtAdapter art) {
RegisterObserver adapter = new RegisterObserver(art);
adapter.hasDbgInfo = !rtRegs.isEmpty();
if (adapter.hasDbgInfo) {
adapter.infoMap = new HashMap<>();
Expand Down Expand Up @@ -91,7 +93,7 @@ private SmaliRegisterMapping getRegListEntry(int regNum) {
try {
return regList.get(regNum);
} catch (IndexOutOfBoundsException e) {
throw new RuntimeException(String.format("Register %d does not exist", regNum), e);
throw new RuntimeException(String.format("Register %d does not exist (%s)", regNum, art.getClass().getSimpleName()), e);
}
}

Expand Down

0 comments on commit fc46c22

Please sign in to comment.