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:
- Make sure you have test selected: CMD + P > launch.json, edit test binary (in
program
field) and test name (inargs
field). - CTRL + P, type “debug”, then select Debug C++ Unit Test.
- The unit test will now run and stop at any breakpoints or exceptions.
Python
To run debugger on an interactive sessions:
- Launch
python
. - Run
import os; os.getpid()
and record the process ID. - CTRL + P, type “debug”, then select LLDB Attach to Python.
- Type in process ID from earlier and wait for debugger to start.
- 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:
- Add a
breakpoint()
call into the unit test. - Run the unit test.
- When Python breakpoint is reached, run
import os; os.gepid()
and record the process ID. - CTRL + P, type “debug”, then select LLDB Attach to Python.
- Type in process ID from earlier and wait for debugger to start.
- In the PDB (Python debugger) console, type “c” for continue.
R
To run debugger on an interactive sessions:
- Launch
R
. - Run
Sys.getpid()
and record the process ID. - CTRL + P, type “debug”, then select LLDB Attach to R
- Type in process ID from earlier and wait for debugger to start.
- 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:
- Add a
browser()
call into the unit test. - Run the unit test (
devtools::test(filter="<filename>"
). - When Python breakpoint is reached, run
Sys.getpid()
and record the process ID. - CTRL + P, type “debug”, then select LLDB Attach to R.
- Type in process ID from earlier and wait for debugger to start.
- In the R console, type “c” for continue.