Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Note: Debugger API

Alex Rønne Petersen edited this page Jun 7, 2013 · 10 revisions

The core::dbg module provides a bunch of useful functions to interact with the cooperative debugger. Some of the functions are backed by those in core::thread.

pub struct RemoteClient {
    // The IP address of the remote client.
    pub address : str;

    // The port that the remote client is connected on.
    pub port : u16;
}

pub fn get_remote_client() -> Option<RemoteClient>;

Gets information about the currently-attached debugger if one is present. Returns None if none is attached.

pub fn breakpoint() -> bool;

This function results in the program being paused if a debugger is attached. If a debugger is attached, the function returns true once the debugger resumes the program. If a debugger is not attached, it immediately returns false.

pub struct StackFrame {
    // Name of the function the frame is part of.
    pub fn_name : str;

    // Name of the module the function is part of.
    pub fn_module : str;

    // Absolute path of the file the function is declared in.
    pub fn_file : str;

    // Line the function is declared on. Starts at 1.
    pub fn_line : u32;

    // Column the function is declared at. Starts at 1.
    pub fn_column : u32;

    // Address of the function.
    pub fn_address : fn() -> unit;

    // A pointer to the shadow stack entry associated with this frame.
    priv shadow : *mut GenericShadowStackEntry;
}

pub fn stack_trace[T](thread : &imm Thread, seed : T, ref handler : fn@(ref StackFrame, T) -> T) -> T;

This function performs a foldl over the list of stack frames in the given thread. The thread must be in a paused state or be the calling thread. The first frame is the calling function and the last frame is the entry point function of the current thread.

If the program is not compiled for debugging, no frames will be iterated. If some frame in the call stack is not compiled for debugging, it will not show up.

(Thread is a type exposed in core::thread.)

pub struct Local {
    // The name of the local variable.
    pub name : str;

    // Pointer to the value that was last written into the shadow stack.
    pub value : *mut u8;

    // The type of the local.
    pub type_ : &TypeInfo;
}

pub fn get_locals[T](ref frame : StackFrame, seed : T, ref handler : fn@(ref Local, T) -> T) -> T;

This function performs a foldl over the list of locals in frame. The thread that frame belongs to must be in a paused state or be the current thread. The locals are sorted in no particular order.

(TypeInfo is a type exposed in core::meta.)

Note that none of the above functions are available in a freestanding build.