[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Additional ltrace detail



The following is some output from a gdb session with ltrace on the hurd,
using the current hurd and libc packages from ftp.debian.org.

The program receives an EXC_BAD_ACCESS signal when it attempts to do a 
'a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr, 0);'

Although I have linked against the debug libraries in libc0.2-dbg, I can't
seem to get
useful information about what's happening inside libc.  Do I need to have
the sources
on the system as well?

# ldd ltrace
        libc.so.0.2 => /lib/libc_debug/libc.so.0.2 (0x0101f000)
        /lib/ld.so => /lib/ld.so (0x00001000)
        libmachuser.so.1 => /lib/libc_debug/libmachuser.so.1 (0x0115f000)
        libhurduser.so.0.0 => /lib/libc_debug/libhurduser.so.0.0
(0x01170000)
# 

I don't see EXC_BAD_ACCESS documented in the glibc stuff anyplace -- is it a
gnumach or hurd-specific entity?  From a review of the hurd glibc sources it
seems to map to SIGSEGV or SIGBUS.  Because of the location of the error,
I'm thinking it is most likely a SIGBUS error induced by dereferencing a bad
pointer.  However, a review of the gdb output doesn't reveal much to me --
the sbp->addr is a pointer to valid memory, although it is a void* -- which
is what the ptrace function documentation requests.

I am probably missing some basic problem here.  Any comments would be
appreciated.

-Brent

============================================================================
======
GDB Session:
============================================================================
======
# gdb ltrace
GNU gdb 4.17.m68k.objc.threads.hwwp.fpu.gnat
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-gnu"...
(gdb) run ls
Starting program: /home/brent/packages/ltrace/ltrace-0.3.7/ltrace ls
[Switching to thread 548.3]
[Switching to thread 548.5]

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x104289d in ?? () from /lib/libc_debug/libc.so.0.2
(gdb) break main
Breakpoint 1 at 0x8049761: file ltrace.c, line 32.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/brent/packages/ltrace/ltrace-0.3.7/ltrace ls
[Switching to thread 550.3]
[Switching to thread 550.5]

Breakpoint 1, main (argc=2, argv=0x1019c28) at ltrace.c:32
32              my_pid = getpid();
(gdb) n
33              atexit(normal_exit);
(gdb) p my_pid
$1 = 550
(gdb) n
34              signal(SIGINT,signal_exit);     /* Detach processes when
interrupted */
(gdb) n
35              signal(SIGTERM,signal_exit);    /*  ... or killed */
(gdb) n
37              argv = process_options(argc, argv);
(gdb) n
38              read_config_file("/etc/ltrace.conf");
(gdb) n
39              if (getenv("HOME")) {
(gdb) n
41                      sprintf(path, getenv("HOME"));  /* FIXME: buffer
overrun */
(gdb) n
42                      strcat(path, "/.ltrace.conf");
(gdb) n
43                      read_config_file(path);
(gdb) n
44              }
(gdb) n
45              if (opt_d && opt_e) {
(gdb) n
52              if (command) {
(gdb) p opt_d
$2 = 0
(gdb) n
53                      execute_program(open_program(command), argv);
(gdb) n
54              }
(gdb) p command
$3 = 0x8053820 "/bin/ls"
(gdb) n
55              opt_p_tmp = opt_p;
(gdb) n
56              while (opt_p_tmp) {
(gdb) n
61                      process_event(wait_for_something());
(gdb) step
wait_for_something () at wait_for_something.c:28
28              if (!list_of_processes) {
(gdb) n
34              pid = wait(&status);
(gdb) n
35              if (pid==-1) {
(gdb) p status
$4 = 1407
(gdb) p pid
$5 = 551
(gdb) n
51              event.proc = pid2proc(pid);
(gdb) n
52              if (!event.proc) {
(gdb) p event.proc
$6 = (struct process *) 0x805c138
(gdb) p *event.proc
$7 = {filename = 0x8053820 "/bin/ls", pid = 551, breakpoints_enabled = -1, 
  current_syscall = -1, current_symbol = 0x0, return_value = {addr = 0x0, 
    orig_value = "", enabled = 0}, list_of_symbols = 0x805c688, 
  instruction_pointer = 0x0, stack_pointer = 0x0, return_addr = 0x0, 
  breakpoint_being_enabled = 0x0, type_being_displayed = LT_TOF_NONE, 
  next = 0x0}
(gdb) n
56              event.proc->instruction_pointer = NULL;
(gdb) n
57              if (opt_d>2) {
(gdb) n
60              if (event.proc->breakpoints_enabled == -1) {
(gdb) n
61                      enable_all_breakpoints(event.proc);
(gdb) step
enable_all_breakpoints (proc=0x805c138) at breakpoints.c:11
11              if (proc->breakpoints_enabled <= 0) {
(gdb) p *proc
$8 = {filename = 0x8053820 "/bin/ls", pid = 551, breakpoints_enabled = -1, 
  current_syscall = -1, current_symbol = 0x0, return_value = {addr = 0x0, 
    orig_value = "", enabled = 0}, list_of_symbols = 0x805c688, 
  instruction_pointer = 0x0, stack_pointer = 0x0, return_addr = 0x0, 
  breakpoint_being_enabled = 0x0, type_being_displayed = LT_TOF_NONE, 
  next = 0x0}
(gdb) n
12                      struct library_symbol * tmp = proc->list_of_symbols;
(gdb) n
14                      if (opt_d>0) {
(gdb) p *tmp
$9 = {name = 0x119dc94 "free", brk = {addr = 0x8049304, orig_value = "", 
    enabled = 0}, next = 0x805c670}
(gdb) p *tmp.brk.addr
Attempt to dereference a generic pointer.
(gdb) n
18                              insert_breakpoint(proc->pid, &tmp->brk);
(gdb) p *proc
$10 = {filename = 0x8053820 "/bin/ls", pid = 551, breakpoints_enabled = -1, 
  current_syscall = -1, current_symbol = 0x0, return_value = {addr = 0x0, 
    orig_value = "", enabled = 0}, list_of_symbols = 0x805c688, 
  instruction_pointer = 0x0, stack_pointer = 0x0, return_addr = 0x0, 
  breakpoint_being_enabled = 0x0, type_being_displayed = LT_TOF_NONE, 
  next = 0x0}
(gdb) l
13      
14                      if (opt_d>0) {
15                              output_line(0, "Enabling breakpoints for pid
%u...", proc->pid);
16                      }
17                      while(tmp) {
18                              insert_breakpoint(proc->pid, &tmp->brk);
19                              tmp = tmp->next;
20                      }
21                      if (proc->current_symbol) {
22                              insert_breakpoint(proc->pid,
&proc->return_value);
(gdb) p tmp->brk
$11 = {addr = 0x8049304, orig_value = "", enabled = 0}
(gdb) x 0x8049304
0x8049304 <_start+20>:  0x68565108
(gdb) p &tmp->brk
$12 = (struct breakpoint *) 0x805c68c
(gdb) x 0x805c68c
0x805c68c:      0x08049304
(gdb) step
insert_breakpoint (pid=551, sbp=0x805c68c) at breakpoint.c:12
12              a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr, 0);
(gdb) p pid
$13 = 551
(gdb) p sbp
$14 = (struct breakpoint *) 0x805c68c
(gdb) p *sbp
$15 = {addr = 0x8049304, orig_value = "", enabled = 0}
(gdb) p *sbp->addr
Attempt to dereference a generic pointer.
(gdb) x sbp->addr
0x8049304 <_start+20>:  0x68565108
(gdb) p a
$16 = 134596236
(gdb) step

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x104289d in ?? () from /lib/libc_debug/libc.so.0.2


Reply to: