Debugging [GDB]

GDB Debugging Compile with Debug Information To allow gdb access to the source code (Provides debug symbols - Do not share publicly as it contains the source code). gcc -g <file> Look for / Fix Bugs First, initialize gdb with the executable to debug. gdb ./<executable> --tui After gdb is ready, we can use the following commands: Command Description lay next Switch to the next layout (Enables TUI mode if disabled - Allows for reading the code while debugging both in C and ASM). ref Refresh (if a program prints to the terminal, it can break gdb’s interface).` q Quit gdb. b main Add a breakpoint at the main function. b Place a breakpoint at the current line. b <N> Place a breakpoint at line N. b +<N> Place a breakpoint N lines down. b <fn> Place a breakpoint at fn function. d Delete all breakpoints. d <N> Delete breakpoint number N. clear <fn> Clear the breakpoint set to fn function. n Execute up to the next line in C. If a function call is found, execute the function completely. s Execute up to the next line in C. (Jump over) s <N> Run N lines. u Same as n, but if in a loop, execute until the loop exits. nexti Execute up to the next instruction (line in ASM). r Run the program until a breakpoint or error is reached. c Continue running the program until a breakpoint or error is reached. x/i $pc Examine the previous instruction (View memory). info registers Read the CPU registers used by the program. bt See the call stack up to the current line. (How we got here, so to speak) print sizeof(<variable>) Check the size of a struct/variable/pointer. p <var> Print variable var value. info break List breakpoints. Check for Memory Leaks Use valgrind to check for lost memory. ...

2 min · 310 words · TrudeEH

Flask

Flask is a web framework for Python. It facilitates the creation of web apps (dynamic web pages). Run Flask Flask comes with its own server for debugging purposes, which can be started with: flask run Folder Structure app.py # main code requirements.txt # required libraries static/ # files that never change templates/ # dynamic files “Hello, name” — Example App templates/index.html <!DOCTYPE html> <html lang="en"> <head> <meta name = "viewport" content="initial-scale=1, width=device-width"> <title>Hello</title> </head> <body> hello, {{ name_placeholder }} <!-- Jinja template --> </body> </html> app.py http://website.domain/?name=Trude ...

4 min · 796 words · TrudeEH

Python

Python3 Documentation number: Replace with a number. *object: Any number of objects. [, ndigits]: Anything between [] is optional. Run Python Code Python is an interpreted language. It is not compiled like C. python hello.py Skipping the compiling step makes the language easier to use but at the cost of performance. Print Print information on the console. print("hello, world") answer = "Some Text" print(f"Your answer is: {answer}") # formatted string (any type) print("Your answer is: " + answer) # answer must be string print("Your answer is:", answer) # answer can be any type print("Same line", end="") print("!" * 4) # "!!!! # '' and "" do the same. Input Prompt the user for information. ...

15 min · 2996 words · TrudeEH

Version Control [GIT]

Git is a version control system first developed by Linus Torvalds. It facilitates collaboration on large projects, keeps track of changes, and allows mistakes to be rolled back into a previous state. Configure Git Git uses a hierarchy of configuration files: System: (/etc/gitconfig) Configuration for all users in a system. Global: (~/.gitconfig) Configure Git for all project of the current user. Local: (.git/config) Configure Git for the current project. Worktree: (.git/config.worktree) Configure part of a project. # Check if user name and email are set. git config --get user.name git config --get user.email # If not, set those values. git config --add --global user.name "username" git config --add --global user.email "email@example.com" git config --add --global init.defaultBranch main # GitHub's default git config --unset example.key # Remove a configuration value git config --unset-all example.key # Remove all instances of a configuration key git config --remove-section section # Remove an entire section # Rebase on pull by default to keep a linear history git config --global pull.rebase true Create a Repository Git stores all project information in the .git directory. This includes branches, commits, and metadata. ...

10 min · 2093 words · TrudeEH