Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!cornell!uw-beaver!tektronix!teklds!copper!stevesu From: stevesu@copper.TEK.COM (Steve Summit) Newsgroups: comp.unix.wizards Subject: Re: Debugging the kernel: proper methods? Message-ID: <1168@copper.TEK.COM> Date: Thu, 25-Jun-87 23:58:35 EDT Article-I.D.: copper.1168 Posted: Thu Jun 25 23:58:35 1987 Date-Received: Sat, 27-Jun-87 05:30:44 EDT References: <2713@uw-june.UUCP> <479@winchester.UUCP> Organization: Tektronix Inc., Beaverton, Or. Lines: 64 Nobody has mentioned this yet, so I'll toss it in, although I don't know the full details: someone once built adb into the kernel, so it could "debug itself," so to speak. You typed some magic command, and the console terminal started talking adb. You could set breakpoints and everything. Building adb into a program is actually easier than it sounds. The only real problem is uniqueifying all of its global variables so they don't clash with those in your program. You also need a special version of ptrace that can examine and modify locations in your own process instead of another one. I built a copy of adb into a window manager I was working on -- invoking a special window manager command would cause a new window to open up with adb "running" in it. This was handy because using conventional adb on a full-screen, interactive process like a window manager is tricky (and requires two terminals), and because most of the problems this window manager had were hard to reproduce, but with adb "already there," you could track down a bug when it appeared, rather than having to recapture it in a later run under adb. (Actually, I lied: it's only easy to build adb in if you leave out breakpoints, which I did, because all I really wanted to do was examine data structures. Getting breakpoints to work would require a writable text segment and a _r_e_a_l clever SIGTRAP handler.) Steve Summit stevesu@copper.tek.com P.S. Here, for your amusement, is the "special version of ptrace that can examine and modify locations in your own process." As you can see, it's not rippingly difficult to write. (Of course, it ignores the requests having to do with running the other process. It also doesn't handle the u-area stuff) ptrace(request, pid, addr, data) int request; int pid; int *addr; int data; { switch(request) { case 0: return(0); case 1: case 2: /* sorry, no split I&D */ return(*addr); case 3: return(*addr); /* ??? */ case 4: case 5: /* sorry, no split I&D */ *addr = data; return(0); case 6: *addr = data; /* ??? */ return(0); } }