Package 'winch'

Title: Portable Native and Joint Stack Traces
Description: Obtain the native stack trace and fuse it with R's stack trace for easier debugging of R packages with native code.
Authors: Kirill Müller [aut, cre] , R Consortium [fnd], Ian Lance Taylor [aut] (Bundled libbacktrace library), Free Software Foundation [cph] (Bundled libbacktrace library)
Maintainer: Kirill Müller <[email protected]>
License: GPL-3
Version: 0.1.1
Built: 2024-11-16 06:26:31 UTC
Source: CRAN

Help Index


Are native tracebacks available?

Description

Returns TRUE if winch_trace_back() is supported on this platform.

Usage

winch_available()

Value

A scalar logical.

Examples

winch_available()

Call an R function from native code

Description

Primarily intended for testing.

Usage

winch_call(fun, env = parent.frame())

Arguments

fun

A function callable without arguments.

env

The environment in which to evaluate the function call.

Value

The return value of fun().

See Also

winch_stop()

Examples

foo <- function() {
  winch_call(bar)
}

bar <- function() {
  writeLines("Hi!")
}

foo()

Set library to collect symbols for native stack traces

Description

On Windows, function names in native stack traces can be obtained for only one library at a time. Call this function to set the library for which to obtain symbols.

Usage

winch_init_library(path = NULL, force = FALSE)

Arguments

path

Path to the DLL.

force

Reinitialize even if the path to the DLL is unchanged from the last call.

Value

This function is called for its side effects.

See Also

winch_call()

Examples

winch_init_library(getLoadedDLLs()[["rlang"]][["path"]])

Raise an error from native code

Description

Primarily intended for testing.

Usage

winch_stop(message)

Arguments

message

The error message.

Value

This function throws an error and does not return.

See Also

winch_call()

Examples

try(winch_stop("Test"))

Native stack trace

Description

This function returns the native stack trace as a data frame. Each native stack frame corresponds to one row in the returned data frame. Deep function calls come first, the last row corresponds to the running process's entry point.

Usage

winch_trace_back()

Details

On Windows, call winch_init_library() to return function names for a specific package.

Value

A data frame with the columns:

  • func: function name

  • ip: instruction pointer

  • pathname: path to shared library

  • is_libr: a logical, TRUE if this entry is from R's shared library, determined via procmaps::path_is_libr() on the pathname component

See Also

sys.calls() for the R equivalent.

Examples

winch_trace_back()

foo <- function() {
  winch_call(bar)
}

bar <- function() {
  winch_trace_back()
}

foo()