Makefile template
[ link: makefile-template | tags: c code make | updated: Sun, 22 Jul 2007 15:21:36 ]
Someone on #oclug was asking about building C programs with make. I wrote up this simple Makefile for him.
vim and linux CodingStyle
[ link: vim-and-linux-coding-style | tags: vim linux kernel c code | updated: Sat, 16 Jun 2007 21:03:49 ]
It would seem that either no one that codes for the Linux kernel does so under vim, or if they do they don't have the time to share their vim configuration that doesn't conflict with the kernel's CodingStyle.
Below I will discuss some changes I had to make to my .vimrc and .vim/c.vim to work with C efficiently.
C style
[ link: c-style | tags: code linux c | updated: Mon, 18 Dec 2006 10:19:30 ]
A new comer to my place of work was asking me how he can improve his code style. Here are some suggestions I had for him.
google-codesearch from vim
[ link: codesearch-from-vim | tags: vim google code | updated: Sat, 07 Oct 2006 15:28:23 ]
I just saw vim hint 1354 pop up in my RSS feed. It's a neat idea... but it's hard to decide what documentation should be looked up. Simply using the file type is insufficient.
It turns out that it's a lot more awesome to do google codesearch lookup on it.
tags/cscope for system headers
[ link: usr-include-tags | tags: code vim tags | updated: Sat, 07 Oct 2006 15:46:50 ]
I love tags files for in coding, and enjoy using the tag feature in vim as well as the derived tag-based completion. I do a lot of my development in the kernel, so all I usually have to do is put /usr/src/linux into my vim tags configuration.
Sometimes I have to do some user space hacking too, and I often forget all the names of glib and pthread library functions. Having a system wide tags file is very very useful. Below is a Makefile that I carry around with me and place in /usr/include to keep my system tags in sync.
pretty function tracing
[ link: pretty-function-tracing | tags: code | updated: Fri, 28 Jul 2006 11:13:35 ]
I wanted to see how different functions got used in a block of code that I was new to... and was having a hard time understanding. My UML instance was acting flaky and didn't cooperate with gdb, so I could not single step the code.
I added a small chunk of C code to generate pretty tracing that looks like this:
,-< ipsec_sa_wipe:946
| ,-< ipsec_sa_put:549
| `-> ipsec_sa_put:561 = 0
`-> ipsec_sa_wipe:1054 = 0
Functions can nest upto 25 times (arbitrary max) and after that it stops indenting nicely. The code has to be modified so that at the entry of each block there is a call to the
IN macro, and on the exit to the OUT macro. Here is an example:
void
foo (void)
{
IN();
// something
OUT();
}
Have a look at the code.
I should probably hack something like this using systemtap or at least use jprobes for the tracing instead of modifying the source.
Related:
- a friend pointed me to gcc
-finstrument-functionsoption that makes gcc generate calls to an arbitrary handler for each function entered and exited. - hrprof uses the
-finstrument-functionfeature and extracts more information. - a bit more research revealed etrace which seems to do this kind of function tracing at run-time.
entropy injection
[ link: entropy-injection-driver | tags: linux kernel code | updated: Fri, 05 May 2006 19:09:18 ]
I was installing openswan on my sbc router box. The sbc doesn't have much hardware on it, and what it does have did not contribute to the entropy pool.
I have a few boxes around with relatively good entropy (keyboard/mouse input), but there was no way to pass that entropy to the router for RSA key generation. I had to write some code to fix it. Be warned, it's pretty EVIL...
UPDATE: see below about rng-tools.
