BeamFile (beam_file v0.1.0)

An interface to the BEAM file format.

This module is mainly a wrapper around Erlangs :beam_lib.

Furthermore, different code representations can be generated from the file.

Link to this section Summary

Functions

Returns the :abstract_code chunk.

Returns the byte code for the BEAM file.

Returns infos for the given chunk reference.

Returns chunk data for all chunks.

Returns chunk data for all chunk names.

Returns the Dbgi/:debug_info chunk.

Returns the :docs chunk.

Returns elixir code recreated from the debug_info chunk.

Returns the Erlang code for the BEAM file.

Returns a keyword list containing some information about a BEAM file.

Returns the binary for the given BEAM file.

Returns the absolute filename for the module.

Link to this section Types

Specs

chunk() :: chunk_id() | chunk_name()

Specs

chunk_id() ::
  :abstract_code
  | :atoms
  | :attributes
  | :compile_info
  | :debug_info
  | :docs
  | :elixir_checker
  | :exports
  | :imports
  | :indexed_imports
  | :labeled_exports
  | :labeled_locals
  | :locals
Link to this type

chunk_name()

Specs

chunk_name() :: charlist()

Specs

info() :: [
  file: Path.t(),
  module: module(),
  chunks: [{charlist(), non_neg_integer(), non_neg_integer()}]
]

Link to this section Functions

Link to this function

abstract_code(input)

Specs

abstract_code(Path.t() | module()) :: {:ok, term()} | {:error, any()}

Returns the :abstract_code chunk.

Link to this function

byte_code(input)

Specs

byte_code(Path.t() | module()) :: {:ok, String.t()} | {:error, any()}

Returns the byte code for the BEAM file.

Link to this function

chunk(input, chunk)

Specs

chunk(Path.t() | module(), chunk()) :: {:ok, term()} | {:error, any()}

Returns infos for the given chunk reference.

Specs

chunks(Path.t() | module()) :: {:ok, map()} | {:error, any()}

Returns chunk data for all chunks.

Link to this function

chunks(input, atom)

Returns chunk data for all chunk names.

Link to this function

debug_info(module)

Specs

debug_info(module()) :: {:ok, term()} | {:error, any()}

Returns the Dbgi/:debug_info chunk.

Specs

docs(Path.t() | module()) :: {:ok, term()} | {:error, any()}

Returns the :docs chunk.

Link to this function

elixir_code(input, opts \\ [])

Specs

elixir_code(Path.t() | module(), keyword()) ::
  {:ok, String.t()} | {:error, any()}

Returns elixir code recreated from the debug_info chunk.

The recreated code comes with resolved macros and references. For now, types and specs will not be recreated.

Options: :docs: With docs: false the docs will not be created.

Link to this function

erl_code(input)

Specs

erl_code(Path.t() | module()) :: {:ok, String.t()} | {:error, any()}

Returns the Erlang code for the BEAM file.

Specs

info(Path.t() | module()) :: info()

Returns a keyword list containing some information about a BEAM file.

  • :file: The name of the BEAM file, or the binary from which the information was extracted.
  • :module: The name of the module.
  • :chunks: For each chunk, the identifier and the position and size of the chunk data, in bytes.

Specs

read(Path.t() | module()) :: {:ok, binary()} | {:error, File.posix()}

Returns the binary for the given BEAM file.

Specs

which(module()) ::
  {:ok, String.t()} | {:error, :non_existing | :preloaded | :cover_compiled}

Returns the absolute filename for the module.

If the module cannot be found, {:error, :non_existing} is returned.

If the module is preloaded, {:error, :preloaded} is returned.

If the module is Cover-compiled, {:error, :cover_compiled} is returned.