Systemtap
Posted: May 6, 2012 Filed under: Uncategorized | Tags: systemtap Leave a comment »I caught the systemtap bug. Not a software bug, but the one that makes you think of a thing every minute of the day.
One nice thing I come up while searching for more systemtap on the net, was this paper from Josh Stone that describes a marriage between dyninst and systemtap.
That would get rid of the permission problems (insmod and stuff)
Compiling Dehydra and Treehydra on Natty Narwhal
Posted: July 29, 2011 Filed under: dehydra Leave a comment »While Dehydra is available as a package, it doesn’t contain treehydra.
So, the only other option is to have it compiled from sources.
One thing to note here is that the latest Dehydra requires xulrunner 2.0.
Pre-requisites
sudo apt-get update
sudo apt-get install gcc-4.5
sudo apt-get install gcc-4.5-plugin-dev
sudo apt-get install xulrunner-2.0-dev
Compiling.
hg clone http://hg.mozilla.org/rewriting-and-analysis/dehydra/
cd dehydra
export CXX="`which g++-4.5`"
export CC="`which gcc-4.5`"
./configure \
--js-libs=/usr/lib/xulrunner-2.0 \
--js-headers=/usr/include/xulrunner-2.0 \
--enable-C \
make
When you can’t use gdb or valgrind, there is /lib/libSegFault.so.
Posted: May 4, 2010 Filed under: Uncategorized Leave a comment »Under certain conditions I can’t get gdb or valgrind to work on my binary and I don’t want
any delays from them. And I just wanted to see where the binary segfaulted so I remembered of
/lib/libSegFault.so.
LD_PRELOAD=/lib/libSegFault.so executable
Backtrace:
/lib/libSegFault.so(+0x206f)[0x11206f]
[0x9d1400]
executable[0x805994d]
executable[0x8059a0d]
executable[0x805d043]
executable[0x8057d59]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xae5bd6]
executable[0x8048e81]
Now I use addr2line to translate the addresses to locations in binary:
addr2line -e executable 0x805994d 0x8059a0d 0x805d043 0x8057d59
sm.c:505
sm.c:564
tmr.c:104
main.c:155
Thats it .
Ruby: undefined method `innerHTML’
Posted: May 3, 2010 Filed under: Uncategorized Leave a comment »In ruby 1.8 seems that renamed/removed the innerHTML method in Mechanize:
main.rb:18: undefined method `innerHTML’ for # (NoMethodError)
it was somehow renamed to inner_html.
Things I want to implement using dehydra/Treehydra.
Posted: April 27, 2010 Filed under: Uncategorized Leave a comment »I’ve started using Dehydra just to get intimate with it. What I would like to use it for would be(in no particular order):
- Proper C++ RMI[1].
- Dia[2] UML diagram generator.
- Stub Testing.
[1]: http://java.sun.com/javase/technologies/core/basic/rmi/index.jsp
[2]: http://projects.gnome.org/dia/
Dehydra and gcc-4.5 on Ubuntu Lucid Lynx
Posted: April 19, 2010 Filed under: programming Leave a comment »gcc-4.5 haven’t reached Ubuntu Lucid repositories just yet.
So I had to grab it from Debian. You can do this by
placing this line in your /etc/apt/sources.list,
deb http://ftp.debian.org/debian/ experimental main
After this, I updated my package list and downloaded dehydra source code from Mozilla, since
the Debian package still have some errors.
sudo apt-get update
sudo apt-get install gcc-4.5
sudo apt-get install gcc-4.5-plugin-dev
sudo apt-get install xulrunner-1.9.2-dev
hg clone http://hg.mozilla.org/rewriting-and-analysis/dehydra/
cd dehydra
CXX=g++-4.5 CC=gcc-4.5 ./configure --js-headers=/usr/include/xulrunner-1.9.2.3/ --js-libs=/usr/lib/xulrunner-1.9.2.3/
CXX=g++-4.5 CC=gcc-4.5 make
CXX=g++-4.5 CC=gcc-4.5 make check_dehydra
Now I can start using dehydra. I looked inside test/unit_test_harness.py to see how I can call gcc with plugins.
This is what I found this:
/usr/lib/gcc/i486-linux-gnu/4.5.0/cc1plus -fplugin=./gcc_dehydra.so -o /dev/null -fplugin-arg-gcc_dehydra-=./test/test_virtual_inheritance.js ./test/virtual_inheritance.cc
C* getC()
Analyzing compilation unit
Performing interprocedural optimizations
Assembling functions:
C* getC()class C : private A,private virtual B
t.bases[0].isVirtual: undefined
Execution times (seconds)
parser : 0.01 (100%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall 288 kB (31%) ggc
TOTAL : 0.01 0.01 0.01 919 kB
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.
OK
[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=535696
[2]: https://developer.mozilla.org/En/Dehydra/Installing_Dehydra#Usage
Obtain the call graph from C sources.
Posted: April 6, 2010 Filed under: programming Leave a comment »When I have to understand how a C program word from a bird-eye view I usually tend to draw on paper the flow of the program.
I looked around to see if there are any tools to do this automatically and found cflow[1].
The downside is that it doesn’t know about dot[2] format.
I looked around and found cflow2vcg[3] that does exactly that: turns a cflow graph in a dot graph. It’s not available in Ubuntus’ repositories
so you’ll have to compile it by hand.
cflow --cpp --format=posix --omit-arguments --level-indent='0=\t' --level-indent='1=\t' --level-indent=start='\t' YOUR_FILE.C > cflow.tmp
cflow2dot < cflow.dot > cflow.dot
dot -Tjpg -G"300,900" cflow.dot -o cflow.jpg
display cflow.jpg
The -G”300,900″ option works around a ‘dot’ segfault.
Stubing the libc functions.
Posted: February 23, 2010 Filed under: programming, testing Leave a comment »I tried to use Mockpp[1] one day to test a scheduling queue.
The queue used gettimeofday to see when a packet expired.
This would prove imposible to test with stub-testing, unless I would wrap gettimeofday
in another class, and then change the code to use that class which would be difficult.
After some googling I found about the GNU ld “-wrap” parameter.
From `man 1 ld`:
--wrap symbol Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "__wrap_symbol". Any undefined reference to "__real_symbol" will be resolved to symbol.
So I put up a little test, made out of two files:
malloc_wrapper.c and test_ld_wrap.c
/* malloc_wrapper.c */
#include <stdio.h>
void *__real_malloc (int);
void * __wrap_malloc (size_t c)
{
void *lptr = __real_malloc(size);
printf("@ %s:[%p] + %p %#x\n", program_invocation_short_name, __builtin_return_address(0), lptr, size );
return lptr;
}
/* test_ld_wrap.c */
#include <stdio.h>
int main()
{
malloc(1);
}
Putting the whole thing together
gcc -c malloc_wrapper.c gcc -c test_ld_wrap.c gcc -Wl,-wrap,malloc test_ld_wrap.o malloc_wrapper.o
Running the test will yield:
~/mine> ./a.out malloc called with 1
Yey, success!
I prefer this method on architectures where LD_PRELOAD is not available,
and this usually happens in the Embedded world.
You will have to recompile your application though.
This parameter can be used either for testing or for memory leak detection, when the C library doesn’t provide
support. ( see `man 3 mtrace` for GNU libc).
———–
[1] http://mockpp.sourceforge.net/
One good reason I ditched ruby for python
Posted: February 5, 2010 Filed under: programming, python 2 Comments »I had a small stuff to do test IPsec with lots of selectors. I thought I might be binding 50k ports and poll them for connections.
I though I’d go for Ruby since everyone praise it as intuitive. I’ve used it before at my testing work and I thought this might be a good
occasion to see how it evolved.
Soon I got in the limit of how many file descriptors select() can watch, that is 1024. That also crashed ruby1.8.7.
Further more, I wasn’t able to find official documentation about detecting EOF(end of file) while doing a recvfrom_nonblock().
You have to go around stackoverflow to find similar questions.
Then I though that python might do better. One search on google was enough to see that python implements epoll. Hooray..!!!
It seems to me that ruby is just some toy language, good for learning how to program OOP style, which should be dropped when doing
performance critical or reliable projects.
