Tuesday, September 3, 2013

Create cdb file using perl

To create cdb file in perl is quite easy when you have the hash ready.

See example below.



#!/usr/bin/perl
use strict;

use CDB_File;

my %t = (
            'a' =>'apple', 
            'b' => 'banana',
        );

CDB_File::create %t, "<cdb file name>", "<temporary file name>";



If you have the key-value pairs in a file, you can parse through it and insert into the cdb by getting the hash ready, or by the pairs.

Say your data file contain this.


a,apple
b,banana


Perl code for getting this flat file data into cdb :


#!/usr/bin/perl
use strict;

use CDB_File;
my $cdb = new CDB_File("<cdb file name>", "<temporary file name>");

open (DATA, "<data file name>");

while (<DATA>) {
    chomp();
    my @data = split /,/;
    $cdb->insert($data[0],$data[1]);
}

$cdb->finish;


Monday, September 2, 2013

Something about object files

This is from a long lost track. I used to deal with object files in my previous job. That was like ages ago. Is VCS still compiling the design into object files to run simulation? Anyway, thanks to Synopsys team that helped me a lot in improving my debugging skills. :)

Some simple steps to create a "test case" here. Let's create a "Hello world!" object file.


#include <stdio.h>

void main() {
    printf("Hello world!\n");
}

Compile into object file.


gcc <source code file name> -o <object file name>


To enable debug mode, compile with -g option. With debug mode, you can set break point when running the program in gdb.



OK, back to the story.

These are a few commands that they taught me to investigate about the object files.

To get the list of the functions in the object file.


strings <object file>

This one is not obvious in my test case. The strings command actually listed all the strings in the object file. Anyway, it was handy during the debug then.


To list the dependencies and its gcc versions of the object file.


ldd <object file>


To list the symbols and its allocated memory of the object file. I added the format option for better readability on thhe output. :P


nm --format sysv <object file>


Then, I googled and tried one command. This command seems it will "decode" the object files into assembly language! My favourite language during Uni-time. :D


objdump -d <object file>

This is too long to include full result. I am putting a small partial of it here. :)