Rtems telnetd/shell question (and Why does fgetc() return 0 for a 0-length socket read?)

Peter Dufault dufault at hda.com
Wed Nov 4 12:26:19 UTC 2009


On Oct 29, 2009, at 11:16 , Chris Johns wrote:

> I am wondering if this is a bug in newlib and should be fixed.

I think it is a compiler issue.  The 0 return from fgetc() is most  
likely an artifact of debugging an optimized binary.

We are stuck within the doloop at line 702 of shell.c.

It's a "do { } while (result && shell_env->forever);", wit result 1  
and shell_env->forever 0:

(gdb) print result
$22 = 0x1
(gdb) print shell_env->forever
$23 = 0x0
(gdb) print shell_env
$24 = <value optimized out>
(gdb)

But note that shell_env is optimized out.  It's been aliased to  
rtems_current_shell_env at line 592:
   shell_env =
   rtems_current_shell_env = rtems_shell_init_env( shell_env_arg );

and note that the value of rtems_current_shell_env->forever differs  
from shell_env->forever:

(gdb) print rtems_current_shell_env->forever
$25 = 0x1

If I change it:
(gdb) set rtems_current_shell_env->forever=0
(gdb) c
Continuing.

Then telnet exits and I can reconnect again.  Unless someone sees  
something questionable in the code it is a compiler issue.  Observe  
this sequence, where gdb will give me the address of "shell_env- 
 >forever" as its offset into the structure:

(gdb) print shell_env
$26 = <value optimized out>
(gdb) print &shell_env
Can't take address of "shell_env" which isn't an lvalue.
(gdb) print &shell_env->forever
$27 = (_Bool *) 0xd
(gdb) print *(_Bool *)0xd
$28 = 0x0
(gdb) set *(_Bool *)0xd=1
(gdb) print shell_env->forever
$29 = 0x1
(gdb)

Peter




More information about the users mailing list