how to build a TFLite so file with debug information

748 views
Skip to first unread message

MuJohnny chan

unread,
Apr 22, 2020, 12:53:11 AM4/22/20
to TensorFlow Lite
Hi,

I know how to build a TFLite so file and then import it into Android app. However, have no idea how to build a TFLite so file so that I could debug line by line using lldb or gdb in order to know more details about the core source code of TFLite framework? is there any solution to do that? any instructions?many thanks.


Jared Duke

unread,
Apr 22, 2020, 2:26:02 PM4/22/20
to MuJohnny chan, TensorFlow Lite
Hi MuJohnny,

If you include `-c dbg` in your bazel build command, does that help when debugging?

Jared

On Tue, Apr 21, 2020 at 9:53 PM MuJohnny chan <chenm...@gmail.com> wrote:
Hi,

I know how to build a TFLite so file and then import it into Android app. However, have no idea how to build a TFLite so file so that I could debug line by line using lldb or gdb in order to know more details about the core source code of TFLite framework? is there any solution to do that? any instructions?many thanks.


--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tflite+un...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tflite/308bf08a-dc8d-46e1-8673-c5f04d8f331c%40tensorflow.org.

MuJohnny chan

unread,
Apr 22, 2020, 9:38:55 PM4/22/20
to TensorFlow Lite, chenm...@gmail.com
Hi Jared,

I tried to make a debug version of tensorflow 2.0 CPU only by using:

bazel build -c opt --copt=-g  --jobs=8 //tensorflow/tools/pip_package:build_pip_package

However, when I tried to debug the code, I could not find any source code with lldb. Is there something wrong with my command? any suggestion? thanks.
(lldb) c
Process 21640 resuming
Process 21640 stopped
* thread #1: tid = 21640, 0x00007fd6f3b5bc90 _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 16 at c_api.cc:2162, name = 'python', stop reason = breakpoint 1.1
    frame #0: 0x00007fd6f3b5bc90 _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 16 at c_api.cc:2162
(lldb) n
Process 21640 stopped
* thread #1: tid = 21640, 0x00007fd6f3b5bc94 _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 20 at c_api.cc:2160, name = 'python', stop reason = step over
    frame #0: 0x00007fd6f3b5bc94 _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 20 at c_api.cc:2160
(lldb) n
Process 21640 stopped
* thread #1: tid = 21640, 0x00007fd6f3b5bc97 _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 23 at c_api.cc:2162, name = 'python', stop reason = step over
    frame #0: 0x00007fd6f3b5bc97 _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 23 at c_api.cc:2162
(lldb) n
Process 21640 stopped
* thread #1: tid = 21640, 0x00007fd6f3b5bc9b _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 27 at c_api.cc:2160, name = 'python', stop reason = step over
    frame #0: 0x00007fd6f3b5bc9b _pywrap_tensorflow_internal.so`::TF_NewSession(graph=0x0000557570a03ac0, opt=0x0000557570981650, status=0x0000557570932ea0) + 27 at c_api.cc:2160

在 2020年4月23日星期四 UTC+8上午2:26:02,Jared Duke写道:
Hi MuJohnny,

If you include `-c dbg` in your bazel build command, does that help when debugging?

Jared

On Tue, Apr 21, 2020 at 9:53 PM MuJohnny chan <chenm...@gmail.com> wrote:
Hi,

I know how to build a TFLite so file and then import it into Android app. However, have no idea how to build a TFLite so file so that I could debug line by line using lldb or gdb in order to know more details about the core source code of TFLite framework? is there any solution to do that? any instructions?many thanks.


--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfl...@tensorflow.org.

YoungSeok Yoon

unread,
Apr 22, 2020, 10:54:19 PM4/22/20
to MuJohnny chan, TensorFlow Lite
Hi MuJohnny,

You could try replacing the '-c opt' flag in your bazel command to '-c dbg' and see if that works.
So, your full bazel command would be:

bazel build -c dbg --copt=-g  --jobs=8 //tensorflow/tools/pip_package:build_pip_package

Not sure if the '-g' would be necessary here.

