Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site aoa.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!bbnccv!bbncca!aoa!mbr From: mbr@aoa.UUCP (Mark Rosenthal) Newsgroups: net.lang.c,net.unix-wizards,net.unix Subject: Help using dbx Message-ID: <461@aoa.UUCP> Date: Tue, 22-Apr-86 18:48:47 EST Article-I.D.: aoa.461 Posted: Tue Apr 22 18:48:47 1986 Date-Received: Thu, 24-Apr-86 06:33:31 EST Reply-To: mbr@aoa.UUCP (Mark Rosenthal) Distribution: net Organization: Adaptive Optics Assoc., Cambridge, Mass. USA Lines: 198 Xref: watmath net.lang.c:8703 net.unix-wizards:17773 net.unix:7689 I posted the following article some weeks ago. I fear it may have dropped into the bit-bucket, so I am reposting it. It appears that most vendors have given up on 'sdb' in favor of 'dbx' or some derivative of 'dbx'. I find that although 'dbx' is generally more powerful than 'sdb' it lacks some capabilities that I used to depend on quite heavily. If anyone is familiar with how to do the following with 'dbx', please let me know. You will earn my undying gratitude. Note that I have not used sdb in over a year. The examples I give below are from my own faulty memory and may not be 100% accurate. By the way, I am running 'dbx' on a Sun workstation. 1. I'd like to be able to specify the format in which a variable is to be displayed. If I have a variable (char *cp), I could do the following with 'sdb': me: cp/x or: cp/s or: cp/ sdb: 0x7fff3ec string string With 'dbx', the dialogue is something like: me: print cp dbx: 0x7fff3ec me: 0x7fff3ec/s dbx: string Having to type back into dbx what it just typed at me is a pain. 2. The man page for 'dbx' claims that the command to display a memory location is: [address] / [count] [mode] where everything but the "/" is optional, and that "if no address is specified, the address following the one displayed most recently is used". Unfortunately, there is also a "/" command which searches the source file for a string. Typing "/" reports: "No saved search string" rather than showing me the next location. This makes it quite a chore to examine an array. Arrays of structures are even worse. 3. With 'sdb', I could display lines of code relative to the current line. 'dbx' appears to limit me to specifying absolute line numbers. This means that anytime I hit a breakpoint and want to see some context, I have to read the current line number from the screen, do some quick arithmetic, and type "list from_line,to_line". The concentration required to do that is a distraction from the problem I am trying to solve, namely finding and fixing bugs in a program. A symbolic way of referencing dbx's line counter would solve the problem, but I can find no mention of any such capability in the documentation. I'd like to be able to do something like: alias w list .-5,.+5 and then just type "w" to see context around the current line. 4. A common construct in C is a linked list of structures. struct foo { struct foo *next; int data; char *moredata; /* Etc., etc., etc. */ }; struct foo *foobar; Let's say my code malloc()s instances of foo, and links them in to the list beginning at foobar. I am at a breakpoint, and I want to examine the list. I don't remember the exact sequence I used with sdb, but it went something like: me: foobar/ show the value of foobar sdb?: 0x7ff2ea me: .->/ show what the last displayed value points at (i.e. foobar->next) sdb?: 0x7e3720 me: +/d show the next location in decimal (i.e. foobar->data) sdb?: 3 me: +/s show the next location as a string pointer (i.e. foobar->moredata) sdb?: string data me: - back up one location (to foobar->data) sdb?: 3 me: - back up one location (to foobar->next) sdb?: 0x7e3720 me: .->/ show what the last displayed value points at (i.e. foobar->next->next) sdb?: 0x748238 me: +/d show the next location in decimal (i.e. foobar->next->data) sdb?: 2 me: +/s show the next location as a string pointer (i.e. foobar->next->moredata) sdb?: more chars me: - back up one location (to foobar->next->data) sdb?: 2 me: - back up one location (to foobar->next->next) sdb?: 0x748238 me: .->/ show what the last displayed value points at (i.e. foobar->next->next->next) sdb?: 0 end of list me: +/d show the next location in decimal (i.e. foobar->next->next->data) sdb?: 1 me: +/s show the next location as a string pointer (i.e. foobar->next->next->moredata) sdb?: still more chars To do the same thing with dbx, the best I've been able to come up with so far is: me: print foobar dbx: 0x7ff2ea me: print foobar->data dbx: 3 me: print foobar->moredata dbx: string data me: print foobar->next dbx: 0x7e3720 me: print foobar->next->data dbx: 2 me: print foobar->next->moredata dbx: more chars me: print foobar->next->next dbx: 0x748238 me: print foobar->next->next->data dbx: 1 me: print foobar->next->next->moredata dbx: still more chars me: print foobar->next->next->next dbx: 0 end of list Note that the sequence of commands I type to sdb is relatively simple, and stays the same no matter how far through the list I've gone: me: foobar/ me: .->/ me: +/d me: +/s me: - me: - me: .->/ me: +/d me: +/s me: - me: - me: .->/ me: +/d me: +/s whereas with dbx, I have to retype the entire sequence from the starting point every time: me: print foobar me: print foobar->data me: print foobar->moredata me: print foobar->next me: print foobar->next->data me: print foobar->next->moredata me: print foobar->next->next me: print foobar->next->next->data me: print foobar->next->next->moredata me: print foobar->next->next->next This makes a list of length 4 a pain to deal with, and a list of length 16 prohibitive. Linked lists with hundreds of elements are not uncommon. Do the authors of 'dbx' really intend that I should have to type: print foobar->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->next->next->next->next->next->next->next->next->next->next->next->next-> next->data to get to the 128'th (or did I only type next 127 times?) item in a list? There MUST be a better way. Can somebody PLEASE enlighten me. Sorry. I got a bit carried away there. I'll be alright in a second. -- Mark of the Valley of Roses ...!{decvax,linus,ima,ihnp4}!bbncca!aoa!mbr ...!{wjh12,mit-vax}!biomed!aoa!mbr