1
votes

Why is gdb showing that the program exited during its startup, so before to stop at the first breakpoint in the main function ?

Some steps:

$ gdb --cd $programhome -tui -tty $reservedtty --args myprogram

b main
r

gdb shows:

Starting program: myprogram
During startup program exited with code 1.

I already tried to break at exit() function, without success.

2

2 Answers

3
votes

Why is gdb exiting before to stop at the first breakpoint in the main function

  1. GDB is not exiting. Your program does.
  2. It does exit before reaching main.

This can happen for a few reasons, such as:

  1. Corrupt binary -- the kernel rejects it in execve system call for some reason and not a single instruction of the program actually runs.
  2. The dynamic linker rejects it (e.g. because some required library or symbol is missing)
  3. Your shell refuses to execute the program (bad ~/.bashrc, bad $PATH, etc).

You can narrow down the actual cause by running the program outside GDB (does it run?), running without ~/.bashrc, using (gdb) catch syscall exit_group (on Linux), etc.

0
votes

There was a permission issue accessing the secondary terminal port.

The gdb is being started with the parameter -tty which switches the input/output to another tty port (in that case pseudo: pts).

When the two terminals are opened by different users, that problem occurs, even if after the first logon you change the user with su command, the first user logged needed to be the same among the two ttys.