* Justin Pryzby <[EMAIL PROTECTED]> [2006-06-23 14:24] :
> On Fri, Jun 23, 2006 at 01:27:18AM +0200, Fr??d??ric Bothamy wrote:
> > * Justin Pryzby <[EMAIL PROTECTED]> [2006-06-21 08:47] :
> > > On Wed, Jun 21, 2006 at 02:25:31AM +0200, Fr??d??ric Bothamy wrote:
> > 
> > [...]
> > 
> > > > pn  openoffice.org2-core             <n?ant>                         
> > > > (aucune description n'est disponible)                                   
> > > >              
> > > > /usr/bin/dlocate: line 55: 26638 Done                    egrep "$1" 
> > > > $DPKGLIST
> > > >      26639 Erreur de segmentation  | while read stat name ver descr; do
> > > >     printf "%-2s  %-${fieldw}.${fieldw}s %-${fieldw}.${fieldw}s 
> > > > %-${fieldd}.${fieldd}s\\n" "$stat" "$name" "$ver" "$descr";
> > > > done
> > > > 
> > > > Program exited normally.
> > > > (gdb)
> > > > 
> > > > Do you have another idea?
> > > Is egrep the one segfaulting?  You can do the same as before to build
> > > a "grep" deb with debugging symbols, then just dpkg -i
> > > ../grep_....deb.  apt-get {--re,}install grep later if you wish.
> > > 
> > > It isn't completely clear to me how gdb would handle debugging the
> > > grep; you might have to change the shell script to use
> > > 
> > >   'gdb egrep "$1" $DPKGLIST'
> > > 
> > > instead, or just dump "$1" and $DPKGLIST to a file to fiddle with it
> > > manually.
> > 
> > Hello Justin,
> > 
> > Thanks for your help.
> > 
> > I have tried to see if this was a problem with egrep and I have replaced
> > the egrep in the dlocate script with a simple "cat $DPKGLIST". The
> > segfault also occurs. But it does not occur if I use a "head $DPKGLIST".
> What is the contents of $DPKGLIST?  you should
> echo "$DPKGLIST" >/tmp/testgrep
> 
> The quotes are important.  It occurs to me that, without quotes, you
> could end up with $DPKGLIST being its own command, eg. if it contains
> any of: ;`& or such characters..  But this is perhaps also intentional
> (and ` is still evaluated within "" quotes).

Sorry, I realize that I have quite unclear. $DPKGLIST is
/var/lib/dlocate/dpkg-list, this file contains the output of:

LINES=40 COLUMNS=200 dpkg -l "*" | sed -e '1,5d' -e 's/  */ /g'

using the current locale.
 
> > I have found that the problem only occurs if I send 276 lines (or more)
> > of text to the "| while ...".
> Interesting..
> 
> > If I try to execute the dlocate script with "sh -x" at the beginning
> > of the script, I need 373 lines to get the segmentation error.
> > 
> > If I execute the lines of the script at the command prompt, I get an
> > error with 22504. Here is the exact command that I used:
> 22504 is the number of lines of input, the line number, or a PID?

