0

I am trying to debug my GTK3 application with the gdb command, but I can't seem to get it to work. When I run the command gdb ./myapp, it loads all the debug symbols successfully. However, when I then call the run command in gdb, the app window doesn't open and this is displayed:

Starting program: /home/user/build/GTKapp/myapp
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe3fff6c0 (LWP 146369)]
[New Thread 0x7fffe37fe6c0 (LWP 146370)]
[New Thread 0x7fffdaffd6c0 (LWP 146371)]
[New Thread 0x7fffca3ff6c0 (LWP 146372)]
[New Thread 0x7fffc9bfe6c0 (LWP 146373)]
[New Thread 0x7fffc93fd6c0 (LWP 146374)]
[Thread 0x7fffc93fd6c0 (LWP 146374) exited]
[New Thread 0x7fffc93fd6c0 (LWP 146375)]
[New Thread 0x7fffbbfff6c0 (LWP 146376)]
[Thread 0x7fffc93fd6c0 (LWP 146375) exited]
[New Thread 0x7fffc93fd6c0 (LWP 146377)]
[New Thread 0x7fffbb7fe6c0 (LWP 146378)]
[Thread 0x7fffc93fd6c0 (LWP 146377) exited]
[Thread 0x7fffbbfff6c0 (LWP 146376) exited]
[Thread 0x7fffbb7fe6c0 (LWP 146378) exited]
[New Thread 0x7fffbb7fe6c0 (LWP 146379)]
[New Thread 0x7fffbbfff6c0 (LWP 146380)]
[New Thread 0x7fffc93fd6c0 (LWP 146381)]
[New Thread 0x7fffbaffd6c0 (LWP 146384)]
[New Thread 0x7fffba7fc6c0 (LWP 146385)]
[New Thread 0x7fffb9ffb6c0 (LWP 146386)]
[New Thread 0x7fffb97fa6c0 (LWP 146387)]
[New Thread 0x7fffb8ff96c0 (LWP 146388)]
[Thread 0x7fffba7fc6c0 (LWP 146385) exited]
[Thread 0x7fffbaffd6c0 (LWP 146384) exited]
[Thread 0x7fffc93fd6c0 (LWP 146381) exited]
[Thread 0x7fffbbfff6c0 (LWP 146380) exited]
[Thread 0x7fffbb7fe6c0 (LWP 146379) exited]

The app window opens fine if I run it without the debugger, and I can run the app beforehand and then attach gdb to it, but it would be nice if I could start the app from inside gdb.

This is the code I use to start the app

int main(int argc, char **argv) 
{
    auto app = Gtk::Application::create(argc, argv, APPID);
    
    Glib::MainContext::get_default()->push_thread_default();

    System system(argc, argv);
    
    return app->run(system.getWindow() );
}
1
  • Could you post a minimal and reproducible example please? Commented Jan 26, 2023 at 23:17

1 Answer 1

0

it would be nice if I could start the app from inside gdb

The usual reason an app behaves differently "inside" vs. "outside" of GDB is a difference in the environment -- GDB invokes a new shell, and if your ~/.bashrc resets the environment, it could be different from "outside" environment and not to application's liking.

You can compare the "inside vs. outside" using:

env > /tmp/env-outside
gdb -q -ex 'shell env > /tmp/env-inside' -ex quit
diff /tmp/env-{outside,inside}

Alternatively, set a breakpoint on _exit and exit and use GDB where command to see where the application exits. The exit stack may provide some clue as to what's going on.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.