Debug the ncurses Program (redirect I/O to other terminals)

Source: Internet
Author: User

Ncurses is a library for managing the screen output of the character interface, so it is written using the ncurses LibraryProgramThe screen is usually cleared, and the output is not in a segment, but in a layout format. This is very awkward in the default format during GDB debugging, which will make the output very messy, therefore, when debugging the ncurses program, we need to make some settings for GDB so that we can locate the error.

One convenient way is to redirect the output of all the programs we want to debug to another terminal. In this way, we will separate the command prompts of GDB from our output, the specific method is as follows:

We open two terminals (one for GDB and the other for displaying the output of the program to be debugged). What are these two terminals? (xterm, rxvt, konsole, or virtualconsoles), but it should not be two tabs of a Multi-page terminal, because I will prompt that the/dev/pts/X file cannot be found at the time of the konsole experiment.

Then, switch to the first terminal and run GDB filename. filename is the name of the file to be debugged (this should not be known...) to open GDB. Switch to the second terminal and check its device name.

$ Tty/dev/pts/2

The above description shows that the device name of the second terminal is/dev/pts/2, then switch back to the first terminal, and then

(GDB) tty/dev/pts/2 (GDB)

In this way, the output of the program to be debugged is redirected to the second terminal. Switch to the second terminal and use the sleep statement to tell the terminal. Do not do anything for the moment:

$ Sleep 100000

In this way, we can ensure that the output of our program will not be disrupted, and the selected time here does not matter, but we must ensure that the second terminal will not "Sleep" during our debugging process ".
Finally, switch back to GDB and follow the normal debugging process. The program output can appear on the second terminal. After debugging, you can use Ctrl + C to wake up the sleeping terminal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.