Last active
March 13, 2016 18:27
-
-
Save pstef/03c9dd842f34f6779b03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
psql -d 'linspector' <<EOF | |
DROP TABLE IF EXISTS symbols, "files"; | |
CREATE TABLE symbols ( | |
filename text NOT NULL, | |
flag "char" NOT NULL, | |
symbol text NOT NULL, | |
PRIMARY KEY (filename, flag, symbol) | |
); | |
COPY symbols (filename, flag, symbol) FROM stdin; | |
$(find . -name '*.o' -type f -print0 | xargs -0 nm -po | tr -s ' ' '\t' | tr ':' '\t' | cut -f1,3,4) | |
\. | |
CREATE TABLE files ("name" text PRIMARY KEY); | |
INSERT INTO files SELECT DISTINCT filename FROM symbols; | |
ALTER TABLE symbols | |
ADD CONSTRAINT "symbols_files_fk" | |
FOREIGN KEY (filename) | |
REFERENCES files ("name") | |
ON UPDATE CASCADE ON DELETE NO ACTION | |
DEFERRABLE; | |
SELECT f.name, consumers.* | |
FROM ( | |
SELECT s.symbol, replace(string_agg(DISTINCT f.name, ' '), '.o', '.c') | |
FROM symbols s | |
JOIN files f ON f.name = s.filename | |
WHERE s.flag = 'U' | |
GROUP BY symbol | |
) consumers | |
JOIN symbols s ON s.symbol = consumers.symbol AND s.flag IN ('C','D','B','R') | |
JOIN files f ON f.name = s.filename | |
ORDER BY f.name; | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment