Tuesday, 22 January 2013

Some gdb tricks you should know


gdb is an amazingly versatile and flexible tool, and mastering it can save you huge amounts of time when trying to debug problems in your code, here is some unusual commands for gdb

1) Logging :
    Set logging file log.txt
     Set logging on 
   To redirect all console output to log.txt

2) Frames and Stacks
   Fr :  To check frames  and move stacked functions.

3) Conditional breakpoints:  
     break WHERE iF COND 

4)  Use a custom command to run every time gdb hit breakpoints
 command  <#>
        use :   # b
                  breakpoint 1 hits at soemfunction 
       #command 1 
          list commands 1per line for to run after breakpoint 1, end with word end 
        > print a 
        >print b
         end  

5) Debugging macros :
        use flags -ggdb3 during compilation 

6) The x command :
     x (for "examine") is used to output regions of memory in various formats. It takes two arguments in a slightly unusual syntax:
        x/ Address
   
 other than these usual command bt,untill,count,watchpoint,source is much effective 

Simple but useful


1)  Share your files and folders residing on your Linux machine with anyone across the web.



Here is the simple way to share files across network on linux , without the need of SMB or NFS .

Open a bash terminal and create an alias as follows:

Next navigate to the directory which you want to share with someone and run  $ python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" command

Your Linux machine will now start serving the whole directory tree on the port number 8000.
And anybody can access all your files within that directory at the following web address – http://:8000/.

Tip:
If you have firewall enabled , you need to open port 8000.

2) Open xwindow apps on remote system:

only local , open a Linux window and type the following:
  • xhost +
  • telnet
  • setenv DISPLAY :0.0
  •      &

Application will open yr local system .


3) Find Out The Top 10 Memory Consuming Process
# ps -auxf | sort -nr -k 4 | head -10
4) Find Out top 10 CPU Consuming Process
# ps -auxf | sort -nr -k 3 | head -10
5) iostat  : average cpu activity
6) pmap -d PID  : memory map of a process
7) copy directory to remote linux 
      scp -r @ :remote .