mvp@v7fs1.UUCP (Mike Van Pelt) (04/07/89)
On the Sun 386i, I just discovered the desperate need to trace a program at the machine language level -- the kind of thing that MessDos DEBUG does, just print the instructions and register contents. In fact, what I want to do in Unix is precisely what DEBUG would do if I typed T 9999999999. First I looked at adb. That ought to be low-level enough, I thought. Its command structure is certainly weird and cryptic enough. But after wading through the manual for a couple of hours trying to figure out how to put that bignum after the T, I came to the horrible realization -- IT AIN'T THERE! Sure, you can type ,9999999 :s, but that will only list the instructions, not any of the invaluble register contents. Worse, I lied about the 's' at the end of "instructions" -- It silently executes them, then prints the last, and only the last, instruction executed. (Still no registers.) In desperation, I piped the script while true do echo ':s ; $r' done to adb, but this is getting too gross for me to deal with any more. (Besides, it filled up my file system before getting to the part of the program I need to look at.) The area I need to scan is far, far too big to dink at it one instruction at a time. I need to go grep'ing through the trace file for IO instructions megabytes at a time. There's also dbx, but dbx won't condescend to touch anything that wasn't compiled with the 'g' option, and if I had the source to recompile the thing, I wouldn't be trying to use adb on it. (I sure wish I had the old Univac debugger, FLIT, on Unix...) Am I missing something obvious? It sure seems like I must be. There *HAS* to be some trace-the-damn-program-an-instruction-at-a-time-AND- TELL-ME-WHAT-IT-DID type of debugger on Unix... doesn't there? -- Mike Van Pelt "I'm not a biologist, but I play one in Video Seven front of Congressional hearings." ...ames!vsi1!v7fs1!mvp -- Meryl Streep
chris@mimsy.UUCP (Chris Torek) (04/07/89)
In article <315@v7fs1.UUCP> mvp@v7fs1.UUCP (Mike Van Pelt) writes: >On the Sun 386i, I just discovered the desperate need to trace a >program at the machine language level -- the kind of thing that MessDos >DEBUG does .... Not being familiar with this, all I can do is talk about adb: >[adb's] command structure is certainly weird and cryptic enough. But >after wading through the manual for a couple of hours trying to figure >out how to put that bignum after the T, I came to the horrible >realization -- IT AIN'T THERE! adb can do it. adb can do anything. :-) >Sure, you can type ,9999999 :s, but >that will only list the instructions, not any of the invaluble register >contents. Worse, I lied about the 's' at the end of "instructions" -- >It silently executes them, then prints the last, and only the last, >instruction executed. (Still no registers.) `:s' steps: it runs single instructions until the count runs out, or until adb hits a breakpoint. When it stops, it prints the reason (breakpoint or `stopped' or illegal memory access or whatnot) and the pc, and decodes the instruction at that location. >In desperation, I piped the script > >while true >do >echo ':s ; $r' >done > >to adb, but this is getting too gross for me to deal with any more. >(Besides, it filled up my file system before getting to the part of the >program I need to look at.) That parenthetical remark sounds like the real problem (but maybe not; see below). The script above works, but you can do it directly in adb, although you need an auxiliary file: put the commands :s $r $<foo in the file `foo', and then `adb prog' and `$<foo'. To make it stop after some number of iterations (the line numbers in parentheses are for the next paragraph): (1) :s (2) $r (3) ,#(<9-1)$< (4) ,<9-1$<foo then type ,500$<foo to run 500 steps. Line 3 means `if variable 9 minus 1 is not 0, give a zero count to the command $<, otherwise give it a count of 1'. $< without a file name ends file input; but $< does nothing at all if it has a zero count. This is a way to stop early. Line 4, then, gives the count `variable 9 minus 1' to the command `$<foo'. Of course, this shows line 3 to be unnecessary after all: a zero count does nothing, which (being followed by EOF) ends the file diversion. I included that third line merely for illustration. (Variable 9 is set by the $< command itself.) To make it print only specific registers, replace the `$r' with something more specific: :s <r6="r6"8tX <r7="r7"8tX <r8="r8"8tX <r9="r9"8tX <r10="r10"8tX <r11="r11"8tX ,<9-1$<foo One warning: if the program is not running, `:s' starts it. Thus an infinite count (or an infinite loop like the `while ... | adb' script) results in an infinitely repeating trace. If the program ends by calling exit(), you can add something like ,#(<pc-_exit)$< to stop iterating when the PC has the value of _exit. (Use _exit+2 on a VAX.) Another warning: despite what the manual says, `^' backs up by two bytes, not the current increment (or rather, it sets the increment to two, then backs up). I fixed this in the 4.4BSD adb, but that turns out to break some scripts, so it might be jiggered again before the release. (And---O joy to systems porters---I deBourned it, and split it into machine dependent and machine independent pieces. It still believes in flat address spaces, however.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
friedl@vsi.COM (Stephen J. Friedl) (04/09/89)
In article <16785@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > > adb can do it. adb can do anything. :-) Unless you're running System V, in which case it's not even available. From my BSD days, I miss adb much more than job control... Steve -- Stephen J. Friedl / V-Systems, Inc. / Santa Ana, CA / +1 714 545 6442 3B2-kind-of-guy / friedl@vsi.com / {attmail, uunet, etc}!vsi!friedl "I do everything in software, even DMA" - Gary W. Keefe (garyk@telxon)
dg@lakart.UUCP (David Goodenough) (04/14/89)
From article <16785@mimsy.UUCP>, by chris@mimsy.UUCP (Chris Torek): > To make it stop > after some number of iterations (the line numbers in parentheses are > for the next paragraph): > > (1) :s > (2) $r > (3) ,#(<9-1)$< > (4) ,<9-1$<foo Ye gads. I think we (CP/M and MS-DOS users) should send copies of the DEBUG / SID / Z8E / DDT / ZDT / ZSID manuals at the rate to 5 a day (each) to the writers of adb, in the forlorn hope that they will learn how to write a useful debug tool. That it takes so much work to do the equivalent of: t9 is beyond my belief. Yes, adb may be able to do anything, BUT IF IT CAN'T DO IT EASILY IT'S USELESS. -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+