Argh, my fault again for being very unclear :-(. 22504 is the number
of lines which is causing a segmentation error in this cas.
 
> > $ echo $COLUMNS
> > 150
> > $ ((fieldw=(COLUMNS-24)/4))
> > $ ((fieldd=COLUMNS-fieldw*2-6))
> > $ cat dpkg-list_fr | while read stat name ver descr; do printf "%-2s 
> > %-${fieldw}.${fieldw}s %-${fieldw}.${fieldw}s %-${fieldd}.${fieldd}s\\n"
> > "$stat" "$name" "$ver" "$descr"; done
> Does this crash cat, printf, or what?  You can get rid of the cat by
> rewriting as:
> 
>   while read .. .. .. ..; do ..; done <dpkg-list_fr
> 
> I suspect this is a bash problem with wide characters or such.

You are right. I have used the following procedure to debug my problem
(I try to be more precise than before):

[EMAIL PROTECTED]:~/debian/bash/bash-3.1/build-bash$ gdb ./bash
GNU gdb 6.4.90-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 "/usr/lib/debug/libthread_db.so.1".

(gdb) r
Starting program: /home/fred/debian/bash/bash-3.1/build-bash/bash 
[EMAIL PROTECTED]:~/debian/bash/bash-3.1/build-bash$ COLUMNS=$(stty -a 2>&- | 
sed -ne '/columns/s/.*columns \([0-9]*\)[^0-9].*/\1/p');
[EMAIL PROTECTED]:~/debian/bash/bash-3.1/build-bash$ ((fieldw=(COLUMNS-24)/4));
[EMAIL PROTECTED]:~/debian/bash/bash-3.1/build-bash$ 
((fieldd=COLUMNS-fieldw*2-6));
[EMAIL PROTECTED]:~/debian/bash/bash-3.1/build-bash$ while read stat name ver 
descr; do printf "%-2s  %-${fieldw}.${fieldw}s %-${fieldw}.${fieldw}s 
%-${fieldd}.${fieldd}s\\n" "$stat" "$name" "$ver" "$descr"; done < 
/home/fred/dlocate/dpkg-list_fr
[...]

pn  libregexp-shellish-perl     <néant>                    (aucune description 
n'est disponible)                                    
pn  libregexx-dev               <néant>                    (aucune description 
n'est disponible)                                    
pn  libregexx1                  <néant>                    (aucune description 
n'est disponible)                                    
pn  libregexx1c102              <néant>                    (aucune description 
n'est disponible)                                    
pn  libreiser4-dev              <néant>                    (aucune description 
n'est disponible)                                    

Program received signal SIGSEGV, Segmentation fault.
*__GI_wcschr (wcs=0x8354000, wc=233) at wcschr.c:29
29      wcschr.c: Aucun fichier ou répertoire de ce type.
        in wcschr.c
(gdb)  bt
#0  *__GI_wcschr (wcs=0x8354000, wc=233) at wcschr.c:29
#1  0x08080849 in string_extract_verbatim (string=0x8353c97 "<néant> (aucune 
description n'est disponible)", slen=46, 
    sindex=0xbfd4e834, charlist=0x80f9148 " \t\n") at ../bash/subst.c:953
#2  0x08080acf in get_word_from_string (stringp=0xbfd4e940, 
separators=0x80f9148 " \t\n", endptr=0xbfd4e93c) at ../bash/subst.c:2056
#3  0x080a82f4 in read_builtin (list=0x82e84c8) at 
../../bash/builtins/../../bash/builtins/read.def:599
#4  0x0806ba17 in execute_builtin (builtin=0x80a7870 <read_builtin>, 
words=0x82d5f28, flags=8, subshell=0)
    at ../bash/execute_cmd.c:3083
#5  0x0806f531 in execute_simple_command (simple_command=0x811a7c8, pipe_in=-1, 
pipe_out=-1, async=0, fds_to_close=0x81add68)
    at ../bash/execute_cmd.c:3458
#6  0x0806d3f7 in execute_command_internal (command=0x81ab7a8, asynchronous=0, 
pipe_in=-1, pipe_out=-1, fds_to_close=0x81add68)
    at ../bash/execute_cmd.c:667
#7  0x0806c141 in execute_command (command=0x81ab7a8) at 
../bash/execute_cmd.c:350
#8  0x0806c1ab in execute_while_or_until (while_command=0x81adaa8, type=0) at 
../bash/execute_cmd.c:2296
#9  0x0806d2fa in execute_command_internal (command=0x81ad8e8, asynchronous=0, 
pipe_in=-1, pipe_out=-1, fds_to_close=0x81f1f48)
    at ../bash/execute_cmd.c:2264
#10 0x0806c141 in execute_command (command=0x81ad8e8) at 
../bash/execute_cmd.c:350
#11 0x0805e886 in reader_loop () at ../bash/eval.c:147
#12 0x0805e315 in main (argc=1, argv=0xbfd4efc4, env=0xbfd4efcc) at 
../bash/shell.c:714
(gdb) 

Notes:
- the file /home/fred/dlocate/dpkg-list_fr is a dlocate dpkg-list
file (I can send it to you if you want, it's about 133 kB bzip2-ed)
- I have installed libc6-dbg and defined LD_LIBARY_PATH to
/usr/lib/debug to be able to get the line for wcschr.c.

Hopefully this can give you a better idea of the real problem with wide
characters.

Greetings,


Fred

Reply via email to