The problem is the way we use debugedit to extract the sources list at do_package The generate debugsources.list did not has sources list any more.
I have a potential fix for this. # This has to be long enough to support remapping DEBUG_REMAP_DIR = "/usr/src/build/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}" DEBUG_FLAGS = "-g -feliminate-unused-debug-types \ -fdebug-prefix-map=${WORKDIR}=${DEBUG_REMAP_DIR} \ -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \ -fdebug-prefix-map=${STAGING_DIR_HOST}= \ " DEBUGSRC_OVERRIDE_PATH = "${@os.path.dirname(os.path.dirname(d.getVar('DEBUG_REMAP_DIR', True) or ""))}" I'm also investigating replacing the 'debugedit' program.
Forgot that fix would go into the bitbake.conf Also each of the three items should likely be ?= or ??=
(In reply to comment #1) > I have a potential fix for this. > > # This has to be long enough to support remapping > DEBUG_REMAP_DIR = > "/usr/src/build/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}" > > DEBUG_FLAGS = "-g -feliminate-unused-debug-types \ > -fdebug-prefix-map=${WORKDIR}=${DEBUG_REMAP_DIR} \ > -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \ > -fdebug-prefix-map=${STAGING_DIR_HOST}= \ > " > > DEBUGSRC_OVERRIDE_PATH = > "${@os.path.dirname(os.path.dirname(d.getVar('DEBUG_REMAP_DIR', True) or > ""))}" > > > I'm also investigating replacing the 'debugedit' program. Got it, thanks, I would like to learn it. //Hongxu
1. Prepare a C source file and use rpm-native's debugedit for testing: mkdir -p /folk/hjia/dir1/dir2 cat << ENDOF > /folk/hjia/dir1/dir2/test.c int main(int argc, char *argv[]) { return 0; } ENDOF DEBUGEDIT="/buildarea/raid0/hjia/build-20160321-yocto-buildpath/tmp/work/x86_64-linux/rpm-native/5.4.16-r0/build/tools/debugedit" 2. Use absolute path to compile, and replace "/folk/hjia" with "/usr/src" in DWARF The result was expected. gcc -g /folk/hjia/dir1/dir2/test.c -o test_absolute $DEBUGEDIT -b "/folk/hjia" -d "/usr/src" -i -l test_absolute.list test_absolute objdump -g test_absolute > test_absolute.log vim test_absolute.log -------- 124 Contents of the .debug_info section: 134 <11> DW_AT_name : (indirect string, offset: 0x5): /usr/src/dir1/dir2/test.c 251 The Directory Table (offset 0x1b): 252 1 /usr/src/dir1/dir2 253 2 X 254 255 The File Name Table (offset 0x31): 256 Entry Dir Time Size Name 257 1 1 0 0 test.c 268 Contents of the .debug_str section: 269 270 0x00000000 61726776 002f7573 722f7372 632f6469 argv./usr/src/di 271 0x00000010 72312f64 6972322f 74657374 2e630063 r1/dir2/test.c.c 272 0x00000020 00617267 63006368 6172006d 61696e00 .argc.char.main. 273 0x00000030 474e5520 4320342e 382e3420 2d6d7475 GNU C 4.8.4 -mtu 274 0x00000040 6e653d67 656e6572 6963202d 6d617263 ne=generic -marc 275 0x00000050 683d7838 362d3634 202d6720 2d667374 h=x86-64 -g -fst 276 0x00000060 61636b2d 70726f74 6563746f 7200 ack-protector. --------
3. Use relative path to compile, if we still use the same repalcement, the result was not expected. '/folk/hjia' still existed in DWARF gcc -g ./dir1/dir2/dir3/test.c -o test_reltive $DEBUGEDIT -b "/folk/hjia/dir1/dir2" -d "/usr/src/debug" -i -l test_reltive.list test_reltive objdump -g test_reltive > test_reltive.log vim test_reltive.log -------- 124 Contents of the .debug_info section: 134 <11> DW_AT_name : (indirect string, offset: 0x0): ./dir1/dir2/test.c 135 <15> DW_AT_comp_dir : (indirect string, offset: 0x1d): /folk/hjia 253 The Directory Table (offset 0x1b): 254 1 dir1/dir2 255 2 X 256 257 The File Name Table (offset 0x28): 258 Entry Dir Time Size Name 259 1 1 0 0 test.c 270 Contents of the .debug_str section: 271 272 0x00000000 2e2f6469 72312f64 6972322f 74657374 ./dir1/dir2/test 273 0x00000010 2e630061 72677600 61726763 002f666f .c.argv.argc./fo 274 0x00000020 6c6b2f68 6a696100 63686172 006d6169 lk/hjia.char.mai 275 0x00000030 6e00474e 55204320 342e382e 34202d6d n.GNU C 4.8.4 -m 276 0x00000040 74756e65 3d67656e 65726963 202d6d61 tune=generic -ma 277 0x00000050 7263683d 7838362d 3634202d 67202d66 rch=x86-64 -g -f 278 0x00000060 73746163 6b2d7072 6f746563 746f7200 stack-protector. --------
4. If we use relative path to compile, we should use '/src' to replace '/folk'. gcc -g ./dir1/dir2/test.c -o test_reltive $DEBUGEDIT -b "/folk" -d "/src" -i -l test_reltive.list test_reltive objdump -g test_reltive > test_reltive.log vim test_reltive.log -------- 124 Contents of the .debug_info section: 134 <11> DW_AT_name : (indirect string, offset: 0x0): ./dir1/dir2/test.c 135 <15> DW_AT_comp_dir : (indirect string, offset: 0x1d): /src/hjia 253 The Directory Table (offset 0x1b): 254 1 dir1/dir2 255 2 X 256 257 The File Name Table (offset 0x28): 258 Entry Dir Time Size Name 259 1 1 0 0 test.c 270 Contents of the .debug_str section: 271 272 0x00000000 2e2f6469 72312f64 6972322f 74657374 ./dir1/dir2/test 273 0x00000010 2e630061 72677600 61726763 002f7372 .c.argv.argc./sr 274 0x00000020 632f686a 69610000 63686172 006d6169 c/hjia..char.mai 275 0x00000030 6e00474e 55204320 342e382e 34202d6d n.GNU C 4.8.4 -m 276 0x00000040 74756e65 3d67656e 65726963 202d6d61 tune=generic -ma 277 0x00000050 7263683d 7838362d 3634202d 67202d66 rch=x86-64 -g -f 278 0x00000060 73746163 6b2d7072 6f746563 746f7200 stack-protector.
5. Drop debugedit, we just use -fdebug-prefix-map=/folk/hjia=/usr/src to compile 1) Use absolute path to compile: gcc -fdebug-prefix-map=/folk/hjia=/usr/src -g /folk/hjia/dir1/dir2/test.c -o test_absolute objdump -g test_absolute > test_absolute.log vim test_absolute.log -------- 124 Contents of the .debug_info section: <11> DW_AT_name : (indirect string, offset: 0x6f): /usr/src/dir1/dir2/test.c 251 The Directory Table (offset 0x1b): 252 1 /usr/src/dir1/dir2 253 254 The File Name Table (offset 0x2f): 255 Entry Dir Time Size Name 256 1 1 0 0 test.c 267 Contents of the .debug_str section: 268 269 0x00000000 61726776 00474e55 20432034 2e382e34 argv.GNU C 4.8.4 270 0x00000010 202d6d74 756e653d 67656e65 72696320 -mtune=generic 271 0x00000020 2d6d6172 63683d78 38362d36 34202d67 -march=x86-64 -g 272 0x00000030 202d6664 65627567 2d707265 6669782d -fdebug-prefix- 273 0x00000040 6d61703d 2f666f6c 6b2f686a 69613d2f map=/folk/hjia=/ 274 0x00000050 7573722f 73726320 2d667374 61636b2d usr/src -fstack- 275 0x00000060 70726f74 6563746f 72006172 6763002f protector.argc./ 276 0x00000070 7573722f 7372632f 64697231 2f646972 usr/src/dir1/dir 277 0x00000080 322f7465 73742e63 006d6169 6e006368 2/test.c.main.ch 278 0x00000090 617200 ar. -------- 2) Use relative path to compile: gcc -fdebug-prefix-map=/folk/hjia=/usr/src -g ./dir1/dir2/test.c -o test_reltive objdump -g test_reltive > test_reltive.log vim test_reltive.log -------- 124 Contents of the .debug_info section: 134 <11> DW_AT_name : (indirect string, offset: 0x0): ./dir1/dir2/test.c 135 <15> DW_AT_comp_dir : (indirect string, offset: 0x18): /usr/src 253 The Directory Table (offset 0x1b): 254 1 ./dir1/dir2 255 256 The File Name Table (offset 0x28): 257 Entry Dir Time Size Name 258 1 1 0 0 test.c 269 Contents of the .debug_str section: 270 271 0x00000000 2e2f6469 72312f64 6972322f 74657374 ./dir1/dir2/test 272 0x00000010 2e630061 72677600 2f757372 2f737263 .c.argv./usr/src 273 0x00000020 00474e55 20432034 2e382e34 202d6d74 .GNU C 4.8.4 -mt 274 0x00000030 756e653d 67656e65 72696320 2d6d6172 une=generic -mar 275 0x00000040 63683d78 38362d36 34202d67 202d6664 ch=x86-64 -g -fd 276 0x00000050 65627567 2d707265 6669782d 6d61703d ebug-prefix-map= 277 0x00000060 2f666f6c 6b2f686a 69613d2f 7573722f /folk/hjia=/usr/ 278 0x00000070 73726320 2d667374 61636b2d 70726f74 src -fstack-prot 279 0x00000080 6563746f 72006172 6763006d 61696e00 ector.argc.main. 280 0x00000090 63686172 00 char. --------
The -fdebug-prefix-map is more powerful than debugedit, If we tweak DEBUG_FLAGS, we could drop the use of debugedit in do_package: -------- DEBUG_FLAGS ?= "-g -feliminate-unused-debug-types \ - -fdebug-prefix-map=${B}=/usr/src/${BPN} \ - -fdebug-prefix-map=${S}=/usr/src/${BPN} \ + -fdebug-prefix-map=${WORKDIR}=/usr/src/debug \ -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \ -fdebug-prefix-map=${STAGING_DIR_HOST}= \ " -------- There is only one situation that it makes sense to keep debugedit: While DEBUG_FLAGS is not used for compiling.(I think it should be a bug) So I think drop invoking debugedit is reasonable and proper. //Hongxu
(In reply to comment #5) > 3. Use relative path to compile, if we still use the same repalcement, > the result was not expected. '/folk/hjia' still existed in DWARF > > gcc -g ./dir1/dir2/dir3/test.c -o test_reltive > > $DEBUGEDIT -b "/folk/hjia/dir1/dir2" -d "/usr/src/debug" -i -l > test_reltive.list test_reltive > s#-b "/folk/hjia/dir1/dir2"#-b "/folk/hjia"#
(In reply to comment #5) > 3. Use relative path to compile, if we still use the same repalcement, > the result was not expected. '/folk/hjia' still existed in DWARF > > gcc -g ./dir1/dir2/dir3/test.c -o test_reltive > > $DEBUGEDIT -b "/folk/hjia/dir1/dir2" -d "/usr/src/debug" -i -l > test_reltive.list test_reltive s#-d "/usr/src/debug"#-d "/usr/src"#
We still need to generate debugsources.list, so just invoke debugedit to generate it and do not edit anything. diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index ef80e50..31e701a 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass @@ -312,8 +312,6 @@ def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d): dvar = d.getVar('PKGD', True) objcopy = d.getVar("OBJCOPY", True) debugedit = d.expand("${STAGING_LIBDIR_NATIVE}/rpm/bin/debugedit") - workdir = d.getVar("WORKDIR", True) - workparentdir = d.getVar("DEBUGSRC_OVERRIDE_PATH", True) or os.path.dirname(os.path.dirname(workdir)) # We ignore kernel modules, we don't generate debug info files. if file.find("/lib/modules/") != -1 and file.endswith(".ko"): @@ -327,7 +325,7 @@ def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d): # We need to extract the debug src information here... if debugsrcdir: - cmd = "'%s' -b '%s' -d '%s' -i -l '%s' '%s'" % (debugedit, workparentdir, debugsrcdir, sourcefile, file) + cmd = "'%s' -i -l '%s' '%s'" % (debugedit, sourcefile, file) (retval, output) = oe.utils.getstatusoutput(cmd) if retval: bb.fatal("debugedit failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else ""))
The debugsources.list is used for copydebugsources, I am still investigating it.
> The debugsources.list is used for copydebugsources, I am still investigating it. To replace debugedit we need to write a new program that will simply iterate the dwarf symbols and provide a list of all of the sources that were referenced. We can then post-process this list to generate the equivalent of the debugsources.list file. I'd also like to see a QA test to identify things NOT using the "-fdebug-prefix-map=" option. Should be obvious if the returned references to file are in the local workdir.
Test case: 1. Modify recipe service in meta-skeleton, execute it caused segment fault diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton_test.c b/meta-skeleton/recipes-skeleton/service/service/skeleton_test.c index 96c67ac..0862882 100644 --- a/meta-skeleton/recipes-skeleton/service/service/skeleton_test.c +++ b/meta-skeleton/recipes-skeleton/service/service/skeleton_test.c @@ -1,12 +1,10 @@ -#include <unistd.h> - -/* This demo does nothing except for testing /etc/init.d/skeleton */ +#include <stdio.h> int main(int argc, char *argv[]) { - daemon(0, 0); - while (1) { - sleep(1); - } + printf("hello world\n"); + + char *p = NULL; + *p = 1; return 0; } diff --git a/meta-skeleton/recipes-skeleton/service/service_0.1.bb b/meta-skeleton/recipes-skeleton/service/service_0.1.bb index c5cd7a9..c4b43f0 100644 --- a/meta-skeleton/recipes-skeleton/service/service_0.1.bb +++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb @@ -3,29 +3,16 @@ SECTION = "base" LICENSE = "GPLv2" LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=349c872e0066155e1818b786938876a4" -SRC_URI = "file://skeleton \ - file://skeleton_test.c \ +SRC_URI = "file://skeleton_test.c \ file://COPYRIGHT \ " do_compile () { - ${CC} ${WORKDIR}/skeleton_test.c -o ${WORKDIR}/skeleton-test + ${CC} ${WORKDIR}/skeleton_test.c ${DEBUG_FLAGS} -o ${WORKDIR}/skeleton-test } do_install () { - install -d ${D}${sysconfdir}/init.d - cat ${WORKDIR}/skeleton | \ - sed -e 's,/etc,${sysconfdir},g' \ - -e 's,/usr/sbin,${sbindir},g' \ - -e 's,/var,${localstatedir},g' \ - -e 's,/usr/bin,${bindir},g' \ - -e 's,/usr,${prefix},g' > ${D}${sysconfdir}/init.d/skeleton - chmod a+x ${D}${sysconfdir}/init.d/skeleton - install -d ${D}${sbindir} install -m 0755 ${WORKDIR}/skeleton-test ${D}${sbindir}/ } -RDEPENDS_${PN} = "initscripts" - -CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
Test Case: 2. Install service, gdb and *-dbg to core-image-minimal vim local.conf ... IMAGE_INSTALL_append = " service gdb" EXTRA_IMAGE_FEATURES_append = " dbg-pkgs" ... vim conf/bblayers.conf ... BBLAYERS ?= " \ /buildarea/raid0/hjia/poky/meta \ /buildarea/raid0/hjia/poky/meta-poky \ /buildarea/raid0/hjia/poky/meta-skeleton \ /buildarea/raid0/hjia/poky/meta-yocto-bsp \ " ... bitbake core-image-minimal
Test Case: 3. Run qemu and invoke gdb to execute skeleton-test, while segment fault, the source printed correctly. runqemu qemux86-64 slirp nographic ... root@qemux86-64:~# gdb skeleton-test (gdb) r Starting program: /usr/sbin/skeleton-test hello world Program received signal SIGSEGV, Segmentation fault. 0x000000000040056b in main (argc=1, argv=0x7fffffffed08) at /usr/src/debug/skeleton_test.c:8 8 *p = 1; (gdb) list 3 int main(int argc, char *argv[]) 4 { 5 printf("hello world\n"); 6 7 char *p = NULL; 8 *p = 1; 9 return 0; 10 } ...
Fixed in oe-core e50d23c30cd8259941b25e336b11cd96e4f6cd31.