gdb Debugging Full Example (Tutorial): ncurses
debugging with gdb
A Sample gdb Session
start
gdb program
set args parameters
r
gdb program core_dump
gdb -p processid
navigator
info threads show threads
info threads
t i switch to thread
t i
f i switch to frame
f i
info args show arguments
info args
break and step into
break functionname
n (next, F10 for visualstudio)
n
s (next.step, F11 for visualstudio)
s
bt (summary of the stack)
bt
f i : goto the stack frame at i level
p(print) variable
l (list ten lines of source surrrouding the current line)
l
c (continue, F5 for visualstudio)
c
end
Ctrl+d : giving it an EOF as input to interrupt program
Ctrl+d
quit : exit gdb
quit
gdb with lua
wget https://github.com/mkottman/lua-gdb-helper/blob/master/luagdb.txt
gdb to find the lua runtime thread
source luagdb.txt
luatrace
coredump
cat /proc/sys/kernel/core_pattern
strace program, history of strace
dtrace, dtrace4linux
pstack processid
lsof, A Unix Utility You Should Know About: lsof
add current directory to library search path: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD
chkconfig
chkconfig iptables on
chkconfig iptables off
restart
service iptables stop
service iptables start
service iptables restart
modify
vim /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m multiport -p tcp --dport from:to -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m multiport -p udp --dport from:to -j ACCEPT
reuse tcp port:
vim /etc/sysctl
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
sysctl -p
tcpdump
tcpdump -i eth1 -vnn udp and host destip -w output.cap
short path in shell: export PS1='[\u@\h \W]\$ '
export PS1='[\u@\h \W]\$ '
change file permission: su chmod 777 file
su chmod 777 file
enable excute: su chmod +x file.sh
su chmod +x file.sh
wiki:chmod
view so info
readelf -a file.so #show all information
readelf -d file.so #show dependence so
readelf -h file.so #show header information
find and kill process, for example, when device busy
ps aux | grep tun0
kill pid
create a TUN interface
echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -o eth1 -j MASQUERADE # IF ubuntu # ip tuntap add dev tun0 mode tun # IF centos, yum install tunctl, then tunctl -p -t br0p0 tunctl -n -t tun0 ifconfig tun0 10.0.0.1 dstaddr 10.0.0.2 up
Sed
An Introduction and Tutorial by Bruce Barnett
Grep
An introduction to grep and egrep. - by Bruce Barnett
Awk
Awk - A Tutorial and Introduction - by Bruce Barnett
Awk in 20 minutes
count file
ll -t|grep -|wc -l
passing arguments to a shell script
if then else fi
tell linux which program to run script: #! /bin/sh
#! /bin/sh
array: array=('one' 'two')
array=('one' 'two')
loop array: for e in @{arrary[@]} do echo e done
for e in @{arrary[@]} do echo e done
for i in {5..10}; do echo $i; done for i in $(seq 10); do echo $i; done
for i in {5..10}; do echo $i; done
for i in $(seq 10); do echo $i; done
copy: cp a b
cp a b
force remove file: rm -f file
rm -f file
if else: if [ "$1""x" = "publicx" ]; then else fi
if [ "$1""x" = "publicx" ]; then else fi
if else tutorial
security crt
file transfer
rz -be
sz -be
use vba macro