How to fix Glib warnings or errors with GDB by Olivier on 18/02/2017 18:37

After adding support for Bluez5 in the latest version of gattlib, the Glib warning message GLib-WARNING **: Invalid file descriptor was printed every time we were closing a gattlib connection.
Even if the error warning was looking harmless, a warning message should never occurs after a normal operation.

Here are the following steps to fix a Glib warning or error:

  1. Ensure debug support is present in the gattlib based applications:

    cd <gattlib_root>
    mkdir build && cd build
    cmake -DCMAKE_BUILD_TYPE=Debug ..
  2. Tell Glib library to treat warnings as error:

    export G_DEBUG=fatal_warnings
  3. Debug one of the gattlib examples using gdb:

    gdb ./examples/read_write/read_write
  4. Start the program and pass its arguments:

    (gdb) run  DA:94:40:95:E0:87 read 0x2a38
    Starting program: /home/olivier/gattlib/build/examples/read_write/read_write DA:94:40:95:E0:87 read 0x2a38
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/i386-linux-gnu/".
    [New Thread 0xb7bdab40 (LWP 3594)]
    Read UUID completed: 03 
    (process:3590): GLib-WARNING **: Invalid file descriptor.
    Thread 1 "read_w" received signal SIGTRAP, Trace/breakpoint trap.
    0xb7cbc749 in g_logv () from /lib/i386-linux-gnu/
  5. Inspect the callstack:

    (gdb) where
    #0  0xb7cbc749 in g_logv () from /lib/i386-linux-gnu/
    #1  0xb7cbc805 in g_log () from /lib/i386-linux-gnu/
    #2  0xb7ca7c28 in g_io_channel_error_from_errno () from /lib/i386-linux-gnu/
    #3  0xb7cfcbee in ?? () from /lib/i386-linux-gnu/
    #4  0xb7ca84ea in g_io_channel_shutdown () from /lib/i386-linux-gnu/
    #5  0xb7ca86cd in g_io_channel_unref () from /lib/i386-linux-gnu/
    #6  0xb7fb988c in io_destroy (io=0xb7200fe8) at /home/olivier/gattlib/bluez5/src/shared/io-glib.c:132
    #7  0xb7fa90cb in bt_att_free (att=0xb7202a00) at /home/olivier/gattlib/bluez5/src/shared/att.c:955
    #8  0xb7fa94be in bt_att_unref (att=0xb7202a00) at /home/olivier/gattlib/bluez5/src/shared/att.c:1065
    #9  0xb7f7f224 in g_attrib_unref (attrib=0xb7200fc0) at /home/olivier/gattlib/bluez5/attrib/gattrib.c:195
    #10 0xb7f7932c in gattlib_disconnect (connection=0x804cef8) at /home/olivier/gattlib/src/gattlib_connect.c:359
    #11 0x08048c72 in main (argc=4, argv=0xbfffee74) at /home/olivier/gattlib/examples/read_write/read_write.c:93
  6. Fix the issue!

Anonymous on 15/07/2018 05:02
<a href=>cheap viagra uk</a>
non prescription viagra usa
cheap viagra uk
Anonymous on 25/02/2023 10:42
Hi! Thanks your article. I have a question: how to fix this issue by inspecting the callstack shown above?
Anonymous on 29/04/2023 00:26
Use TS processes to optimize improvements <a href=>cialis 5mg online</a>
Anonymous on 30/05/2023 00:00
<a href=>propecia alternative</a> Elroy LhulDQcqacBwqwJ 6 17 2022
Anonymous on 16/09/2023 09:26 <a href="">152643</a> <a href="">254881</a> <a href="">290954</a> <a href="">Good Work!</a> <a href="">271892</a> <a href="">302133</a> <a href="">1071</a>
Anonymous on 02/01/2024 08:08
13 Publication year 223 687 1572 1 <a href=>cialis daily</a>
Anonymous on 14/04/2024 22:14
Hello! I could have sworn I've visited this website before but after looking at a
few of the articles I realized it's new to me.
Regardless, I'm certainly delighted I came across it and I'll
be bookmarking it and checking back frequently!
?????? ?????? ? ??????
Anonymous on 20/04/2024 08:43
Pretty part of content. I simply stumbled upon your web site and in accession capital to assert that I acquire in fact loved account your blog posts.
Any way I will be subscribing for your augment and even I fulfillment you get entry to persistently rapidly.
????? ??? ??? ?????? ???

Login to comment Comment as anonymous