An open API service indexing awesome lists of open source software.

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.

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.