@@ 50,11 50,21 @@ class Symbolizer
end
end
+ class Error
+ include JSON::Serializable
+
+ @[JSON::Field(key: "Message")]
+ property message : String
+ end
+
class Output
include JSON::Serializable
+ @[JSON::Field(key: "Error")]
+ property error : Error?
+
@[JSON::Field(key: "Symbol")]
- property symbols : Array(OutputSymbol)
+ property symbols : Array(OutputSymbol)?
end
@llvm_symbolizer : Process
@@ 89,14 99,23 @@ class Symbolizer
return symbol
end
- # TODO: handle errors from the command more cleanly than just letting the
- # JSON parsing inevitably fail
@llvm_symbolizer.input.puts "FILE:\"#{exe}\" #{ip}\n"
@llvm_symbolizer.input.flush
line = @llvm_symbolizer.output.gets
raise "llvm-symbolizer died" if !line
- symbol = Output.from_json(line).symbols[0].try(&.to_symbol)
+
+ begin
+ output = Output.from_json line
+ rescue ex : JSON::SerializableError
+ raise Exception.new("Failed to parse llvm-symbolizer output line: #{line}", ex)
+ end
+
+ if error = output.error
+ raise "llvm-symbolizer returned an error: #{error.message}"
+ end
+
+ symbol = Output.from_json(line).symbols.try(&.[0]?).try(&.to_symbol)
@cache[ip] = symbol if symbol
symbol