-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qemu: heuristics to get Qemu related directories using debug info only
Signed-off-by: Efimov Vasily <[email protected]>
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
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)) |