9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit f414d8cb32f4fdb42f59a9ce02873b9c18418284
parent be320a82eeeeed047f80eae043750ed493d2fe76
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 18 Oct 2020 10:05:49 +0200

os9/dlang: Add X command

X command has sane syntax than adb() command and
it can be used to debug panics.

Change-Id: Id3b9263ce007f40cc77f5017cbe3fd9086cc77bb

Diffstat:
Msrc/os9/dlang.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)

diff --git a/src/os9/dlang.c b/src/os9/dlang.c @@ -192,6 +192,53 @@ err: return 0; } +static int +do_x(const struct cmd *cmd, struct args *args) +{ + char *p, *s; + int n; + void *addr; + size_t len; + uint16_t *u16; + uint32_t *u32; + uint64_t *u64; + + s = args->argv[1]; + if ((p = strchr(s, '/')) == NULL) + goto badfmt; + *p++ = '\0'; + + addr = (void *) strtoll(s, NULL, 0); + n = atoi(p); + if (n == 0) + n = 1; + + len = strspn(p, "0123456789"); + switch (p[len]) { + case 'x': + u16 = addr; + while (n-- > 0) + kprint("%x\n", (int) *u16++); + return 0; + case 'X': + u32 = addr; + while (n-- > 0) + kprint("%lx\n", (long) *u32++); + return 0; + case 'Y': + u64 = addr; + while (n-- > 0) + kprint("%x\n", (long long) *u64++); + return 0; + default: + goto badfmt; + } + +badfmt: + kprint(PREFIX "ERR x: bad format"); + return 0; +} + static const struct cmd * parse_cmd(char *buf, struct args *args) { @@ -311,6 +358,13 @@ static const struct cmd cmds[] = { .helpmsg = "Display stat attribute: stat path", }, { + .name = "x", + .eval = do_x, + .min = 2, + .max = 2, + .helpmsg = "Examine memory: x addr/fmt", + }, + { .name = NULL } };