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)
Monday, November 30, 2015
Python - Create Instance, Initialize Constructors, and verify objects
The example listed below demonstrates how to create an instance of an object and run a method. Note, when initializing myCompEmp1 and myCompEmp2, the variables passed in match the parameters the __init__ takes. This is how the constructor initializes the variables for future use. The method displayEmployee will print out the variables previously passed in to the constructor. The displayCount method will display the total number of instances created. Note, this was accomplished by initializing empCount variable in companyA to zero. Everytime a new instance is created, the constructor will add one.
main.py
main.py
import sys import mylist import anotherList import companyA __author__ = 'linos' def main(): myCompEmp1 = companyA.Employee("Zara",4000) myCompEmp1.displayEmployee() myCompEmp1.displayCount() myCompEmp2 = companyA.Employee("Bill",1000) myCompEmp2.displayEmployee() myCompEmp2.displayCount() if __name__ == '__main__': main()
companyA.py
__author__ = 'linos'
class Employee: empCount = 0 def __init__(self,name,salary): self.name = name self.salary = salary Employee.empCount += 1 def displayCount(self): print ("Total Employee %d" % Employee.empCount) def displayEmployee(self): print ("Name: ", self.name, ", Salary", self.salary)
Sunday, November 29, 2015
Python - Calling functions after instantiating instance of an object
An quick explanation on how to call a function after importing the python file (as reference), then creating an instance of an object and calling a function to run. The following example is very simple since it does not care about input parameters to the printList() function.
main.py:
main.py:
import sys import anotherList __author__ = 'linos' def main(): print(__author__) #Create an instance of mylistObject and assign it to the variable mylistObj mylstObj = anotherList.mylistObject()
#Call the printList function that takes not arguments.
mylstObj.printList()
print(sys.version)
if __name__ == '__main__':
main()
anotherList.py:
__author__ = 'linos' class mylistObject: #Allows you to control how objects are initialized. The __init__ is a special method within a class called the constructor or initialization method. The pass in this example is used to quickly setup the __init__ without having it setup or assigning any variables. def __init__(self): pass def printList(self): aList = ["list1", "list2", "list3"] print(aList) print(aList[1]) print(len(aList)) aList.append("list4") print(len(aList)) print(aList) aList.pop() print("Test", aList) aList.insert(2, "list0") print(aList)
Python - Calling functions without instantiating instances of objects
An quick explanation on how to call a function from python files without instantiating and instance of an object. The example python file list below contains a main.py and a mylist.py files. The mylist.py file does not contain any class object heading information. It is just a simple python file that can be imported and used without instantiating an instance to create an object. In the main.py file is an import mylist that imports the functions previously defined. Very similar to 'using' statement at the top of C# files when referencing capabilities from other libraries.
main.py:
import sys import mylist __author__ = 'linos' def main(): a = mylist.printList() print(__author__) #a.printList() if __name__ == '__main__': main()
mylist.py:
__author__ = 'linos'#This is not a class, but rather just another python file.#As you can see here, there are no imports or indentation on the def listed below.#The file behaves as an extention from the Main.py file when calling the functions.def printList(): aList = ["list1", "list2", "list3"] print(aList) print(aList[1]) print(len(aList)) aList.append("list4") print(len(aList)) print(aList) aList.pop() print("Test", aList) aList.insert(2, "list0") print(aList)
Wednesday, November 18, 2015
Git Cheat-Sheet
From here on in, every command start with the 'git' followed
by a space, then the command.
List of commands:
1. init
The
word init means initialize. The command sets up all the tools Git needs to
begin tracking changes made to
the project.
2. status
As you
write the screenplay, you will be changing the contents of the working
directory. You can check the
status of those changes
3. add 'filename.txt'
add a
file to the staging area
4. diff 'filename.txt'
check
the differences between the working directory and the staging area
5. commit -m "Some notes before committing"
6. log
Commits
are stored chronologically in the repository and can be viewed
7. show HEAD
commit
you are currently on is known as the HEAD commit
8. checkout HEAD filename
discard
a change and restore the file in your working directory to look exactly as it
did when you last made a
commit
9. add filename_1.txt filename_2.txt
add
multiple files to the staging area
10. reset HEAD filename.txt
to unstage
a file from the staging area
11. reset SHA
rewind
to the part before you made the wrong turn and create a new destiny for the
project
To better understand git reset commit_SHA, notice the diagram on the right. Each circle represents a
commit.
Before
reset:
·
HEAD is at the most recent commit
After
resetting:
·
HEAD goes to a previously made commit of your choice
·
The gray commits are no longer part of your project
·
You have in essence rewinded the project's
history
12. branch
Check
what branch you are currently on. In the
output, the * (asterisk) is showing you what branch you’re on.
13. branch new_branch
create
a new branch
14. checkout branch_name
switch to the new branch
15. merge branch_name
merging
the branch into master
16. branch -d branch_name
delete
the specified branch from your Git project
17. clone remote_location clone_name
cloning
remote_location repository with new name clone_name
18. remote -v
see a list of a Git project's remotes. You will need to cd to the clone_name
repository
19. fetch
will
not merge changes from the remote into your local. It will bring those changes
onto what's called a remote
branch
20. merge
origin/master
first,
make sure to cd to the cloned repository.
Then git merge command to integrate origin/master into your
local master branch
21. branch
<branch_name>
create
a branch to develop questions for the biology quiz
22. checkout
<branch_name>
Switch
to new branch
23. push origin your_branch_name
push
your branch up to the remote, origin.
Use what you created for a branch name in step
Introduction to Reflection API
Set Property Value Using Reflection
1) Create new instance of Student
2) Get instance type
3) Get property FullName by name from type
4) Set property value to "John Smith" using reflection
using System.Reflection;
public class Program
{
public static void Main()
{
//1. Create new instance of Student
Student student = new Student();
//2. Get instance type
var getType = student.GetType();
//3. Get property FullName by name from type
var fullNameProperty = getType.GetProperty("FullName");//,
//typeof(string));
//4. Set property value to "Some Name" using reflection
fullNameProperty.SetValue(student, "John Smith");
Console.WriteLine(fullNameProperty.GetValue(student)); // GetValue(sT.FullName.ToString()));
}
}
public class Student
{
public string FullName { get; set; }
public int Class { get; set; }
public DateTime DateOfBirth { get; set; }
public string GetCharacteristics()
{
return "";
}
}
Sunday, September 27, 2015
Ubuntu 15.04 mouse problems
So, I recently install a VM using VirtualBox. Everything seems to be working fine until I tried to navigate over the activities pane. To my surprise, I encountered a problem where my mouse pointer disappeared. After trying to google a solution, I tried various suggestions with regards to restarted the gdm or reinstalling packages, I had no luck. Until I can into the following website. http://askubuntu.com/questions/126491/how-do-i-change-the-cursor-and-its-size
Here I happen to put two and two together. So, for my case, my mouse pointer was black, and when I navigate over to the activities pane, the mouse pointer would just magically disappear. Strange as is was, I figured, why not just change the color of my mouse pointer to something other than black.
So here is what I did. Hit the CTRL+ALT+T keys to open the command shell. Next, type in the following: sudo update-alternatives --config x-cursor-theme
Now, select something other than black. I chose #17, which in my case is crystal white.
Changing the value here requires a reboot - a logout and login will not suffice. For me it worked right away.
Secondly, using
navigate to
I hope this helps.
Cheers to fossfreedom who helped me figure this out.
http://askubuntu.com/questions/126491/how-do-i-change-the-cursor-and-its-size
Here I happen to put two and two together. So, for my case, my mouse pointer was black, and when I navigate over to the activities pane, the mouse pointer would just magically disappear. Strange as is was, I figured, why not just change the color of my mouse pointer to something other than black.
So here is what I did. Hit the CTRL+ALT+T keys to open the command shell. Next, type in the following: sudo update-alternatives --config x-cursor-theme
Now, select something other than black. I chose #17, which in my case is crystal white.
Changing the value here requires a reboot - a logout and login will not suffice. For me it worked right away.
Secondly, using
dconf-editor (install using sudo apt-get install dconf-tools)navigate to
org.gnome.desktop.interface change the cursor size to 24 and cursor theme to crystalwhiteI hope this helps.
Cheers to fossfreedom who helped me figure this out.
http://askubuntu.com/questions/126491/how-do-i-change-the-cursor-and-its-size
Wednesday, September 23, 2015
Difference between Unmanaged Code and Managed Code
Managed
code is what Visual Basic .NET and C# compilers create. It runs on the CLR (Common Language
Runtime),
which, among other things, offers services like garbage collection, run-time
type checking, and reference checking. So, think of it as, "My code is managed by
the CLR."
Visual Basic and C# can only produce managed code, so if you're writing an application in one of those languages you are writing an application managed by the CLR. If you are writing an application in Visual C++ .NET you can produce managed code if you like, but it's optional.
Visual Basic and C# can only produce managed code, so if you're writing an application in one of those languages you are writing an application managed by the CLR. If you are writing an application in Visual C++ .NET you can produce managed code if you like, but it's optional.
Unmanaged code
compiles straight to machine code. So, by that definition all code
compiled by traditional C/C++ compilers is 'unmanaged code'. Also, since it
compiles to machine code and not an intermediate language it
is non-portable.
No free memory management or
anything else the CLR provides
Since you cannot create unmanaged code with Visual Basic or C#, in Visual Studio all unmanaged code is written in C/C++.
Since you cannot create unmanaged code with Visual Basic or C#, in Visual Studio all unmanaged code is written in C/C++.
http://en.wikipedia.org/wiki/Managed_code
http://blog.shienandy.com/search/label/LabVIEW
Thursday, September 17, 2015
Visual Studio project "Load Failed"
Just recently I started to encounter this annoying problem in Visual Studio 2013.
I received the "solution loading..." message and (load failed) on the majority of my projects in my solution.
So after searching through the net and seeing what other have done to fix this problem, I did not have much luck. Fortunately I found one point of information located here: NUGET Causing Problem on stack overflow. Before uninstalling NUGET, I decided to first open NUGET package manager and clear package cache. You can do this by performing the following: Tools>NUGET Package Manager>Package Manager Settings. Here you will press 'Clear package Cache'.
OR
If your using clearcase, then change your mapped drive from (the pooled M:) to a specific drive such X, Y, or Z. And alse set your Current source control plug-in to None.
I received the "solution loading..." message and (load failed) on the majority of my projects in my solution.
So after searching through the net and seeing what other have done to fix this problem, I did not have much luck. Fortunately I found one point of information located here: NUGET Causing Problem on stack overflow. Before uninstalling NUGET, I decided to first open NUGET package manager and clear package cache. You can do this by performing the following: Tools>NUGET Package Manager>Package Manager Settings. Here you will press 'Clear package Cache'.
OR
If your using clearcase, then change your mapped drive from (the pooled M:) to a specific drive such X, Y, or Z. And alse set your Current source control plug-in to None.
Thursday, August 27, 2015
C# Overloading
Simple class file created to display how overloading works in C#.
The following example was done in LINQPad
Overloading Example: (https://www.youtube.com/watch?v=cN7ZlpJsAnQ)
class Class1
{
public int Num1 = 0;
public static Class1 operator +(Class1 obj1, Class1 obj2)
{
Class1 obj3 = new Class1();
obj3.Num1 = obj1.Num1 + obj2.Num1;
return obj3;
}
}
void Main()
{
Class1 obj1 = new Class1();
obj1.Num1 = 10;
Class1 obj2 = new Class1();
obj2.Num1 = 10;
Class1 obj3 = new Class1();
obj3 = obj1 + obj2;
Console.WriteLine("The value of obj3 is: {0}",obj3.Num1);
}
The following example was done in LINQPad
Overloading Example: (https://www.youtube.com/watch?v=cN7ZlpJsAnQ)
class Class1
{
public int Num1 = 0;
public static Class1 operator +(Class1 obj1, Class1 obj2)
{
Class1 obj3 = new Class1();
obj3.Num1 = obj1.Num1 + obj2.Num1;
return obj3;
}
}
void Main()
{
Class1 obj1 = new Class1();
obj1.Num1 = 10;
Class1 obj2 = new Class1();
obj2.Num1 = 10;
Class1 obj3 = new Class1();
obj3 = obj1 + obj2;
Console.WriteLine("The value of obj3 is: {0}",obj3.Num1);
}
Thursday, August 20, 2015
Python calling function within a class from another class from Visual Studio
The following example listed below was done using Visual Studio Visual Studio. https://www.visualstudio.com/en-us/features/python-vs.aspx
The scope of this example was create a python file and call a function within a class file from the __init__, the init is the constructor for a class. Then passing in the variables to set locally within the class file.
PythonApplication.py:
import sys
import pClass
def main():
print "test"
def anothermain():
thisClass = pClass.pClass("Lino","39","1")
#del thisClass # this is how to use the destructor in python
pClass.pClass.aClass(thisClass)
print "testing"
if __name__ == "__main__":
main()
anothermain()
ClassFile.py:
class pClass(object):
def __init__(self, name,age,net):#,*args, **kwargs):
self.name = name
self.age = age
self.net = net
self.aClass()
def aClass(object):
print "Name is %s, age is %s, net worth is %s" % (object.name, object.age, object.net) #(self.name, self.age, self.net)
The scope of this example was create a python file and call a function within a class file from the __init__, the init is the constructor for a class. Then passing in the variables to set locally within the class file.
PythonApplication.py:
import sys
import pClass
def main():
print "test"
def anothermain():
thisClass = pClass.pClass("Lino","39","1")
#del thisClass # this is how to use the destructor in python
pClass.pClass.aClass(thisClass)
print "testing"
if __name__ == "__main__":
main()
anothermain()
ClassFile.py:
class pClass(object):
def __init__(self, name,age,net):#,*args, **kwargs):
self.name = name
self.age = age
self.net = net
self.aClass()
def aClass(object):
print "Name is %s, age is %s, net worth is %s" % (object.name, object.age, object.net) #(self.name, self.age, self.net)
Subscribe to:
Comments (Atom)




