View Source edb_dap_id_mappings (edb v0.4.0)

An mapper of IDs for the debug adapter

The DAP protocol expects numeric ids for threads, frames, scopes, etc. These ids are represented as number() in the JSON specification, and are expected to fit in a 64-bit float. Some ids like thread_ids are expected to be unique across the debugging session, while others (frame-ids, etc), need be unique only between pauses. The specification recommends adapters to reset them on continue requests. For more details see https://microsoft.github.io/debug-adapter-protocol/overview

This module implements the mapping fo PIDs to thread-ids, etc, generically.

Summary

Types

An integer that fits in a 64-bit float. This is the requirement the DAP spec puts on ids.

Types

frame_scope()

-type frame_scope() :: #{frame := id(), scope := scope()}.

frame_scope_or_structured()

-type frame_scope_or_structured() :: frame_scope() | structured().

id()

-type id() :: non_neg_integer().

An integer that fits in a 64-bit float. This is the requirement the DAP spec puts on ids.

id_mapping(A)

-type id_mapping(A) ::
          #{validator := validator(A), back := #{id() => A}, forth := #{A => id()}, next := id()}.

pid_frame()

-type pid_frame() :: #{pid := pid(), frame_no := non_neg_integer()}.

scope()

-type scope() :: locals | registers | messages.

state(A)

-type state(A) :: id_mapping(A).

structured()

-type structured() :: #{elements := [{binary(), edb:value()}]}.

validator(A)

-type validator(A) :: fun((term()) -> {ok, A} | invalid).

Functions

frame_id_to_pid_frame(Id)

-spec frame_id_to_pid_frame(id()) -> {ok, pid_frame()} | {error, not_found}.

frame_scope_or_structured_to_var_reference/1

-spec frame_scope_or_structured_to_var_reference(frame_scope_or_structured()) -> id().

handle_call/3

-spec handle_call({get_id, A}, gen_server:from(), state(A)) -> {reply, id(), state(A)};
                 ({get_ids, [A]}, gen_server:from(), state(A)) -> {reply, #{A => id()}, state(A)};
                 ({from_id, id()}, gen_server:from(), state(A)) ->
                     {reply, {ok, A} | {error, not_found}, state(A)};
                 (reset, gen_server:from(), state(A)) -> {reply, ok, state(A)}.

handle_cast(Request, State)

-spec handle_cast(term(), state(A)) -> {noreply, state(A)}.

handle_info/2

-spec handle_info(term(), state(A)) -> {noreply, state(A)}.

init(ServerType)

-spec init(edb_dap_thread_id_mappings) -> {ok, state(pid())};
          (edb_dap_frame_id_mappings) -> {ok, state(pid_frame())};
          (edb_dap_var_reference_id_mappings) -> {ok, state(id())}.

pid_frame_to_frame_id/1

-spec pid_frame_to_frame_id(pid_frame()) -> id().

pid_to_thread_id(Pid)

-spec pid_to_thread_id(pid()) -> id().

pids_to_thread_ids(Pids)

-spec pids_to_thread_ids([pid()]) -> #{pid() => id()}.

reset()

-spec reset() -> ok.

thread_id_to_pid(Id)

-spec thread_id_to_pid(id()) -> {ok, pid()} | {error, not_found}.

var_reference_to_frame_scope_or_structured(VarReference)

-spec var_reference_to_frame_scope_or_structured(id()) ->
                                                    {ok, frame_scope_or_structured()} |
                                                    {error, not_found}.