s

Openwrt no debugging symbols found


2 description

I have added -g to the package Makefile, but when I debug the program, I got
the following issue:

(gdb) file /usr/bin/test
Reading symbols from /usr/bin/test...(no debugging symbols found)...done.
              

3 analysis

3.1 theory guide

The most frequent cause of "no debugging symbols found" when -g is present is
that there is some "stray" -s or -S argument somewhere on the link line.

from man ld:

-s
--strip-all
    Omit all symbol information from the output file.

-S
--strip-debug
    Omit debugger symbol information (but not all symbols) from the output file.
                

3.2 build log

Then I serach the build terminal, I found "strip":

export CROSS="arm-openwrt-linux-uclibcgnueabi-" NO_RENAME=1 ;
NM="arm-openwrt-linux-uclibcgnueabi-nm"
STRIP="/home/a/bb/staging_dir/host/bin/sstrip"
STRIP_KMOD="/home/a/bb/scripts/strip-kmod.sh"
PATCHELF="/home/a/bb/staging_dir/host/bin/patchelf"
/home/a/bb/scripts/rstrip.sh
/home/a/bb/build_dir/target-arm_cortex-a7_uClibc-1.0.14_eabi/test/ipkg-ipq806x/test
rstrip.sh: /home/a/bb/build_dir/target-arm_cortex-a7_uClibc-1.0.14_eabi/test/ipkg-ipq806x/test/bin/test: executable
                

3.3 openwrt rstrip

the strip function defined in rules.mk

# strip an entire directory
ifneq ($(CONFIG_NO_STRIP),)
  RSTRIP:=:
  STRIP:=:
else
  ifneq ($(CONFIG_USE_STRIP),)
    STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS))
  else
    ifneq ($(CONFIG_USE_SSTRIP),)
      STRIP:=$(STAGING_DIR_HOST)/bin/sstrip
    endif
  endif
  RSTRIP:= \
    export CROSS="$(TARGET_CROSS)" \
        $(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \
        $(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \
    NM="$(TARGET_CROSS)nm" \
    STRIP="$(STRIP)" \
    STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \
    PATCHELF="$(STAGING_DIR_HOST)/bin/patchelf" \
    $(SCRIPT_DIR)/rstrip.sh
endif
                

where RSTRIP used?

the call flow is:

include $(INCLUDE_DIR)/package.mk
  include $(INCLUDE_DIR)/package-ipkg.mk
    $(RSTRIP) $$(IDIR_$(1))
                

4 fix

To disable the strip feature, add code below

RSTRIP:=:
              

after

include $(INCLUDE_DIR)/package.mk
              

in our package Makefile