delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/10/18/07:22:33

From: kunst AT prl DOT philips DOT nl
Subject: Possible 'debug32' improvement ?!?
To: djgpp AT sun DOT soe DOT clarkson DOT edu (DJGPP users list)
Date: Mon, 18 Oct 1993 12:01:39 +0100 (MET)

There have been a lot of questions in the past to this list if a 
source level debugger (such as 'gdb') exists for usage with DJGPP.

For those of you who think they need a better debugger than the one 
supplied with DJGPP (i.e. debug32) the following posting might provide
an interesting option (see below), discussing 'duel':

  Article: 70865 of comp.lang.c
  From: mg AT hart DOT Princeton DOT EDU (Michael Golan)

I only copied this message from the net; I have no experience with 
DUEL myself, but it might be possible to add it to debug32, since 
the text below states:

  'Duel is debugger-independent, but the current distribution inter-
  faces only with gdb. You will need the source for gdb-4.6, or above.'

I don't have the time now to do the integration of 'duel' to 'debug32',
but perhaps someone else finds this a challenging task ;-)


PS: I personally still use the 'mother-of-all-debuggers', called 'printf'.

 .^^^^^^^^           _____________________________________
 |      |          / Pieter Kunst (P.J.)                   \
 |  _  _|        /   Philips Research Laboratories,          \
.--(o)(o)      /     Building WY3, Prof. Holstlaan 4,         \
|@      _)   /       5656 AA  Eindhoven, The Netherlands.      |
  | ,___|   /        e-mail: kunst AT prl DOT philips DOT nl             /
  |   /     \_______________________________________________/
  /____\

=============================================================================
Article: 70865 of comp.lang.c
From: mg AT hart DOT Princeton DOT EDU (Michael Golan)

[stuff deleted]

It is nice to have more than an expression-evaluator
under the debugger, which seems to be the principle difference
between a fast compile-debug cycle and an interpreter with fast pcode.

If you use the DUEL extension to gdb ( can ftp it from 
ftp.cs.princeton.edu:/duel), you get most of the useful
capabilities of a C interpreter under gdb, e.g., to print out
the positive elements of x[100]:

(gdb) duel int i; for(i=0; i<100; i++) if(x[i]>0) printf("x[%d]=%d\n",i,x[i]);

