This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

inferior function calls SEGV for statically linked programs


Using a freshly checked out gdb+dejagnu tree compiled under
RedHat Linux 7.2 on x86, I'm unable to evaluate inferior
functions when the programs are statically linked.

For example, if program.c is:

int sub(int arg)
{
  printf("in sub(%d)\n", arg);
  return arg;
}

int main(int argc, char *argv[])
{
  printf("sub(1) = %d\n", sub(1));
  return 0;
} 

and it's compiled and statically linked:

cc -g -static -o program program.c

gdb gives:
...
(gdb) call sub(1)

Program received signal SIGSEGV, Segmentation fault.
...
In solib-svr4.c, gdb inserts a "bp_shlib_event" breakpoint via
enable_break() at _start because the dynamic linker symbols
like "_dl_debug_state" aren't found in the executable. The code
at the bottom of enable_break() searches through bkpt_names[]
until it finds a match with _start.

When a inferior (dummy) function call is made, e.g. "call sub(1)",
hand_function_call() inserts a breakpoint of type "bp_call_dummy"
also at _start because gdbarch->call_dummy_address() returns
symfile_objfile->ei.entry_point.

In handle_inferior_event(), stop_pc is _start+1 and the function
bpstat_stop_status() returns 2 entries: one for "bp_shlib_event"
and one for "bp_call_dummy". Then, the table lookup in bpstat_what()
returns BPSTAT_WHAT_CHECK_SHLIBS, with call_dummy = 1 instead of
BPSTAT_WHAT_STOP_SILENT. As a result, evaluation continues and gdb
drops back into handle_inferior_event() where bpstat_what() returns
BPSTAT_WHAT_KEEP_CHECKING and the inferior eventually SEGVs.

There are couple of ways of fixing this including just setting
"stop-on-solib-events" in gdb. But, why is the "bp_shlib_event"
breakpoint added to statically linked programs in the first place?

Thanks,

Joe Landers


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]