[PATCH] Implement backend dispatch table

Stan Cox scox at redhat.com
Wed May 10 15:57:44 UTC 2017


I modified the gdbserver backend to use this dispatch patch mechanism    
A backend struct dispatch table is defined through which all backend 
specific functions are called.  The default dispatch table is setup in init:
     backend.cleanup = NULL;
     backend.detach = NULL;
     backend.end_init = NULL;
     backend.get_regs = NULL;
     backend.get_scno = NULL;
     backend.getfdpath = getfdpath;
     backend.handle_arg = handle_arg;
     backend.prog_pid_check = prog_pid_check;
     backend.start_init = NULL;
     backend.startup_attach = NULL;
     backend.startup_child = startup_child;
     backend.trace = trace;
     backend.test_ptrace_seize = test_ptrace_seize;
     backend.umoven = umoven;
     backend.umovestr = umovestr;
     backend.upeek_ = upeek;
     backend.upoke_ = upoke;

With this patch the only reference to the gdbserver backend in the 
frontend sources is:
          case 'G':
             gdb_handle_arg (c, optarg);
             break;
which does the setup for the gdbserver backend.
     backend.cleanup = gdb_cleanup;
     backend.detach = gdb_detach;
     backend.end_init = gdb_end_init;
     backend.get_regs = gdb_get_regs;
     backend.get_scno = gdb_get_scno;
     backend.getfdpath = gdb_getfdpath;
     backend.prog_pid_check = gdb_prog_pid_check;
     backend.start_init = gdb_start_init;
     backend.startup_attach = gdb_startup_attach;
     backend.startup_child = gdb_startup_child;
     backend.trace = gdb_trace;
     backend.umoven = gdb_umoven;
     backend.umovestr = gdb_umovestr;
     backend.upeek_ = gdb_upeek;
     backend.verify_args = gdb_verify_args;

The gdbserver in gdb-7.11 has support for syscall handling; so an strace 
built from the gdbserver0 branch in github.com:stanfordcox/strace.git
can interface to it via, e.g.  using the testcase tests/gdbrsp:
  gdbserver --once --multi :65432 & ./strace -G localhost:65432 
$(readlink -f tests/gdbrsp)
Remote debugging from host 127.0.0.1
Process /work/scox/strace/mysrc/tests/gdbrsp created; pid = 27663
brk(NULL)                               = 0x602000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) 
= 0x7ffff7ff7000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or 
directory)
open("/home/scox/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 
ENOENT (No such file or directory)
stat("/home/scox/lib/tls/x86_64", 0x7fffffffd9b0) = -1 ENOENT (No such 
file or directory)
open("/home/scox/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No 
such file or directory)
stat("/home/scox/lib/tls", 0x7fffffffd9b0) = -1 ENOENT (No such file or 
directory)
open("/home/scox/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT 
(No such file or directory)
stat("/home/scox/lib/x86_64", 0x7fffffffd9b0) = -1 ENOENT (No such file 
or directory)
open("/home/scox/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No 
such file or directory)
stat("/home/scox/lib", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
open("/usr/local/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 
ENOENT (No such file or directory)
stat("/usr/local/lib/tls/x86_64", 0x7fffffffd9b0) = -1 ENOENT (No such 
file or directory)
open("/usr/local/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No 
such file or directory)
stat("/usr/local/lib/tls", 0x7fffffffd9b0) = -1 ENOENT (No such file or 
directory)
open("/usr/local/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT 
(No such file or directory)
stat("/usr/local/lib/x86_64", 0x7fffffffd9b0) = -1 ENOENT (No such file 
or directory)
open("/usr/local/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No 
such file or directory)
stat("/usr/local/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=138937, ...}) = 0
mmap(NULL, 138937, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffff7fd5000
close(3)                                = 0
open(0x7ffff7ff7708, O_RDONLY|O_CLOEXEC) = 3
read(3, 
"\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\10\2\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2089496, ...}) = 0
mmap(NULL, 3938656, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 
0) = 0x7ffff7a17000
mprotect(0x7ffff7bd0000, 2093056, PROT_NONE) = 0
mmap(0x7ffff7dcf000, 24576, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b8000) = 0x7ffff7dcf000
mmap(0x7ffff7dd5000, 14688, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffff7dd5000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) 
= 0x7ffff7fd4000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) 
= 0x7ffff7fd3000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) 
= 0x7ffff7fd2000
arch_prctl(ARCH_SET_FS, 0x7ffff7fd3700) = 0
mprotect(0x7ffff7dcf000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ)     = 0
mprotect(0x7ffff7ffc000, 4096, PROT_READ) = 0
munmap(0x7ffff7fd5000, 138937)          = 0
close(-1)                               = -1 EBADF (Bad file descriptor)
chroot(0x400890)                        = -1 EPERM (Operation not permitted)
pipe([3, 4])                            = 0
write(4, "a\0", 2)                      = 2
read(3, "a\0", 2)                       = 2
vfork(
Child exited with status 0
  <unfinished ...>
[pid 27664] +++ exited with 0 +++
<... vfork resumed> )                   = 27664
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27664, 
si_uid=2558, si_status=0, si_utime=0, si_stime=0} ---
syscall_123456789(0, 0x80000000, 0x7ffff7adfd74, 0x7ffff7dd35d8, 
0x7ffff7de91c0, 0x61) = -1 (errno 38)
exit_group(0Detaching from process 27663
./strace: Process 27663 detached





More information about the Strace-devel mailing list