GP-5977 refactor DWARF DIE serialization into its own class

This will allow reading DIEs from multiple files.
This commit is contained in:
dev747368
2026-02-09 18:50:32 +00:00
parent f51dfa9299
commit 7dff240fe6
44 changed files with 1550 additions and 1337 deletions

View File

@@ -21,7 +21,6 @@ import java.io.IOException;
import java.util.List;
import ghidra.app.script.GhidraScript;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.dwarf.*;
import ghidra.app.util.bin.format.dwarf.line.DWARFLine.SourceFileAddr;
import ghidra.app.util.bin.format.dwarf.sectionprovider.DWARFSectionProvider;
@@ -42,25 +41,23 @@ public class DWARFLineInfoCommentScript extends GhidraScript {
}
DWARFImportOptions importOptions = new DWARFImportOptions();
try (DWARFProgram dprog = new DWARFProgram(currentProgram, importOptions, monitor, dsp)) {
try (DWARFProgram dprog = new DWARFProgram(currentProgram, importOptions, dsp)) {
dprog.init(monitor);
addSourceLineInfo(dprog);
}
}
private void addSourceLineInfo(DWARFProgram dprog) throws CancelledException, IOException {
BinaryReader reader = dprog.getDebugLineBR();
if (reader == null) {
if (!dprog.getDIEContainer().hasLineInfo()) {
return;
}
int count = 0;
monitor.initialize(reader.length(), "DWARF Source Line Info");
List<DWARFCompilationUnit> compUnits = dprog.getCompilationUnits();
for (DWARFCompilationUnit cu : compUnits) {
monitor.initialize(dprog.getDIEContainer().getLineDataSize(), "DWARF Source Line Info");
for (DWARFCompilationUnit cu : dprog.getDIEContainer().getCompilationUnits()) {
try {
monitor.checkCancelled();
monitor.setProgress(cu.getLine().getStartOffset());
List<SourceFileAddr> allSFA = cu.getLine().getAllSourceFileAddrInfo(cu, reader);
List<SourceFileAddr> allSFA = cu.getLine().getAllSourceFileAddrInfo(cu);
for (SourceFileAddr sfa : allSFA) {
Address addr = dprog.getCodeAddress(sfa.address());
DWARFUtil.appendComment(currentProgram, addr, CommentType.EOL, "",

View File

@@ -24,7 +24,6 @@ import java.io.IOException;
import java.util.*;
import ghidra.app.script.GhidraScript;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.dwarf.*;
import ghidra.app.util.bin.format.dwarf.external.*;
import ghidra.app.util.bin.format.dwarf.line.DWARFLine;
@@ -65,7 +64,7 @@ public class DWARFLineInfoSourceMapScript extends GhidraScript {
}
DWARFImportOptions importOptions = new DWARFImportOptions();
try (DWARFProgram dprog = new DWARFProgram(currentProgram, importOptions, monitor, dsp)) {
try (DWARFProgram dprog = new DWARFProgram(currentProgram, importOptions, dsp)) {
dprog.init(monitor);
addSourceLineInfo(dprog);
}
@@ -73,8 +72,7 @@ public class DWARFLineInfoSourceMapScript extends GhidraScript {
private void addSourceLineInfo(DWARFProgram dprog)
throws CancelledException, IOException, LockException, AddressOverflowException {
BinaryReader reader = dprog.getDebugLineBR();
if (reader == null) {
if (!dprog.getDIEContainer().hasLineInfo()) {
popup("Unable to get reader for debug line info");
return;
}
@@ -127,7 +125,7 @@ public class DWARFLineInfoSourceMapScript extends GhidraScript {
continue;
}
}
sourceInfo.addAll(cu.getLine().getAllSourceFileAddrInfo(cu, reader));
sourceInfo.addAll(cu.getLine().getAllSourceFileAddrInfo(cu));
}
monitor.setIndeterminate(true);

View File

@@ -37,8 +37,7 @@ public class DWARFMacroScript extends GhidraScript {
return;
}
try (DWARFProgram dprog =
new DWARFProgram(currentProgram, new DWARFImportOptions(), monitor, dsp)) {
try (DWARFProgram dprog = new DWARFProgram(currentProgram, new DWARFImportOptions(), dsp)) {
dprog.init(monitor);
for (DWARFCompilationUnit cu : dprog.getCompilationUnits()) {
dumpMacros(cu.getMacros(), 0);