mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GT-3348 fixing stale dynamic symbol names
This commit is contained in:
parent
c15b263b90
commit
cec9d954ed
3 changed files with 149 additions and 21 deletions
|
@ -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 String cachedName;
|
||||
private 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
|
||||
|
@ -83,7 +85,7 @@ 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;
|
||||
String temp = cachedName;
|
||||
if (temp != null) {
|
||||
return temp;
|
||||
}
|
||||
|
@ -97,7 +99,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 +165,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 +533,6 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
|
|||
|
||||
lock.acquire();
|
||||
try {
|
||||
name = null;
|
||||
checkDeleted();
|
||||
checkEditOK();
|
||||
|
||||
|
@ -575,10 +586,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);
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue