Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1 | -- Copyright 2011 the V8 project authors. All rights reserved. |
| 2 | -- Redistribution and use in source and binary forms, with or without |
| 3 | -- modification, are permitted provided that the following conditions are |
| 4 | -- met: |
| 5 | -- |
| 6 | -- * Redistributions of source code must retain the above copyright |
| 7 | -- notice, this list of conditions and the following disclaimer. |
| 8 | -- * Redistributions in binary form must reproduce the above |
| 9 | -- copyright notice, this list of conditions and the following |
| 10 | -- disclaimer in the documentation and/or other materials provided |
| 11 | -- with the distribution. |
| 12 | -- * Neither the name of Google Inc. nor the names of its |
| 13 | -- contributors may be used to endorse or promote products derived |
| 14 | -- from this software without specific prior written permission. |
| 15 | -- |
| 16 | -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | -- This is main driver for gcmole tool. See README for more details. |
| 29 | -- Usage: CLANG_BIN=clang-bin-dir lua tools/gcmole/gcmole.lua [arm|ia32|x64] |
| 30 | |
| 31 | local DIR = arg[0]:match("^(.+)/[^/]+$") |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 32 | |
| 33 | local FLAGS = { |
| 34 | -- Do not build gcsuspects file and reuse previously generated one. |
| 35 | reuse_gcsuspects = false; |
| 36 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 37 | -- Don't use parallel python runner. |
| 38 | sequential = false; |
| 39 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 40 | -- Print commands to console before executing them. |
| 41 | verbose = false; |
| 42 | |
| 43 | -- Perform dead variable analysis (generates many false positives). |
| 44 | -- TODO add some sort of whiteliste to filter out false positives. |
| 45 | dead_vars = false; |
| 46 | |
| 47 | -- When building gcsuspects whitelist certain functions as if they |
| 48 | -- can be causing GC. Currently used to reduce number of false |
| 49 | -- positives in dead variables analysis. See TODO for WHITELIST |
| 50 | -- below. |
| 51 | whitelist = true; |
| 52 | } |
| 53 | local ARGS = {} |
| 54 | |
| 55 | for i = 1, #arg do |
| 56 | local flag = arg[i]:match "^%-%-([%w_-]+)$" |
| 57 | if flag then |
| 58 | local no, real_flag = flag:match "^(no)([%w_-]+)$" |
| 59 | if real_flag then flag = real_flag end |
| 60 | |
| 61 | flag = flag:gsub("%-", "_") |
| 62 | if FLAGS[flag] ~= nil then |
| 63 | FLAGS[flag] = (no ~= "no") |
| 64 | else |
| 65 | error("Unknown flag: " .. flag) |
| 66 | end |
| 67 | else |
| 68 | table.insert(ARGS, arg[i]) |
| 69 | end |
| 70 | end |
| 71 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 72 | local ARCHS = ARGS[1] and { ARGS[1] } or { 'ia32', 'arm', 'x64', 'arm64' } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 73 | |
| 74 | local io = require "io" |
| 75 | local os = require "os" |
| 76 | |
| 77 | function log(...) |
| 78 | io.stderr:write(string.format(...)) |
| 79 | io.stderr:write "\n" |
| 80 | end |
| 81 | |
| 82 | ------------------------------------------------------------------------------- |
| 83 | -- Clang invocation |
| 84 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 85 | local CLANG_BIN = os.getenv "CLANG_BIN" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 86 | local CLANG_PLUGINS = os.getenv "CLANG_PLUGINS" |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 87 | |
| 88 | if not CLANG_BIN or CLANG_BIN == "" then |
| 89 | error "CLANG_BIN not set" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 90 | end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 91 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 92 | if not CLANG_PLUGINS or CLANG_PLUGINS == "" then |
| 93 | CLANG_PLUGINS = DIR |
| 94 | end |
| 95 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 96 | local function MakeClangCommandLine( |
| 97 | plugin, plugin_args, triple, arch_define, arch_options) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 98 | if plugin_args then |
| 99 | for i = 1, #plugin_args do |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 100 | plugin_args[i] = "-Xclang -plugin-arg-" .. plugin |
| 101 | .. " -Xclang " .. plugin_args[i] |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 102 | end |
| 103 | plugin_args = " " .. table.concat(plugin_args, " ") |
| 104 | end |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | return CLANG_BIN .. "/clang++ -std=c++11 -c " |
| 106 | .. " -Xclang -load -Xclang " .. CLANG_PLUGINS .. "/libgcmole.so" |
| 107 | .. " -Xclang -plugin -Xclang " .. plugin |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 108 | .. (plugin_args or "") |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | .. " -Xclang -triple -Xclang " .. triple |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 110 | .. " -D" .. arch_define |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 111 | .. " -DENABLE_DEBUGGER_SUPPORT" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | .. " -DV8_I18N_SUPPORT" |
| 113 | .. " -I./" |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 114 | .. " -Iinclude/" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 115 | .. " -Ithird_party/icu/source/common" |
| 116 | .. " -Ithird_party/icu/source/i18n" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 117 | .. " " .. arch_options |
| 118 | end |
| 119 | |
| 120 | local function IterTable(t) |
| 121 | return coroutine.wrap(function () |
| 122 | for i, v in ipairs(t) do |
| 123 | coroutine.yield(v) |
| 124 | end |
| 125 | end) |
| 126 | end |
| 127 | |
| 128 | local function SplitResults(lines, func) |
| 129 | -- Splits the output of parallel.py and calls func on each result. |
| 130 | -- Bails out in case of an error in one of the executions. |
| 131 | local current = {} |
| 132 | local filename = "" |
| 133 | for line in lines do |
| 134 | local new_file = line:match "^______________ (.*)$" |
| 135 | local code = line:match "^______________ finish (%d+) ______________$" |
| 136 | if code then |
| 137 | if tonumber(code) > 0 then |
| 138 | log(table.concat(current, "\n")) |
| 139 | log("Failed to examine " .. filename) |
| 140 | return false |
| 141 | end |
| 142 | log("-- %s", filename) |
| 143 | func(filename, IterTable(current)) |
| 144 | elseif new_file then |
| 145 | filename = new_file |
| 146 | current = {} |
| 147 | else |
| 148 | table.insert(current, line) |
| 149 | end |
| 150 | end |
| 151 | return true |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 152 | end |
| 153 | |
| 154 | function InvokeClangPluginForEachFile(filenames, cfg, func) |
| 155 | local cmd_line = MakeClangCommandLine(cfg.plugin, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 156 | cfg.plugin_args, |
| 157 | cfg.triple, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 158 | cfg.arch_define, |
| 159 | cfg.arch_options) |
| 160 | if FLAGS.sequential then |
| 161 | log("** Sequential execution.") |
| 162 | for _, filename in ipairs(filenames) do |
| 163 | log("-- %s", filename) |
| 164 | local action = cmd_line .. " " .. filename .. " 2>&1" |
| 165 | if FLAGS.verbose then print('popen ', action) end |
| 166 | local pipe = io.popen(action) |
| 167 | func(filename, pipe:lines()) |
| 168 | local success = pipe:close() |
| 169 | if not success then error("Failed to run: " .. action) end |
| 170 | end |
| 171 | else |
| 172 | log("** Parallel execution.") |
| 173 | local action = "python tools/gcmole/parallel.py \"" |
| 174 | .. cmd_line .. "\" " .. table.concat(filenames, " ") |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 175 | if FLAGS.verbose then print('popen ', action) end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 176 | local pipe = io.popen(action) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 177 | local success = SplitResults(pipe:lines(), func) |
| 178 | local closed = pipe:close() |
| 179 | if not (success and closed) then error("Failed to run: " .. action) end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 180 | end |
| 181 | end |
| 182 | |
| 183 | ------------------------------------------------------------------------------- |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | -- GYP file parsing |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 185 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | local function ParseGYPFile() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | local result = {} |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 188 | local gyp_files = { |
| 189 | { "src/v8.gyp", "'([^']-%.cc)'", "src/" }, |
| 190 | { "test/cctest/cctest.gyp", "'(test-[^']-%.cc)'", "test/cctest/" } |
| 191 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 192 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 193 | for i = 1, #gyp_files do |
| 194 | local filename = gyp_files[i][1] |
| 195 | local pattern = gyp_files[i][2] |
| 196 | local prefix = gyp_files[i][3] |
| 197 | local gyp_file = assert(io.open(filename), "failed to open GYP file") |
| 198 | local gyp = gyp_file:read('*a') |
| 199 | for condition, sources in |
| 200 | gyp:gmatch "'sources': %[.-### gcmole%((.-)%) ###(.-)%]" do |
| 201 | if result[condition] == nil then result[condition] = {} end |
| 202 | for file in sources:gmatch(pattern) do |
| 203 | table.insert(result[condition], prefix .. file) |
| 204 | end |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 205 | end |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 206 | gyp_file:close() |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 207 | end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 208 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 209 | return result |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 210 | end |
| 211 | |
| 212 | local function EvaluateCondition(cond, props) |
| 213 | if cond == 'all' then return true end |
| 214 | |
| 215 | local p, v = cond:match "(%w+):(%w+)" |
| 216 | |
| 217 | assert(p and v, "failed to parse condition: " .. cond) |
| 218 | assert(props[p] ~= nil, "undefined configuration property: " .. p) |
| 219 | |
| 220 | return props[p] == v |
| 221 | end |
| 222 | |
| 223 | local function BuildFileList(sources, props) |
| 224 | local list = {} |
| 225 | for condition, files in pairs(sources) do |
| 226 | if EvaluateCondition(condition, props) then |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 227 | for i = 1, #files do table.insert(list, files[i]) end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 228 | end |
| 229 | end |
| 230 | return list |
| 231 | end |
| 232 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 233 | local sources = ParseGYPFile() |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 234 | |
| 235 | local function FilesForArch(arch) |
| 236 | return BuildFileList(sources, { os = 'linux', |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 237 | arch = arch, |
| 238 | mode = 'debug', |
| 239 | simulator = ''}) |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 240 | end |
| 241 | |
| 242 | local mtConfig = {} |
| 243 | |
| 244 | mtConfig.__index = mtConfig |
| 245 | |
| 246 | local function config (t) return setmetatable(t, mtConfig) end |
| 247 | |
| 248 | function mtConfig:extend(t) |
| 249 | local e = {} |
| 250 | for k, v in pairs(self) do e[k] = v end |
| 251 | for k, v in pairs(t) do e[k] = v end |
| 252 | return config(e) |
| 253 | end |
| 254 | |
| 255 | local ARCHITECTURES = { |
| 256 | ia32 = config { triple = "i586-unknown-linux", |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 257 | arch_define = "V8_TARGET_ARCH_IA32", |
| 258 | arch_options = "-m32" }, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 259 | arm = config { triple = "i586-unknown-linux", |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 260 | arch_define = "V8_TARGET_ARCH_ARM", |
| 261 | arch_options = "-m32" }, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 262 | x64 = config { triple = "x86_64-unknown-linux", |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 263 | arch_define = "V8_TARGET_ARCH_X64", |
| 264 | arch_options = "" }, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | arm64 = config { triple = "x86_64-unknown-linux", |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 266 | arch_define = "V8_TARGET_ARCH_ARM64", |
| 267 | arch_options = "" }, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | ------------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 271 | -- GCSuspects Generation |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 272 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 273 | local gc, gc_caused, funcs |
| 274 | |
| 275 | local WHITELIST = { |
| 276 | -- The following functions call CEntryStub which is always present. |
| 277 | "MacroAssembler.*CallExternalReference", |
| 278 | "MacroAssembler.*CallRuntime", |
| 279 | "CompileCallLoadPropertyWithInterceptor", |
| 280 | "CallIC.*GenerateMiss", |
| 281 | |
| 282 | -- DirectCEntryStub is a special stub used on ARM. |
| 283 | -- It is pinned and always present. |
| 284 | "DirectCEntryStub.*GenerateCall", |
| 285 | |
| 286 | -- TODO GCMole currently is sensitive enough to understand that certain |
| 287 | -- functions only cause GC and return Failure simulataneously. |
| 288 | -- Callsites of such functions are safe as long as they are properly |
| 289 | -- check return value and propagate the Failure to the caller. |
| 290 | -- It should be possible to extend GCMole to understand this. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 291 | "Heap.*AllocateFunctionPrototype", |
| 292 | |
| 293 | -- Ignore all StateTag methods. |
| 294 | "StateTag", |
| 295 | |
| 296 | -- Ignore printing of elements transition. |
| 297 | "PrintElementsTransition" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | local function AddCause(name, cause) |
| 301 | local t = gc_caused[name] |
| 302 | if not t then |
| 303 | t = {} |
| 304 | gc_caused[name] = t |
| 305 | end |
| 306 | table.insert(t, cause) |
| 307 | end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 308 | |
| 309 | local function resolve(name) |
| 310 | local f = funcs[name] |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 311 | |
| 312 | if not f then |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 313 | f = {} |
| 314 | funcs[name] = f |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 315 | |
| 316 | if name:match "Collect.*Garbage" then |
| 317 | gc[name] = true |
| 318 | AddCause(name, "<GC>") |
| 319 | end |
| 320 | |
| 321 | if FLAGS.whitelist then |
| 322 | for i = 1, #WHITELIST do |
| 323 | if name:match(WHITELIST[i]) then |
| 324 | gc[name] = false |
| 325 | end |
| 326 | end |
| 327 | end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 328 | end |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 329 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 330 | return f |
| 331 | end |
| 332 | |
| 333 | local function parse (filename, lines) |
| 334 | local scope |
| 335 | |
| 336 | for funcname in lines do |
| 337 | if funcname:sub(1, 1) ~= '\t' then |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 338 | resolve(funcname) |
| 339 | scope = funcname |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 340 | else |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 341 | local name = funcname:sub(2) |
| 342 | resolve(name)[scope] = true |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 343 | end |
| 344 | end |
| 345 | end |
| 346 | |
| 347 | local function propagate () |
| 348 | log "** Propagating GC information" |
| 349 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 350 | local function mark(from, callers) |
| 351 | for caller, _ in pairs(callers) do |
| 352 | if gc[caller] == nil then |
| 353 | gc[caller] = true |
| 354 | mark(caller, funcs[caller]) |
| 355 | end |
| 356 | AddCause(caller, from) |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 357 | end |
| 358 | end |
| 359 | |
| 360 | for funcname, callers in pairs(funcs) do |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 361 | if gc[funcname] then mark(funcname, callers) end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 362 | end |
| 363 | end |
| 364 | |
| 365 | local function GenerateGCSuspects(arch, files, cfg) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 366 | -- Reset the global state. |
| 367 | gc, gc_caused, funcs = {}, {}, {} |
| 368 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 369 | log ("** Building GC Suspects for %s", arch) |
| 370 | InvokeClangPluginForEachFile (files, |
| 371 | cfg:extend { plugin = "dump-callees" }, |
| 372 | parse) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 373 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 374 | propagate() |
| 375 | |
| 376 | local out = assert(io.open("gcsuspects", "w")) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 377 | for name, value in pairs(gc) do if value then out:write (name, '\n') end end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 378 | out:close() |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 379 | |
| 380 | local out = assert(io.open("gccauses", "w")) |
| 381 | out:write "GC = {" |
| 382 | for name, causes in pairs(gc_caused) do |
| 383 | out:write("['", name, "'] = {") |
| 384 | for i = 1, #causes do out:write ("'", causes[i], "';") end |
| 385 | out:write("};\n") |
| 386 | end |
| 387 | out:write "}" |
| 388 | out:close() |
| 389 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 390 | log ("** GCSuspects generated for %s", arch) |
| 391 | end |
| 392 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 393 | -------------------------------------------------------------------------------- |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 394 | -- Analysis |
| 395 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 396 | local function CheckCorrectnessForArch(arch) |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 397 | local files = FilesForArch(arch) |
| 398 | local cfg = ARCHITECTURES[arch] |
| 399 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 400 | if not FLAGS.reuse_gcsuspects then |
| 401 | GenerateGCSuspects(arch, files, cfg) |
| 402 | end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 403 | |
| 404 | local processed_files = 0 |
| 405 | local errors_found = false |
| 406 | local function SearchForErrors(filename, lines) |
| 407 | processed_files = processed_files + 1 |
| 408 | for l in lines do |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 409 | errors_found = errors_found or |
| 410 | l:match "^[^:]+:%d+:%d+:" or |
| 411 | l:match "error" or |
| 412 | l:match "warning" |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 413 | print(l) |
| 414 | end |
| 415 | end |
| 416 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 417 | log("** Searching for evaluation order problems%s for %s", |
| 418 | FLAGS.dead_vars and " and dead variables" or "", |
| 419 | arch) |
| 420 | local plugin_args |
| 421 | if FLAGS.dead_vars then plugin_args = { "--dead-vars" } end |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 422 | InvokeClangPluginForEachFile(files, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 423 | cfg:extend { plugin = "find-problems", |
| 424 | plugin_args = plugin_args }, |
| 425 | SearchForErrors) |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 426 | log("** Done processing %d files. %s", |
| 427 | processed_files, |
| 428 | errors_found and "Errors found" or "No errors found") |
| 429 | |
| 430 | return errors_found |
| 431 | end |
| 432 | |
| 433 | local function SafeCheckCorrectnessForArch(arch) |
| 434 | local status, errors = pcall(CheckCorrectnessForArch, arch) |
| 435 | if not status then |
| 436 | print(string.format("There was an error: %s", errors)) |
| 437 | errors = true |
| 438 | end |
| 439 | return errors |
| 440 | end |
| 441 | |
| 442 | local errors = false |
| 443 | |
| 444 | for _, arch in ipairs(ARCHS) do |
| 445 | if not ARCHITECTURES[arch] then |
| 446 | error ("Unknown arch: " .. arch) |
| 447 | end |
| 448 | |
| 449 | errors = SafeCheckCorrectnessForArch(arch, report) or errors |
| 450 | end |
| 451 | |
| 452 | os.exit(errors and 1 or 0) |