Merge remote-tracking branch 'origin/patch'

This commit is contained in:
Ryan Kurtz 2021-07-21 14:21:44 -04:00
commit 8fbf33c3e6
27 changed files with 769 additions and 673 deletions

View file

@ -15,7 +15,7 @@
*/
package agent.gdb.manager.impl;
import static ghidra.async.AsyncUtils.loop;
import static ghidra.async.AsyncUtils.*;
import java.io.*;
import java.util.*;
@ -40,6 +40,7 @@ import ghidra.async.AsyncLock.Hold;
import ghidra.dbg.error.DebuggerModelTerminatingException;
import ghidra.dbg.util.HandlerMap;
import ghidra.dbg.util.PrefixMap;
import ghidra.framework.Application;
import ghidra.lifecycle.Internal;
import ghidra.util.Msg;
import ghidra.util.datastruct.ListenerSet;
@ -71,22 +72,9 @@ public class GdbManagerImpl implements GdbManager {
CLI, MI2;
}
private static final boolean LOG_IO = true |
Boolean.parseBoolean(System.getProperty("agent.gdb.manager.log"));
private static final PrintWriter DBG_LOG;
static {
if (LOG_IO) {
try {
DBG_LOG = new PrintWriter(new FileOutputStream(new File("GDB.log")));
}
catch (FileNotFoundException e) {
throw new AssertionError(e);
}
}
else {
DBG_LOG = null;
}
}
private static final boolean LOG_IO =
Boolean.getBoolean("agent.gdb.manager.log");
private static PrintWriter DBG_LOG = null;
private static final String PROMPT_GDB = "(gdb)";
public static final int INTERRUPT_MAX_RETRIES = 3;
public static final int INTERRUPT_RETRY_PERIOD_MILLIS = 100;
@ -111,6 +99,9 @@ public class GdbManagerImpl implements GdbManager {
@Override
public void run() {
if (LOG_IO && DBG_LOG == null) {
initLog();
}
try {
String line;
while (isAlive() && null != (line = reader.readLine())) {
@ -208,6 +199,20 @@ public class GdbManagerImpl implements GdbManager {
defaultHandlers();
}
private void initLog() {
try {
File userSettings = Application.getUserSettingsDirectory();
File logFile = new File(userSettings, "GDB.log");
if (!logFile.canWrite()) {
throw new AssertionError(logFile.getPath() + " appears to be unwritable");
}
DBG_LOG = new PrintWriter(new FileOutputStream(logFile));
}
catch (FileNotFoundException e) {
throw new AssertionError(e);
}
}
CompletableFuture<Void> event(Runnable r, String text) {
//Msg.debug(this, "Queueing event: " + text);
return CompletableFuture.runAsync(r, eventThread).exceptionally(ex -> {

View file

@ -67,7 +67,35 @@ public class GdbModelTargetProcessMemory
synchronized (this) {
regions =
byStart.values().stream().map(this::getTargetRegion).collect(Collectors.toList());
if (regions.isEmpty()) {
Map<BigInteger, GdbMemoryMapping> defaultMap =
new HashMap<BigInteger, GdbMemoryMapping>();
AddressSet addressSet = impl.getAddressFactory().getAddressSet();
BigInteger start = addressSet.getMinAddress().getOffsetAsBigInteger();
BigInteger end = addressSet.getMaxAddress().getOffsetAsBigInteger();
if (end.longValue() < 0) {
BigInteger split = BigInteger.valueOf(Long.MAX_VALUE);
GdbMemoryMapping lmem = new GdbMemoryMapping(start, split,
split.subtract(start), start.subtract(start), "defaultLow");
defaultMap.put(start, lmem);
split = split.add(BigInteger.valueOf(1));
GdbMemoryMapping hmem = new GdbMemoryMapping(split, end,
end.subtract(split), split.subtract(split), "defaultHigh");
defaultMap.put(split, hmem);
}
else {
GdbMemoryMapping mem = new GdbMemoryMapping(start, end,
end.subtract(start), start.subtract(start), "default");
defaultMap.put(start, mem);
}
regions =
defaultMap.values()
.stream()
.map(this::getTargetRegion)
.collect(Collectors.toList());
}
}
setElements(regions, "Refreshed");
}
@ -78,7 +106,10 @@ public class GdbModelTargetProcessMemory
setElements(List.of(), "Refreshed (while no process)");
return AsyncUtils.NIL;
}
return inferior.listMappings().thenAccept(this::updateUsingMappings);
return inferior.listMappings().exceptionally(ex -> {
Msg.error(this, "Could not list regions", ex);
return Map.of(); // empty map will be replaced with default
}).thenAccept(this::updateUsingMappings);
}
protected synchronized GdbModelTargetMemoryRegion getTargetRegion(GdbMemoryMapping mapping) {

View file

@ -66,7 +66,9 @@ public class LinuxPtyChild extends LinuxPtyEndpoint implements PtyChild {
protected PtySession sessionUsingJavaLeader(String[] args, Map<String, String> env)
throws IOException {
final List<String> argsList = new ArrayList<>();
argsList.add("java");
String javaCommand =
System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
argsList.add(javaCommand);
argsList.add("-cp");
argsList.add(System.getProperty("java.class.path"));
argsList.add(LinuxPtySessionLeader.class.getCanonicalName());

View file

@ -118,6 +118,19 @@ src/main/help/help/topics/DebuggerWatchesPlugin/DebuggerWatchesPlugin.html||GHID
src/main/help/help/topics/DebuggerWatchesPlugin/images/DebuggerWatchesPlugin.png||GHIDRA||||END|
src/main/resources/defaultTools/Debugger.tool||GHIDRA||||END|
src/main/resources/images/add.png||FAMFAMFAM Icons - CC 2.5|||famfamfam silk icon set|END|
src/main/resources/images/alt-breakpoint-clear.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoint-disable.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoint-enable.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoint-ineffective-d.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoint-ineffective-e.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoint-mixed-de.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoint-mixed-ed.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoint-set.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoints-clear-all.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoints-disable-all.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoints-enable-all.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoints-make-effective.png||GHIDRA||||END|
src/main/resources/images/alt-breakpoints.png||GHIDRA||||END|
src/main/resources/images/attach.png||GHIDRA||||END|
src/main/resources/images/autoread.png||GHIDRA||||END|
src/main/resources/images/blank.png||GHIDRA||||END|

View file

@ -89,18 +89,32 @@ public interface DebuggerResources {
ImageIcon ICON_SNAP_BACKWARD = ResourceManager.loadImage("images/2leftarrow.png");
ImageIcon ICON_SEEK_PRESENT = ICON_RESUME;
ImageIcon ICON_SET_BREAKPOINT = ResourceManager.loadImage("images/breakpoint-set.png");
ImageIcon ICON_CLEAR_BREAKPOINT = ResourceManager.loadImage("images/breakpoint-clear.png");
ImageIcon ICON_ENABLE_BREAKPOINT = ResourceManager.loadImage("images/breakpoint-enable.png");
boolean altIcons = Boolean.getBoolean("debugger.breakpoints.alt.icons");
ImageIcon ICON_SET_BREAKPOINT =
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-set.png")
: ResourceManager.loadImage("images/breakpoint-set.png");
ImageIcon ICON_CLEAR_BREAKPOINT =
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-clear.png")
: ResourceManager.loadImage("images/breakpoint-clear.png");
ImageIcon ICON_ENABLE_BREAKPOINT =
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-enable.png")
: ResourceManager.loadImage("images/breakpoint-enable.png");
ImageIcon ICON_ENABLE_ALL_BREAKPOINTS =
ResourceManager.loadImage("images/breakpoints-enable-all.png");
ImageIcon ICON_DISABLE_BREAKPOINT = ResourceManager.loadImage("images/breakpoint-disable.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoints-enable-all.png")
: ResourceManager.loadImage("images/breakpoints-enable-all.png");
ImageIcon ICON_DISABLE_BREAKPOINT =
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-disable.png")
: ResourceManager.loadImage("images/breakpoint-disable.png");
ImageIcon ICON_DISABLE_ALL_BREAKPOINTS =
ResourceManager.loadImage("images/breakpoints-disable-all.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoints-disable-all.png")
: ResourceManager.loadImage("images/breakpoints-disable-all.png");
ImageIcon ICON_CLEAR_ALL_BREAKPOINTS =
ResourceManager.loadImage("images/breakpoints-clear-all.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoints-clear-all.png")
: ResourceManager.loadImage("images/breakpoints-clear-all.png");
ImageIcon ICON_MAKE_BREAKPOINTS_EFFECTIVE =
ResourceManager.loadImage("images/breakpoints-make-effective.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoints-make-effective.png")
: ResourceManager.loadImage("images/breakpoints-make-effective.png");
// TODO: Some overlay to indicate dynamic, or new icon altogether
ImageIcon ICON_LISTING = ResourceManager.loadImage("images/Browser.gif");
@ -279,16 +293,21 @@ public interface DebuggerResources {
int PRIORITY_BREAKPOINT_INEFFECTIVE_D_MARKER = MarkerService.BREAKPOINT_PRIORITY;
int PRIORITY_BREAKPOINT_MIXED_ED_MARKER = MarkerService.BREAKPOINT_PRIORITY;
int PRIORITY_BREAKPOINT_MIXED_DE_MARKER = MarkerService.BREAKPOINT_PRIORITY;
ImageIcon ICON_BREAKPOINT_ENABLED_MARKER = ICON_ENABLE_BREAKPOINT;
ImageIcon ICON_BREAKPOINT_DISABLED_MARKER = ICON_DISABLE_BREAKPOINT;
ImageIcon ICON_BREAKPOINT_MIXED_ED_MARKER =
ResourceManager.loadImage("images/breakpoint-mixed-ed.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-mixed-ed.png")
: ResourceManager.loadImage("images/breakpoint-mixed-ed.png");
ImageIcon ICON_BREAKPOINT_MIXED_DE_MARKER =
ResourceManager.loadImage("images/breakpoint-mixed-de.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-mixed-de.png")
: ResourceManager.loadImage("images/breakpoint-mixed-de.png");
ImageIcon ICON_BREAKPOINT_INEFFECTIVE_E_MARKER =
ResourceManager.loadImage("images/breakpoint-ineffective-e.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-ineffective-e.png")
: ResourceManager.loadImage("images/breakpoint-ineffective-e.png");
ImageIcon ICON_BREAKPOINT_INEFFECTIVE_D_MARKER =
ResourceManager.loadImage("images/breakpoint-ineffective-d.png");
altIcons ? ResourceManager.loadImage("images/alt-breakpoint-ineffective-d.png")
: ResourceManager.loadImage("images/breakpoint-ineffective-d.png");
Icon ICON_UNIQUE_REF_READ =
new RotateIcon(ResourceManager.loadImage("images/cursor_arrow.gif"), 180); // TODO
@ -1734,4 +1753,5 @@ public interface DebuggerResources {
action.setSelected(value);
}
}
}

View file

@ -61,6 +61,7 @@ public class DebuggerBreakpointEnablementTableCellRenderer
setIcon(iconForEnablement(en));
setHorizontalAlignment(SwingConstants.CENTER);
setText("");
setToolTipText(en.name());
return this;
}

View file

@ -46,6 +46,7 @@ public class DebuggerBreakpointLocEnabledTableCellRenderer
setIcon(iconForEnabled(en));
setHorizontalAlignment(SwingConstants.CENTER);
setText("");
setToolTipText(en ? "ENABLED" : "DISABLED");
return this;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -278,8 +278,9 @@ void Range::restoreXml(const Element *el,const AddrSpaceManager *manage)
{
spc = (AddrSpace *)0;
bool seenLast = false;
first = 0;
last = ~((uintb)0);
last = 0;
for(int4 i=0;i<el->getNumAttributes();++i) {
if (el->getAttributeName(i) == "space") {
spc = manage->getSpaceByName(el->getAttributeValue(i));
@ -295,6 +296,7 @@ void Range::restoreXml(const Element *el,const AddrSpaceManager *manage)
istringstream s(el->getAttributeValue(i));
s.unsetf(ios::dec | ios::hex | ios::oct);
s >> last;
seenLast = true;
}
else if (el->getAttributeName(i) == "name") {
const Translate *trans = manage->getDefaultCodeSpace()->getTrans();
@ -302,12 +304,16 @@ void Range::restoreXml(const Element *el,const AddrSpaceManager *manage)
spc = point.space;
first = point.offset;
last = (first-1) + point.size;
break; // There should be no (space,first,last) attributes
return; // There should be no (space,first,last) attributes
}
}
if (spc == (AddrSpace *)0)
throw LowlevelError("No address space indicated in range tag");
last = spc->wrapOffset(last);
if (!seenLast) {
last = spc->getHighest();
}
if (first > spc->getHighest() || last > spc->getHighest() || last < first)
throw LowlevelError("Illegal range tag");
}
/// Insert a new Range merging as appropriate to maintain the disjoint cover

View file

@ -98,7 +98,7 @@ void IfcLoadFile::execute(istream &s)
if (capa->getName() == "xml") // If file is xml
dcp->conf->readLoaderSymbols("::"); // Read in loader symbols
#ifdef OPACTION_DEBUG
dcp->conf->setDebugStream(status->optr);
dcp->conf->setDebugStream(status->fileoptr);
#endif
*status->optr << filename << " successfully loaded: " << dcp->conf->getDescription() << endl;
}
@ -160,7 +160,7 @@ void IfcRestore::execute(istream &s)
}
#ifdef OPACTION_DEBUG
dcp->conf->setDebugStream(status->optr);
dcp->conf->setDebugStream(status->fileoptr);
#endif
*status->optr << savefile << " successfully loaded: " << dcp->conf->getDescription() << endl;
}

File diff suppressed because it is too large Load diff

View file

@ -545,7 +545,7 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH
<defblock>[0-9]|[1-9][0-9]+ { return scan_number(yytext,&yylval,false); }
<defblock>0x[0-9a-fA-F]+ { return scan_number(yytext,&yylval,false); }
<defblock>0b[01]+ { return scan_number(yytext,&yylval,false); }
<defblock>\"([^\"]|\"\")*\" { yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; }
<defblock>\"([^\"[:cntrl:]]|\"\")*\" { yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; }
<defblock>[\r\ \t\v]+
<defblock>\n { slgh->nextLine(); }
<defblock>. { return yytext[0]; }
@ -557,7 +557,7 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH
<print>\^ { yylval.ch = '^'; return '^'; }
<print>is { BEGIN(pattern); actionon=0; return IS_KEY; }
<print>[a-zA-Z_.][a-zA-Z0-9_.]* { yylval.str = new string(yytext); return SYMBOLSTRING; }
<print>\"([^\"]|\"\")*\" { yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; }
<print>\"([^\"[:cntrl:]]|\"\")*\" { yylval.str = new string(yytext+1,strlen(yytext)-2); return STRING; }
<print>[\r\ \t\v]+ { yylval.ch = ' '; return ' '; }
<print>\n { slgh->nextLine(); return ' '; }
<print>. { return yytext[0]; }

View file

@ -1058,13 +1058,13 @@ public class DecompileCallback {
Address last = range.getMaxAddress();
boolean readonly = true; // Treat function body as readonly
return buildHoleXML(first.getAddressSpace().getPhysicalSpace().getName(),
first.getOffset(), last.getOffset(), readonly, false);
first.getUnsignedOffset(), last.getUnsignedOffset(), readonly, false);
}
}
// There is probably some sort of error, just return a block
// containing the single queried address
return buildHoleXML(addr.getAddressSpace().getPhysicalSpace().getName(), addr.getOffset(),
addr.getOffset(), true, false);
return buildHoleXML(addr.getAddressSpace().getPhysicalSpace().getName(),
addr.getUnsignedOffset(), addr.getUnsignedOffset(), true, false);
}
private int getExtraPopOverride(Function func, Address addr) {
@ -1175,8 +1175,8 @@ public class DecompileCallback {
// after.getOffset(),readonly,isVolatile);
boolean readonly = isReadOnlyNoData(addr);
boolean isvolatile = isVolatileNoData(addr);
return buildHoleXML(addr.getAddressSpace().getPhysicalSpace().getName(), addr.getOffset(),
addr.getOffset(), readonly, isvolatile);
return buildHoleXML(addr.getAddressSpace().getPhysicalSpace().getName(),
addr.getUnsignedOffset(), addr.getUnsignedOffset(), readonly, isvolatile);
}
private String buildExternalRef(Address addr, ExternalReference ref) {

View file

@ -516,7 +516,8 @@ public class CppExporter extends Exporter {
Address entryPoint = function.getEntryPoint();
CodeUnit codeUnitAt = function.getProgram().getListing().getCodeUnitAt(entryPoint);
if (codeUnitAt == null || !(codeUnitAt instanceof Instruction)) {
return new CPPResult(entryPoint, function.getPrototypeString(false, false), null);
return new CPPResult(entryPoint, function.getPrototypeString(false, false) + ';',
null);
}
monitor.setMessage("Decompiling " + function.getName());

View file

@ -808,7 +808,7 @@ public class BasicCompilerSpec implements CompilerSpec {
seenLast = true;
}
if (!seenLast) {
last = addressSpace.getMaxAddress().getOffset();
last = addressSpace.getMaxAddress().getUnsignedOffset();
}
if (extraRanges == null) {
extraRanges = new ArrayList<>();