Class: Udb::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/udb/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


367
368
369
# File 'lib/udb/cli.rb', line 367

def self.exit_on_failure?
  true
end

Instance Method Details

#disasm(encoding_str) ⇒ Object

Raises:

  • (ArgumentError)


391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/udb/cli.rb', line 391

def disasm(encoding_str)
  raise ArgumentError, "Arch directory does not exist: #{options[:arch]}" unless File.directory?(options[:arch])
  raise MalformattedArgumentError, "encoding must be a hex string" unless encoding_str =~ /\A(0[xX])?[a-fA-F0-9]+\z/

  cfg_file =
    if File.file?(options[:config])
      Pathname.new(options[:config])
    elsif File.file?("#{options[:config_dir]}/#{options[:config]}.yaml")
      Pathname.new("#{options[:config_dir]}/#{options[:config]}.yaml")
    else
      raise ArgumentError, "Cannot find config: #{options[:config]}"
    end

  resolver =
    Udb::Resolver.new(
      std_path_override: Pathname.new(options[:arch]),
      gen_path_override: Pathname.new(options[:gen]),
      custom_path_override: Pathname.new(options[:arch_overlay])
    )
  cfg_arch = resolver.cfg_arch_for(cfg_file.realpath)

  encoding = encoding_str.to_i(16)

  matches = { 32 => [], 64 => [] }

  cfg_arch.possible_xlens.each do |xlen|
    say "RV#{xlen}:"

    matches[xlen] = cfg_arch.instructions.select do |i|
      next unless i.defined_in_base?(xlen)

      opcode_mask = i.encoding(xlen).format.gsub(/[01]/, "1").gsub("-", "0").to_i(2)
      match = i.encoding(xlen).format.gsub("-", "0").to_i(2)
      (opcode_mask & encoding) == match
    end

    if matches[xlen].empty?
      say "  Illegal Instruction"
    else
      matches[xlen].each do |inst|
        say "  #{inst.name}"
      end
    end
  end
end

#versionObject



372
373
374
# File 'lib/udb/cli.rb', line 372

def version
  puts Udb.version
end