home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / bsd / 5130 < prev    next >
Encoding:
Text File  |  1992-09-04  |  3.5 KB  |  103 lines

  1. Newsgroups: comp.unix.bsd
  2. Path: sparky!uunet!mcsun!sun4nl!eur.nl!pk
  3. From: pk@cs.few.eur.nl (Paul Kranenburg)
  4. Subject: Re: GDB under 386bsd 0.1
  5. Message-ID: <1992Sep4.153554.4387@cs.few.eur.nl>
  6. Keywords: gdb, ptrace
  7. Sender: news@cs.few.eur.nl
  8. Reply-To: pk@cs.eur.nl
  9. Organization: Erasmus University Rotterdam
  10. References: <1992Sep4.005417.3876@gumby.dsd.trw.com>
  11. Date: Fri, 4 Sep 1992 15:35:54 GMT
  12. Lines: 89
  13.  
  14. In <1992Sep4.005417.3876@gumby.dsd.trw.com> gottloeb@eel.dsd.trw.com writes:
  15.  
  16. >I have noticed a problem using gdb under 386bsd 0.1.
  17.  
  18. >When at least one breakpoint has been set and the program terminates,
  19. >e.g. executes exit(), the breakpoint is not removed from the process's
  20. >text image.  When the program is subsequently re-executed under gdb,
  21. >gdb remembers that a breakpoint is supposed to at the memory location
  22. >and puts one there again.  However this time it shadows the breakpoint
  23. >instruction from the previous run rather than the original instruction.
  24. >When execution begins after reaching the breakpoint, various traps occur.
  25.  
  26. >If the program is run after quitting gdb, a Trace/BPT trap occurs.
  27.  
  28. >I think the problem is that gdb assumes that when ptrace modifies the
  29. >process's image the kernel either makes a private copy of the text image
  30. >or it will throw away the text image after the process terminates.
  31. >However, this is not the case - the kernel keeps the modified text image
  32. >around and executes it rather than a fresh copy from the original file.
  33.  
  34. The 386 does not generate a page protection fault while it is executing
  35. in supervisor mode :-(, so copy on write handling never takes place when
  36. the kernel stuffs data into a process's text- or any other non-anonymous
  37. segment. So these cases must be explicitly checked for. Here's a patch
  38. for kern/sys_process.c:
  39.  
  40.  
  41. ------- sys_process.c -------
  42. *** /tmp/da05975    Fri Sep  4 16:51:50 1992
  43. --- sys_process.c    Fri Sep  4 16:51:18 1992
  44. ***************
  45. *** 278,286 ****
  46.           break;
  47.   
  48.       case PT_WRITE_I:
  49. !     case PT_WRITE_D:
  50. !         ipc.error = copyout((char *)&ipc.data, (char *)ipc.addr, sizeof(ipc.data));
  51.           break;
  52.   
  53.       case PT_WRITE_U:
  54.           if ((u_int)ipc.addr > UPAGES * NBPG - sizeof(int)) {
  55. --- 278,318 ----
  56.           break;
  57.   
  58.       case PT_WRITE_I:
  59. !     case PT_WRITE_D: {
  60. !         vm_prot_t prot;        /* current protection of region */
  61. !         int cow;        /* ensure copy-on-write happens */
  62. !         if (cow = (useracc(ipc.addr, sizeof(ipc.data), B_WRITE) == 0)) {
  63. !             vm_offset_t    addr = (vm_offset_t)ipc.addr;
  64. !             vm_size_t    size;
  65. !             vm_prot_t    max_prot;
  66. !             vm_inherit_t    inh;
  67. !             boolean_t    shared;
  68. !             vm_object_t    object;
  69. !             vm_offset_t    objoff;
  70. !             if (vm_region(&p->p_vmspace->vm_map, &addr, &size,
  71. !                     &prot, &max_prot, &inh, &shared,
  72. !                     &object, &objoff) != KERN_SUCCESS ||
  73. !                 vm_protect(&p->p_vmspace->vm_map, ipc.addr,
  74. !                     sizeof(ipc.data), FALSE,
  75. !                     prot|VM_PROT_WRITE) != KERN_SUCCESS ||
  76. !                 vm_fault(&p->p_vmspace->vm_map,trunc_page(ipc.addr),
  77. !                     VM_PROT_WRITE, FALSE) != KERN_SUCCESS) {
  78. !                 ipc.error = EFAULT;
  79. !                 break;
  80. !             }
  81. !         }
  82. !         ipc.error = copyout((char *)&ipc.data,
  83. !                     (char *)ipc.addr, sizeof(ipc.data));
  84. !         if (cow)
  85. !             if (vm_protect(&p->p_vmspace->vm_map, ipc.addr,
  86. !                     sizeof(ipc.data), FALSE,
  87. !                     prot) != KERN_SUCCESS)
  88. !                 printf("ptrace: oops\n");
  89.           break;
  90. +     }
  91.   
  92.       case PT_WRITE_U:
  93.           if ((u_int)ipc.addr > UPAGES * NBPG - sizeof(int)) {
  94. ------------ EOP --------------------
  95.  
  96. I am not entirely happy about the call to `vm_fault', but at this moment 
  97. I don't see another way to enforce a copy on write.
  98.  
  99. -pk
  100.