Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB - Display output of target application in a separate window

Tags:

I'm using GDB to debug some of my C applications. What I currently do is load the target application, set a breakpoint on line 30 and run it.

I would like to make GDB display the output of my own application in a new terminal window while I'm still able to control the breakpoint handling via the GDB terminal window, but I couldn't seem to find a proper switch. Is there any way making GDB display my program's output in its own window?

like image 717
beta Avatar asked Jan 22 '12 17:01

beta


People also ask

How do I detach a process in GDB?

When you have finished debugging the attached process, you can use the detach command to release it from GDB control. Detaching the process continues its execution. After the detach command, that process and GDB become completely independent once more, and you are ready to attach another process or start one with run .

What is LWP in GDB?

The operating system's lightweight process (LWP) ID value for the thread. This ID is used in part for the OS to keep track of this thread for scheduling purposes. The GDB ID for the thread. This is the ID to use when specifying a specific thread in GDB commands.

Can you attach GDB to a running process?

With GDB it is always possible to debug a running process by attaching to it. It is possible to debug a DLL this way. The limitation of this approach is that the DLL must run long enough to perform the attach operation.

Where is GDB path in Windows?

You can find it at path\\to\\MinGW\\bin\\gdb.exe `. So now you have a C/C++ compiler and a debugger. You compile your target.


2 Answers

For people wondering how to use the GDB tty command here is a short description...

  • Open a new console window. We will redirect output from the program running under GDB here. This is our output window.
  • Run the tty command in the output window. This will show the name of the tty being used by the underlying console.

    $ tty
    /dev/pts/4

  • Open another console window and start GDB here. Let us call this the GDB window.

  • Now run the tty command in GDB using the tty file name obtained above and then start the debugging process.

    (gdb) tty /dev/pts/4
    (gdb) run

Now you should be able to see the program output separately in the output window.

Note: The GDB set new-console on command does not work on Linux! It is meant to be run on windows only. Use the tty method described above on Linux.

like image 90
Autodidact Avatar answered Sep 24 '22 12:09

Autodidact


You can use set new-console on to accomplish this as shown here.

like image 20
greatwolf Avatar answered Sep 25 '22 12:09

greatwolf