Skip to content

Instantly share code, notes, and snippets.

@kergoth
Created July 19, 2022 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kergoth/49f98320ccd84a7dc22fa8fd85ef9830 to your computer and use it in GitHub Desktop.
Save kergoth/49f98320ccd84a7dc22fa8fd85ef9830 to your computer and use it in GitHub Desktop.
From ba7f0374ed98dcfef60fffe52c5845df2abc6ffa Mon Sep 17 00:00:00 2001
From: Christopher Larson <chris_larson@mentor.com>
Date: Fri, 5 Feb 2021 02:43:04 +0500
Subject: [PATCH] copydebugsources_extra: check alternative paths for source
files for debug
This handles paths being pulled from paths that package.bbclass currently
does not handle, such as generated sources written to ${B}, as is the case
for libstdc++, or those from work-shared.
Signed-off-by: Christopher Larson <chris_larson@mentor.com>
---
classes/copydebugsources_extra.bbclass | 48 ++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/classes/copydebugsources_extra.bbclass b/classes/copydebugsources_extra.bbclass
index 91f4da2..d10c6d2 100644
--- a/classes/copydebugsources_extra.bbclass
+++ b/classes/copydebugsources_extra.bbclass
@@ -1,3 +1,5 @@
+# Handle any source paths owned by us which are not in the assumed path relative to WORKDIR, such as
+# sources generated and written in ${B}
def copydebugsources(debugsrcdir, sources, d):
# The debug src information written out to sourcefile is further processed
# and copied to the destination here.
@@ -39,6 +41,52 @@ def copydebugsources(debugsrcdir, sources, d):
bb.utils.mkdirhier(basepath)
cpath.updatecache(basepath)
+ copy_extra = {}
+ prefix_map = d.getVar('DEBUG_PREFIX_MAP')
+ if prefix_map:
+ # Handle any source paths owned by us which are not in the assumed path relative to WORKDIR, such as
+ # sources generated and written in ${B}
+ import shlex
+
+ prefix_maps = []
+ for arg in shlex.split(prefix_map):
+ if arg.startswith('-fdebug-prefix-map=') or arg.startswith('-ffile-prefix-map='):
+ _, from_path, to_path = arg.split('=', 2)
+ if to_path and from_path != workdir:
+ # Entries like recipe-sysroot are excluded here
+ prefix_maps.append((from_path, to_path))
+
+ if prefix_maps:
+ copy_extra = {}
+ srcroot = os.path.join(localsrc_prefix, workbasedir)
+ for srcfile in list(sources):
+ if any(srcfile.endswith(i) for i in ['<internal>', '<built-in>']):
+ continue
+ elif 'recipe-sysroot' in srcfile:
+ continue
+
+ relative = srcfile.replace(localsrc_prefix, '')
+ existing = os.path.join(workparentdir, relative)
+ if not os.path.exists(existing):
+ if prefix_maps:
+ for from_path, to_path in reversed(prefix_maps):
+ if srcfile.startswith(to_path + os.sep):
+ candidate = os.path.join(from_path, srcfile[len(to_path) + 1:])
+ if os.path.exists(candidate):
+ dest = oe.path.join(dvar, debugsrcdir, relative)
+ copy_extra[candidate] = dest
+ break
+ else:
+ bb.debug(1, 'copydebugsources: %s does not exist' % existing)
+ else:
+ bb.debug(1, 'copydebugsources: %s does not exist' % existing)
+
+ for src, dest in copy_extra.items():
+ src = os.path.realpath(src)
+ bb.utils.mkdirhier(os.path.dirname(dest))
+ bb.debug(1, 'copydebugsources: %s -> %s' % (src, dest))
+ oe.path.copyhardlink(src, dest)
+
# Ignore files from the recipe sysroots (target and native)
processdebugsrc = "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | "
# We need to ignore files that are not actually ours
--
2.36.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment