'How can I put a prefix on every information outputed from GDB?

I would like to put a prefix, like "GDB> ", on every output from gdb to distinguish it from the output of my program.

Is that possible?

An example:

test.c

#include <stdio.h>

int main(int argc, char **argv)
{
    char *p = NULL;

    printf("Test begins...\n");

    p[0] = '\0'; // Forcing a segmentation fault.

    printf("Test finished.\n");

    return 0;
}

Debugging with this command line:

$ gdb -q -ex "set confirm off" -ex run -ex quit --args ./test

The output is:

Reading symbols from ./test...
Starting program: /home/me/tst/test
Test begins...

Program received signal SIGSEGV, Segmentation fault.
0x000000000040113b in main ()

What I have in mind is set the output to something like that:

GDB> Reading symbols from ./test...
GDB> Starting program: /home/me/tst/test
Test begins...
GDB> 
GDB> Program received signal SIGSEGV, Segmentation fault.
GDB> 0x000000000040113b in main ()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source