DragonFly BSD

C Development Under DragonFly BSD

C Development Under DragonFly BSD

This is the project page for "Developing for DragonFly BSD with the C programming language.".

This is very much a work in progress . Please check frequently for updates!

At the moment, this outline (especially the part(s) at the end) is not in a logical order. This will need to be discussed.

Please keep these rules in mind when contributing!

This document and contributions to this document are licensed to the DragonFly BSD project under the [C Book License](DragonFly_BSD_License]]. For all other use, please observe the [[/C_Book_License); the DragonFly BSD license does not apply to this external usage. The "DragonFly BSD project" is defined as the collective of individuals who would use this information to better their understanding of the DragonFly BSD operating system.


Those are obsolete now:

?Volume 2: Programming for the DragonFly BSD Userland)

?Volume 3: Developing the DragonFly BSD Kernel)

?Volume 4: Resources for DragonFly BSD Developers)

?Volume 5: Networking and Interprocess Communication in DragonFly BSD)

?Volume 6: Secure Programming Concepts)


Unorganized Info


Discuss the concept of optimization Compiler optimization Useful compiler options Tips for guiding the compiler to make certain optimizations Code profiling Speed of various library functions Overview, exercises and examples

Section Notes


Using the GDB debugger

The GDB (GNU Debugger) gives you the facility to control and examine your program while runtime and after a crash. To compile a program with debugging information, add the compiler flag '-g', be sure to omit optimization flags.

To debug a program, you can either start it in the debugger

% gdb ./a.out
% gdb /usr/bin/gzip
(gdb) run -9 file.txt  

or attach to a running process

(gdb) attach PID

The FSF provides the GDB manual (http://sources.redhat.com/gdb/current/onlinedocs/gdb_toc.html) Debugging malloc

Errors in allocating and deallocating memory in C can lead to strange behaviour of the program. Crashes can occur, a memory leak can degrade system performance and even a heap overflow can threaten the system.

The malloc implementation that is used by DragonFly BSD (phkmalloc) comes with some means of debugging memory allocation: the name of the file referenced by the symbolic link named /etc/malloc.conf the value of the environment variable MALLOC_OPTIONS and the string pointed to by the global variable mallocoptions

will be interpreted, in that order, character by character as flags. See malloc(3) for the flags.

Third Party malloc debuggers

ElectricFence (http://perens.com/FreeSoftware/ElectricFence/) by Bruce Perens can spot overruns of boundaries of memory chunks and read and write access to memory chunks that have been released already.

Valgrind (http://valgrind.kde.org/) is another memory debugger that can detect memory managment bugs

Reading output Dereferencing of variables and areas of memory The usage of breakpoints Backtracing Write abilities

The above seems given and could probably be aptly explained in a mere couple of paragraphs. What other kind of beef can we put in this kind of chapter?

Section Notes

Authors and Contributors

(Listed alphabetically): Samy Al Bahra - Christian Klein - Adrian Nida - Devon H. O'Dell - Simon Schubert - Sascha Wildner

Small improvements: WMD