Using gdb to debug TensorFlow

83 views
Skip to first unread message

Novo Bruna David

unread,
Aug 14, 2021, 6:04:54 AM8/14/21
to TensorFlow Developers
Hi,

What's the best approach to debug TensorFlow C++ source code?

I've compiled TensoFlow with "--config=dbg", but I'm having problems to reach the C++ code from python. This is the approach I'm following:

1) I've created the following test TensorFlow program named test_gdb.py

import tensorflow as tf
import os

input("pid: " + str(os.getpid()) +", press enter to continue")

a = tf.constant([[1,3]])
b = tf.constant([[3],[1]])
c = tf.matmul(a, b)

print(c)

2) I run the script in one terminal:

$ python test_gdb.py
pid: 54974, press enter to continue

3) In a second terminal, I connect gdb to the pid:

$ gdb -p 54974
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-6.el8_0
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:

For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 54974 
[New LWP 55049]
[New LWP 55050]
[New LWP 55051]
...
[New LWP 55128]
[New LWP 55129]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Missing separate debuginfo for /linkhome/rech/genlir01/umx47tt/.local/lib/python3.8/site-packages/numpy/core/../../numpy.libs/libgfortran-2e0d59d6.so.5.0.0
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/5e/f8275331f3c7aea4d0b59f2fa7ae783457a91a.debug
Missing separate debuginfo for /linkhome/rech/genlir01/umx47tt/.local/lib/python3.8/site-packages/numpy/core/../../numpy.libs/libquadmath-2d0c479f.so.0.0.0
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/e9/e2b7af3158e70f8af44f54f17ca0d14d95ed2d.debug
Missing separate debuginfo for /linkhome/rech/genlir01/umx47tt/.local/lib/python3.8/site-packages/numpy/core/../../numpy.libs/libz-eb09ad1d.so.1.2.3
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/5f/a8e5038ec04a774af72a9bb62dc86e1049c4d6.debug
Killed

Is there a problem with my debugging method or with my system configuration? Is there a better method to debug TensorFlow C++ source code?

JB Data31

unread,
Aug 15, 2021, 4:36:10 AM8/15/21
to Novo Bruna David, TensorFlow Developers
Your way to debug works fine on my apt-get installed ubuntu system, except not all lib have been -g compiled.

$ sudo gdb -p 18733
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
...
Attaching to process 18733
Reading symbols from /usr/bin/python3.8...
(No debugging symbols found in /usr/bin/python3.8)
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...
Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.31.so...
...
(gdb) bt
#0  0x00007fe10657a142 in __GI___libc_read (fd=0, buf=0x1e77910, nbytes=1024) at ../sysdeps/unix/sysv/linux/read.c:26
...
#20 0x00000000005f96de in _start ()

As a first step, I suggest you to use a simpler test to avoid tf complexity:
import os
import sys

print(sys.path)

input("pid: " + str(os.getpid()) +", press enter to continue")

It sounds like a yum config issue. Did you try dnf commands as suggested
Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/5e/f8275331f3c7aea4d0b59f2fa7ae783457a91a.debug

@JBΔ



--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/developers/e11d5832-421c-49f0-8fc0-8a02d0cf6a50n%40tensorflow.org.
Reply all
Reply to author
Forward
0 new messages