User Tools

Site Tools


info:development

Development

This page lists some hints and tricks for setting up a development environment.

Editor

I suggest using Vim. It provides many features to edit text and syntax highlighting. On Debian-based systems, install vim-gnome to get the graphical interface gvim.

Default configuration

Vim stores its configuration in ~/.vimrc. This file contains a list of commands. These commands are executed whenever vim starts. The following example enables syntax highlighting, sets tabs to four spaces width, and replaces all tabs by spaces. The autoindent option causes Vim to start the next line with the same indentation the previous line had.

syn on
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent

Eclipse

For many applications, Eclipse is the best editor and IDE. See eclipse for more details.

C/C++ Development

To get help on C functions like printf, install manpages-dev. Having it installed, one can issue man printf on the console to get the function's description.

Variables in C

Make

To simplify building C (or other) projects, make can be used (or any derivative.) A simple make file would be:

program:
	gcc -o program -Wall -g -O1 program.c

Note that commands must start with a tab character.

Working with assembly

Example to disable a function call in a compiled application. Assume the binary is called prog and inside there is a call to a function that needs to be disabled. The tools required are objdump, a hex editor and diff for correctness checking.

  1. Disassemble the whole program:
    $ objdump -D prog > prog.s
  2. Find the function call assuming it is in <main>:
    less prog.s

    and search for main:

    /main

    Something like this should appear:

    080489a4 <main>:
     80489a4:       8d 4c 24 04             lea    0x4(%esp),%ecx
     80489a8:       83 e4 f0                and    $0xfffffff0,%esp
     80489ab:       ff 71 fc                pushl  -0x4(%ecx)
     80489ae:       55                      push   %ebp
     80489af:       89 e5                   mov    %esp,%ebp
  3. Now look for the instruction to be replaced. In our example, we want to get rid of some call. So we look for
     8048a30:       e8 40 0b 00 00          call   8049575 <some_function>
  4. Now the code that needs to be replaced is identified, it is the byte sequence e8 40 0b 00 00. Open a hex editor, and search for this sequence. It is not possible to map the addresses created by objdump to addresses in the binary file, that's why we just have to stick to do a plain search. Make sure that it is the right function call by checking that the surrounding bytes match the ones in the objdump output.
  5. Now replace e8 40 0b 00 00 by 90 90 90 90 90, the Intel command for NOP.
  6. To test if the patch was successful, use
    $ objdump -D prog > prog.s2
    diff prog.s prog.s2

    The output should be something like this:

    <  8048a30:     e8 40 0b 00 00          call   8049575 <some_function>
    ---
    >  8048a30:     90                      nop
    >  8048a31:     90                      nop
    >  8048a32:     90                      nop
    >  8048a33:     90                      nop
    >  8048a34:     90                      nop
  7. Test your program and see if it behaves correctly. All other instructions can be changed using the same mechanism. Be careful not to change something to a wrong value, and always backup between patching. It is very easy to introduce errors that are later hard to correct.

Debian

Restoring installed packages

Debian offers a wide range of packages. Using a system for a longer time causes more and more packages to be installed. At some points in time it may happen that a new system needs to be installed. In this case, it takes a while to install the packages one was used to again, especially as there are a lot of packages with rather cryptic names.

To overcome the problem, here is a script that takes a snapshot of the installed packaged for some system. From the generated file, a Debian package can be created. It depends on all the packages that are manually installed on the current system.

#/bin/sh
 
# generater a lost of installed packages
PKG_LST=$(aptitude search "~i !~M "|awk '{print $2","}'|tr -d "\n")
DATE=-$(date +"%s")
 
cat - <<EOF
### Uncomment to edit them.
Section: misc
Priority: optional
Standards-Version: 3.6.2
 
Package: YOURNAME-environment
Version: 1.0$DATE
Maintainer: your name <user@host.tld>
# Pre-Depends: <comma-separated list of packages>
Depends: $PKG_LST
# Recommends: <comma-separated list of packages>
# Suggests: <comma-separated list of packages>
# Provides: <comma-separated list of packages>
# Replaces: <comma-separated list of packages>
Architecture: all
# Copyright: <copyright file; defaults to GPL2>
# Changelog: <changelog file; defaults to a generic changelog>
# Readme: <README.Debian file; defaults to a generic one>
# Extra-Files: <comma-separated list of additional files for the doc directory>
Description: Moritz Debian customizations
  .
    This package depends on all packages I expect my system to have installed.
EOF

