Skip to content

Helpers provided by Ark for the C/C++ debugger #7174

Closed
posit-dev/ark
#769

Description

@lionel-

When debugging native code with codelldb, you can see R variables of type SEXP but they are currently completely opaque. First because the variable pane doesn't reveal anything about the variable such as the type or contents (see #7171). But also because the Debug Console isn't currently of much help by default as there is no way of seeing the output of called functions.

Currently that output is captured by Ark and sent over IOPub but when Ark is paused in the debugger, the code in charge of sending IOPub message is not running. The output accumulates in the IOPub thread's incoming channel until Ark is unpaused.

To work around this Ark could implement a diversion system in the WriteConsole() hook that redirects output to another location than IOPub. When Ark is in that state, output would no longer be sent to IOPub. This could be managed automatically with a function taking a closure, e.g. capture_console_output(|| Rf_PrintValue(x)), that would be in charge of setting up the redirection and resetting it. This helper would be used to implement easy to call wrappers provided by Ark, e.g. ark_print(). Users would then be able to

  • Call these helpers in the Watch Pane.
  • Call them in the Debug Console.

Ideally the output would be redirected to stdout but for reasons I'll explain in the PR that's very hard and I couldn't find a nice way to do it. Alternatively the helpers can return the redirected output as a C string. It is nicely printed with this LLDB setting:

settings set escape-non-printables false

Ark could expose different helpers such as:

  • Print a variable
  • Inspect the structure of a variable
  • Print the R level call stack (can be very useful to figure out how the C code was called)

Activity

  1. added
    area: debugger
    on Apr 8, 2025
  2. added this to the Future milestone on Apr 9, 2025
  3. locked as resolved and limited conversation to collaborators on Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: debuggerlang: r

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions