Thursday, August 31, 2006

一点debug技巧

怎么样打印出一个函数的stack backtrace,也就是函数的调用路径?
可以使用glibc的backtrace()/backtrace_symbols()函数,info在这里
http://www.gnu.org/software/libc/manual/html_mono/libc.html#Backtraces
这里有一段代码,可以拿去用
#include<execinfo.h>
int i;
void *bt[128];
int bt_size;
char **bt_sym;
printf("\n########## Backtrace ##########\n");
bt_size = backtrace(bt, sizeof(bt) / sizeof(void *));
printf("Number of elements in backtrace: %d\n", bt_size);
bt_sym = backtrace_symbols(bt, bt_size);

for (i = 0; i < bt_size; i++) {
printf("%s\n", bt_sym[i]);
}
free(bt_sym);
printf("########## Done ##########\n");

我参考了这个
http://sources.redhat.com/ml/crossgcc/2003-02/msg00013.html
如果不幸是C++程序可以利用c++filt来得到真正的函数原型
这里有段shell代码可以拿去用:
sed -e 's/[^(]\+(/c++filt /' -e 's/+0x.*$//g' | xargs -0 sh -c

还有一个gcc内建函数,gcc的扩展,也可能有用,不过只能得到返回地址
http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Return-Address.html#Return-Address

Wednesday, August 30, 2006

当一个软件的文档与当前实现严重脱节的时候

应该怎么办?
恐怕答案只有一个:RTFS
d4rkstar, how should i learn to program using bayonne script language, i am really frustrated
also i was :)
i adopted a tecnique
the sources are always update
the documentation often not
so i use a text editor and greps the sources for the keywords i need
for example
search "foreach" in all .cpp files in bayonne directory and subdirectories (i include ccscript and bayonne in my search)
so i look at the sources for keyword requirements
thank you, may i can follow your way, :)
s/may/maybe

Sunday, August 20, 2006

Simplify or not to simplify, this is a question.

超级无敌全能forturn-zh脚本:
#!/bin/bash

# fortune-zh V1.0
#
# Copyright (C) 2006 Zhang Le
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

FORTUNE="/usr/bin/fortune"
CMD=`basename "$0"`

if [ -f "${HOME}"/.fortune-zh.conf ] ; then
CONF="${HOME}"/.fortune-zh.conf
elif [ -f /etc/fortune-zh.conf ]; then
CONF=/etc/fortune-zh.conf
fi

if [ -z $CONF ] || [ ! -s $CONF ] ; then
exec $FORTUNE
fi

if [ ! -z $LC_ALL ]
then
LANG="$LC_ALL"
fi

CHARSET=`echo ${LANG#*.} | tr A-Z a-z | sed -e 's/-//g'`

if [ $# -eq 0 ] ; then
DICT=`cat ${CONF}`
else
DICT=`echo $@ | sed -e 's/[^0-9% ]\+/zh-&/g'`

fi

if test $CMD == "fortune-zh"; then
case "$CHARSET" in
big5)
LC_ALL=zh_CN.GB18030 $FORTUNE $DICT | autob5
;;
*)
$FORTUNE $DICT
;;
esac
elif test $CMD == "fortune-sc"; then
case "$CHARSET" in
big5)
echo 'Not available in BIG5 environment, try UTF-8'
;;
*)
$FORTUNE $DICT
;;
esac
elif test $CMD == "fortune-tc"; then
case "$CHARSET" in
gb*)
echo 'Not available in GB environment, try UTF-8'
;;
big5)
LC_ALL=zh_CN.GB18030 $FORTUNE $DICT | autob5
;;
utf8)
LC_ALL=zh_CN.GB18030 $FORTUNE $DICT | autob5 | autogb -i big5 -o utf8
;;
esac
fi


Traditional Chinese
《行路難》
作者:李白
金樽清酒鬥十千,玉盤珍饈直萬錢。
停杯投箸不能食,拔劍四顧心茫然。
欲渡黃河冰塞川,將登太行雪暗天。
閒來垂釣坐溪上,忽復乘舟夢日邊。
行路難,行路難,多歧路,今安在。
長風破浪會有時,直掛雲帆濟滄海。

