gdb unable to debug application

Test program:

#include <gtk/gtk.h>
#include <stdio.h>
#include <glib.h>

int main(int argc, char *argv)
{
gtk_init(&argc, &argv);
GtkIconTheme
theme = gtk_icon_theme_get_default();

    if ( theme == NULL )
    {
            puts("no theme set");
            return 0;
    }

    gchar **path;
    gint n;

    gtk_icon_theme_get_search_path(theme, &path, &n);

    printf("%u %u

",
gtk_icon_theme_has_icon(theme, “fonts-package”),
gtk_icon_theme_has_icon(theme, argv[1])
);

    gint *l = gtk_icon_theme_get_icon_sizes(theme, argv[1]);
    gint *p;

    for ( p = l; *p; p++ )
            printf("*l = %d

", *p );

    GtkIconInfo *info = gtk_icon_theme_lookup_icon(theme, argv[1], -1, GTK_ICON_LOOKUP_USE_BUILTIN );
    printf("info = %p

", info);

    if ( info )
    {
            GError *error = NULL;
            GdkPixbuf *buf = gtk_icon_info_load_icon(info, &error);
            printf("buf = %p

", buf);

            if ( buf )
                    g_object_unref(buf);

            if ( error )
                    g_error_free(error);

            gtk_icon_info_free( info );
    }

    GError *error = NULL;
    GdkPixbuf *pbuf = gtk_icon_theme_load_icon(theme, argv[1], -1, GTK_ICON_LOOKUP_USE_BUILTIN, &error );
    printf("pbuf = %p

", pbuf);

    if ( pbuf )
            g_object_unref( pbuf );

    if ( error )
            g_error_free(error);

    gint i;

    for ( i = 0; i &lt; n; i++ )
            printf("path = %s

", path*);

    g_strfreev(path);
    g_free(l);
    return 0;

}

$ cc -W -Wall -Wextra -g 20.c pkg-config --cflags --libs gtk+-2.0

$ gdb -q --args ./a.out application-x-vnc --g-fatal-warnings
(gdb) (gdb) r
Starting program: /home/user/a.out application-x-vnc --g-fatal-warnings
0 1
*l = 22
*l = 24
*l = -1
*l = 48
*l = 16
l = 32
info = 0x806e098
[Thread debugging using libthread_db enabled]
Error while reading shared library symbols:
Cannot find new threads: generic error
Cannot find new threads: generic error
(gdb) c
Continuing.
Cannot execute this command while the selected thread is running.
(gdb)

I’ve been able to shorten the program and found a workaround:

Test program:

#include <gtk/gtk.h>
#include <stdio.h>
#include <glib.h>

int main(int argc, char *argv)
{
gtk_init(&argc, &argv);
GtkIconTheme
theme = gtk_icon_theme_get_default();

    if ( theme == NULL )
    {
            puts("no theme set");
            return 0;
    }

    GtkIconInfo *info = gtk_icon_theme_lookup_icon(theme, argv[1], -1, GTK_ICON_LOOKUP_USE_BUILTIN);
    printf("info = %p

", info);

    if ( info )
    {
            GError *error = NULL;
            GdkPixbuf *buf = gtk_icon_info_load_icon(info, &error);
            gtk_icon_info_free( info );
    }

    return 0;

}

If I compile the program with the following options:

$ cc -W -Wall -Wextra -g 20.c pkg-config --cflags --libs gtk+-2.0

gdb -q --args ./a.out application-x-vnc --g-fatal-warnings
(gdb) r
Starting program: /home/user/progs/a.out application-x-vnc --g-fatal-warnings
info = 0x806e098
[Thread debugging using libthread_db enabled]
Error while reading shared library symbols:
Cannot find new threads: generic error
Cannot find new threads: generic error
(gdb)

But however, if I compile the program with -pthread option, am able to debug the program:
$ cc -W -Wall -Wextra -g 20.c pkg-config --cflags --libs gtk+-2.0 -pthread

Again if I compare the output of
$ readelf -d a.out
in both the cases, I see libpthread.so.0 as an extra dependency in the second case.

My application is not using threads. Why do I need to specify libpthread.so.0 as an extra dependency?

And Isn’t gdb able to handle threads implicitly?

Also, I remove:

GdkPixbuf *buf = gtk_icon_info_load_icon(info, &error);

statement, then also it works fine.

Any ideas? Thanks.

I encounter the same problem with an application I cannot easily recompile:

 
gdb php5 
run '-r' ';'

GNU gdb (GDB) SUSE (7.1-3.12)
This GDB was configured as “i586-suse-linux”.
[Thread debugging using libthread_db enabled]
Cannot find new threads: generic error

Workaround:


set env LD_PRELOAD=/lib/libpthread.so.0 gdb