[英]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.我正在调试来自 TensorFlow 的 decode_raw_op_test。测试文件是在 python 中编写的,但是它执行来自底层 C++ 文件的代码。
Using pdb, I could debug python test file however it doesn't recognize c++ file.使用 pdb,我可以调试 python 测试文件,但它无法识别 c++ 文件。 Is there a way in which we can debug underlying c++ code?
有没有一种方法可以调试底层 c++ 代码?
(I tried using gdb on decode_raw_op_test but it gives "File not in executable format: File format not recognized") (我尝试在 decode_raw_op_test 上使用 gdb 但它给出“文件不是可执行格式:文件格式无法识别”)
Debugging a mixed Python and C++ program is tricky. 调试混合的Python和C ++程序很棘手。 You can use
gdb
to debug the C++ parts of TensorFlow, however. 但是,您可以使用
gdb
来调试TensorFlow的C ++部分。 There are two main ways to do this: 有两种主要方法可以做到这一点:
Run python
under gdb
, rather than the test script itself. 在
gdb
下运行python
,而不是测试脚本本身。 Let's say that your test script is in bazel-bin/tensorflow/python/kernel_tests/decode_raw_op_test
. 假设您的测试脚本位于
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. 请注意,
gdb
对调试代码的Python部分没有很大的支持。 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. 我建议缩小您运行到单个简单测试的测试用例,并在TensorFlow C API方法上设置断点,例如
TF_Run
,这是从TensorFlow中Python到C ++的主要入口点。
Attach gdb
to a running process. 将
gdb
附加到正在运行的进程。 You can get the process ID of the Python test using ps
and then run (where $PID
is the process ID): 您可以使用
ps
获取Python测试的进程ID,然后运行(其中$PID
是进程ID):
$ gdb -p $PID
You will probably need to arrange for your Python code to block so that there's time to attach. 您可能需要安排您的Python代码阻止,以便有时间附加。 Calling the
raw_input()
function is an easy way to do this. 调用
raw_input()
函数是一种简单的方法。
Could debug using below steps: 可以使用以下步骤调试:
gdb python
then on gdb prompt, type 然后在gdb提示符下键入
run bazel-bin/tensorflow/python/kernel_tests/decode_raw_op_test
Adding on mrry's answer, in today's TF2 environment, the main entry point would be TFE_Execute, this should be where you add the breakpoint.添加 mrry 的答案,在今天的 TF2 环境中,主要入口点将是 TFE_Execute,这应该是您添加断点的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.