Subject: PT_IO + gdb
To: None <tech-kern@netbsd.org>
From: Love <lha@stacken.kth.se>
List: tech-kern
Date: 07/22/2002 12:55:30
So when I added support for dumping core to gdb/ptrace I noticed that it
took quite long time dump a core for my test program. The core becomes
2892144 bytes and it takes gdb around 7.5 seconds to dump the core.

This is because gdb uses PT_{WRITE,READ}_[ID] to read/write from the target
and it can only access of size PTRACE_XFER_TYPE (that is int on netbsd).

Now there is a new interface PT_IO and it speeds up this quite a lot, to
around 0.6 seconds.

I've appended a new child_xfer_memory() for current gdb that uses PT_IO to
this mail.

There is a just a problem with this that I need to understand first.

It seems that uvm_io() sometimes returns EINVAL for some mappings (quite
consistently) when reading some pages with it. Retrying again at the last
failed offset works though. Why is that ?

I've added a log that show the memory region to dump and what regions
failed (the readonly have size 0 since you don't need to dump their
contents)

Love

int
child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
		   struct mem_attrib *attrib, struct target_ops *target)
{
    struct ptrace_io_desc d;
    int error, xfered_len = 0;

    if (write)
      d.piod_op = PIOD_WRITE_D;
    else
      d.piod_op = PIOD_READ_D;
    d.piod_offs = (void *)memaddr;
    d.piod_addr = myaddr;
    d.piod_len = len;

    error = ptrace (PT_IO, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE)&d, 0);
    if (error && (errno != EINVAL || d.piod_len == 0))
      {
	warning("ptrace PT_IO failed with %d mem %d len %d didlen %d\n", 
		errno, (int)memaddr, len, d.piod_len);
	return 0;
      }

    if (info_verbose && len != d.piod_len)
      warning("failed to read/write the whole region %x len 0x%x, "
	      "just got 0x%x bytes",
	      (int)memaddr, len, d.piod_len);
      
    
    if (write)
      {
#ifdef CLEAR_INSN_CACHE
	CLEAR_INSN_CACHE ();
#endif
      }

    return d.piod_len;
}




