章 12. 小技巧

內容目錄

12.1. 在 UTF-8 環境下構建
12.2. UTF-8 轉換
12.3. Hints for Debugging

Please also read insightful pages linked from “Notes on Debian” by Russ Allbery (long time Debian developer) which have best practices for advanced packaging topics.

構建環境的預設語言環境是 C。

某些程式(如 Python3 的 read 函式)會根據區域設定改變行為。

新增以下程式碼到 debian/rules 檔案可以確保程式使用 C.UTF-8 的區域語言設定(locale)進行構建。

LC_ALL := C.UTF-8
export LC_ALL

If upstream documents are encoded in old encoding schemes, converting them to UTF-8 is a good idea.

Use the iconv command in the libc-bin package to convert the encoding of plain text files.

[debhello] $ iconv -f latin1 -t utf8 foo_in.txt > foo_out.txt

使用 w3m(1) 將 HTML 檔案轉換為 UTF-8 純文字檔案。 執行此操作時,請確保在 UTF-8 語言環境下執行它。

[debhello] $ LC_ALL=C.UTF-8 w3m -o display_charset=UTF-8 \
        -cols 70 -dump -no-graph -T text/html \
        < foo_in.html > foo_out.txt

在 debian/rules 檔案的 override_dh_* 目標中執行這些指令碼。

當您遇到構建問題或者生成的二進位制程式核心轉儲時,您需要自行解決他們。這就是除錯(debug)。

This is too deep a topic to describe here. So, let me just list few pointers and hints for some typical debug tools.

  • Wikipedia: “core dump”

    • “man core”
    • Update the “/etc/security/limits.conf” file to include the following:

      * soft core unlimited
    • “ulimit -c unlimited” in ~/.bashrc
    • “ulimit -a” to check
    • Press Ctrl-\ or “kill -ABRT 'PID'” to make a core dump file
  • gdb - The GNU Debugger

    • “info gdb”
    • “Debugging with GDB” in /usr/share/doc/gdb-doc/html/gdb/index.html
  • strace - 追蹤系統呼叫和訊號

    • 使用 /usr/share/doc/strace/examples/ 中的 strace-graph 指令碼來建立一個好看的樹形圖
    • “man strace”
  • ltrace - 追蹤程式庫呼叫

    • “man ltrace”
  • “sh -n script.sh” - Syntax check of a Shell script
  • “sh -x script.sh” - Trace a Shell script
  • “python3 -m py_compile script.py” - Syntax check of a Python script
  • “python3 -mtrace --trace script.py” - Trace a Python script
  • “perl -I ../libpath -c script.pl” - Syntax check of a Perl script
  • “perl -d:Trace script.pl” - Trace a Perl script

    • 安裝 libterm-readline-gnu-perl 套件或者同類型軟體來新增輸入行編輯功能與歷史記錄支援。
  • lsof - 按程序列出開啟的檔案

    • “man lsof”
[提示]提示

script 命令能幫助記錄控制檯輸出。

[提示]提示

在 ssh 命令中搭配使用 screen 和 tmux 命令,能夠提供安全並且強健的遠端連線終端。

[提示]提示

A Python- and Shell-like REPL (=READ + EVAL + PRINT + LOOP) environment for Perl is offered by the reply command from the libreply-perl (new) package and the re.pl command from the libdevel-repl-perl (old) package.

[提示]提示

The rlwrap and rlfe commands add input line editing capability with history support to any interactive commands. E.g. “rlwrap dash -i'” .