Saturday, February 19, 2011

beginning xen and gdb.

Some quick notes for beginning to work with xen and using gdb for remote debugging.

XEN:

  1. Creating domain with xen :-
    1. xm create "domain_configuration_file"
  2. To list all domains running on xen:
    1. xm list 
  3. To kill a domain 
    1. xm destroy <domain_name>
        Here is more information on simple commands for working with xen 

GDB:
   Terminal 1: create the domain on a paused state. 
        xm create "domain_config" -p
  
  Terminal 2: run gdbsx and create network interface
       xm list   - get the domain id number 
       gdbsx -a <domainId> 32 9999 - 32 bit version at port number 9999 

  Terminal 3: run gdb 
      gdb path_to_the_os_executable
      gdb target remote localhost:9999 

   Some useful gdb commands:

      1. gdb break function_name     # set break point at function
      2. gdb continue                        # execute the program till the break point
      3. gdb print var_name              # print the content of the variable
      4. gdb next                               # execute one line at a time after the break point.
  

Tuesday, February 15, 2011

Creating C Headers

Here are a few steps that will help in creating a C header file.

1. Create your .h file. Your header file should only include function declarations.

// my_math.h
int sum(int,int);


To avoid multiple definitions, when a header file is included in other files, use the #ifndef preprocessor directive.

// my_math.h
#ifndef my_math_h
#def my_math_h


int sum(int,int);


#endif

2. Create the function definition file.
Here you provide the definition to the functions declared in the header file.

// my_math.c
#include "my_math.h"
int sum(int x, int y){
   return x+y;


3. Compile your program:

gcc -c my_match.c my_math.o

Note that were are not linking this program, hence the -c option. (not to run the linker).

4. Create Your main program that uses the header.

#include "my_math.h"
int main()
{
     int s=0;
    s = sum(10,4);
}


click here for more info on static and shared linking.