Opening corefile 'core.7599' for output.
Reading memory regions
Save segment, 389120 bytes at 0x8048000 (r-x)
Save segment, 0 bytes at 0x8048000
Save segment, 4096 bytes at 0x80a7000 (rw-)
Save segment, 4096 bytes at 0x80a7000
Save segment, 16384 bytes at 0x80a8000 (rw-)
Save segment, 16384 bytes at 0x80a8000
Save segment, 180224 bytes at 0x80ac000 (rwx)
Save segment, 180224 bytes at 0x80ac000
Save segment, 36864 bytes at 0x480a7000 (r-x)
Save segment, 0 bytes at 0x480a7000
Save segment, 4096 bytes at 0x480b0000 (rw-)
Save segment, 4096 bytes at 0x480b0000
Save segment, 36864 bytes at 0x480b1000 (rw-)
Save segment, 36864 bytes at 0x480b1000
Save segment, 86016 bytes at 0x480ba000 (r-x)
Save segment, 0 bytes at 0x480ba000
Save segment, 8192 bytes at 0x480cf000 (rw-)
Save segment, 8192 bytes at 0x480cf000
Save segment, 8192 bytes at 0x480d1000 (r-x)
Save segment, 0 bytes at 0x480d1000
Save segment, 4096 bytes at 0x480d3000 (rw-)
Save segment, 4096 bytes at 0x480d3000
Save segment, 4096 bytes at 0x480d4000 (rw-)
Save segment, 4096 bytes at 0x480d4000
Save segment, 12288 bytes at 0x480d5000 (r-x)
Save segment, 0 bytes at 0x480d5000
Save segment, 4096 bytes at 0x480d8000 (rw-)
Save segment, 4096 bytes at 0x480d8000
Save segment, 204800 bytes at 0x480d9000 (r-x)
Save segment, 0 bytes at 0x480d9000
Save segment, 12288 bytes at 0x4810b000 (rw-)
Save segment, 12288 bytes at 0x4810b000
Save segment, 122880 bytes at 0x4810e000 (r-x)
Save segment, 0 bytes at 0x4810e000
Save segment, 8192 bytes at 0x4812c000 (rw-)
Save segment, 8192 bytes at 0x4812c000
Save segment, 708608 bytes at 0x4812e000 (r-x)
Save segment, 0 bytes at 0x4812e000
Save segment, 45056 bytes at 0x481db000 (rw-)
Save segment, 45056 bytes at 0x481db000
Save segment, 12288 bytes at 0x481e6000 (rw-)
Save segment, 12288 bytes at 0x481e6000
Save segment, 77824 bytes at 0x481e9000 (r-x)
Save segment, 0 bytes at 0x481e9000
Save segment, 8192 bytes at 0x481fc000 (rw-)
Save segment, 8192 bytes at 0x481fc000
Save segment, 12288 bytes at 0x481fe000 (rw-)
Save segment, 12288 bytes at 0x481fe000
Save segment, 40960 bytes at 0x48201000 (r-x)
Save segment, 0 bytes at 0x48201000
Save segment, 8192 bytes at 0x4820b000 (rw-)
Save segment, 8192 bytes at 0x4820b000
Save segment, 20480 bytes at 0x4820d000 (r-x)
Save segment, 0 bytes at 0x4820d000
Save segment, 8192 bytes at 0x48212000 (rw-)
Save segment, 8192 bytes at 0x48212000
Save segment, 12288 bytes at 0x48214000 (rw-)
Save segment, 12288 bytes at 0x48214000
Save segment, 4096 bytes at 0x48217000 (r-x)
Save segment, 0 bytes at 0x48217000
Save segment, 8192 bytes at 0x48218000 (rw-)
Save segment, 8192 bytes at 0x48218000
Save segment, 20480 bytes at 0x4821a000 (r-x)
Save segment, 0 bytes at 0x4821a000
Save segment, 8192 bytes at 0x4821f000 (rw-)
Save segment, 8192 bytes at 0x4821f000
Save segment, 577536 bytes at 0x48221000 (r-x)
Save segment, 0 bytes at 0x48221000
Save segment, 20480 bytes at 0x482ae000 (rw-)
Save segment, 20480 bytes at 0x482ae000
Save segment, 57344 bytes at 0x482b3000 (rw-)
Save segment, 57344 bytes at 0x482b3000
Save segment, 4096 bytes at 0x482c1000 (---)
Save segment, 0 bytes at 0x482c1000
Save segment, 102400 bytes at 0x482c2000 (rw-)
Save segment, 102400 bytes at 0x482c2000
Save segment, 4096 bytes at 0x482db000 (---)
Save segment, 0 bytes at 0x482db000
Save segment, 4096 bytes at 0x482dc000 (---)
Save segment, 0 bytes at 0x482dc000
Save segment, 102400 bytes at 0x482dd000 (rw-)
Save segment, 102400 bytes at 0x482dd000
Save segment, 4096 bytes at 0x482f6000 (---)
Save segment, 0 bytes at 0x482f6000
Save segment, 4096 bytes at 0x482f7000 (---)
Save segment, 0 bytes at 0x482f7000
Save segment, 102400 bytes at 0x482f8000 (rw-)
Save segment, 102400 bytes at 0x482f8000
Save segment, 4096 bytes at 0x48311000 (---)
Save segment, 0 bytes at 0x48311000
Save segment, 31457280 bytes at 0xbdbfe000 (---)
Save segment, 0 bytes at 0xbdbfe000
Save segment, 2039808 bytes at 0xbf9fe000 (rwx)
Save segment, 2039808 bytes at 0xbf9fe000
Save segment, 57344 bytes at 0xbfbf0000 (rwx)
Save segment, 57344 bytes at 0xbfbf0000
warning: failed to read/write the whole region 80ac000 len 0x2c000, just got 0x20000 bytes
warning: failed to read/write the whole region 482f8000 len 0x19000, just got 0x10000 bytes
Saved corefile core.7599