Don't wanna be here? Send us removal request.
Text
GDB Debugging
For debugger to display the symbols while debugging, we need to build the code with -g flag.
> gcc -g -o test-pgm test-pgm.c
To start debugger with the program execute on your shell
> gdb test-pgm
To set a breakpoint on function main, execute
> break main
To start the program, execute
> run
The command runs till the break point is hit or the program terminates
To step through execution, run
> step
Step command steps into functions.
If you don’t want to step into functions, run next command
> next
List next few lines
> list
To exit, run
> quit
Once the program is started you can ask the program to continue running till the next break point by running
> continue
To print the value of a variable i, run
> print i
To display the command continuously run
> display i
To stop displaying variable
> undisplay i
To finish the current function and then return, run
> finish
To return from the current function without proceeding
> return
To execute a function, call
> call my_function
To see the current stacktrace
> bt
To ignore a signal
> handle SIGSEGV ignore
To see backtrace of all threads
> thread apply all bt
To open a coredump file to debug from shell
> gdb my_program my_coredump
To set watch point, to break execution when the condition is met
> watch i == 10
0 notes
Text
Automate ssh to remote server using expect
Expect command is part of tcl/tk tool, which is commonly used for CLI testing automation. Expect command can launch a process and read and write from/to the stdin/stdout.
For example to login to remote server and execute command we can use the command
#!/usr/bin/expect
set server [lindex $argv 0] set usr root set passwd mypass set cmd [lrange $argv 1 end]
log_user 0
set timeout 10
spawn -noecho ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $usr@$server $cmd
expect ".*password:" { send "$passwd\r" expect -re ".*\r.*" log_user 1 expect -re ".*password.*" { puts "\tERROR:\r" exit 3 } eof { catch wait result } exit 0 } eof { log_user 0 puts "\tERROR: \r" exit 1; }
0 notes
Text
How to build vim from code
Vim is one of the favorite editor of most of the programmers. It is always good, to build the vim from source code to get the latest features/fixes without waiting the official release or your office system admin’s mercy.
The procedure is simple and it doesn’t need much expertise.
Download the code from git hub
https://github.com/vim/vim
You can either fetch the code using git or download the zip file directly
Run configure script
./configure --with-features=huge \ --enable-multibyte \ --enable-pythoninterp \ --enable-perlinterp \ --enable-luainterp \ --enable-gui=gnome2 \ --enable-cscope \ --prefix=/home/$USER/usr
Run make to build the binaries
make all
Install the package to ~/usr/bin directory.
make install
0 notes