From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jimmy Guo To: Elena Zannoni Cc: gdb-patches@sourceware.cygnus.com Subject: Re: [PATCH 1 of 2] readline rl_prompt corruption fix Date: Tue, 01 Aug 2000 10:33:00 -0000 Message-id: References: <14727.1571.65160.775918@kwikemart.cygnus.com> X-SW-Source: 2000-08/msg00017.html >In general patches to readline should be sent to the official >readline maintainer, Chet Ramey. ftp://ftp.cwru.edu/pub/bash/ We don't >want to diverge from the official readline release unless absolutely >necessary. Thanks for the info. I will work with Chet Ramey once we agree if this is something that we need to patch readline up. >In any event, I am sligltly confused about the 2 patches. >What was the original problem? The positioning of the cursor in the TUI? >Can you explain a little more? GDB (event-top.c, couple of places) calls rl_callback_install to set the prompt and the callback function. In one place the prompt string is allocated via malloc, in another it's allocated via alloca. Today, readline use the passed in prompt parameter directly and assign the pointer value to rl_prompt, a global -- no matter what this implementation is questionable, since it should save a copy itself. In the TUI mode, TUI code does strlen (rl_prompt) when handling arrow key input events. Unfortunately rl_prompt can be corrupted if it was originally from one of the event-top.c callback install which uses alloca(), and the behavior would be when a user presses arrow keys in TUI mode to browse source listings, cursor placement will become random. There are several ways to fix it, some with side effects like memory leaks (which exist in today's gdb BTW wrt the malloc'd prompt), others with changes to probably the tui code to use the prompt length calculated by readline, etc. However, I think the way readline handles passed in prompt is inviting trouble, and fixing that is probably the most appropriate approach. - Jimmy