diff options
| 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) | |
| tree | 83024e2a62564b0b1996c8ef0aef5e7217f65d2c | |
| parent | 7288e081d7ca39d6e5501d74f912fd92f9aee58d (diff) | |
| download | toy-debugger-d82db3ea9a36b15aab5fae2021948ef4b96e92b0.tar.gz | |
Update readme with new debugger commands and usage examples
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | example.c | 89 |
2 files changed, 57 insertions, 42 deletions
@@ -26,6 +26,13 @@ After you clone the repository build the debugger and a sample program with Run the debugger with: `./tdbg <target_executable>` +Example with arguments and environment variables: + +```sh +./tdbg ./example arg1 arg2 arg3 +./tdbg ./example -e MYENV=qwe -- arg1 arg2 arg3 +``` + ### Interactive Commands | Key | Action | @@ -37,7 +44,10 @@ Run the debugger with: `./tdbg <target_executable>` | `s` | **Step into** | | `o` | **Step out** | | `c` | **Continue** execution | +| `w` | **Watch** expression | | `q` | **Quit** debugger | +| `>` | **Reduces sidebar width** | +| `<` | **Increases sidebar width** | ### Input Mode @@ -2,76 +2,81 @@ #include <stdlib.h> typedef enum { - STATUS_IDLE, - STATUS_RUNNING, - STATUS_STOPPED + STATUS_IDLE, + STATUS_RUNNING, + STATUS_STOPPED } Status; typedef struct { - int x; - int y; + int x; + int y; } Point; typedef struct { - Point top_left; - Point bottom_right; + Point top_left; + Point bottom_right; } Rectangle; typedef struct { - int q; - int w; + int q; + int w; } Bar; int add_numbers(int a, int b) { - int result = a + b; - return result; + int result = a + b; + return result; } int fibonacci(int n) { - if (n <= 1) return n; - return fibonacci(n - 1) + fibonacci(n - 2); + if (n <= 1) return n; + return fibonacci(n - 1) + fibonacci(n - 2); } void print_rectangle(Rectangle rect) { - printf("> Rect: (%d, %d) to (%d, %d)\n", - rect.top_left.x, rect.top_left.y, - rect.bottom_right.x, rect.bottom_right.y); + printf("> Rect: (%d, %d) to (%d, %d)\n", + rect.top_left.x, rect.top_left.y, + rect.bottom_right.x, rect.bottom_right.y); } int main(int argc, char **argv) { - const char *myenv = getenv("MYENV"); + const char *myenv = getenv("MYENV"); - int a = 100; - int b = 123; - int c = add_numbers(a, b); + char *args[3]; + for (int i = 0; i < argc; i++) { + args[i] = argv[i]; + } - Bar bar = { .q = 565, .w = 949 }; - Status status = STATUS_RUNNING; + int a = 100; + int b = 123; + int c = add_numbers(a, b); - Rectangle rect = { - .top_left = { .x = 10, .y = 20 }, - .bottom_right = { .x = 50, .y = 80 } - }; + Bar bar = { .q = 565, .w = 949 }; + Status status = STATUS_RUNNING; - printf("> MYENV: %s\n", myenv ? myenv : "NULL"); - printf("> c: %d (via add_numbers)\n", c); - printf("> bar.q: %d\n", bar.q); - printf("> status: %d\n", status); + Rectangle rect = { + .top_left = { .x = 10, .y = 20 }, + .bottom_right = { .x = 50, .y = 80 } + }; - print_rectangle(rect); + printf("> MYENV: %s\n", myenv ? myenv : "NULL"); + printf("> c: %d (via add_numbers)\n", c); + printf("> bar.q: %d\n", bar.q); + printf("> status: %d\n", status); - int fib5 = fibonacci(5); - printf("> fib(5): %d\n", fib5); + print_rectangle(rect); - int arr[] = {10, 20, 30, 40, 50}; - int *ptr = arr; - for (int i = 0; i < 5; i++) { - printf("> arr[%d] = %d (via ptr: %d)\n", i, arr[i], *(ptr + i)); - } + int fib5 = fibonacci(5); + printf("> fib(5): %d\n", fib5); - for (int i = 0; i < 3; i++) { - printf("> loop %d\n", i); - } + int arr[] = {10, 20, 30, 40, 50}; + int *ptr = arr; + for (int i = 0; i < 5; i++) { + printf("> arr[%d] = %d (via ptr: %d)\n", i, arr[i], *(ptr + i)); + } - return 0; + for (int i = 0; i < 3; i++) { + printf("> loop %d\n", i); + } + + return 0; } |
