scripts/xldd.in
changeset 2190 9b9a0bb51cfb
parent 2189 52e1698ac243
child 2191 226d9684bf3c
     1.1 --- a/scripts/xldd.in	Tue Nov 23 21:35:41 2010 +0100
     1.2 +++ b/scripts/xldd.in	Tue Nov 23 21:35:45 2010 +0100
     1.3 @@ -24,6 +24,16 @@
     1.4      printf "Try \`%s --help' for more information\n" >&2
     1.5  }
     1.6  
     1.7 +do_trace() {
     1.8 +    local depth=0
     1.9 +
    1.10 +    [ -z "${CT_XLDD_VERBOSE}" ] && return 0
    1.11 +
    1.12 +    for((depth=0; "${#FUNCNAME[$((depth+1))]}" != 0; depth++)); do :; done
    1.13 +    printf "%*s" $((4*(depth-1))) "" >&2
    1.14 +    printf -- "$@" >&2
    1.15 +}
    1.16 +
    1.17  show_version() {
    1.18      # Fake a real ldd, just in case some dumb script would check
    1.19      cat <<_EOF_
    1.20 @@ -50,6 +60,10 @@
    1.21  used in a cross-development environment. Here is how it differs from a
    1.22  real native ldd:
    1.23  
    1.24 +If the CT_XLDD_DEBUG variable is set and non-empty, then ${myname} will
    1.25 +print a lot of debug messages, explaining how it builds the library
    1.26 +search path, and how each library was found and why.
    1.27 +
    1.28  The LD_LIBRARY_PATH variable is not used, as it can not reliably be
    1.29  guessed except at runtime, and we can't run.
    1.30  
    1.31 @@ -175,16 +189,22 @@
    1.32      local found_sysroot
    1.33      local d
    1.34  
    1.35 +    do_trace "Searching for '${needed}'\n"
    1.36 +
    1.37      for d in "${needed_search_path[@]}"; do
    1.38 +        do_trace "-> looking in '${d}'\n"
    1.39          if [ -f "${root}${d}/${needed}" ]; then
    1.40              found="${d}/${needed}"
    1.41 +            do_trace "---> found\n"
    1.42              break
    1.43          fi
    1.44      done
    1.45      if [ -z "${found}" ]; then
    1.46      for d in "${needed_search_path[@]}"; do
    1.47 +        do_trace "-> looking in '${d}' (sysroot)\n"
    1.48          if [ -f "${sysroot}${d}/${needed}" ]; then
    1.49              found_sysroot="${d}/${needed}"
    1.50 +            do_trace "---> found\n"
    1.51              break
    1.52          fi
    1.53      done
    1.54 @@ -205,6 +225,8 @@
    1.55  do_process_file() {
    1.56      local file="${1}"
    1.57  
    1.58 +    do_trace "Parsing file '${file}'\n"
    1.59 +
    1.60      "${readelf}" -d "${file}"                                           \
    1.61      |"${grep}" -E '\(NEEDED\)'                                          \
    1.62      |"${sed}" -r -e 's/^.*Shared library:[[:space:]]+\[(.*)\]$/\1/;'    \
    1.63 @@ -220,11 +242,13 @@
    1.64      local f
    1.65  
    1.66      [ -f "${ldsoconf}" ] || return 0
    1.67 +    do_trace "Parsing ld.so.conf: '${ldsoconf}'\n"
    1.68  
    1.69      while read line; do
    1.70          case "${line}" in
    1.71              include\ *)
    1.72                  g="${root}${line#include }"
    1.73 +                do_trace "-> handling include directive '${g}'\n"
    1.74                  for f in ${g}; do
    1.75                      do_scan_etc_ldsoconf "${f}"
    1.76                  done
    1.77 @@ -232,6 +256,7 @@
    1.78              \#*|"")
    1.79                  ;;
    1.80              *)
    1.81 +                do_trace "-> adding search dir '${line}'\n"
    1.82                  needed_search_path+=( "${line}" )
    1.83                  ;;
    1.84          esac
    1.85 @@ -240,12 +265,22 @@
    1.86  
    1.87  # Build up the full list of search directories
    1.88  declare -a needed_search_path
    1.89 +do_trace "Adding basic lib dirs\n"
    1.90  ld_library_path="${ld_library_path}:"
    1.91  while [ -n "${ld_library_path}" ]; do
    1.92      d="${ld_library_path%%:*}"
    1.93 -    [ -n "${d}" ] && needed_search_path+=( "${d}" )
    1.94 +    if [ -n "${d}" ]; then
    1.95 +        do_trace "-> adding search dir '${d}'\n"
    1.96 +        needed_search_path+=( "${d}" )
    1.97 +    fi
    1.98      ld_library_path="${ld_library_path#*:}"
    1.99  done
   1.100 +do_trace "Scanning '/etc/ld.so.conf'\n"
   1.101  do_scan_etc_ldsoconf "${root}/etc/ld.so.conf"
   1.102 +do_trace "Search path:\n"
   1.103 +for p in "${needed_search_path[@]}"; do
   1.104 +    do_trace "-> '${p}'\n"
   1.105 +done
   1.106  
   1.107 +do_trace "Scanning file '${1}'\n"
   1.108  do_process_file "${1}"