This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH 1 of 2] readline rl_prompt corruption fix


>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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]