title: How to resolve function name through memory address?
body: <p>Although <code>Linux</code> doesn't provide <code>pstack</code> as <code>Solaris</code> does, <code>RedHat</code> provides a script can do the same thing:  </p>
  
  <pre><code>#!/bin/bash
  
  if test $# -ne 1; then
      echo "Usage: `basename $0 .sh` &lt;process-id&gt;" 1&gt;&amp;2
      exit 1
  fi
  
  if test ! -r /proc/$1; then
      echo "Process $1 not found." 1&gt;&amp;2
      exit 1
  fi
  
  # GDB doesn't allow "thread apply all bt" when the process isn't
  # threaded; need to peek at the process to determine if that or the
  # simpler "bt" should be used.
  
  backtrace="bt"
  if test -d /proc/$1/task ; then
      # Newer kernel; has a task/ directory.
      if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2&gt;/dev/null ; then
          backtrace="thread apply all bt"
      fi
  elif test -f /proc/$1/maps ; then
      # Older kernel; go by it loading libpthread.
      if /bin/grep -e libpthread /proc/$1/maps &gt; /dev/null 2&gt;&amp;1 ; then
          backtrace="thread apply all bt"
      fi
  fi
  
  GDB=${GDB:-/usr/bin/gdb}
  
  if $GDB -nx --quiet --batch --readnever &gt; /dev/null 2&gt;&amp;1; then
      readnever=--readnever
  else
      readnever=
  fi
  
  # Run GDB, strip out unwanted noise.
  $GDB --quiet $readnever -nx /proc/$1/exe $1 &lt;&lt;EOF 2&gt;&amp;1 |
  $backtrace
  EOF
  /bin/sed -n \
      -e 's/^(gdb) //' \
      -e '/^#/p' \
      -e '/^Thread/p'
  </code></pre>
  
  <p>Executing the script in <code>Suse</code>:  </p>
  
  <pre><code>linux:~ # pstack 7286
  Thread 3 (Thread 0x7f7c074b5700 (LWP 7287)):
  #0  0x00007f7c055f7a9d in read () from /lib64/libpthread.so.0
  #1  0x00007f7c050a3b76 in ?? () from /usr/lib64/libxenstore.so.3.0
  #2  0x00007f7c050a3c2f in ?? () from /usr/lib64/libxenstore.so.3.0
  #3  0x00007f7c050a3f72 in ?? () from /usr/lib64/libxenstore.so.3.0
  #4  0x00007f7c055f10a4 in start_thread () from /lib64/libpthread.so.0
  #5  0x00007f7c03c9104d in clone () from /lib64/libc.so.6
  Thread 2 (Thread 0x7f7bfe4b0700 (LWP 7288)):
  #0  0x00007f7c055f505f in pthread_cond_wait@@GLIBC_2.3.2 ()
  #1  0x00007f7c07199d99 in ?? ()
  #2  0x00007f7c0709a213 in ?? ()
  #3  0x00007f7c0709a610 in ?? ()
  #4  0x00007f7c055f10a4 in start_thread () from /lib64/libpthread.so.0
  #5  0x00007f7c03c9104d in clone () from /lib64/libc.so.6
  Thread 1 (Thread 0x7f7c07483980 (LWP 7286)):
  #0  0x00007f7c03c88cdf in ppoll () from /lib64/libc.so.6
  #1  0x00007f7c07060ec9 in ?? ()
  #2  0x00007f7c07026654 in ?? ()
  #3  0x00007f7c06edcb36 in ?? ()
  #4  0x00007f7c03bcdb05 in __libc_start_main () from /lib64/libc.so.6
  #5  0x00007f7c06ee0eec in ?? ()
  </code></pre>
  
  <p>My question is how to resolve the function name from the address? such as <code>0x00007fe4ab73eb36</code>. I know maybe through installing <code>debug-info</code> packages, but how to know install which packages?</p>
  
  <p>Update:<br>
  According to Mark Plotnick's comments, I use the following command to get which <code>debuginfo</code> packages are lacked:  </p>
  
  <pre><code>linux:~ # gdb --quiet -nx --readnever /proc/7286/exe 7286
  ......
  Missing separate debuginfos, use: zypper install glibc-debuginfo-2.19-31.5.x86_64 ......
  </code></pre>
  
  <p>After installing all need <code>debuginfo</code> packages, the symbols can be resolved:  </p>
  
  <pre><code>linux:~ # pstack 7286
  Thread 3 (Thread 0x7f7c074b5700 (LWP 7287)):
  #0  0x00007f7c055f7a9d in read () from /lib64/libpthread.so.0
  #1  0x00007f7c050a3b76 in read_all.part.1.constprop ()
  #2  0x00007f7c050a3c2f in read_message.constprop ()
  #3  0x00007f7c050a3f72 in read_thread () from /usr/lib64/libxenstore.so.3.0
  #4  0x00007f7c055f10a4 in start_thread () from /lib64/libpthread.so.0
  #5  0x00007f7c03c9104d in clone () from /lib64/libc.so.6
  Thread 2 (Thread 0x7f7bfe4b0700 (LWP 7288)):
  #0  0x00007f7c055f505f in pthread_cond_wait@@GLIBC_2.3.2 ()
  #1  0x00007f7c07199d99 in qemu_cond_wait ()
  #2  0x00007f7c0709a213 in vnc_worker_thread_loop ()
  #3  0x00007f7c0709a610 in vnc_worker_thread ()
  #4  0x00007f7c055f10a4 in start_thread () from /lib64/libpthread.so.0
  #5  0x00007f7c03c9104d in clone () from /lib64/libc.so.6
  Thread 1 (Thread 0x7f7c07483980 (LWP 7286)):
  #0  0x00007f7c03c88cdf in ppoll () from /lib64/libc.so.6
  #1  0x00007f7c07060ec9 in qemu_poll_ns ()
  #2  0x00007f7c07026654 in main_loop_wait ()
  #3  0x00007f7c06edcb36 in main ()
  </code></pre>
  
  <p>But "<code>objdump -t /proc/7286/exe | grep main</code>" outputs nothing:  </p>
  
  <pre><code>linux:~ # objdump -t /proc/7286/exe | grep main
  linux:~ #
  </code></pre>