Daftar Isi
I provide some pointers for people to learn programming on the Debian system enough to trace the packaged source code. Here are notable packages and corresponding documentation packages for programming.
Online references are available by typing "man name
"
after installing manpages
and
manpages-dev
packages. Online references for the GNU
tools are available by typing "info program_name
" after
installing the pertinent documentation packages. You may need to include
the contrib
and non-free
archives in
addition to the main
archive since some GFDL
documentations are not considered to be DFSG compliant.
Please consider to use version control system tools. See Bagian 10.5, “Git”.
![]() |
Awas |
---|---|
Do not use " |
![]() |
Perhatian |
---|---|
You should install software programs directly compiled from source into
" |
![]() |
Tip |
---|---|
Code examples of creating "Song 99 Bottles of Beer" should give you good ideas of practically all the programming languages. |
The shell script is a text file with the execution bit set and contains the commands in the following format.
#!/bin/sh ... command lines
The first line specifies the shell interpreter which read and execute this file contents.
Reading shell scripts is the best way to understand how a Unix-like system works. Here, I give some pointers and reminders for shell programming. See "Shell Mistakes" (http://www.greenend.org.uk/rjk/2001/04/shell.html) to learn from mistakes.
Tidak seperti mode interaktif shell (lihat Bagian 1.5, “Perintah shell sederhana” dan Bagian 1.6, “Pemrosesan teks mirip Unix”), skrip shell sering menggunakan parameter, kondisional, dan loop.
Banyak skrip sistem dapat diinterpretasi oleh salah satu shell POSIX (lihat Tabel 1.13, “Daftar program shell”).
The default non-interactive POSIX shell "/bin/sh
" is a
symlink pointing to /usr/bin/dash
and used by many system
programs.
The default interactive POSIX shell is /usr/bin/bash
.
Avoid writing a shell script with bashisms or zshisms to make it portable among all POSIX
shells. You can check it using checkbashisms
(1).
Tabel 12.1. List of typical bashisms
Baik: POSIX | Hindari: bashisme |
---|---|
if [ "$foo" = "$bar" ] ; then … |
if [ "$foo" == "$bar" ] ; then … |
diff -u file.c.orig file.c |
diff -u file.c{.orig,} |
mkdir /foobar /foobaz |
mkdir /foo{bar,baz} |
funcname() { … } |
function funcname() { … } |
format oktal: "\377 " |
format heksadesimal: "\xff " |
The "echo
" command must be used with following cares
since its implementation differs among shell builtin and external commands.
Avoid using any command options except "-n
".
Avoid using escape sequences in the string since their handling varies.
![]() |
Catatan |
---|---|
Although " |
![]() |
Tip |
---|---|
Use the " |
Special shell parameters are frequently used in the shell script.
Tabel 12.2. Daftar parameter shell
parameter shell | nilai |
---|---|
$0 |
nama shell atau skrip shell |
$1 |
argumen shell pertama |
$9 |
argumen shell kesembilan |
$# |
cacah parameter posisional |
"$*" |
"$1 $2 $3 $4 … " |
"[email protected]" |
"$1" "$2" "$3" "$4" … |
$? |
status keluar dari perintah terkini |
$$ |
PID dari skrip shell ini |
$! |
PID dari pekerjaan latar belakang yang baru-baru ini dimulai |
Basic parameter expansions to remember are as follows.
Tabel 12.3. Daftar ekspansi parameter shell
bentuk ekspresi parameter | value if var is set |
value if var is not set |
---|---|---|
${var:-string} |
"$var " |
"string " |
${var:+string} |
"string " |
"null " |
${var:=string} |
"$var " |
"string " (and run "var=string ") |
${var:?string} |
"$var " |
echo "string " to stderr (and exit with error) |
Here, the colon ":
" in all of these operators is actually
optional.
with ":
" = operator
test for exist and not null
without ":
" = operator
test for exist only
Tabel 12.4. List of key shell parameter substitutions
parameter substitution form | hasil |
---|---|
${var%suffix} |
remove smallest suffix pattern |
${var%%suffix} |
remove largest suffix pattern |
${var#prefix} |
remove smallest prefix pattern |
${var##prefix} |
remove largest prefix pattern |
Each command returns an exit status which can be used for conditional expressions.
Success: 0 ("True")
Error: non 0 ("False")
![]() |
Catatan |
---|---|
"0" in the shell conditional context means "True", while "0" in the C conditional context means "False". |
![]() |
Catatan |
---|---|
" |
Basic conditional idioms to remember are the following.
"command &&
if_success_run_this_command_too || true
"
"command ||
if_not_success_run_this_command_too || true
"
A multi-line script snippet as the following
if [ conditional_expression ]; then if_success_run_this_command else if_not_success_run_this_command fi
Here trailing "|| true
" was needed to ensure this shell
script does not exit at this line accidentally when shell is invoked with
"-e
" flag.
Tabel 12.5. List of file comparison operators in the conditional expression
persamaan | kondisi yang mengembalikan logis benar (true) |
---|---|
-e berkas |
berkas ada |
-d berkas |
berkas ada dan berupa direktori |
-f berkas |
berkas ada dan berupa berkas biasa |
-w berkas |
berkas ada dan dapat ditulis |
-x berkas |
berkas ada dan dapat dieksekusi |
berkas1 -nt
berkas2 |
berkas1 lebih baru dari berkas2 (modifikasi) |
berkas1 -ot
berkas2 |
berkas1 lebih tua dari berkas2 (modifikasi) |
berkas1 -ef
berkas2 |
berkas1 dan berkas2 berada di perangkat yang sama dan nomor inode yang sama |
Tabel 12.6. Daftar operator perbandingan string dalam ekspresi bersyarat
persamaan | kondisi yang mengembalikan logis benar (true) |
---|---|
-z str |
panjang str adalah nol |
-n str |
panjang str adalah bukan nol |
str1 = str2 |
str1 dan str2 adalah sama |
str1 != str2 |
str1 dan str2 tidak sama |
str1 < str2 |
str1 diurut sebelum str2 (tergantung lokal) |
str1 > str2 |
str1 diurut setelah str2 (tergantung lokal) |
Arithmetic integer comparison operators
in the conditional expression are "-eq
",
"-ne
", "-lt
",
"-le
", "-gt
", and
"-ge
".
Ada beberapa idiom pengulangan untuk digunakan dalam shell POSIX.
"for x in foo1 foo2 … ; do perintah ; done
" mengulang
dengan menetapkan butir dari daftar "foo1 foo2 …
" ke
variabel "x
" dan mengeksekusi
"perintah
".
"while condition ; do perintah ; done
" mengulangi
"perintah
" saat "kondisi
" adalah
benar.
"until condition ; do perintah ; done
" mengulangi
"perintah
" saat "kondisi
" tidak benar.
"break
" memungkinkan untuk keluar dari pengulangan.
"continue
" memungkinkan untuk melanjutkan iterasi
pengulangan berikutnya.
![]() |
Tip |
---|---|
The C-language like numeric iteration can be
realized by using |
Some popular environment variables for the normal shell command prompt may not be available under the execution environment of your script.
Untuk "$USER
", gunakan "$(id -un)
"
Untuk "$UID
", gunakan "$(id -u)
"
Untuk "$HOME
", gunakan "$(getent passwd "$(id
-u)"|cut -d ":" -f 6)
" (ini juga berfungsi pada Bagian 4.5.2, “Manajemen sistem terpusat modern”)
Shell memproses skrip kira-kira sebagai urutan berikut.
Shell membaca satu baris.
The shell groups a part of the line as one
token if it is within "…"
or
'…'
.
The shell splits other part of a line into tokens by the following.
Whitespaces: space tab
newline
Karakter meta: | ; & ( )
The shell checks the reserved word for
each token to adjust its behavior if not within "…"
or
'…'
.
reserved word: if then elif else
fi for in while unless do done case esac
The shell expands alias if not within
"…"
or '…'
.
The shell expands tilde if not within
"…"
or '…'
.
"~
" → direktori rumah pengguna saat ini
"~~pengguna
" → direktori rumah
pengguna
The shell expands parameter to its value
if not within '…'
.
parameter:
"$PARAMETER
" or "${PARAMETER}
"
The shell expands command substitution if
not within '…'
.
"$( command )
" → the output of
"command
"
"` command `
" → the output of
"command
"
The shell expands pathname glob to
matching file names if not within "…"
or
'…'
.
*
→ sebarang karakter
?
→ satu karakter
[…]
→ any one of the characters in "…
"
The shell looks up command from the following and execute it.
definisi fungsi
perintah builtin
executable file in
"$PATH
"
Shell pergi ke baris berikutnya dan mengulangi proses ini lagi dari puncak urutan ini.
Kutip tunggal dalam kutip ganda tidak berpengaruh.
Executing "set -x
" in the shell or invoking the shell
with "-x
" option make the shell to print all of commands
executed. This is quite handy for debugging.
In order to make your shell program as portable as possible across Debian systems, it is a good idea to limit utility programs to ones provided by essential packages.
"aptitude search ~E
" menampilkan daftar paket-paket
penting.
"dpkg -L package_name |grep
'/man/man.*/'
" lists manpages for commands offered by
package_name
package.
Tabel 12.7. List of packages containing small utility programs for shell scripts
paket | popcon | ukuran | deskripsi |
---|---|---|---|
dash
|
V:896, I:994 | 222 | small and fast POSIX-compliant shell for sh |
coreutils
|
V:898, I:999 | 17372 | Utilitas inti GNU |
grep
|
V:815, I:999 | 1118 | GNU grep , egrep , dan
fgrep |
sed
|
V:804, I:999 | 912 | GNU sed |
mawk
|
V:392, I:997 | 247 | awk yang kecil dan cepat |
debianutils
|
V:924, I:999 | 242 | utilitas lain-lain khusus untuk Debian |
bsdutils
|
V:646, I:999 | 419 | utilitas dasar dari 4.4BSD-Lite |
bsdextrautils
|
V:304, I:392 | 422 | utilitas tambahan dari 4.4BSD-Lite |
moreutils
|
V:12, I:37 | 244 | utilitas Unix tambahan |
![]() |
Tip |
---|---|
Although |
Lihat Bagian 1.6, “Pemrosesan teks mirip Unix” misalnya.
Tabel 12.8. List of interpreter related packages
paket | popcon | ukuran | dokumentasi |
---|---|---|---|
dash
|
V:896, I:994 | 222 | sh: small and fast POSIX-compliant shell for
sh |
bash
|
V:803, I:999 | 6450 | sh: "info bash " provided by
bash-doc |
mawk
|
V:392, I:997 | 247 | AWK: small and fast awk |
gawk
|
V:334, I:417 | 2456 | AWK: "info gawk " provided by
gawk-doc |
perl
|
V:611, I:991 | 719 | Perl: perl (1) and html pages
provided by perl-doc and perl-doc-html |
libterm-readline-gnu-perl
|
V:2, I:29 | 380 | Perl extension for the GNU ReadLine/History Library:
perlsh (1) |
libreply-perl
|
V:0, I:0 | 170 | REPL untuk Perl: reply (1) |
libdevel-repl-perl
|
V:0, I:0 | 237 | REPL untuk Perl: re.pl (1) |
python3
|
V:694, I:917 | 90 | Python: python3 (1) and html
pages provided by python3-doc |
tcl
|
V:26, I:318 | 22 | Tcl: tcl (3) and detail manual
pages provided by tcl-doc |
tk
|
V:26, I:310 | 22 | Tk: tk (3) and detail manual
pages provided by tk-doc |
ruby
|
V:102, I:279 | 35 | Ruby: ruby (1),
erb (1), irb (1),
rdoc (1), ri (1) |
When you wish to automate a task on Debian, you should script it with an interpreted language first. The guide line for the choice of the interpreted language is:
Use dash
, if the task is a simple one which combines CLI
programs with a shell program.
Use python3
, if the task isn't a simple one and you are
writing it from scratch.
Use perl
, tcl
,
ruby
, ... if there is an existing code using one of these
languages on Debian which needs to be touched up to do the task.
If the resulting code is too slow, you can rewrite only the critical portion for the execution speed in a compiled language and call it from the interpreted language.
Most interpreters offer basic syntax check and code tracing functionalities.
"dash -n script.sh" - Pemeriksaan sintaks dari suatu skrip Shell
"dash -x script.sh"" - Melacak suatu skrip Shell
"python -m py_compile script.py"" - Pemeriksaan sintaks skrip Python
"python -mtrace --trace script.py"" - Melacak suatu skrip Python
"perl -I .. /libpath -c script.pl"" - Pemeriksaan sintaks dari suatu skrip Perl
"perl -d:Trace script.pl" - Melacak suatu skrip Perl
For testing code for dash
, try Bagian 9.1.4, “Pembungkus readline” which accommodates
bash
-like interactive environment.
For testing code for perl
, try REPL environment for Perl
which accommodates Python-like REPL (=READ + EVAL + PRINT + LOOP)
environment for Perl.
The shell script can be improved to create an attractive GUI program. The
trick is to use one of so-called dialog programs instead of dull interaction
using echo
and read
commands.
Tabel 12.9. Daftar program dialog
paket | popcon | ukuran | deskripsi |
---|---|---|---|
x11-utils
|
V:169, I:581 | 712 | xmessage (1): menampilkan pesan atau kueri di jendela (X) |
whiptail
|
V:253, I:996 | 71 | menampilkan kotak dialog yang mudah digunakan dari skrip shell (newt) |
dialog
|
V:13, I:114 | 1217 | menampilkan kotak dialog yang mudah digunakan dari skrip shell (ncurses) |
zenity
|
V:71, I:381 | 167 | menampilkan kotak dialog grafis dari skrip shell (GTK) |
ssft
|
V:0, I:0 | 75 | Shell Scripts Frontend Tool (wrapper for zenity, kdialog, and dialog with gettext) |
gettext
|
V:49, I:292 | 5843 | "/usr/bin/gettext.sh ": terjemahkan pesan |
Berikut adalah contoh program GUI untuk menunjukkan betapa mudahnya itu hanya dengan suatu skrip shell.
Skrip ini menggunakan zenity
untuk memilih berkas (baku
/etc/motd)
dan menampilkannya.
Peluncur GUI untuk skrip ini dapat dibuat berikut Bagian 9.4.10, “Memulai program dari GUI”.
#!/bin/sh -e
# Copyright (C) 2021 Osamu Aoki <[email protected]>, Public Domain
# vim:set sw=2 sts=2 et:
DATA_FILE=$(zenity --file-selection --filename="/etc/motd" --title="Select a file to check") || \
( echo "E: File selection error" >&2 ; exit 1 )
# Check size of archive
if ( file -ib "$DATA_FILE" | grep -qe '^text/' ) ; then
zenity --info --title="Check file: $DATA_FILE" --width 640 --height 400 \
--text="$(head -n 20 "$DATA_FILE")"
else
zenity --info --title="Check file: $DATA_FILE" --width 640 --height 400 \
--text="The data is MIME=$(file -ib "$DATA_FILE")"
fi
This kind of approach to GUI program with the shell script is useful only for simple choice cases. If you are to write any program with complexities, please consider writing it on more capable platform.
GUI filer programs can be extended to perform some popular actions on selected files using additional extension packages. They can also made to perform very specific custom actions by adding your specific scripts.
Untuk GNOME, lihat NautilusScriptsHowto.
Untuk KDE, lihat Membuat Menu Layanan Dolphin.
Untuk Xfce, lihat Thunar - Tindakan Ubahan dan https://help.ubuntu.com/community/ThunarCustomActions.
Untuk LXDE, lihat Tindakan Ubahan.
Untuk memproses data, sh
perlu men-spawn sub-proses yang
menjalankan cut
, grep
,
sed
, dll, dan lambat. Di sisi lain,
perl
memiliki kemampuan internal untuk memroses data, dan
cepat. Begitu banyak skrip pemeliharaan sistem pada Debian menggunakan
perl
.
Mari kita pikirkan untuk mengikuti cuplikan skrip AWK satu-baris dan yang setara di Perl.
awk '($2=="1957") { print $3 }' |
Ini setara dengan salah satu dari baris berikut.
perl -ne '@f=split; if ($f[1] eq "1957") { print "$f[2]\n"}' |
perl -ne 'if ((@f=split)[1] eq "1957") { print "$f[2]\n"}' |
perl -ne '@f=split; print $f[2] if ( $f[1]==1957 )' |
perl -lane 'print $F[2] if $F[1] eq "1957"' |
perl -lane 'print$F[2]if$F[1]eq+1957' |
Yang terakhir adalah teka-teki. Itu mengambil keuntungan dari mengikuti fitur Perl.
The whitespace is optional.
Konversi otomatis ada dari angka ke string.
Trik eksekusi perl melalui opsi baris perintah:
perlrun
(1)
Variabel khusus Perl: perlvar
(1)
Fleksibilitas ini adalah kekuatan Perl. Pada saat yang sama, ini memungkinkan kita untuk membuat kode sulit dibaca dan kusut. Jadi berhati-hatilah.
Untuk skrip Perl yang lebih gila, Perl Golf mungkin menarik.
Tabel 12.10. Daftar paket terkait kompiler
paket | popcon | ukuran | deskripsi |
---|---|---|---|
gcc
|
V:145, I:580 | 45 | Kompiler GNU C |
libc6-dev
|
V:233, I:596 | 13859 | GNU C Library: Pustaka Pengembangan dan Berkas Header |
g++
|
V:59, I:510 | 15 | Kompiler GNU C++ |
libstdc++-10-dev
|
V:31, I:200 | 17575 | GNU Standard C++ Library v3 (berkas pengembangan) |
cpp
|
V:322, I:748 | 42 | GNU C preprocessor |
gettext
|
V:49, I:292 | 5843 | GNU Internationalization utilities |
glade
|
V:0, I:7 | 1332 | GTK User Interface Builder |
valac
|
V:0, I:6 | 713 | C# like language for the GObject system |
flex
|
V:8, I:85 | 1279 | LEX-compatible fast lexical analyzer generator |
bison
|
V:9, I:94 | 3111 | YACC-compatible parser generator |
susv2
|
I:0 | 16 | fetch "The Single UNIX Specifications v2" |
susv3
|
I:0 | 16 | fetch "The Single UNIX Specifications v3" |
golang
|
I:21 | 12 | Kompiler bahasa pemrograman Go |
rustc
|
V:2, I:13 | 9018 | Bahasa pemrograman sistem Rust |
haskell-platform
|
I:5 | 12 | Standard Haskell libraries and tools |
gfortran
|
V:10, I:86 | 16 | Kompiler GNU Fortran 95 |
fpc
|
I:3 | 121 | Free Pascal |
Here, Bagian 12.3.3, “Flex - Lex yang lebih baik” and Bagian 12.3.4, “Bison - Yacc yang lebih baik” are included to indicate how compiler-like program can be written in C language by compiling higher level description into C language.
You can set up proper environment to compile programs written in the C programming language by the following.
# apt-get install glibc-doc manpages-dev libc6-dev gcc build-essential
The libc6-dev
package, i.e., GNU C Library, provides
C standard library which is
collection of header files and library routines used by the C programming
language.
See references for C as the following.
"info libc
" (C library function reference)
gcc
(1) dan "info gcc
"
each_C_library_function_name
(3)
Kernighan & Ritchie, "The C Programming Language", 2nd edition (Prentice Hall)
A simple example "example.c
" can compiled with a library
"libm
" into an executable
"run_example
" by the following.
$ cat > example.c << EOF #include <stdio.h> #include <math.h> #include <string.h> int main(int argc, char **argv, char **envp){ double x; char y[11]; x=sqrt(argc+7.5); strncpy(y, argv[0], 10); /* prevent buffer overflow */ y[10] = '\0'; /* fill to make sure string ends with '\0' */ printf("%5i, %5.3f, %10s, %10s\n", argc, x, y, argv[1]); return 0; } EOF $ gcc -Wall -g -o run_example example.c -lm $ ./run_example 1, 2.915, ./run_exam, (null) $ ./run_example 1234567890qwerty 2, 3.082, ./run_exam, 1234567890qwerty
Here, "-lm
" is needed to link library
"/usr/lib/libm.so
" from the libc6
package for sqrt
(3). The actual library is in
"/lib/
" with filename "libm.so.6
",
which is a symlink to "libm-2.7.so
".
Look at the last parameter in the output text. There are more than 10
characters even though "%10s
" is specified.
The use of pointer memory operation functions without boundary checks, such
as sprintf
(3) and strcpy
(3), is
deprecated to prevent buffer overflow exploits that leverage the above
overrun effects. Instead, use snprintf
(3) and
strncpy
(3).
Flex is a Lex-compatible fast lexical analyzer generator.
Tutorial for flex
(1) can be found in "info
flex
".
You need to provide your own "main()
" and
"yywrap()
". Otherwise, your flex program should look
like this to compile without a library. This is because that
"yywrap
" is a macro and "%option main
"
turns on "%option noyywrap
" implicitly.
%option main %% .|\n ECHO ; %%
Alternatively, you may compile with the "-lfl
" linker
option at the end of your cc
(1) command line (like
AT&T-Lex with "-ll
"). No
"%option
" is needed in this case.
Several packages provide a Yacc-compatible lookahead LR parser or LALR parser generator in Debian.
Tutorial for bison
(1) can be found in "info
bison
".
You need to provide your own "main()
" and
"yyerror()
". "main()
" calls
"yyparse()
" which calls "yylex()
",
usually created with Flex.
%% %%
Lint like tools can help automatic static code analysis.
Indent like tools can help human code reviews by reformatting source codes consistently.
Ctags like tools can help human code reviews by generating an index (or tag) file of names found in source codes.
![]() |
Tip |
---|---|
Configuring your favorite editor ( |
Tabel 12.12. Daftar alat untuk analisis kode statis
paket | popcon | ukuran | deskripsi |
---|---|---|---|
vim-ale
|
I:0 | 2167 | Asynchronous Lint Engine for Vim 8 and NeoVim |
vim-syntastic
|
I:3 | 1240 | Syntax checking hacks for vim |
elpa-flycheck
|
V:0, I:1 | 792 | modern on-the-fly syntax checking for Emacs |
elpa-relint
|
I:0 | 133 | Emacs Lisp regexp mistake finder |
cppcheck-gui
|
V:0, I:1 | 6253 | tool for static C/C++ code analysis (GUI) |
shellcheck
|
V:2, I:10 | 15883 | lint tool for shell scripts |
pyflakes3
|
V:0, I:15 | 23 | passive checker of Python 3 programs |
pylint
|
V:4, I:17 | 1653 | Pemeriksa statis kode python |
perl
|
V:611, I:991 | 719 | interpreter with internal static code checker:
B::Lint (3perl) |
rubocop
|
V:0, I:0 | 2390 | Penganalisis kode statis Ruby |
clang-tidy
|
V:1, I:7 | 25 | clang-based C++ linter tool |
splint
|
V:0, I:3 | 2320 | tool for statically checking C programs for bugs |
flawfinder
|
V:0, I:0 | 205 | tool to examine C/C++ source code and looks for security weaknesses |
black
|
V:1, I:6 | 559 | uncompromising Python code formatter |
perltidy
|
V:0, I:5 | 2101 | Perl script indenter and reformatter |
indent
|
V:0, I:11 | 425 | C language source code formatting program |
astyle
|
V:0, I:3 | 761 | Source code indenter for C, C++, Objective-C, C#, and Java |
bcpp
|
V:0, I:0 | 110 | C(++) beautifier |
xmlindent
|
V:0, I:1 | 53 | Pemformat ulang stream XML |
global
|
V:0, I:3 | 1896 | Alat pencarian dan penelusuran kode sumber |
exuberant-ctags
|
V:4, I:29 | 345 | membangun indeks berkas tag atas definisi kode sumber |
Debug is important part of programming activities. Knowing how to debug programs makes you a good Debian user who can produce meaningful bug reports.
Primary debugger on Debian is
gdb
(1) which enables you to inspect a program while it
executes.
Let's install gdb
and related programs by the following.
# apt-get install gdb gdb-doc build-essential devscripts
Good tutorial of gdb
can be found:
“info gdb
”
"Debugging dengan GDB" di
/usr/share/doc/gdb-doc/html/gdb/index.html
Here is a simple example of using gdb
(1) on a
"program
" compiled with the "-g
"
option to produce debugging information.
$ gdb program (gdb) b 1 # set break point at line 1 (gdb) run args # run program with args (gdb) next # next line ... (gdb) step # step forward ... (gdb) p parm # print parm ... (gdb) p parm=12 # set value to 12 ... (gdb) quit
![]() |
Tip |
---|---|
Many |
Since all installed binaries should be stripped on the Debian system by
default, most debugging symbols are removed in the normal package. In order
to debug Debian packages with gdb
(1),
*-dbgsym
packages need to be installed
(e.g. coreutils-dbgsym
in the case of
coreutils
). The source packages generate
*-dbgsym
packages automatically along with normal binary
packages and those debug packages are placed separately in debian-debug archive. Please refer to articles on Debian Wiki for more
information.
If a package to be debugged does not provide its *-dbgsym
package, you need to install it after rebuilding it by the following.
$ mkdir /path/new ; cd /path/new $ sudo apt-get update $ sudo apt-get dist-upgrade $ sudo apt-get install fakeroot devscripts build-essential $ apt-get source package_name $ cd package_name* $ sudo apt-get build-dep ./
Perbaiki bug jika diperlukan.
Bump package version to one which does not collide with official Debian
versions, e.g. one appended with "+debug1
" when
recompiling existing package version, or one appended with
"~pre1
" when compiling unreleased package version by the
following.
$ dch -i
Compile and install packages with debug symbols by the following.
$ export DEB_BUILD_OPTIONS="nostrip noopt" $ debuild $ cd .. $ sudo debi package_name*.changes
You need to check build scripts of the package and ensure to use
"CFLAGS=-g -Wall
" for compiling binaries.
When you encounter program crash, reporting bug report with cut-and-pasted backtrace information is a good idea.
The backtrace can be obtained by gdb
(1) using one of the
following approaches:
Crash-in-GDB approach:
Jalankan program dari GDB.
Crash the program.
Type "bt
" at the GDB prompt.
Crash-first approach:
Update the “/etc/security/limits.conf” file to include the following:
* soft core unlimited
Type "ulimit -c unlimited
" to the shell prompt.
Menjalankan program dari prompt shell ini.
Crash the program to produce a core dump file.
Load the core dump file to GDB as
"gdb gdb ./program_binary core
" .
Type "bt
" at the GDB prompt.
For infinite loop or frozen keyboard situation, you can force to crash the
program by pressing Ctrl-\
or Ctrl-C
or executing “kill -ABRT PID
”. (See
Bagian 9.4.12, “Membunuh sebuah proses”)
![]() |
Tip |
---|---|
Often, you see a backtrace where one or more of the top lines are in
" $ MALLOC_CHECK_=2 gdb hello |
Tabel 12.14. Daftar perintah gdb tingkat lanjut
perintah | deskripsi untuk tujuan perintah |
---|---|
(gdb) thread apply all bt |
get a backtrace for all threads for multi-threaded program |
(gdb) bt full |
get parameters came on the stack of function calls |
(gdb) thread apply all bt full |
get a backtrace and parameters as the combination of the preceding options |
(gdb) thread apply all bt full 10 |
get a backtrace and parameters for top 10 calls to cut off irrelevant output |
(gdb) set logging on |
write log of gdb output to a file (the default is
"gdb.txt ") |
Use ldd
(1) to find out a program's dependency on
libraries by the followings.
$ ldd /bin/ls librt.so.1 => /lib/librt.so.1 (0x4001e000) libc.so.6 => /lib/libc.so.6 (0x40030000) libpthread.so.0 => /lib/libpthread.so.0 (0x40153000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
For ls
(1) to work in a `chroot`ed environment, the above
libraries must be available in your `chroot`ed environment.
There are several dynamic call tracing tools available in Debian. See Bagian 9.4, “Memantau, mengendalikan, dan memulai aktivitas program”.
If a GNOME program preview1
has received an X error, you
should see a message as follows.
The program 'preview1' received an X Window System error.
If this is the case, you can try running the program with
"--sync
", and break on the
"gdk_x_error
" function in order to obtain a backtrace.
Ada beberapa alat deteksi kebocoran memori yang tersedia di Debian.
Tabel 12.15. Daftar alat deteksi kebocoran memori
paket | popcon | ukuran | deskripsi |
---|---|---|---|
libc6-dev
|
V:233, I:596 | 13859 | mtrace (1): fungsi debugging malloc di glibc |
valgrind
|
V:6, I:43 | 77249 | memory debugger and profiler |
electric-fence
|
V:0, I:5 | 72 | malloc (3) debugger |
libdmalloc5
|
V:0, I:3 | 393 | debug pustaka alokasi memori |
duma
|
V:0, I:0 | 293 | library to detect buffer overruns and under-runs in C and C++ programs |
leaktracer
|
V:0, I:2 | 57 | pelacak kebocoran memori untuk program C++ |
Tabel 12.16. Daftar paket alat build
paket | popcon | ukuran | dokumentasi |
---|---|---|---|
make
|
V:133, I:588 | 1592 | "info make " disediakan oleh make-doc |
autoconf
|
V:29, I:270 | 2033 | "info autoconf " disediakan oleh
autoconf-doc |
automake
|
V:28, I:268 | 1836 | "info automake " disediakan oleh
automake1.10-doc |
libtool
|
V:22, I:253 | 1198 | "info libtool " disediakan oleh
libtool-doc |
cmake
|
V:17, I:118 | 26660 | cmake (1) sistem make open-source yang lintas platform |
ninja-build
|
V:5, I:31 | 347 | ninja (1) sistem build kecil yang paling dekat dalam
semangat ke Make |
meson
|
V:2, I:19 | 3255 | meson (1) sistem build produktivitas tinggi di atas
ninja |
xutils-dev
|
V:1, I:10 | 1485 | imake (1), xmkmf (1), etc. |
Make is a utility to maintain groups of
programs. Upon execution of make
(1),
make
read the rule file, "Makefile
",
and updates a target if it depends on prerequisite files that have been
modified since the target was last modified, or if the target does not
exist. The execution of these updates may occur concurrently.
Sintaks berkas aturan adalah sebagai berikut.
target: [ prerequisites ... ] [TAB] command1 [TAB] -command2 # ignore errors [TAB] @command3 # suppress echoing
Here "[TAB]
" is a TAB code. Each line is interpreted by
the shell after make variable substitution. Use "\
" at
the end of a line to continue the script. Use "$$
" to
enter "$
" for environment values for a shell script.
Implicit rules for the target and prerequisites can be written, for example, by the following.
%.o: %.c header.h
Here, the target contains the character "%
" (exactly one
of them). The "%
" can match any nonempty substring in the
actual target filenames. The prerequisites likewise use
"%
" to show how their names relate to the actual target
name.
Tabel 12.17. Daftar variabel otomatis make
variabel otomatis | nilai |
---|---|
[email protected] |
target |
$< |
prasyarat pertama |
$? |
semua prasyarat yang lebih baru |
$^ |
semua prasyarat |
$* |
"% " matched stem in the target pattern |
Tabel 12.18. Daftar ekspansi variabel make
ekspansi variabel | deskripsi |
---|---|
foo1 := bar |
ekspansi satu kali |
foo2 = bar |
ekspansi rekursif |
foo3 += bar |
append |
Jalankan "make -p -f/dev/null
" untuk melihat aturan
internal otomatis.
Autotools is a suite of programming tools designed to assist in making source code packages portable to many Unix-like systems.
Autoconf is a tool to produce a shell script
"configure
" from "configure.ac
".
"configure
" is used later to produce
"Makefile
" from "Makefile.in
"
template.
Automake is a tool to produce
"Makefile.in
" from "Makefile.am
".
Libtool is a shell script to address the software portability problem when compiling shared libraries from source code.
![]() |
Awas |
---|---|
Jangan menimpa berkas sistem dengan program yang dikompilasi saat menginstalnya. |
Debian does not touch files in "/usr/local/
" or
"/opt
". So if you compile a program from source, install
it into "/usr/local/
" so it does not interfere with
Debian.
$ cd src $ ./configure --prefix=/usr/local $ make # this compiles program $ sudo make install # this installs the files in the system
If you have the original source and if it uses
autoconf
(1)/automake
(1) and if you can
remember how you configured it, execute as follows to uninstall the program.
$ ./configure all-of-the-options-you-gave-it
$ sudo make uninstall
Alternatively, if you are absolutely sure that the install process puts
files only under "/usr/local/
" and there is nothing
important there, you can erase all its contents by the following.
# find /usr/local -type f -print0 | xargs -0 rm -f
If you are not sure where files are installed, you should consider using
checkinstall
(8) from the checkinstall
package, which provides a clean path for the uninstall. It now supports to
create a Debian package with "-D
" option.
The software build system has been evolving:
Autotools on the top of Make has been the de facto standard for the portable build infrastructure since 1990s. This is extremely slow.
CMake initially released in 2000 improved speed significantly but was still build on the top of inherently slow Make.
Ninja initially released in 2012 is meant to replace Make for the further improved build speed but is also designed to have its input files generated by a higher-level build system.
Meson initially released in 2013 is the new popular and fast higher-level build system which uses Ninja as its backend.
See documents found at "The Meson Build system" and "The Ninja build system".
Basic interactive dynamic web pages can be made as follows.
Queries are presented to the browser user using HTML forms.
Filling and clicking on the form entries sends one of the following URL string with encoded parameters from the browser to the web server.
"http://www.foo.dom/cgi-bin/program.pl?VAR1=VAL1&VAR2=VAL2&VAR3=VAL3
"
"http://www.foo.dom/cgi-bin/program.py?VAR1=VAL1&VAR2=VAL2&VAR3=VAL3
"
"http://www.foo.dom/program.php?VAR1=VAL1&VAR2=VAL2&VAR3=VAL3
"
"%nn
" in URL is replaced with a character with
hexadecimal nn
value.
The environment variable is set as: "QUERY_STRING="VAR1=VAL1
VAR2=VAL2 VAR3=VAL3"
".
CGI program (any one of
"program.*
") on the web server executes itself with the
environment variable "$QUERY_STRING
".
stdout
of CGI program is sent to the web browser and is
presented as an interactive dynamic web page.
For security reasons it is better not to hand craft new hacks for parsing CGI parameters. There are established modules for them in Perl and Python. PHP comes with these functionalities. When client data storage is needed, HTTP cookies are used. When client side data processing is needed, Javascript is frequently used.
For more, see the Common Gateway Interface, The Apache Software Foundation, and JavaScript.
Searching "CGI tutorial" on Google by typing encoded URL http://www.google.com/search?hl=en&ie=UTF-8&q=CGI+tutorial directly to the browser address is a good way to see the CGI script in action on the Google server.
Jika Anda ingin membuat paket Debian, baca berikut ini.
Bab 2, Manajemen paket Debian untuk memahami sistem paket dasar
Bagian 2.7.13, “Mem-port paket ke sistem stable” untuk memahami proses porting dasar
Bagian 9.11.4, “Sistem chroot” untuk memahami teknik chroot dasar
debuild
(1), dan sbuild
(1)
Bagian 12.5.2, “Debugging paket Debian” untuk kompilasi ulang untuk pengawakutuan (debugging)
Panduan untuk Pemelihara
Debian (paket debmake-doc
)
Referensi Pengembang Debian
(paket developers-reference
)
Manual Kebijakan Debian (paket
debian-policy
)
Ada paket seperti debmake
, dh-make
,
dh-make-perl
, dll., yang membantu pengemasan.