Crashed while step debug

Started by iNPRwANG, October 20, 2014, 08:23:45 PM

Previous topic - Next topic

iNPRwANG

I have obtain newlisp.exe from:

http://www.newlisp.org/downloads/UTF-8_win32/">//http://www.newlisp.org/downloads/UTF-8_win32/



Verion is 10.6.0.



And let it run this program:



(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:



(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:



(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??

rrq

#1
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)

rrq

#2
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

#3
And in the debugging state, the code's behavior is different from direct run.

Such as this example:



(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:


Quote
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.



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

RESULT: nil


This cause people hard to find issuses from debugging.

Lutz

#4
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:



-----

(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/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/