commit c1b3a84940c2da7d493e5a5e4eafbe55fc7a0428
parent f19b72606dd48564f76577477b161523bbaf77f9
Author: phoebos <ben@bvnf.space>
Date: Tue, 7 Jun 2022 16:22:56 +0100
add -g flag to generate debug info
Without the -g flag, uxndebug is now identical to uxnasm.
Now, these changes could be incorporated into upstream uxnasm.
Diffstat:
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
@@ -4,7 +4,7 @@ This is a suite of tools for use in debugging uxn programs.
### uxndebug
This is a modified version of uxnasm which operates exactly the same way, but
-also generates a debug info file when run. The format of this file is documented
+also generates a debug info file when run with the `-g` flag. The format of this file is documented
in the `uxndebug(5)` manpage.
### uxnsolve
@@ -19,7 +19,7 @@ make
Then compile your program:
```
-./uxndebug test.tal test.rom
+./uxndebug -g test.tal test.rom
```
This will generate a file `test.tal.debug` in addition to the rom.
diff --git a/uxndebug.5 b/uxndebug.5
@@ -56,7 +56,7 @@ and debug information file
.Pa example.tal.debug
are created by running:
.Bd -literal -offset indent
-uxndebug example.tal example.rom
+uxndebug -g example.tal example.rom
.Ed
.Sh EXAMPLES
Consider a source file
@@ -69,7 +69,7 @@ BRK
.Pp
Running the command
.Bd -literal -offset indent -compact
-uxndebug test.tal test.rom
+uxndebug -g test.tal test.rom
.Ed
produces files
.Pa test.tal.debug
diff --git a/uxndebug.c b/uxndebug.c
@@ -495,9 +495,15 @@ int
main(int argc, char *argv[])
{
FILE *src, *dst;
+ int do_debug = 0;
setlocale(LC_ALL, "C");
+ if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'g' && argv[1][2] == '\0') {
+ do_debug = 1;
+ argc--;
+ argv++;
+ }
if(argc < 3)
- return !error("usage", "input.tal output.rom");
+ return !error("usage", "[-g] input.tal output.rom");
if(!(src = fopen(argv[1], "r")))
return !error("Invalid input", argv[1]);
if(!assemble(src))
@@ -508,7 +514,7 @@ main(int argc, char *argv[])
return !error("Assembly", "Output rom is empty.");
fwrite(p.data + TRIM, p.length - TRIM, 1, dst);
review(argv[2]);
- if (!save_debug_info(argv[1]))
+ if (do_debug && !save_debug_info(argv[1]))
return !error("Debug", "Failed to save info.");
return 0;
}