Skip to content

Commit 2ed58f8

Browse files
committed
Added use DWARF information option
1 parent 4c15a4e commit 2ed58f8

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

generate-objc-dependencies-to-json.rb

+52-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
options = {}
66

77
#Defaults
8-
options[:exclusion_prefixes] = "NS|UI|CA"
8+
options[:exclusion_prefixes] = "NS|UI|CA|CG|CI"
99

1010

1111
parser = OptionParser.new do |o|
@@ -24,6 +24,10 @@
2424
options[:exclusion_prefixes] = exclusion_prefixes
2525
}
2626

27+
o.on("-d", "--use-dwarf-info", "Use DWARF Information also") { |v|
28+
options[:use_dwarf] = v
29+
}
30+
2731
o.separator "Common options:"
2832
o.on_tail('-h', "Prints this help") { puts o; exit }
2933
o.parse!
@@ -84,6 +88,7 @@
8488
[
8589
THEEND
8690

91+
links = {}
8792

8893
#Searching all the .o files and showing its information through nm call
8994
IO.popen("find \"#{options[:search_directory]}\" -name \"*.o\" -exec /usr/bin/nm -o {} \\;") { |f|
@@ -103,15 +108,57 @@
103108

104109
source,dest = /[^\w]*([^\.\/]+)\.o.*_OBJC_CLASS_\$_(.*)/.match(line)[1,2]
105110
if source != dest
106-
puts " { \"source\" : \"#{source}\", \"dest\" : \"#{dest}\" },"
111+
destinations = links[source] ? links[source] : (links[source] = {})
112+
destinations[dest] = "set up"
107113
end
108114
end
109-
end
110-
end
115+
end
116+
end
111117
}
112118

119+
if options[:use_dwarf]
120+
121+
# Search files again
122+
IO.popen("find \"#{options[:search_directory]}\" -name \"*.o\"") { |f|
123+
f.each do |line|
124+
125+
# puts "Running dwarfdump #{line} | grep -A1 TAG_pointer_type"
126+
source = /.*\/(.+)\.o/.match(line)[1]
127+
IO.popen("dwarfdump #{line.strip} | grep -A1 TAG_pointer_type") { |fd|
128+
fd.each do |line2|
129+
# Finding the name in types
130+
# AT_type( {0x00000456} ( objc_object ) )
131+
name = /.*?AT_type\(\s\{.*?\}.*\(\s((function|const)\s)?([A-Z][^\)]+?)\*?\s\).*/.match(line2)
132+
if name != nil
133+
dest = name[3]
134+
if /^(#{options[:exclusion_prefixes]})/.match(dest) == nil
135+
if source != dest and dest != "BOOL"
136+
destinations = links[source] ? links[source] : (links[source] = {})
137+
destinations[dest] = "set up"
138+
end
139+
end
140+
end
141+
end
142+
}
143+
end
144+
}
145+
end
146+
147+
sources_count = links.length
148+
links_count = 0
149+
links.each do |source, dest_hash|
150+
links_count = links_count + dest_hash.length
151+
dest_hash.each do |dest, _ |
152+
puts " { \"source\" : \"#{source}\", \"dest\" : \"#{dest}\" },"
153+
end
154+
end
155+
156+
157+
113158
puts <<-THEEND
114-
]
159+
],
160+
"source_files_count":#{sources_count},
161+
"links_count":#{links_count},
115162
}
116163
;
117164
THEEND

0 commit comments

Comments
 (0)