Monday, February 21, 2011

Mounting Remote machine using ssh

sshfs :/home/zakir/ /mnt

Using netcat for chatting and file transfer

Run

At server
nc -l 1234

At client
nc 1234


Start chatting

For file transfer
nc -vv -l 5678 > dump.mp3

Receive
nc -vv -l 5678 < dump.mp3

Using Zenity to create the dialog boxes

Zenity is a tool that help you to create a common functional GTK+ dialogs. It have various dialogs that each of them have different ways of presenting data and acquire data from user input.

We have introduce how to make use of GUI dialog box in Using GUI dialog box, where we give an example of how zenity create a question dialog box. Besides question dialog box, zenity can create more than that, such as calendar, entry, error, info, file selection, list, notification, progress, warning, scale and text info. In this tutorial, we would like to illustrate how to create every single zenity dialog by examples.

zenity --warning --text "Could you please tell me who you are"

How to create zenity calendar dialog?
You are allow to specify the initial selection of date in calendar dialog, specified with options –day –month –year. The default selection will be today’s date. Zenity will returns the date selected by user.

Squeeze multiple blank lines to one

Documents like RFCs may contain many blank-line blocks.

To save the trees, i always squeeze multiple blank lines down to single blank line, before printing.

Once I did this manually (yes, it’s like hell), but now I use cat -s:

cat -s rfc2324.txt | tr -d '\\f' | lpr

I use tr -d to remove any form feed character, and lpr will submit the document for printing.

Sunday, January 30, 2011

Remote debugging using gdbserver

Remote debugging is rather straightforward:

On the target platform, launch the application with GDBserver, while specifying the host and port for listening to an incoming TCP connection:

gdbserver HOST:PORT PROG [ARGS ...]
gdbserver 10.19.103.55:123 test_rsh_sw.bin r
sh/1bit/

On the development workstation, launch the cross-target GDB:

arm-none-linux-gnueabi-gdb PROG

Be sure to specify the non-stripped executable. At the GDB console, type:

target remote HOST:PORT


break main
continue

These commands will connect GDB to the GDBserver running on the target platform, set a breakpoint at the start of the program, and let it run until it reaches that first breakpoint.

You can also attach GDBserver to a process that's already running:

gdbserver HOST:PORT --attach PID

The process is then stopped, and you can then debug it with a remote GDB.

Wednesday, December 1, 2010

What is an address space

When a program is built(compilation, assembler invocation, and linking)
it is stored in a file with a special format. One such format is
ELF(Executable and Linking Format)in Unix like systems. It has the
necessary information ( in the ELF header and program header) to help
the program loader to load and create the process image in memory at
runtime, and also do run time linking (for shared libraries linked
dynamically).
At the time program is built, storage for all uninitialised data (static or
global) are not allocated, but only the total size is noted in program
header table of the ELF file. Later when program is being loaded, loader
read the metadata from the ELF file and allocate one large chunk (page
aligned) of memory to hose all such variables. This section is called
BSS(Block Static Storage or Block started by symbol).
Data( storage for all initialized static and global variables) and STACK
section should be familiar to you. HEAP is created by dynamic invocation
by memory-alloc routines of your program. In addition to this there will
be shared memory mappings as well. If you process a file using mmap()
system call interface, those regions are also mapped to your program.
Now the sum total of all such memory is called the address space of your
program.

Now what’s an address? Is that a virtual address, physical address
or logical address?
The value you see when you apply an & operator to a C variable
is actually the program-relative logical address. It has to be
processed by segmentation unit(coupled with the value in the CS
register) to create a linear address and then processed by the
paging unit to create the physical address in your RAM. So these
details are not at the control of C, but is at the control of the
memory management subsystems of the operating system.