Update readme with new debugger commands and usage examples

Author Mitja Felicijan <mitja.felicijan@gmail.com> 2026-01-17 02:16:23 +0100
Committer Mitja Felicijan <mitja.felicijan@gmail.com> 2026-01-17 02:16:23 +0100
Commit d82db3ea9a36b15aab5fae2021948ef4b96e92b0 (patch)
-rw-r--r-- README.md 10
-rw-r--r-- example.c 89
2 files changed, 57 insertions, 42 deletions
diff --git a/README.md b/README.md
...
26
  
26
  
27
Run the debugger with: `./tdbg <target_executable>`
27
Run the debugger with: `./tdbg <target_executable>`
28
  
28
  
  
29
Example with arguments and environment variables:
  
30
  
  
31
```sh
  
32
./tdbg ./example arg1 arg2 arg3
  
33
./tdbg ./example -e MYENV=qwe -- arg1 arg2 arg3
  
34
```
  
35
  
29
### Interactive Commands
36
### Interactive Commands
30
  
37
  
31
| Key | Action                                                            |
38
| Key | Action                                                            |
...
37
| `s` | **Step into**                                                     |
44
| `s` | **Step into**                                                     |
38
| `o` | **Step out**                                                      |
45
| `o` | **Step out**                                                      |
39
| `c` | **Continue** execution                                            |
46
| `c` | **Continue** execution                                            |
  
47
| `w` | **Watch** expression                                              |
40
| `q` | **Quit** debugger                                                 |
48
| `q` | **Quit** debugger                                                 |
  
49
| `>` | **Reduces sidebar width**                                         |
  
50
| `<` | **Increases sidebar width**                                       |
41
  
51
  
42
### Input Mode
52
### Input Mode
43
  
53
  
...
diff --git a/example.c b/example.c
...
2
#include <stdlib.h>
2
#include <stdlib.h>
3
  
3
  
4
typedef enum {
4
typedef enum {
5
    STATUS_IDLE,
5
	STATUS_IDLE,
6
    STATUS_RUNNING,
6
	STATUS_RUNNING,
7
    STATUS_STOPPED
7
	STATUS_STOPPED
8
} Status;
8
} Status;
9
  
9
  
10
typedef struct {
10
typedef struct {
11
    int x;
11
	int x;
12
    int y;
12
	int y;
13
} Point;
13
} Point;
14
  
14
  
15
typedef struct {
15
typedef struct {
16
    Point top_left;
16
	Point top_left;
17
    Point bottom_right;
17
	Point bottom_right;
18
} Rectangle;
18
} Rectangle;
19
  
19
  
20
typedef struct {
20
typedef struct {
21
    int q;
21
	int q;
22
    int w;
22
	int w;
23
} Bar;
23
} Bar;
24
  
24
  
25
int add_numbers(int a, int b) {
25
int add_numbers(int a, int b) {
26
    int result = a + b;
26
	int result = a + b;
27
    return result;
27
	return result;
28
}
28
}
29
  
29
  
30
int fibonacci(int n) {
30
int fibonacci(int n) {
31
    if (n <= 1) return n;
31
	if (n <= 1) return n;
32
    return fibonacci(n - 1) + fibonacci(n - 2);
32
	return fibonacci(n - 1) + fibonacci(n - 2);
33
}
33
}
34
  
34
  
35
void print_rectangle(Rectangle rect) {
35
void print_rectangle(Rectangle rect) {
36
    printf("> Rect: (%d, %d) to (%d, %d)\n",
36
	printf("> Rect: (%d, %d) to (%d, %d)\n",
37
           rect.top_left.x, rect.top_left.y,
37
			rect.top_left.x, rect.top_left.y,
38
           rect.bottom_right.x, rect.bottom_right.y);
38
			rect.bottom_right.x, rect.bottom_right.y);
39
}
39
}
40
  
40
  
41
int main(int argc, char **argv) {
41
int main(int argc, char **argv) {
42
    const char *myenv = getenv("MYENV");
42
	const char *myenv = getenv("MYENV");
43
  
43
  
44
    int a = 100;
44
	char *args[3];
45
    int b = 123;
45
	for (int i = 0; i < argc; i++) {
46
    int c = add_numbers(a, b);
46
		args[i] = argv[i];
  
47
	}
  
48
  
  
49
	int a = 100;
  
50
	int b = 123;
  
51
	int c = add_numbers(a, b);
47
  
52
  
48
    Bar bar = { .q = 565, .w = 949 };
53
	Bar bar = { .q = 565, .w = 949 };
49
    Status status = STATUS_RUNNING;
54
	Status status = STATUS_RUNNING;
50
  
55
  
51
    Rectangle rect = {
56
	Rectangle rect = {
52
        .top_left = { .x = 10, .y = 20 },
57
		.top_left = { .x = 10, .y = 20 },
53
        .bottom_right = { .x = 50, .y = 80 }
58
		.bottom_right = { .x = 50, .y = 80 }
54
    };
59
	};
55
  
60
  
56
    printf("> MYENV: %s\n", myenv ? myenv : "NULL");
61
	printf("> MYENV: %s\n", myenv ? myenv : "NULL");
57
    printf("> c: %d (via add_numbers)\n", c);
62
	printf("> c: %d (via add_numbers)\n", c);
58
    printf("> bar.q: %d\n", bar.q);
63
	printf("> bar.q: %d\n", bar.q);
59
    printf("> status: %d\n", status);
64
	printf("> status: %d\n", status);
60
  
65
  
61
    print_rectangle(rect);
66
	print_rectangle(rect);
62
  
67
  
63
    int fib5 = fibonacci(5);
68
	int fib5 = fibonacci(5);
64
    printf("> fib(5): %d\n", fib5);
69
	printf("> fib(5): %d\n", fib5);
65
  
70
  
66
    int arr[] = {10, 20, 30, 40, 50};
71
	int arr[] = {10, 20, 30, 40, 50};
67
    int *ptr = arr;
72
	int *ptr = arr;
68
    for (int i = 0; i < 5; i++) {
73
	for (int i = 0; i < 5; i++) {
69
        printf("> arr[%d] = %d (via ptr: %d)\n", i, arr[i], *(ptr + i));
74
		printf("> arr[%d] = %d (via ptr: %d)\n", i, arr[i], *(ptr + i));
70
    }
75
	}
71
  
76
  
72
    for (int i = 0; i < 3; i++) {
77
	for (int i = 0; i < 3; i++) {
73
        printf("> loop %d\n", i);
78
		printf("> loop %d\n", i);
74
    }
79
	}
75
  
80
  
76
    return 0;
81
	return 0;
77
}
82
}