Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging TensorFlow tests: pdb or gdb?

I am debugging decode_raw_op_test from TensorFlow. The test file is written in python however it executes code from underlying C++ files.

Using pdb, I could debug python test file however it doesn't recognize c++ file. Is there a way in which we can debug underlying c++ code?

(I tried using gdb on decode_raw_op_test but it gives "File not in executable format: File format not recognized")

like image 477
Nayana Avatar asked Nov 30 '16 13:11

Nayana


2 Answers

Debugging a mixed Python and C++ program is tricky. You can use gdb to debug the C++ parts of TensorFlow, however. There are two main ways to do this:

  1. Run python under gdb, rather than the test script itself. Let's say that your test script is in bazel-bin/tensorflow/python/kernel_tests/decode_raw_op_test. You would run the following command:

    $ gdb python bazel-bin/tensorflow/python/kernel_tests/decode_raw_op_test
    (gdb) run
    

    Note that gdb does not have great support for debugging the Python parts of the code. I'd recommend narrowing down the test case that you run to a single, simple test, and setting a breakpoint on a TensorFlow C API method, such as TF_Run, which is the main entry point from Python into C++ in TensorFlow.

  2. Attach gdb to a running process. You can get the process ID of the Python test using ps and then run (where $PID is the process ID):

    $ gdb -p $PID
    

    You will probably need to arrange for your Python code to block so that there's time to attach. Calling the raw_input() function is an easy way to do this.

like image 196
mrry Avatar answered Sep 21 '22 13:09

mrry


Could debug using below steps:

gdb python

then on gdb prompt, type

run bazel-bin/tensorflow/python/kernel_tests/decode_raw_op_test
like image 23
Nayana Avatar answered Sep 21 '22 13:09

Nayana