mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
Merge remote-tracking branch 'origin/patch'
This commit is contained in:
@@ -144,9 +144,9 @@ public class DWARFLineInfoSourceMapScript extends GhidraScript {
|
|||||||
|
|
||||||
SourceFile source = sfasToSourceFiles.get(sourceFileAddr);
|
SourceFile source = sfasToSourceFiles.get(sourceFileAddr);
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
String path = SourceFileUtils.fixDwarfRelativePath(sourceFileAddr.fileName(),
|
|
||||||
COMPILATION_ROOT_DIRECTORY);
|
|
||||||
try {
|
try {
|
||||||
|
String path = SourceFileUtils.normalizeDwarfPath(sourceFileAddr.fileName(),
|
||||||
|
COMPILATION_ROOT_DIRECTORY);
|
||||||
SourceFileIdType type =
|
SourceFileIdType type =
|
||||||
sourceFileAddr.md5() == null ? SourceFileIdType.NONE : SourceFileIdType.MD5;
|
sourceFileAddr.md5() == null ? SourceFileIdType.NONE : SourceFileIdType.MD5;
|
||||||
source = new SourceFile(path, type, sourceFileAddr.md5());
|
source = new SourceFile(path, type, sourceFileAddr.md5());
|
||||||
|
|||||||
@@ -283,9 +283,9 @@ public class DWARFImporter {
|
|||||||
|
|
||||||
SourceFile source = sfasToSourceFiles.get(sfa);
|
SourceFile source = sfasToSourceFiles.get(sfa);
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
String path = SourceFileUtils.fixDwarfRelativePath(sfa.fileName(),
|
|
||||||
DEFAULT_COMPILATION_DIR);
|
|
||||||
try {
|
try {
|
||||||
|
String path = SourceFileUtils.normalizeDwarfPath(sfa.fileName(),
|
||||||
|
DEFAULT_COMPILATION_DIR);
|
||||||
SourceFileIdType type =
|
SourceFileIdType type =
|
||||||
sfa.md5() == null ? SourceFileIdType.NONE : SourceFileIdType.MD5;
|
sfa.md5() == null ? SourceFileIdType.NONE : SourceFileIdType.MD5;
|
||||||
source = new SourceFile(path, type, sfa.md5());
|
source = new SourceFile(path, type, sfa.md5());
|
||||||
|
|||||||
@@ -152,17 +152,19 @@ public class SourceFileUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Corrects potentially relative paths encountered in DWARF debug info.
|
* Normalizes paths encountered in DWARF debug info.
|
||||||
* Relative paths are based at /{@code baseDir}/. If normalization of "/../" subpaths
|
* Relative paths are made absolute with base /{@code baseDir}/. If normalization of "/../"
|
||||||
* results in a path "above" /{@code baseDir}/, the returned path will be based at "baseDir_i"
|
* subpaths results in a path "above" /{@code baseDir}/, the returned path will be based at
|
||||||
* where i is the count of initial "/../" in the normalized path.
|
* "baseDir_i" where i is the count of initial "/../" in the normalized path.
|
||||||
|
* Additionally, any backslashes are converted to forward slashes (backslashes can occur in
|
||||||
|
* files produced by MinGW).
|
||||||
* @param path path to normalize
|
* @param path path to normalize
|
||||||
* @param baseDir name of artificial root directory
|
* @param baseDir name of artificial root directory
|
||||||
* @return normalized path
|
* @return normalized path
|
||||||
* @throws IllegalArgumentException if the path is not valid or if baseDir contains a
|
* @throws IllegalArgumentException if the path is not valid or if baseDir contains a
|
||||||
* non-alphanumeric, non-underscore character
|
* non-alphanumeric, non-underscore character
|
||||||
*/
|
*/
|
||||||
public static String fixDwarfRelativePath(String path, String baseDir) {
|
public static String normalizeDwarfPath(String path, String baseDir) {
|
||||||
if (StringUtils.isEmpty(baseDir)) {
|
if (StringUtils.isEmpty(baseDir)) {
|
||||||
throw new IllegalArgumentException("baseDir cannot be empty");
|
throw new IllegalArgumentException("baseDir cannot be empty");
|
||||||
}
|
}
|
||||||
@@ -176,6 +178,7 @@ public class SourceFileUtils {
|
|||||||
path = "/" + baseDir + path.substring(1);
|
path = "/" + baseDir + path.substring(1);
|
||||||
based = true;
|
based = true;
|
||||||
}
|
}
|
||||||
|
path = FSUtilities.normalizeNativePath(path);
|
||||||
try {
|
try {
|
||||||
URI uri = new URI("file", null, path, null).normalize();
|
URI uri = new URI("file", null, path, null).normalize();
|
||||||
path = uri.getPath();
|
path = uri.getPath();
|
||||||
|
|||||||
@@ -76,17 +76,19 @@ public class SourceFileTest extends AbstractSourceFileTest {
|
|||||||
public void testFixDwarfRelativePath() {
|
public void testFixDwarfRelativePath() {
|
||||||
String baseDirName = "root_dir";
|
String baseDirName = "root_dir";
|
||||||
assertEquals("/src/file.c",
|
assertEquals("/src/file.c",
|
||||||
SourceFileUtils.fixDwarfRelativePath("/src/file.c", baseDirName));
|
SourceFileUtils.normalizeDwarfPath("/src/file.c", baseDirName));
|
||||||
assertEquals("/file.c",
|
assertEquals("/file.c",
|
||||||
SourceFileUtils.fixDwarfRelativePath("/src/../file.c", baseDirName));
|
SourceFileUtils.normalizeDwarfPath("/src/../file.c", baseDirName));
|
||||||
assertEquals("/root_dir/file.c",
|
assertEquals("/root_dir/file.c",
|
||||||
SourceFileUtils.fixDwarfRelativePath("./file.c", baseDirName));
|
SourceFileUtils.normalizeDwarfPath("./file.c", baseDirName));
|
||||||
assertEquals("/root_dir_1/file.c",
|
assertEquals("/root_dir_1/file.c",
|
||||||
SourceFileUtils.fixDwarfRelativePath("/../file.c", baseDirName));
|
SourceFileUtils.normalizeDwarfPath("/../file.c", baseDirName));
|
||||||
assertEquals("/root_dir_2/file.c",
|
assertEquals("/root_dir_2/file.c",
|
||||||
SourceFileUtils.fixDwarfRelativePath("/.././../file.c", baseDirName));
|
SourceFileUtils.normalizeDwarfPath("/.././../file.c", baseDirName));
|
||||||
assertEquals("/root_dir_1/file.c",
|
assertEquals("/root_dir_1/file.c",
|
||||||
SourceFileUtils.fixDwarfRelativePath("./../file.c", baseDirName));
|
SourceFileUtils.normalizeDwarfPath("./../file.c", baseDirName));
|
||||||
|
assertEquals("/C:/Users/test/src/dir1/file.c",
|
||||||
|
SourceFileUtils.normalizeDwarfPath("C:\\Users\\test/src/dir1/file.c", baseDirName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user