Merge remote-tracking branch 'origin/GT-3348_ghidravore_dynamic_symbol_names'

This commit is contained in:
Ryan Kurtz 2019-11-27 08:01:31 -05:00
commit 288969711f
3 changed files with 148 additions and 25 deletions

View file

@ -45,11 +45,13 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
private Record record;
private boolean isDeleting = false;
protected String name;
protected Address address;
protected SymbolManager symbolMgr;
protected Lock lock;
private volatile String cachedName;
private volatile long cachedNameModCount;
/**
* Creates a Symbol that is just a placeholder for use when trying to find symbols by using
* {@link Symbol#getID()}. This is useful for locating symbols in Java collections when
@ -82,11 +84,6 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
@Override
public String toString() {
// prefer cached name for speed; it may be stale; call getName() for current value
String temp = name;
if (temp != null) {
return temp;
}
return getName();
}
@ -97,7 +94,6 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
@Override
protected boolean refresh(Record rec) {
name = null;
if (record != null) {
if (rec == null) {
rec = symbolMgr.getSymbolRecord(key);
@ -164,20 +160,31 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
}
@Override
public String getName() {
public final String getName() {
String name = cachedName;
if (hasValidCachedName(name)) {
return name;
}
lock.acquire();
try {
checkIsValid();
if (name == null) {
name = doGetName();
}
return name;
cachedName = doGetName();
cachedNameModCount = symbolMgr.getProgram().getModificationNumber();
return cachedName;
}
finally {
lock.release();
}
}
private boolean hasValidCachedName(String name) {
if (name == null) {
return false;
}
return symbolMgr.getProgram().getModificationNumber() == cachedNameModCount;
}
/**
* The code for creating the name content for this symbol. This code will be called
* with the symbol's lock.
@ -521,7 +528,6 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
lock.acquire();
try {
name = null;
checkDeleted();
checkEditOK();
@ -575,10 +581,10 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
record.setLongValue(SymbolDatabaseAdapter.SYMBOL_PARENT_COL, newNamespace.getID());
record.setString(SymbolDatabaseAdapter.SYMBOL_NAME_COL, newName);
name = newName;
updateSymbolSource(record, source);
updateRecord();
cachedName = null; // we can't clear it until now, since any call to getName()
// will cause the cached name to reset to the old name
if (namespaceChange) {
symbolMgr.symbolNamespaceChanged(this, oldNamespace);
}

View file

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +15,11 @@
*/
package ghidra.program.database.symbol;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import db.*;
import ghidra.program.database.map.*;
import ghidra.program.database.util.DatabaseTableUtils;
import ghidra.program.database.util.RecordFilter;
@ -25,12 +29,6 @@ import ghidra.program.model.symbol.*;
import ghidra.util.exception.*;
import ghidra.util.task.TaskMonitor;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import db.*;
/**
* SymbolDatabaseAdapter for version 2
*/
@ -183,13 +181,12 @@ class SymbolDatabaseAdapterV2 extends SymbolDatabaseAdapter {
}
}
/* (non-Javadoc)
* @see ghidra.program.database.symbol.SymbolDatabaseAdapter#createSymbol(java.lang.String, ghidra.program.model.address.Address, long, ghidra.program.model.symbol.SymbolType, long, int, int)
*/
@Override
Record createSymbol(String name, Address address, long namespaceID, SymbolType symbolType,
long data1, int data2, String data3, SourceType source) throws IOException {
long nextID = symbolTable.getKey();
// avoiding key 0, because we use the negative of the address offset as keys for dynamic symbols
if (nextID == 0) {
nextID++;
}