Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Nov 2022 16:04:49 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 268076] dc(1): crash on window size change
Message-ID:  <bug-268076-227-Yyn8jMJB48@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-268076-227@https.bugs.freebsd.org/bugzilla/>
References:  <bug-268076-227@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D268076

--- Comment #4 from Marcin Cie=C5=9Blak <saper@saper.info> ---
Thank you for a very quick response, here is how it looks now:

dc(1) prints "ready for more input" every time I resize the window, but does
not crash at all

radziecki> ./bin/dc=20=20=20=20=20=20=20=20=20=20=20=20=20=20
2 2 + p
4
ready for more input
5 # resize
ready for more input
ready for more input
ready for more input

bc(1) exists as before

radziecki> ./bin/bc
>>> 2 + 2=20
4
>>>=20
Fatal error: I/O error
    Function: (main)



This is your software and I fully respect your right to design its features=
 as
you see fit, especially given the maintenance burden is mostly on you.

I think classic "perror()" would be slighly better here (of course without =
all
the i18n goodies).

diff --git a/src/history.c b/src/history.c
index bc15da5b..15e6e25b 100644
--- a/src/history.c
+++ b/src/history.c
@@ -264,8 +264,7 @@ bc_history_line(BcHistory* h, BcVec* vec, const char*
prompt)
                // If this is true, there was an error. Otherwise, it's just
EOF.
                if (len =3D=3D -1)
                {
-                       if (errno =3D=3D ENOMEM) bc_err(BC_ERR_FATAL_ALLOC_=
ERR);
-                       bc_err(BC_ERR_FATAL_IO_ERR);
+                       perror("reading next input line failed");
                }
                else
                {

Maybe it could be helpful to tell you how I approached the problem.
This is just my personal story and certainly not a case for everyone
approaching unknown software:

1. First I did=20

git grep "Fatal error"

to find out there is i18n system in place and it looks like "I/O Error" is =
an
error number 5 (counted by hand in "bc_err_msgs")

2. Then I did

git grep bc_err_msgs

to learn that the whole i18n thing is initialized via bc_vm_defaultMsgs()
but still no clue regarding what might have caused it

3. Then tried my luck to

git grep bc_err_ids

that reveals there is bc_vm_handleError() and the name looks promising

4. Having learned that it was easier:

(gdb) b bc_vm_handleError
Breakpoint 1 at 0x2372f8: file ./src/vm.c, line 351.
(gdb) run
Starting program: /usr/home/saper/src/bc/bin/bc=20
warning: Could not load shared library symbols for [vdso].
Do you need "set solib-search-path" or "set sysroot"?
>>>=20
Breakpoint 1, bc_vm_handleError (e=3DBC_ERR_FATAL_IO_ERR, line=3D0) at
./src/vm.c:351
351             uchar id =3D bc_err_ids[e];
(gdb) bt
#0  bc_vm_handleError (e=3DBC_ERR_FATAL_IO_ERR, line=3D0)
    at ./src/vm.c:351
#1  0x0000000000218169 in bc_history_line (
    h=3D0x23e440 <vm_data+1584>, vec=3D0x23e228 <vm_data+1048>,=20
    prompt=3D0x201ca5 ">>> ") at ./src/history.c:268
#2  0x0000000000234e10 in bc_read_line (
    vec=3D0x23e228 <vm_data+1048>, prompt=3D0x201ca5 ">>> ")
    at ./src/read.c:236
#3  0x000000000023827e in bc_vm_readLine (clear=3Dtrue)
    at ./src/vm.c:1114
#4  0x000000000023ac20 in bc_vm_stdin () at ./src/vm.c:1165
#5  0x0000000000239b7d in bc_vm_exec () at ./src/vm.c:1501
#6  0x0000000000238eae in bc_vm_boot (argc=3D1, argv=3D0x7fffffffe6b0)
    at ./src/vm.c:1691
#7  0x000000000021131c in bc_main (argc=3D1, argv=3D0x7fffffffe6b0)
    at ./src/bc.c:62
#8  0x000000000021a199 in main (argc=3D1, argv=3D0x7fffffffe6b0)
    at ./src/main.c:108
(gdb) down
Bottom (innermost) frame selected; you cannot go down.
(gdb) up
#1  0x0000000000218169 in bc_history_line (h=3D0x23e440 <vm_data+1584>,=20
    vec=3D0x23e228 <vm_data+1048>, prompt=3D0x201ca5 ">>> ")
    at ./src/history.c:268
268                             bc_err(BC_ERR_FATAL_IO_ERR);
(gdb) list -
263             {
264                     // If this is true, there was an error. Otherwise, =
it's
just EOF.
265                     if (len =3D=3D -1)
266                     {
267                             if (errno =3D=3D ENOMEM)
bc_err(BC_ERR_FATAL_ALLOC_ERR);
268                             bc_err(BC_ERR_FATAL_IO_ERR);
269                     }
270                     else
271                     {
272                             bc_file_printf(&vm->fout, "\n");
(gdb)=20
253                             }
254                     }
255                     else bc_history_prompt =3D bc_vm_strdup(prompt);
256             }
257=20=20=20=20=20
258             // Get the line.
259             line =3D el_gets(h->el, &len);
260=20=20=20=20=20
261             // If there is no line...
262             if (BC_ERR(line =3D=3D NULL))
(gdb) p line
$1 =3D 0x0
(gdb) p h->el
$2 =3D (EditLine *) 0x800a6a000
(gdb) p len
$3 =3D -1


What certainly would help is some unique identification of the position of =
the
error in the code (be it __FILE__, __LINE__ if need be). BC_ERR_FATAL_IO_ER=
R is
thrown in dozen or so places so I can't quickly tell where did it fail.

Since FreeBSD runs optimized binaries, but with debug symbols available, it=
 was
frustrating to see all local variables optimized out, only errno was there:

(gdb) p len
$1 =3D <optimized out>
(gdb) p line
$2 =3D <optimized out>
(gdb) p h->el
value has been optimized out
(gdb) p errno
$3 =3D 4

(feel free to move this conversation somewhere else, sadly could not regist=
er
at https://git.yzena.com/gavin/bc/)

But again, thank you for building this software for us.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-268076-227-Yyn8jMJB48>