Simplified Chinese
《行路难》
作者:李白
金樽清酒斗十千,玉盘珍馐直万钱。
停杯投箸不能食,拔剑四顾心茫然。
欲渡黄河冰塞川,将登太行雪暗天。
闲来垂钓坐溪上,忽复乘舟梦日边。
行路难,行路难,多歧路,今安在。
长风破浪会有时,直挂云帆济沧海。

emake -j1

If you can manually make, but always fail in src_compile(), look at your MAKEOPTS, if it is "-j2", consider using "emake -j1"

Saturday, August 19, 2006

I committed bayonne2-1.5.26.ebuild to voip overlay

First of all, thanks to genstef!
Two days ago, I was very happy to see that bayonne2 was in voip overlay.
After a while I was disappointed, coz I found the version was too old and would not compile sip driver.
So I modified the original ebuild to make a ebuild for bayonne2's latest version.
Now I have commited it to voip overlay.
It was not that easy(well, at least not for a newbie like me). I made a patch for it, otherwise sandbox violation would occur.
It is here:
http://overlays.gentoo.org/proj/voip/browser/trunk/net-misc/bayonne2/bayonne2-1.5.26.ebuild

Wednesday, August 16, 2006

nogetch = on in prozilla.conf

If you want to enable parallel-fetch FEATURE and use prozilla as your fetch command, DO remember to enbale nogetch option in prozilla.conf.
Otherwise there exists the possibility that you'll be driven mad, :)

Tuesday, August 15, 2006

I talked to Redhatter on #gentoo-mips about Godson

Wikipedia article about Godson.

(zhllg) http://www.lemote.com/lmpc.wmv Linux running on China's Godson CPU
(zhllg) Godson's instruction set is compatible with MIPS
(redhatter) wmv?
* Redhatter points out that Microsoft don't produce a Linux version of Windows Media Player
(redhatter) s/don't/doesn't/ rather
(zhllg) however, we can play it with mplayer if win32codec USE flag is enabled.
(zhllg) btw, i just find that link somewhere else, i am not the publisher
(redhatter) we can play it with mplayer on x86 with win32codecs USE flag :-)
(redhatter) Those Godson machines _do_ look nice though... pity they're damn hard to get hold of outside of China.
(zhllg) i have a dream that one day Gentoo could have Godson support, haha
(redhatter) Indeed... although that won't happen unless one of us can get hold of one.
(zhllg) Maybe you have known this, http://en.wikinews.org/wiki/Yellow_Sheep_River_develops_%E2%82%AC123_Linux_based_computer
(redhatter) Indeed, those are the ones I have heard about.
(redhatter) If I see someone selling them in Brisbane, I'll certainly look into buying one. :-)
:-D

Compile kernel as a normal user

I just heard this trick from my friend, rae.
It is quite easy:
  1. make a dir, cd into it
  2. cp /boot/config .config (suppose you use "make install" to install kernel, :-D)
  3. make -C /usr/src/linux O=$PWD oldconfig, (and optionally make menuconfig to tweak a little bit)
  4. make && sudo make modules_install && sudo make install
The trick is on step 3, ;)

PS: However, there is a problem with this approach.
My original intention is to avoid touching the sources in /usr/src/linux and running as root.
But in fact, before you emerge kernel modules such as x11-drm, you still have to run 'make modules_prepare' in /usr/src/linux as root. Even I have used this command:
sudo env KBUILD_OUTPUT=/home/zhangle/build emerge x11-drm
What's worse, the hints given in the output of the above command can't solve the problem:
* Found kernel source directory:
* /usr/src/linux
* Found kernel object directory:
* /home/zhangle/build
* Found sources for kernel version:
* 2.6.17-suspend2-r4
* Please verify that your /usr/src/linux symlink is pointing
* to your current kernel sources, and that you did run:
*
* # make dep

Monday, August 14, 2006

制作中文可以拷贝的PDF

本来如果严格按照中文Gentoo wiki上的这篇文章来做的话应该是没有问题的,这篇文章使用的字符集是GBK。
不过我曾经按照及永刚大哥的一篇文章配置过UTF-8环境下的teTeX。
前者的主要文件放在/usr/local/share里,后者放在$HOME里。有些文件是重复的,这就有个取舍的问题,到底用的是哪个。

