~refi64/alys

d3cfa66f55396c94824aa89850facc02fd21b4bb — Ryan Gonzalez 4 months ago bfe5e12
Improve handling of llvm-symbolizer errors
1 files changed, 23 insertions(+), 4 deletions(-)

M tools/alys_converter.cr
M tools/alys_converter.cr => tools/alys_converter.cr +23 -4
@@ 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