Crashed while step debug

Q&A's, tips, howto's
Locked
iNPRwANG
Posts: 32
Joined: Sun May 08, 2011 1:45 pm

Crashed while step debug

Post by iNPRwANG »

I have obtain newlisp.exe from:
http://www.newlisp.org/downloads/UTF-8_win32/

Verion is 10.6.0.

And let it run this program:

Code: Select all

(define (db-clear-sync-queues-vlog clearlist)
	(let ((conds '())
		  (sql ""))
		
		(dolist (_item clearlist)			
			(if (and (> (length _item) 1)
					 (string? (nth 0 _item))
					 (number? (nth 2 _item))
					)
				(extend conds (list (format "(tablename='%s' and orderid=%d)" (nth 0 _item) (nth 2 _item))))				
				)
			)
		
		(setq sql (append "delete from tbl_sync_queues_vlog where " (join conds " or ")))
		))

(debug (db-clear-sync-queues-vlog '(("tbl_test" "2014-10-21 10:35:35.873000000" 1))))
While in step debugging, the debug output like this:

Code: Select all

(define (db-clear-sync-queues-vlog clearlist)
  (let ((conds '()) (sql ""))
   (dolist (_item clearlist)
    (if (and (> (length _item) 1) (string? (nth 0 _item)) (number? (nth 2 _item)))
     (extend conds (list (format "(tablename='(null)' and orderid=10503914)" (nth 0 _item)
        (nth 2 _item))))))
   (setq sql (append "delete from tbl_sync_queues_vlog where " (join conds " or ")))))
Take notice of the string "(tablename='(null)' and orderid=10503914)", that's different from my code.

And while I step and step, the program will crash in this step:

Code: Select all

(define (db-clear-sync-queues-vlog clearlist)
  (let ((conds '()) (sql ""))
   #(dolist (_item clearlist)
    (if (and (> (length _item) 1) (string? (nth 0 _item)) (number? (nth 2 _item)))
     (extend conds (list (format "(tablename='(null)' and orderid=10503914)" (nth 0 _item)
        (nth 2 _item))))))#
   (setq sql (append "delete from tbl_sync_queues_vlog where " (join conds " or ")))))
Any suggestions??

ralph.ronnquist
Posts: 228
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Crashed while step debug

Post by ralph.ronnquist »

I can confirm that I get the same peculiar behaviour on
newLISP v.10.6.0 32-bit on Linux IPv4/6 UTF-8 libffi.
using xubuntu 12.04.5

With the debug clause, even at its very first stop, before any user interaction, the format argument has got filled in with (null) and a number replacing %s and %d.

.. and the same with today's 10.6.2 (built using configure-alt)

ralph.ronnquist
Posts: 228
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Crashed while step debug

Post by ralph.ronnquist »

Upon inspection, I would suggest that that varPrintf call at nl-debug.c:355 (referring into today's 10.6.2 tgz) is changed to include an "%s" format string before the strStream.buffer. As is, the buffer contents is treated as a format string.

Likewise for many (most?) varPrintf calls.

In human speak: it appears there is a bug such that one cannot safely debug code that includes format specifiers like %s and %d. To debug such code, you need to lift out all such specifiers, or the format strings in full, into constants or similar. Likewise, function results must also not include any format specifiers.

iNPRwANG
Posts: 32
Joined: Sun May 08, 2011 1:45 pm

Re: Crashed while step debug

Post by iNPRwANG »

And in the debugging state, the code's behavior is different from direct run.
Such as this example:

Code: Select all

(define (test)
	(setq *a* (array 1))
	(rest *a*))

(test)
By direct run this code, the rest function apply to an 1 element array, it throw the error:
ERR: array index out of bounds in function rest : 1
called from user defined function test
By run debug for step inspect, the rest function result a nil, that looks like no problem.

Code: Select all

(define (test )
  (setq *a* (array 1))
  #(rest *a*)#
  (println "OK"))

RESULT: nil
This cause people hard to find issuses from debugging.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Crashed while step debug

Post by Lutz »

This is on purpose. The debugger will not exit when an error happened. The error still is printed in the console when in debugging mode:

Code: Select all

-----

(define (test )
  (setq *a* (array 1))
  #(rest *a*)#)


[-> 3 ] s|tep n|ext c|ont q|uit > s

ERR: array index out of bounds in function rest : 1
called from user defined function test

-----

(define (test )
  (setq *a* (array 1))
  #(rest *a*)#)


RESULT: nil

[<- 3 ] s|tep n|ext c|ont q|uit > *a*
(nil)

[<- 3 ] s|tep n|ext c|ont q|uit >
... but now after coming out of the statement (rest *a*) with nil because the error occured, I can still inspect the variable *a* as shown above. The debugger command line accepts any newLISP statement, not only the s,n,c,q commands.

ps: note, that arithmetic expressions return 0 not nil on error when debugging
ps2: varPrintf() now always avoids printing format strigs without args.
See http://www.newlisp.org/downloads/develo ... nprogress/

Locked