YoungSeok

To unsubscribe from this group and stop receiving emails from it, send an email to tflite+un...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tflite/ef899c15-de95-4cdf-91c6-50cd7e50be49%40tensorflow.org.

MuJohnny chan

unread,
Apr 26, 2020, 9:46:18 AM4/26/20
to TensorFlow Lite, chenm...@gmail.com
Hi,

still could not find the source code during lldb debugging. any other suggestion? thanks.

在 2020年4月23日星期四 UTC+8上午10:54:19,YoungSeok Yoon写道:

Andrew Stevens

unread,
Apr 27, 2020, 3:06:57 AM4/27/20
to MuJohnny chan, TensorFlow Lite
Hi,

> > You could try replacing the '-c opt' flag in your bazel command to
> > '-c dbg' and see if that works.
> > So, your full bazel command would be:
> >
> > bazel build -c dbg --copt=-g --jobs=8
> > //tensorflow/tools/pip_package:build_pip_package


To force -g for C++ (which 99.9% of TF) you need to set --cxxopt in
addition to -copt. Even with -c db and --cxxopt in (limited) my
experience you'ĺl find build of the third-party/external stuff may
still set -g0. Also, yocne to start inlcuding debug info youĺl find
the resulting object-files/binaries are VAST (presumably C++ code-bloat
from templating) so youĺl need plenty of memory! If found tinkering
with --fission / --cxxopt=-gsplit-dwarf could help.


Regards,

Andrew


MuJohnny chan

unread,
Apr 28, 2020, 9:15:24 AM4/28/20
to TensorFlow Lite, chenm...@gmail.com
Hi Andrew,

thanks for your reply.

Do you mean the command should be as below?

bazel build -c dbg --copt=-g --jobs=8 --fission / --cxxopt=-gsplit-dwarf //tensorflow/tools/pip_package:build_pip_package

thanks

在 2020年4月27日星期一 UTC+8下午3:06:57,Andrew Stevens写道:

Andrew Stevens

unread,
Apr 28, 2020, 9:25:12 AM4/28/20
to MuJohnny chan, TensorFlow Lite
On Tue, 2020-04-28 at 06:15 -0700, MuJohnny chan wrote:
Do you mean the command should be as below?

bazel build -c dbg --copt=-g --jobs=8 --fission / --cxxopt=-gsplit-dwarf //tensorflow/tools/pip_package:build_pip_package


Need to setup the rest up too.

add --fission=yes

If you read the bazel docs it would seem that "ordinarily" setting --fission would be enough however the TF build seemed to require explicitly adding the -gsplit-dwarf.

The TF build seems be fairly aggressive in doing its own thing but this may simply be the result so much being included as external projects.


Regards,

Andrew

MuJohnny chan

unread,
Apr 29, 2020, 12:48:03 AM4/29/20
to TensorFlow Lite, chenm...@gmail.com
I used the below command to build the CPU only whl file.

bazel build -c dbg --copt=-g --jobs=8 --fission=yes --cxxopt=-gsplit-dwarf //tensorflow/tools/pip_package:build_pip_package


However, when I try to use "list" or "next" command to single line debug with lldb -p xxx, there are no c++ code shown.


Did I miss something important?

thanks.
  
在 2020年4月28日星期二 UTC+8下午9:25:12,Andrew Stevens写道:

Terry Heo (Woncheol)

unread,
Apr 29, 2020, 1:09:10 AM4/29/20
to MuJohnny chan, TensorFlow Lite
Hi, MuJohnny.

It's a bit confusing if you want to debug TF or TFLite.

//tensorflow/tools/pip_package:build_pip_package is Python Pip target of Tensorflow.
I'm wondering why you built this package for your Android app debugging.

For TFLite, you need to build following targets.
//tensorflow/lite/java:tensorflow-lite is AAR target of Tensorflow Lite.
If you're using Flex ops, you need to also build //tensorflow/lite/java:tensorflow-lite-select-tf-ops

Terry

--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tflite+un...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tflite/e4efae09-3315-4965-8d51-d51efd1ad756%40tensorflow.org.