Using gdb with C and need this thing? it exists! its free (public domain)!
it should be part of gdb, but the GNU people won't incorporate it
due to "political problems" :-(  [you can send mail to gnu AT cygnus DOT com and
ask them to incorporate the code]

Plus, you can use the generators functionality of DUEL to test your
functions much faster, e.g., the code

(gdb) dl my_test_func(1..5,("hello","world"))

will call my_test_func with (1,"hello"), (1,"world"), (2,"hello") ... etc.
you can then check and display the results with Duel, e.g.,

(gdb) dl x[..100] >? 0

will show which elements of array x[100] are positive - compare this
short code to the big C line above - they do the exact same thing!

if you are using gdb and doing C programming, and still haven't tried
Duel, you should. One user went as far as to say:

    ``Personally, I think it's the greatest thing since 
      source-code debuggers,''

here is more tempting info for you:

-----------------------------------------------------------------------------
DUEL -  A high level language for debugging C programs.
-----------------------------------------------------------------------------

Duel is a special purpose language designed for concise state exploration 
of debugged C programs under existing debuggers. It lets you to explore 
the program's state better than either the debugger's commands, a C 
interpreter, or print statements added to your code. The debugger is 
extended with the new 'dl' command for Duel expressions, e.g.,

     gdb> dl x[0..10].level >? 5
     x[3].level = 14
     x[8].level = 6

prints the "level" fields of array elements x[0] to x[10] that are greater 
than 5.  The output includes the values 14 and 6, as well as their 
symbolic representation "x[3].level" and "x[8].level". Linked list and
other complex data structures are just as easy. Most of C (e.g. for, if)
is also supported, e.g., int i; for(i=0; i<11; i++) if(x[i].level>5) x[i].

Duel is debugger-independent, but the current distribution interfaces only
with gdb. You will need the source for gdb-4.6, or above. All supported
gdb environments should work with Duel. It was tried at least on dec/mips,
sparc, sgi/iris, sony, hp9000, aix/rs6000, and sysV. Duel is public 
domain code. Do whatever you like with it - add it to commercial debuggers, 
to dbx/sdb or even make it part of the GNU project. No part of this 
distribution contains any copyright or derived code, (i.e. no GPL code, 
either). No disclaimer - free public domain software don't need one!
Even if you don't normally use debuggers, but you are programming in C, give
Duel a try! The man page & help even include a summary of useful gdb commands.

Duel is available for anonymous ftp from ftp.cs.princeton.edu, in 
/duel/duel.tar.Z. A "tar.Z" format means you should use the command
 "zcat duel.tar.Z | tar xf -" to unpack the files.
The Usenix Jan/93 paper about Duel is also available as tech report 399,
in /reports/1992/399.ps.Z on ftp.cs.princeton.edu. My PhD thesis dealing
with debuggers & duel will be available within a month - send me email 
if you would like a copy.


DUEL is "Debugging U (might) Even Like" or "Don't Use this Exotic Language"
you should judge which is better!

Michael Golan
mg AT cs DOT princeton DOT edu
-----------------------------------------------------------------------------
The tutorial part from the manual page follows:

     Duel is based on expressions which return	multiple  values.   The  x..y
     operator  returns	the  integers from x to y; the x,y operator returns x
     and then y, e.g.

     gdb> dl (1,9,12..15,22)

     prints 1, 9, 12, 13, 14, 15 and 22. Such expressions can be  used	wher-
     ever a single value is used, e.g.

     gdb> dl x[0..99]=0 ;

     assigns zero to the first 100 elements of array x. The semantics of x[i]
     are  the  same as in C. They are applied for each of the values returned
     by 0..99, which can be thought of as  an  implied	external  loop.   The
     trailing  semicolon  indicates evaluation for side-effects only, with no
     output. Duel incorporates C operators, casts  C  statements  as  expres-
     sions, and supports limited  variable declaration:

     gdb> dl int i;for(i=0;i<100;i++)
		      if(x[i]<0) printf("x[%d]=%d\n",i,x[i]);
     x[7] = -4

     The semicolon prevents Duel output; only output from printf is  printed.
     Aliases  are  defined  with  x:=y and provide an alternative to variable
     declaration. We could also return x[i] instead of using printf:

     gdb> dl if(x[i:=0..99]<0) x[i]
     x[i] = -4

     The symbolic output "x[i]" can be fixed by surrounding i with {}, i.e.

     gdb> dl if(x[i:=0..99]<0) x[{i}]
     x[7] = -4

     The {} are like (), but force the symbolic evaluation to use i's  value,
     instead  of  "i". You can usually avoid this altogether with direct Duel
     operators:

     gdb> dl x[..100] <? 0
     x[7] = -4

     The ..n operator is a shorthand for 0..n-1, i.e. ..100 is	the  same  as
     0..99.   The x<?y, x==?y, x>=?y, etc., operators compare their left side
     operand to their right side operand as in C, but return  the  left  side
     value  if	the  comparison  result is true. Otherwise, they look for the
     next values to compare, without returning anything.

     Duel's x.y and x->y allow an expression y, evaluated under x's scope:

     gdb> dl emp[..100].(if(code>400) (code,name))
     emp[46].code = 682
     emp[46].name = "Ela"

     The if() expression is evaluated under the  scope	of  each  element  of
     emp[], an array of structures. In C terms, we had to write:

     gdb> dl int i; for(i=0; i<100 ; i++)
	   if(emp[i].code>400) emp[{i}].code,emp[{i}].name

     A useful alternative to loops is the x=>y operator.  It  returns  y  for
     each value of x, setting `_' to reference x's value, e.g.

     gdb> ..100 => if(emp[_].code>400) emp[_].code,emp[_].name

     Using `_' instead of `i' also avoids the  need  for  {i}.	Finally,  the
     x-->y  operator  expands lists and other data structures. If head points
     to a linked list threaded through the next field, then:

     gdb> dl head-->next->data
     head->data = 12
     head->next->data = 14
     head-->next[[2]]->data = 20
     head-->next[[3]]->data = 26

     produce the data field for each node in the list. x-->y returns x, x->y,
     x->y->y,  x->y->y->y,  ...  until	a  NULL is found. The symbolic output
     "x-->y[[n]]" indicates that ->y was applied n times. x[[y]] is also  the
     selection operator:

     gdb> dl head-->next[[50..60]]->data

     return the 50th through the 60th elements in the list. The #/x  operator
     counts the number of values, so

     gdb> dl #/( head-->next->data >? 50 )

     counts the number of data elements over 50 on the list.

[There is a lot more in the full manual. Cyclic lists, strings, arrays like
argv, etc]

===============================================================================

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019