Some tips and examples for remote debug with newLisp

Started by iNPRwANG, May 13, 2018, 11:43:36 PM

Previous topic - Next topic

iNPRwANG

Here are some share tips of doing remoting debug with newLisp : )



Before, I suggested to add a "debugConsole" function for embedded newLisp library debugging, that can establish a new console window for windows GUI applications and can do the step debug in the window.



Now, I want to step debug the newLisp for embedded device, such as android devices or embedded linux facilities, a remote debugger can make debug works be very comfortable.



With these codes, U may have a simple remote debug without change any newLisp's source, these two parts code is a remote debugger services and a debugger terminal, the debugger services looks like this:



(import "libc.so.6" "dup2")

;Standard input value, stdin. Its value is 0.
(constant 'STDIN_FILENO 0)
   
;Standard output value, stdout. Its value is 1.
(constant 'STDOUT_FILENO 1)
   
;Standard error value, stderr. Its value is 2.
(constant 'STDERR_FILENO 2)

(println STDOUT_FILENO)

(set 'socket (net-listen 1234))
(set 'cnn (net-accept socket))
(net-close socket)

(println "Connection successed!")

;/* duplicate socket on stdout */
(dup2 cnn STDOUT_FILENO)

;  /* duplicate socket on stderr too */
(dup2 cnn STDIN_FILENO)

(debug (fibo 2))

(exit)


The "fibo" function is a route you want to debug, and the debugger terminal looks like this:




(set 'socket (net-connect "127.0.0.1" 1234))
(println "Connection successed!")

(setq g_end "s|tep n|ext c|ont q|uit >")

(catch
(let ((buffer (dup "x00" 1))
 (output ""))
(while true
;判断是否 s|tep n|ext c|ont q|uit > 结尾,如果是,则打印出来后再读取一个字符

(net-select socket "e" 0)
(when (net-error)
(println (net-error))
(throw 'Exception))

(net-receive socket buffer 1)
(print buffer)

(setq output (append output buffer))
(when (ends-with output g_end)
(setq output "")

(letn ((cmd (read-line))
  (send_cmd (append cmd "n")))
(net-send socket send_cmd)
)
)
)
)
'Result)

(exit)





Then, run the debugger services and then run the debugger terminal, U will like the remote debuger practice : )



Under are some notes for remote debug with a newLisp library:



The library of newLisp does not use the standard IO for debugger, unless you set a debug console flag for it. The "newlispLibConsole" exported function of newLisp.so can be called and to enable the flag, then it will use the standard IO and the above codes will works good.