RE: [PATCH v2 2/2] mi-out: Implement mi redirection using a stack.

Adrian Sendroiu
2014-07-30T08:38:04Z

> -----Original Message-----
> From: Pedro Alves [mailto:palves@redhat.com]
> Sent: Tuesday, July 29, 2014 5:55 PM
> To: Sendroiu Adrian-B46904; gdb-patches@sourceware.org;
> tromey@redhat.com
> Subject: Re: [PATCH v2 2/2] mi-out: Implement mi redirection using a
> stack.
>
> I'm guessing we can trigger this by using "save breakpoints" while
> logging is enabled, like gdb.base/ui-redirect.exp ?
> I think it'd be very good if a test to the testsuite was added.
> Sounds like gdb.mi/mi-logging.exp would be a good place?
>
> --
> Thanks,
> Pedro Alves

This won't trigger the bug, because the logging code doesn't call ui_out_redirect if the interpreter is MI. The way I caught it was through some python script that executes commands and catches their output into a string. For example, if you have

gdb.execute("break main", False, True)

The call sequence will be something like:
execute_command_to_string
ui_out_redirect
execute_command
...
mi_breakpoint_created
ui_out_redirect

Then, after executing this, the mi_uiout->data->buffer will incorrectly point to a freed ui_file structure, and any subsequent command will overwrite the pointers inside this ui_file with random data, causing a crash.

Do you have any suggestions on how to make a test case from this scenario?

Adrian