Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gui): multi-threading issue in DebugController fixed #1702

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
import jadx.gui.utils.NLS;

public final class DebugController implements SmaliDebugger.SuspendListener, IDebugController {
private static final Logger LOG = LoggerFactory.getLogger(DebugController.class);

private static final Logger LOG = LoggerFactory.getLogger(DebugController.class);
private static final String ONCREATE_SIGNATURE = "onCreate(Landroid/os/Bundle;)V";
private static final Map<String, RuntimeType> TYPE_MAP = new HashMap<>();
private static final RuntimeType[] POSSIBLE_TYPES = { RuntimeType.OBJECT, RuntimeType.INT, RuntimeType.LONG };
private static final int DEFAULT_CACHE_SIZE = 512;

private JDebuggerPanel debuggerPanel;
private SmaliDebugger debugger;
Expand Down Expand Up @@ -1115,7 +1116,7 @@ public class FrameNode implements IListElement {
private long thisID;

public FrameNode(long threadID, SmaliDebugger.Frame frame) {
cache = new StringBuilder(16);
cache = new StringBuilder(DEFAULT_CACHE_SIZE);
this.frame = frame;
this.threadID = threadID;
regNodes = Collections.emptyList();
Expand Down Expand Up @@ -1153,7 +1154,7 @@ public void setThisID(long thisID) {
public void setSignatures(String clsSig, String mthSig) {
this.clsSig = clsSig;
this.mthSig = mthSig;
this.cache.delete(0, this.cache.length());
resetCache();
}

public String getClsSig() {
Expand All @@ -1167,7 +1168,7 @@ public String getMthSig() {
public void updateCodeOffset(long codeOffset) {
this.codeOffset = codeOffset;
if (this.codeOffset > -1) {
this.cache.delete(0, this.cache.length());
resetCache();
}
}

Expand Down Expand Up @@ -1209,27 +1210,34 @@ public void onSelected() {
}
}

private void resetCache() {
// Do not reuse thee existing cache instance as this can result in
// multi-threading access issues in case toString() method is active
this.cache = new StringBuilder(DEFAULT_CACHE_SIZE);
}

@Override
public String toString() {
if (cache.length() == 0) {
StringBuilder sbCache = cache;
if (sbCache.length() == 0) {
long off = getCodeOffset();
if (off < 0) {
cache.append(String.format("index: %-4d ", off));
sbCache.append(String.format("index: %-4d ", off));
} else {
cache.append(String.format("index: %04x ", off));
sbCache.append(String.format("index: %04x ", off));
}
if (clsSig == null) {
cache.append("clsID: ").append(frame.getClassID());
sbCache.append("clsID: ").append(frame.getClassID());
} else {
cache.append(clsSig).append("->");
sbCache.append(clsSig).append("->");
}
if (mthSig == null) {
cache.append(" mthID: ").append(frame.getMethodID());
sbCache.append(" mthID: ").append(frame.getMethodID());
} else {
cache.append(mthSig);
sbCache.append(mthSig);
}
}
return cache.toString();
return sbCache.toString();
}
}

Expand Down