If only one section/archive should be listed, use: !~s_section_ ~A_archive as additional aptitude search parameters. Replace _section_ and _archive_ by something that is appropriate for your system.

Save the file, for example as pkg_lst and make it runnable: chmod 755 pkg_lst. Now, run

./pkg_lst > my-env

followed by

equivs-build my-env

This creates a package, which can now be installed as root:

dpkg -i YOURNAME-environment_1.0_all.deb

To install a new package, edit YOURNAME-env and add the desired package to the Depends: list. Install the package again, and it will complain about unsatisfied dependencies. Just run aptitude to install the dependencies and everything should be fine. This technique can also be used to have the same software environment on a number of machines. TODO: How to setup a Debian repository with own packages.

Moritz's package list

### Uncomment to edit them.
Section: misc
Priority: optional
Standards-Version: 3.6.2

Package: moritz-environment
Version: 1.0
Maintainer: Moritz Hoffmann <...@.....>
# Pre-Depends: <comma-separated list of packages>
Depends: acpi,acpi-support,acpid,adduser,agrep,alien,alsa-base,alsamixergui,anacron,ant,antlr3,aptitude,aspell-de,atop,audacious,autoconf,autotools-dev,bash,cdbs,cdebootstrap,chktex,cpufrequtils,crosshurd,cups,deborphan,default-jdk,dh-make,ding,dissy,dnsutils,doxygen,dvipost,ed,enigmail,fbset,flashplugin-nonfree,galternatives,gcc,gconf-editor,gdb,gimp,gksu,gnome-keyring,gnupg,gpm,grandr,groff-base,grub-pc,gthumb,gv,hdapsd,hexedit,hwinfo,icedove,icedove-gnome-support,iceweasel,ifupdown,indent,info,initscripts,intel-microcode,intltool,iputils-ping,irssi,irssi-scripts,jabref,jfsutils,keepassx,kernel-package,laptop-mode-tools,less,lftp,lha,libdrm-dev,libncurses5-dev,libpam-ssh,libqt3-headers,libsensors3,libtool,libxvmc-dev,linux-image-686,linux-tree-2.6.30,locate,lyx,man-db,manpages,manpages-dev,mc,memtest86+,menu,mimetex,mplayer,nano,network-manager-dev,network-manager-gnome,ntfs-config,ntfsprogs,ntp,ntpdate,octave3.2,openjdk-6-source,openoffice.org,openoffice.org-help-en-us,openssh-server,openttd,orbit2,p7zip-rar,pbuilder,pcmciautils,perl-tk,perlindex,pidgin,pidgin-blinklight,pidgin-facebookchat,popularity-contest,powertop,printconf,procps,quicksynergy,quilt,rpm,rsyslog,screen,sdparm,seahorse,smartmontools,smbclient,smbfs,sshfs,subversion-tools,sudo,synergy,sysv-rc,sysvinit,sysvinit-utils,tasksel,tasksel-data,telnet,texlive,texlive-bibtex-extra,texlive-doc-de,texlive-doc-en,texlive-fonts-extra,texlive-lang-german,texlive-math-extra,tightvncserver,tk-dev,tp-smapi-modules-2.6-686,traceroute,udev,unrar,userinfo,vim-gtk,vino,vpnc,wget,whois,wpasupplicant,x11proto-gl-dev,x11proto-xf86dri-dev,x86dis,xchat,xfce4,xfce4-goodies,xfce4-hdaps,xfce4-volumed,xgdvi,xine-ui,xorg-docs,xsane,xserver-xorg-dev,xtightvncviewer,xutils-dev,zenmap,zsh,
# Recommends: <comma-separated list of packages>
# Suggests: <comma-separated list of packages>
# Provides: <comma-separated list of packages>
# Replaces: <comma-separated list of packages>
Architecture: all
# Copyright: <copyright file; defaults to GPL2>
# Changelog: <changelog file; defaults to a generic changelog>
# Readme: <README.Debian file; defaults to a generic one>
# Extra-Files: <comma-separated list of additional files for the doc directory>
Description: Moritz Debian customizations
  .
    This package depends on all packages I expect my system to have installed.

Lotus Notes on Debian

At some point in time, Debian decided to rename libcupsys to libcups, breaking Note's dependencies. To make it run with the new library, create a dummy library libcupsys2 that depends on libcups2 and creates a symlink from libcups.so.2 to libcupsys.so.2.

info/development.txt · Last modified: 2011/08/23 16:42 by moritz