Created
October 26, 2016 16:15
-
-
Save mskvortsov/245148234934a4715f7fb728fa5297d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Use like this: | |
# cd into empty directory where source tree will be reconstructed | |
# objdump --dwarf=decodedline <list of elfs> |dwarf-recover-src-tree.py | |
# (tested only with GNU objdump 2.26.1) | |
import sys, os, string | |
dictionary = {} | |
for line in sys.stdin: | |
line = line.rstrip() | |
if line == "": | |
continue | |
if (line.find("file format elf") > 0 or | |
line == "Decoded dump of debug contents of section .debug_line:" or | |
line.startswith("CU:") or | |
line.startswith("File name")): | |
continue | |
if line.endswith(":"): | |
last_path = os.path.normpath(line[:-1]) | |
last_file = os.path.basename(last_path) | |
if not last_path in dictionary: | |
dictionary[last_path] = 0 | |
else: | |
(current_file, line_count, _) = string.split(line, None, 2) | |
line_count = int(line_count) | |
if current_file == last_file: | |
if dictionary[last_path] < line_count: | |
dictionary[last_path] = line_count | |
for path in dictionary: | |
os.system("mkdir -p ." + os.path.dirname(path)) | |
with open("." + path, "w") as fake: | |
fake.write("\n" * dictionary[path]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment