Commonly used gdb commands
--------------------------
gdb also understands abreviations of commands, so you can just type up to
the unique part of a command name ("cont" for "continue", or "p" for "print")
help # List classes of all gdb commands
help <topic> # Shows help available for topic or command
where (or bt) # Shows stack: sequence of function calls executed so far
# (good for pinpointing location of a program crash)
frame # Shows all stack frames
frame <frame-num> # Sets current stack frame to <frame-num>
# (useful for checking parameter and argument values)
run # Starts program execution from the beginning
break <line> # Sets breakpoint at line number <line>
break <func-name> # Sets breakpoint at beginning of named function
continue # Continues execution from breakpoint
condition <bp-num> <exp> # Set breakpoint <bp-num> to
# break only when <exp> is true
info break # Shows current breakpoints
disable [breakpoints] # [bnums ...] Disable one or more breakpoints
enable [breakpoints] # [bnums ...] Enable one or more breakpoints
clear <line> # Clears breakpoint at line number <line>
delete <bp-num> # Deletes breakpoint number <bp-num>
delete # Deletes all breakpoints
step (or s) # Executes next line of program (steping into functions)
step <count> # Executes next <count> lines of program
next (or n) # Like step, but treats a function call as a single instr
until <line> # Executes program until line number <line>
print <exp> (or inspect <exp> # Displays the value of expression <exp>
display <exp> # Automatic display of <exp> each time a breakpt hit
whatis <exp> # Shows data type of expression <exp>
info locals # Shows local variables in current stack frame
set variable <variable> = <exp> # Sets variable <variable> to expression <exp>
list # Lists next few lines of program
list <line> # Lists lines around line number <line> of program
list <start> <end> # Lists line numbers <start> through <end>
list <func-name> # Lists lines at beginning of function <func-name>
help status # lists a bunch of info X commands, including:
info frame # list information about the current stack frame
info locals # list local variable values of current stack frame
info args # list argument values of current stack frame
info registers # list register values
quit # quits gdb
Monday, December 7, 2015
GNU Debugger (GDB) Commands
Sunday, December 6, 2015
Python - MultiThreading example using socket connect (Python2.x)
The following example created displays how to create multiple threads in python, a client and server. A server thread is created first to create a socket connection and waits for client to connect. The client will start and attempt to connect with server. When the second thread starts, the client will connect with the server and receive a message from the server.
main.py:
main.py:
import server import client from threading import Thread import threading def main(): try:
#Create a new thread
threadA = Thread(target=server.connServer)
#Start thread
threadA.start()
#Wait was added to allow some time for threadA to start.
threading._sleep(1) #Create a new thread
threadB = Thread(target=client.connClient) #Start thread
threadB.start() except: print("Error unable to start thread") if __name__ == '__main__': main()
client.py:
import socket #Import socket module def connClient():
#Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) # Get local machine name
host = socket.gethostname() # Reserve a port for your service.
port = 12345 s.connect((host, port)) print s.recv(1024)
# Close the socket when done
s.close()
server.py:
import socket import threading def connServer():
#Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#Get local machine name
host = socket.gethostname()
#Reserve a port for your service.
port = 12345
#Create a socket object
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) s.bind((host,port)) try:
# Now wait for client connection
s.listen(5) # Establish connection with client
c, addr = s.accept()
print ('Got connection from', addr)
c.send('Thank You for connecting')
# Close the connection
c.close()
# Close the socket when done
s.close()
except: s.shutdown(1)
Subscribe to:
Comments (Atom)