https://github.com/gitteja19/basic-c-debbuger
Linux - mini project.
https://github.com/gitteja19/basic-c-debbuger
c linux-shell signal-handling system-calls
Last synced: 12 months ago
JSON representation
Linux - mini project.
- Host: GitHub
- URL: https://github.com/gitteja19/basic-c-debbuger
- Owner: gitteja19
- Created: 2025-05-04T09:16:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-04T09:16:55.000Z (about 1 year ago)
- Last Synced: 2025-05-07T02:41:55.559Z (about 1 year ago)
- Topics: c, linux-shell, signal-handling, system-calls
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ my_gdb โ A Minimal Signal-Based Debugger in C
`my_gdb` is a command-line mini-debugger for C programs, built from scratch using **Linux signals**, **process forking**, and **runtime code instrumentation**. It mimics GDB-like behavior for stepping through `main()` line-by-line using keyboard commands.
> ๐ฏ Ideal for students and system programmers learning **signal handling**, **process control**, and **basic debugging internals**.
---
## ๐ง Features
- ๐ง **Custom signal handlers** to pause/resume execution
- ๐ **Fork-based process control** for parent-child interaction
- โธ๏ธ **Line-by-line stepping** using inserted `pause()` calls
- ๐งผ **Preprocessing** and filtering via `gcc -E` and `grep`
- ๐จ **Color-coded terminal UI** using ANSI escape codes
- ๐งพ Simple debugger interface: `(r)un`, `(n)ext`, `(q)uit`
---
## ๐ ๏ธ How It Works
1. Parses the given `.c` file.
2. Rewrites it:
- Inserts signal handlers.
- Adds `pause()` after every line inside `main()`.
3. Compiles and forks:
- Child runs the modified binary.
- Parent controls execution via **SIGUSR1**.
---
## ๐งช Example Usage
```bash
$ ./my_gdb test.c
use:./my_gdb
press (r)un to start,(q)uit
(my_gdb) : r
Running gdb
gdb:4321, temp:4322
***** MY GDB BASIC *****
(n)ext line, (q)uit
line-nn : x = 10;
(my_gdb) : n
line-nn : y = x + 5;
```
---
## ๐ Files
```bash
my_gdb/
โโโ my_gdb.c # Source code
โโโ test.c # Sample program to debug
โโโ prog.c # Instrumented source
โโโ prog.i # Preprocessed file
โโโ temp.i # Final file with pause() inserted
```
---
## ๐ Concepts Used
- Linux Signals: `SIGUSR1`, `SIGUSR2`, `SIGKILL`, `pause()`
- Process Creation: `fork()`, `execl()`, `kill()`
- File I/O and parsing: `fopen()`, `fgets()`, `fputs()`
- ANSI Escape Sequences for color terminal output
- GCC Preprocessing: `gcc -E`
- Input Flushing: `__fpurge(stdin)`
---
## ๐ก Educational Value
- Helps understand how debuggers work behind the scenes.
- Excellent mini-project for **OS**, **System Programming**, or **Debugging Tools** coursework.
- Demonstrates practical use of signals, forks, and inter-process control.
---
## ๐งโ๐ป Author
Tej, B.Tech in Electrical Engineering
Focused on Embedded Systems, Linux Internals & C Systems Programming
๐ฎ๐ณ India
---
## ๐ License
MIT License โ feel free to learn and build on this project.