Skip to content

Commit

Permalink
qemu: heuristics to get Qemu related directories using debug info only
Browse files Browse the repository at this point in the history
Signed-off-by: Efimov Vasily <[email protected]>
  • Loading branch information
laerreal committed Sep 22, 2020
1 parent 4ac42da commit 7027cc5
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions qemu/dwarf_hacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
__all__ = [
"qemu_build_dir_by_dwarf"
, "qemu_target_dir_by_dwarf"
]

from os.path import (
abspath,
dirname
)
from six import (
PY3
)
from common import (
bsep
)


def qemu_build_dir_by_dwarf(dia):
# Sometimes trace-root.h is included by its absolute path:
# /path/to/build/directory/./trace-root.h
for cu in dia.di.iter_CUs():
for f in dia.get_CU_files(cu):
# v--- because of /./
if len(f) > 2 and f[-1] == b"trace-root.h":
break
else:
continue
break
else:
raise RuntimeError(
"Nothing includes trace-root.h by absolute path"
)

f = bsep.join(f)

if PY3:
# TODO: Is DWARF file name encoding always utf-8?
f = f.decode("utf-8")

return dirname(abspath(f))


def qemu_target_dir_by_dwarf(dwarf_info):
# There is a convention that TCG frontend (qemu target) has
# translate.c file in its directory.
# Also, there is only one TCG frontend per qemu binary.
for cu in dwarf_info.iter_CUs():
src_file = cu.get_top_DIE().attributes["DW_AT_name"].value
if src_file.endswith(b"translate.c"):
break
else:
raise RuntimeError("No compile unit for translate.c found")

if PY3:
# TODO: Is DWARF file name encoding always utf-8?
src_file = src_file.decode("utf-8")

return dirname(abspath(src_file))

0 comments on commit 7027cc5

Please sign in to comment.