Arrow Development Environment Part 4: Using the Debugger

arrow
dev-env
Author

Will Jones

Published

August 13, 2022

This is part of a series on setting up an Arrow development environment. If you haven’t gone through part 1 on setting up C++, start there.

Debuggers, true to their name, make debugging much easier. And by following the setup instructions earlier in this series, you have easy access to one whether you are looking at an issue in C++, Python, or R. You shouldn’t have a reason to reach for print-statement-debugging when launching LLDB (or GDB) is this easy!

Attaching the debugger

C++

To run a unit test under the debugger:

  1. Make sure you have test selected: CMD + P > launch.json, edit test binary (in program field) and test name (in args field).
  2. CTRL + P, type “debug”, then select Debug C++ Unit Test.
  3. The unit test will now run and stop at any breakpoints or exceptions.

Python

To run debugger on an interactive sessions:

  1. Launch python.
  2. Run import os; os.getpid() and record the process ID.
  3. CTRL + P, type “debug”, then select LLDB Attach to Python.
  4. Type in process ID from earlier and wait for debugger to start.
  5. You can now set breakpoints in C++ and they will be stopped at if you run Python commands.

To run debugger on a unit test:

  1. Add a breakpoint() call into the unit test.
  2. Run the unit test.
  3. When Python breakpoint is reached, run import os; os.gepid() and record the process ID.
  4. CTRL + P, type “debug”, then select LLDB Attach to Python.
  5. Type in process ID from earlier and wait for debugger to start.
  6. In the PDB (Python debugger) console, type “c” for continue.

R

To run debugger on an interactive sessions:

  1. Launch R.
  2. Run Sys.getpid() and record the process ID.
  3. CTRL + P, type “debug”, then select LLDB Attach to R
  4. Type in process ID from earlier and wait for debugger to start.
  5. You can now set breakpoints in C++ and they will be stopped at if you run R commands.

To run debugger on a unit test:

  1. Add a browser() call into the unit test.
  2. Run the unit test (devtools::test(filter="<filename>").
  3. When Python breakpoint is reached, run Sys.getpid() and record the process ID.
  4. CTRL + P, type “debug”, then select LLDB Attach to R.
  5. Type in process ID from earlier and wait for debugger to start.
  6. In the R console, type “c” for continue.