Juliano Garcia

September 24, 2016

How to create an online server in one line of code

Requirements: Python
Just open the terminal and type $ python -m SimpleHTTPServer. The server will be created in the IP of your machine. (To find the IP, type ifconfig -all or ip a.)
OBS: If you use a newer version of Python (3.x) you should type $ python -m http.server .


Back

Juliano Garcia

August 21, 2016

Debug C programs using gdb

NOTE: To install gdb in debian or another debian based distro, just use 4 sudo apt-get gdb.
Using gdb helps to debug C programs in real execution time, i.e. you can put break points in the program to evaluate the value of variables, detect when something has gone wrong, and many other uses. Here I'll cover the basics that I use to debug simple programs.

NOTE (2): If your program receives CLI args, the gdb have support for it using the --args tag, but for testing purposes it's better to just automate the input inside the program (i.e. automatically create a test input and not reading from the CLI).

How to use

  • 1. Compile it with $ cc -g file.c
  • 2.Open the generated file with $ gdb a.out
  • 3. The gdb should open it. Now if you want to, you can create a break point using $ break file.c:xx . Replace 'xx' with the number of line to pause the execution
  • 4. Run the program with $ run -v -da -Q
  • 5. As the program executes, you can print the value of variables using $ print x , where x is the name of the variable.
  • 6. A segmentation Fault will display more info, allowing you to debug your program more easily! To exit the gdb and go back to your default terminal, just type $ quit

This is just the very basic of gdb. For those who want something a little more sophisticated, I reccomend to study the frame, backtrack and navigation command in gdb (usually the up and continue). For more information and details about each argument used in the commands, I recommend the following pages:
How to debug a GCC segmentation fault
How do I use breakpoints?


Back

Juliano Garcia

October 06, 2016

Python Map

A Subway map to know more about the things you can do with Python!

by Hairy Sun - Geek blog

Back