I wrote a shell in C. There are some problems while running some programs on it.How can I run a program on a shell while debugging the shell in the gdb?
2 Answers
First use -g
option to compile with debugging flags, for use with gdb
.
Then run.
gdb shellapp
...
run someapps
...
For a quick reading How to Debug C Program using gdb in 6 Simple Steps and GDB Tutorial
Or do you mean run a program in the background?

- 1
- 1

- 39,972
- 7
- 52
- 94
You can attach by gdb to already running shell process from another console. This way your shell output will not interfere with gdb output and you can run programs in shell as usual.
- Run your implementation of shell in 1st console window
- Open 2nd console and find pid number of already running shell using
ps
command Start
gdb
in 2nd console and attach to shell using it's pid number like this::~$ gdb -q
(gdb) attach 3479
Attaching to process 3479Now you can set breakpoints and continue shell execution:
(gdb) b SomeFunction
(gdb) c
Continuing.
From this point you have 2 consoles:
- the one where your shell is running
- and the second where
gdb
runs attached to shell
You can use shell as usual: run other programs on it or do whatever else. And at the same time you can observe shell execution in 2nd console inside gdb
. The point is that output of these 2 processes are separated from each other which would be impossible if you run shell directly inside gdb in just one console.

- 33,961
- 14
- 109
- 164
-
-
@Grijesh Chauhan, I mean that it's hard to debug interactive shell from the same console where gdb runs, because gdb itself is interactive. Output from both gdb and shell will mix up and it makes difficulties during debug. – ks1322 Oct 26 '13 at 08:02
-
-
1@ks1322 Oh! get your point now, and you are correct If OP already don't know how to use GDB ..your point is valid. – Grijesh Chauhan Oct 26 '13 at 11:29