0

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?

mohit
  • 124
  • 7

2 Answers2

1

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?

Community
  • 1
  • 1
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
1

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.

  1. Run your implementation of shell in 1st console window
  2. Open 2nd console and find pid number of already running shell using ps command
  3. Start gdb in 2nd console and attach to shell using it's pid number like this:

    :~$ gdb -q
    (gdb) attach 3479
    Attaching to process 3479

  4. Now 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.

ks1322
  • 33,961
  • 14
  • 109
  • 164