GP-5924 DWARF debuginfod support

This commit is contained in:
dev747368
2025-09-17 16:37:40 +00:00
parent e4e2df4a09
commit fe5ea1c91a
51 changed files with 3861 additions and 708 deletions

View File

@@ -19,12 +19,14 @@
// Note that you can run this script on a program that has already been analyzed by the
// DWARF analyzer.
//@category DWARF
import java.io.File;
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;
import ghidra.app.util.bin.format.dwarf.line.DWARFLine.SourceFileAddr;
import ghidra.app.util.bin.format.dwarf.line.DWARFLine.SourceFileInfo;
@@ -76,6 +78,11 @@ public class DWARFLineInfoSourceMapScript extends GhidraScript {
popup("Unable to get reader for debug line info");
return;
}
ExternalDebugInfo extDebugInfo = ExternalDebugInfo.fromProgram(dprog.getGhidraProgram());
boolean hasBuildId = extDebugInfo != null && extDebugInfo.hasBuildId();
ExternalDebugFilesService edfs =
ExternalDebugFilesService.forProgram(dprog.getGhidraProgram());
int entryCount = 0;
List<DWARFCompilationUnit> compUnits = dprog.getCompilationUnits();
SourceFileManager sourceManager = currentProgram.getSourceFileManager();
@@ -103,6 +110,14 @@ public class DWARFLineInfoSourceMapScript extends GhidraScript {
SourceFile sFile = new SourceFile(path, type, sfi.md5());
sourceManager.addSourceFile(sFile);
sourceFileInfoToSourceFile.put(sfi, sFile);
if (hasBuildId) {
ExternalDebugInfo srcFileDebugInfo =
extDebugInfo.withType(ObjectType.SOURCE, path);
File srcFile = edfs.find(srcFileDebugInfo, monitor);
if (srcFile != null) {
println("Source file: " + srcFile);
}
}
}
catch (IllegalArgumentException e) {
if (numErrors++ < MAX_ERROR_MSGS_TO_DISPLAY) {

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,15 +41,16 @@ public class DWARFSetExternalDebugFilesLocationPrescript extends GhidraScript {
Msg.warn(this, "Invalid DWARF external debug files location specified: " + dir);
return;
}
List<SearchLocation> searchLocations = new ArrayList<>();
List<DebugInfoProvider> searchLocations = new ArrayList<>();
File buildIdDir = new File(dir, ".build-id");
if (buildIdDir.isDirectory()) {
searchLocations.add(new BuildIdSearchLocation(buildIdDir));
searchLocations.add(new BuildIdDebugFileProvider(buildIdDir));
}
searchLocations.add(new LocalDirectorySearchLocation(dir));
ExternalDebugFilesService edfs = new ExternalDebugFilesService(searchLocations);
DWARFExternalDebugFilesPlugin.saveExternalDebugFilesService(edfs);
searchLocations.add(new LocalDirDebugLinkProvider(dir));
ExternalDebugFilesService edfs = new ExternalDebugFilesService(
LocalDirDebugInfoDProvider.getGhidraCacheInstance(), searchLocations);
ExternalDebugFilesService.saveToPrefs(edfs);
}
}