生成可以拷贝中文的pdf要用dvipdfmx,这个都有共识。
可是还要配置两个文件,一个是UGBK.sfd,一个是cid-x.map。
这次就栽在了后一个文件上,没有搞清楚用的是哪个。

我用strace分析了dvipdfmx运行时打开的配置文件,发现dvipdfmx依据的是$HOME里的cid-x.map。
strace dvipdfmx test.dvi 2>&1 | grep cid-x.map

然后我又发现了FerretL的这篇文章,原来有个命令可以查的
kpsewhich cid-x.map

Sunday, August 13, 2006

今天重温了去年与一个Fedora Core使用者的吵架贴

有一点感悟
虽然他对Gentoo的某些指责有悖事实,但是有些话还是有些道理
以前谈到Gentoo的好,文档丰富是必须要夸赞的
可是我现在却突然感觉到
与其说那是我们的优点,倒不如说那是我们赖以生存的根本

Saturday, August 12, 2006

#gentoo-cn on freenode

I registered #gentoo-cn several days ago. I am still a irc newbie op. But I am trying my best to catch up.
I am playing with supybot. It is interesting. I will try to write some plugins for it. That will be more interesting!
Yesterday Alastair Tse dropped in #gentoo-cn, I asked him if there are some better irc bot. To my surprise, he is the maintainer of supybot. Such a coincidents! hehe.

PS: The number of people hanging on #gentoo-cn reached 23 yesterday, although 2-3 of them are bots, :).

Thursday, August 10, 2006

Screenshot


My friend midx's desktop

Wednesday, August 09, 2006

Fwd: zh_cn GWN 20060731

WOO~~
Thanks to ALL members of zh_CN GWN translations team!!!!
This is not just my honur, but also everyone else's honor!!!
Thank you!!!

---------- Forwarded message ----------
From: Chris Gianelloni
Date: Aug 8, 2006 11:26 PM
Subject: Re: zh_cn GWN 20060731
To: Zhang Le
Cc: gwn-feedback AT gentoo DOT org, neysx AT gentoo DOT org

On Sun, 2006-08-06 at 19:23 +0800, Zhang Le wrote:
> Please help to commit, thanks!
>
> --
> Zhang Le, Robert

They're now committed to the tree.

I'm going to put you in touch with Xavier Neys, who is the Gentoo
Documentation Project lead. He (or someone from his team) is going to
mentor you so you can become a Gentoo staff member. This will allow you
to commit your translations directly, as you and your team have been
doing an excellent job, and I'm just holding you guys back now.

--
Chris Gianelloni
Release Engineering - Strategic Lead
x86 Architecture Team
Games - Developer
Gentoo Linux



--
Zhang Le, Robert
Linux Engineer/Trainer
http://zhllg.spaces.msn.com
http://zh.gentoo-wiki.com
http://savannah.nongnu.org/projects/pgubook
http://groups.google.com/group/gentoo-china
http://groups.google.com/group/szlug

Tuesday, August 08, 2006

Gentoo takes you a lot of time?

I saw someone expressed this concern about Gentoo in a Chinese Linux forum. His original word is "Gentoo and LFS are only suitable for those who have a lot of time and a good machine".

I replied him. Here are my main points:
Maybe inevitable at the beginning, especially for Chinese users. Lots of apps need to be tuned, configured.
But not necessarily afterwards, especially if the number of packages on your systme remains unchanged or fluctuates not so much.
Your time maybe wasted under probably only one situation, i.e. you need a software desperately, but you haven't installed it yet.
But if someone really often faces this situation, my suggestion to him is to choose something else, be it Debian or Arch.
Also, I expressed one of my speculations of the future: Software compiling speed and the complexity of software, which increases faster? I think it's the former. :) But will OOo be compiled in minutes someday in the future? I am not sure.

[Gentoo]Two things for me to remember

  1. Never try to use x11-drivers/ati-drivers, it stopped to function normally on my hp pavilion zt3000 since several months ago.
  2. Never try to enable option "FastAGPWrite" in xorg.conf, my notebook simply hangs whenever I startx with this option enabled.