Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i use find, nm, and grep to find a symbol among many shared libraries?

Tags:

grep

find

bash

nm

I'm struggling with the right command to do the following:

find all shared libraries (*.so) that contain a certain symbol.

This is what I've tried:

find -iname '*.so*' -exec nm {} \; | grep -H _ZN6QDebugD1Ev

The above gives some output with symbols found, but doesn't pinpoint the filename that the symbol occurred in. Any flag that I give to grep to tell it to print a filename is lost because grep is being fed from stdin.

(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):0015e928 T _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev

Another attempt:

find -iname '*.so*' -exec nm {} \; -exec grep _ZN6QDebugD1Ev {} \;

This doesn't work because the two execs are completely independent.

What should I do?

like image 271
Rich von Lehe Avatar asked Apr 20 '15 22:04

Rich von Lehe


1 Answers

Pass the "-A" option to nm which will prefix its output with the filename. Then just grep for the symbol you're interested in, for example:

find -iname '*.so*' -exec nm -A {} \; | grep _ZN6QDebugD1Ev
like image 178
bgstech Avatar answered Oct 25 '22 22:10

bgstech