MuJohnny chan

unread,
Apr 29, 2020, 9:46:16 PM4/29/20
to TensorFlow Lite, chenm...@gmail.com
Hi,

yeah. I am trying to build a TF whl with debug information so that I could debug the c++ code by stepping line and line with gdb or lldb. My main purpose is getting through the internal mechanism of TF/TFLite. I think TF Lite CPU implementation could also be debugged by this method using PC platform, right?

thanks

在 2020年4月29日星期三 UTC+8下午1:09:10,Terry (Woncheol) Heo写道:
To unsubscribe from this group and stop receiving emails from it, send an email to tfl...@tensorflow.org.

Iosif Hamlatzis

unread,
Apr 30, 2020, 9:12:18 AM4/30/20
to TensorFlow Lite
Hi!

I've done all the above and I have the debug version. In order to verify it I created with bazel two builds (release & debug) and for the Android platform I opened the .aar files and see the difference in the size of the shared libraries.

I imported the .aar library in my Android project but I haven't found a way to inform Android Studio where the source code and the object files that bazel created, so when I go step by step from Java into c++ code I don't see anything.

I even intentionally  crashed my code in order to check the call stack, again nothing

Any idea?
 

Jared Duke

unread,
Apr 30, 2020, 1:16:00 PM4/30/20
to Iosif Hamlatzis, TensorFlow Lite
I even intentionally  crashed my code in order to check the call stack, again nothing

Would you mind attaching the associated logcat that includes the cras? Or pm me directly with that data? Thanks.

--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tflite+un...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tflite/9e4019ba-8d87-4e47-880c-4e1b9be809c7%40tensorflow.org.

Wei Wei

unread,
May 2, 2020, 7:46:09 AM5/2/20
to Jared Duke, Iosif Hamlatzis, TensorFlow Lite
@losif, if you are looking to debug TFLite, can you take a step back and make sure your Android Studio allows you to debug native code at all? For example, you can try a NDK sample (like this one) to be sure you AS is set up correctly. Recent AS versions seem to have some issue w/ native debugging.



--
thanks,
Wei Wei

Iosif Hamlatzis

unread,
May 2, 2020, 3:38:17 PM5/2/20
to Wei Wei, Jared Duke, TensorFlow Lite
Ok, I'll check it out.
--
Sent from Gmail Mobile

Iosif Hamlatzis

unread,
May 6, 2020, 5:52:53 AM5/6/20
to TensorFlow Lite, jdd...@google.com, i.ham...@gmail.com
Just tested the sample you sent and I can place breakpoints both in Java and C++. The code stops in Java and can step into C++ and investigate the variables. So I am sure Android Studio is correctly setup


On Saturday, 2 May 2020 14:46:09 UTC+3, Wei Wei wrote:
@losif, if you are looking to debug TFLite, can you take a step back and make sure your Android Studio allows you to debug native code at all? For example, you can try a NDK sample (like this one) to be sure you AS is set up correctly. Recent AS versions seem to have some issue w/ native debugging.

On Fri, May 1, 2020 at 1:16 AM 'Jared Duke' via TensorFlow Lite <tfl...@tensorflow.org> wrote:
I even intentionally  crashed my code in order to check the call stack, again nothing

Would you mind attaching the associated logcat that includes the cras? Or pm me directly with that data? Thanks.

On Thu, Apr 30, 2020 at 6:12 AM Iosif Hamlatzis <i.ham...@gmail.com> wrote:
Hi!

I've done all the above and I have the debug version. In order to verify it I created with bazel two builds (release & debug) and for the Android platform I opened the .aar files and see the difference in the size of the shared libraries.

I imported the .aar library in my Android project but I haven't found a way to inform Android Studio where the source code and the object files that bazel created, so when I go step by step from Java into c++ code I don't see anything.

I even intentionally  crashed my code in order to check the call stack, again nothing

Any idea?
 

--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfl...@tensorflow.org.

--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfl...@tensorflow.org.


--
thanks,
Wei Wei
Reply all
Reply to author
Forward
0 new messages