0

I'm working on a program where I have 2 ncurses window, one displaying my custom shell implemented with fork+exec and on the other I want show some info about command ran on my shell. For that, I'm trying to use GDB.

My idea is to run GDB on backgroun, with some breakpoints set and printing some info to a file, which my ncurses application read, format and display.

The problem is I'm not able to run GDB without the prompt, as it will quit automatically if input is not from terminal. I'm using the following script:

./bin/pE_application &
pid=$(ps -C pE_application -o pid=)
gdb --command=examine_memory.gdb --pid="$pid" > "$GDB_TMP" 2>&1 &
pE_jid=$(jobs | grep pE_application | grep -oE "^\[[0-9]\]" | sed 's/\[//g' | sed 's/\]//g')
fg "%""$pE_jid"

Where pE_application is my ncurses application. examine_memory.gdb is a startup script that tries to set a breakpoint to my run_shell function so I can dump info when it starts:

set follow-fork-mode parent

info functions

break run_shell
        command 1
        p 'pE_application.c'::unparsed_cmd
        continue
end

I have tried using batch mode but GDB will quit after init script runs. Without batch mode, GDB will quit because output is not from terminal, output file will look like:

*some info*
...
Quit anyway? (y or n) [answered Y; input not from terminal]

Or it will not run because of tty stop signal. I'm trying to find out if there's any way of running GDB on background without I/O, just keep to startup script with breakpoints and commands.

Thanks

brunos098
  • 1
  • 1
  • What do you mean by _"GDB will quit after init script runs"_? What is the "init script"? What is the output of your `gdb` command when you use the `-batch` flag? Your question isn't clear as at is. Please [edit] your question and clarify it, and if possible add a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – aviro Jun 11 '23 at 12:57

0 Answers0