debug segfault

Q&A's, tips, howto's
Locked
frontera000
Posts: 72
Joined: Sun Jun 11, 2006 8:02 pm
Location: berkeley, california
Contact:

debug segfault

Post by frontera000 »

[root@andLinux ~]# newlisp
newLISP v.9.3.3 on Linux IPv4, execute 'newlisp -h' for more info.

> (define ( x y ) (setq x y ))
(lambda (y) (setq x y))
> (debug (x 1))

-----

(define (x y)
#(setq x y)#)


[-> 3 ] s|tep n|ext c|ont q|uit > n
Segmentation fault
[root@andLinux ~]#

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Hi!

It's not a debug problem...

Code: Select all

newLISP v.9.3.2 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.

> (define (x y) (set 'x y))
(lambda (y) (set 'x y))
> 
> 
> (x 2)
Bus error
Dunno what's happening there...

frontera000
Posts: 72
Joined: Sun Jun 11, 2006 8:02 pm
Location: berkeley, california
Contact:

not sure if this helps

Post by frontera000 »

gdb ./newlisp
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r
Starting program: /root/newlisp-9.3.3/newlisp
newLISP v.9.3.3 on Linux IPv4, execute 'newlisp -h' for more info.

> (define (x y) (set 'x y))
(lambda (y) (set 'x y))
> (x 2)

Program received signal SIGSEGV, Segmentation fault.
evaluateExpression (cell=0x0) at newlisp.c:1090
1090 if(cell->type & EVAL_SELF_TYPE_MASK) return cell;
(gdb) bt
#0 evaluateExpression (cell=0x0) at newlisp.c:1090
#1 0x08052f4c in evaluateLambda (localLst=0x8080808, arg=<value>,
newContext=0x80830b0) at newlisp.c:1411
#2 0x0804e8bc in evaluateExpression (cell=0x80805b8) at newlisp.c:1179
#3 0x0805334b in evaluateStream (stream=0xbff35cd4, outDevice=2, flag=0)
at newlisp.c:946
#4 0x08053a2b in executeCommandLine (command=0xbff35e45 "(x 2)\n", outDevice=2,
cmdStream=0xbff35e2c) at newlisp.c:924
#5 0x080540a9 in main (argc=1, argv=0xbff35ff4) at newlisp.c:732
(gdb) up
#1 0x08052f4c in evaluateLambda (localLst=0x8080808, arg=<value>,
newContext=0x80830b0) at newlisp.c:1411
1411 result = evaluateExpression(cell);
(gdb) p cell
$1 = (CELL *) 0x0
(gdb) l
1406 /* evaluate body expressions */
1407 cell = localLst->next;
1408 result = nilCell;
1409 while(cell != nilCell)
1410 {
1411 result = evaluateExpression(cell);
1412 cell = cell->next;
1413 }
1414 result = copyCell(result);
1415
(gdb) p nilCell
$2 = (CELL *) 0x807f0a8
(gdb) up
#2 0x0804e8bc in evaluateExpression (cell=0x80805b8) at newlisp.c:1179
1179 result = evaluateLambda((CELL *)pCell->contents, args->next, newContext);
(gdb) p *(CELL *)pCell->contents
$3 = {type = 255, next = 0x80807e8, aux = 134738088, contents = 134744040}
(gdb) down
#1 0x08052f4c in evaluateLambda (localLst=0x8080808, arg=<value>,
newContext=0x80830b0) at newlisp.c:1411
1411 result = evaluateExpression(cell);
(gdb) l 1400
1395 goto GET_LOCAL;
1396
1397 GOT_LOCALS:
1398 /* put unassigned args in $args */
1399 pushEnvironment(argsSymbol->contents);
1400 pushEnvironment((UINT)argsSymbol);
1401 argsSymbol->contents = (UINT)getCell(CELL_EXPRESSION);
1402 if(result != nilCell)
1403 ((CELL*)argsSymbol->contents)->contents = (UINT)result;
1404 ++localCount;
(gdb) p *(CELL*)argsSymbol->contents
$4 = {type = 59, next = 0x807f0a8, aux = 134738088, contents = 134738088}
(gdb)

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

Post by Lutz »

The function symbol is modifying itself while executing. The following definition writing 'func' instead of 'x', make this more visible:

Code: Select all

(defun (func y) (set 'func y))
Self modifying functions are only possible when not setting the symbol but when manipulating the lambda list directly as in:

Code: Select all

(> (define (func y) (push y func -1))
(lambda (y) (push y func -1))
> (func 99)
99
> func
(lambda (y) (push y func -1) 99)
> (func 99)
This can be used to simulate some kind of closure by redefining parameter defaults:

Code: Select all

> (define (acc (y 0)) (nth-set (acc 0 0 1) (+ $0 1)))
(lambda ((y 0)) (nth-set (acc 0 0 1) (+ $0 1)))
> (acc)
0
> (acc)
1
> (acc)
2
> (acc)
3
> acc
(lambda ((y 4)) (nth-set (acc 0 0 1) (+ $0 1)))
> 
the function always produces the previous value.

ps: see also http://www.alh.net/newlisp/phpbb/viewto ... ying#10673

frontera000
Posts: 72
Joined: Sun Jun 11, 2006 8:02 pm
Location: berkeley, california
Contact:

thanks for clarification

Post by frontera000 »

i was confused. too used to clisp still...

# clisp
i i i i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I 8 8 8 8 8 o 8 8
I \ `+' / I 8 8 8 8 8 8
\ `-+-' / 8 8 8 ooooo 8oooo
`-__|__-' 8 8 8 8 8
| 8 o 8 8 o 8 8
------+------ ooooo 8oooooo ooo8ooo ooooo 8

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2006

[1]> (defun x (y) (setq x y))
X
[2]> (x 2)
2
[3]> x
2

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

Post by Lutz »

Common Lisp uses separate namespaces for function and other variables.

Locked