I'm using M-x gdb to debug a program that produces some output. The output appears in the buffer *input/output of a.out*.

I often run the same program multiple times during a session, often after having killed the previous instance prematurely. This often results in a partial output line from the previous instance, immediately followed on the same line by the first line from the next instance. This makes the output hard to read.

I'd like Emacs to figure out when the program is being started and to insert a line break in the output buffer. Sometimes I'd like to clear the output buffer but usually I do want to keep the previous output; in any case, if I know how to run code when the program is being started, I can figure out what to run. I want this to happen automatically. Manually going to the output buffer and inserting a newline before restarting the program is not a solution.

For example, I have the following C program.

#include <stdio.h>
int main(void) {
    printf("Hello ");

In Gdb, I put a breakpoint on the second call to printf, run the program until this breakpoint, then re-run it from the start.

break 5

The output buffer contains this:

Hello Hello world

I want it to contain this instead:

Hello world

How do I make Emacs do something when the program is being started? Doing something when the program is being killed would also work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.