debugger - implement nifty list t command to lookup toolcall information.

example:

] 0101t
0001  (04408e)  TLBootInit()
This commit is contained in:
Kelvin Sherlock 2019-06-02 13:32:21 -04:00
parent df1ae6ad98
commit e8d6d17a1a
2 changed files with 75 additions and 11 deletions

View File

@ -50,7 +50,7 @@ static int g_templates_loaded = 0;
extern void debug_load_templates(const char *path);
extern word32 debug_apply_template(word32 address, const char *name);
extern void debug_load_nifty(const char *path);
extern const char *debug_tool_name(unsigned, unsigned vector);
extern const char *debug_tool_name(unsigned number, unsigned vector, unsigned full);
@ -240,6 +240,57 @@ static void do_handle(word32 value, int action) {
}
word32 tool_lookup(unsigned tool) {
enum {
TPtr = 0xe103c0,
UTPtr = 0xe103c4,
};
unsigned tn = tool & 0xff;
unsigned ix = (tool >> 8) & 0xff;
word32 ptr;
word32 count;
ptr = get_memory32_c(TPtr, 0);
if (ptr == 0 || ptr > 0xffffff) return 0;
count = get_memory32_c(ptr, 0);
if (count == 0 || count > 255 || count < tn) return 0;
ptr = get_memory32_c(ptr + tn * 4, 0);
if (ptr == 0 || ptr > 0xffffff) return 0;
count = get_memory32_c(ptr, 0);
if (count == 0 || count > 255) return 0;
if (ix && ix > count) return 0;
/* if ix == 0, list all tool calls in the set */
/* otherwise, just the specific tool call */
/* todo -- also lookup tool name */
word32 addr = 0;
const char *cp;
if (ix) {
unsigned n = tn + (ix << 8);
addr = get_memory24_c(ptr + ix * 4, 0);
if (addr) ++addr;
cp = debug_tool_name(n, 0xe10000, 1);
if (!cp) cp = "---unknown---";
printf("%04x (%06x) %s\n", n, addr, cp);
} else {
for(ix = 1; ix < count; ++ix) {
unsigned n = tn + (ix << 8);
addr = get_memory24_c(ptr + ix * 4, 0);
if (addr) ++addr;
cp = debug_tool_name(n, 0xe10000, 1);
if (!cp) cp = "---unknown---";
printf("%04x (%06x) %s\n", n, addr, cp);
}
}
return addr;
}
word32 do_hexdump(word32 address, int lines) {
static char hex[] = "0123456789abcdef";
@ -624,7 +675,7 @@ word32 do_list(word32 address, int lines) {
if (!comment) {
bank = pc >> 16;
if (bank == 0xe0 || bank == 0xe1 || bank == 0x01 || bank == 0xff)
comment = debug_tool_name(pc & 0xffff, bank);
comment = debug_tool_name(pc & 0xffff, bank, 1);
}
switch (opcode) {
@ -640,7 +691,7 @@ word32 do_list(word32 address, int lines) {
case 0xa2: /* ldx # */
if (is_jsl_e10000(address)) {
/* tool call ... */
const char *name = debug_tool_name(operand, 0xe10000);
const char *name = debug_tool_name(operand, 0xe10000, 0);
if (name) {
opcode_string = name;
buffer[0] = 0;
@ -668,7 +719,7 @@ word32 do_list(word32 address, int lines) {
if (operand == 0xe100a8) {
/* inline GS/OS call? */
unsigned num = get_memory16_c(address, 0);
const char *name = debug_tool_name(num, operand);
const char *name = debug_tool_name(num, operand, 0);
if (name) {
comment = NULL;
opcode_string = name;
@ -685,7 +736,7 @@ word32 do_list(word32 address, int lines) {
ea = (operand | (address & 0xff0000));
if (ea == 0x00bf00) {
unsigned num = get_memory_c(address, 0);
const char *name = debug_tool_name(num, operand);
const char *name = debug_tool_name(num, operand, 0);
if (name) {
opcode_string = name;
unsigned parms = get_memory16_c(address + 1, 0);
@ -1666,6 +1717,11 @@ command:
return 0;
}
"t" {
g_prev_address = tool_lookup(addr & 0xffff);
return 0;
}
*/
}

View File

@ -401,6 +401,7 @@ word32 debug_apply_template(word32 address, const char *name) {
struct tool {
char *name;
char *fullname;
unsigned number;
unsigned vector;
};
@ -415,6 +416,7 @@ struct tool *tool_names = NULL;
int tool_name_count = 0;
static void add_tool(struct tool *t) {
if (tool_count == tool_alloc) {
size_t size = (tool_alloc + 1024) * sizeof(struct tool);
@ -426,6 +428,7 @@ static void add_tool(struct tool *t) {
tools[tool_count++] = *t;
}
static word32 to_hex(const char *iter, const char *end) {
word32 rv = 0;
while(iter != end) {
@ -513,7 +516,7 @@ void debug_load_nifty(const char *path) {
for (line = 1;;++line) {
const char *start;
const char *end;
struct tool tool = { 0, 0, vector };
struct tool tool = { 0, 0, 0, vector };
const char *cp = fgets(buffer, sizeof(buffer), f);
if (!cp) break;
@ -566,12 +569,15 @@ prefix:
if (end > start) {
int l = end - start;
tool.fullname = NULL;
if (vector > 0x0100) {
/* add a leading _ */
tool.name = malloc(l + 2);
tool.name[0] = '_';
strncpy(tool.name + 1, start, l);
tool.name[l + 1] = 0;
tool.fullname = strdup(start);
}
else tool.name = strndup(start, l);
add_tool(&tool);
@ -606,14 +612,15 @@ prefix:
qsort(tool_names, tool_name_count, sizeof(struct tool), tool_name_compare);
}
const char *debug_tool_name(unsigned number, unsigned vector) {
const char *debug_tool_name(unsigned number, unsigned vector, unsigned full) {
if (!tool_count) return NULL;
struct tool tmp = { 0, number, vector };
struct tool tmp = { 0, 0, number, vector };
struct tool *t = bsearch(&tmp, tools, tool_count, sizeof(struct tool), tool_compare);
if (t) return t->name;
return NULL;
if (!t) return NULL;
if (full && t->fullname) return t->fullname;
return t->name;
}
@ -621,9 +628,10 @@ int lookup_tool_number(const char *name, unsigned vector) {
if (!tool_name_count) return 0;
struct tool tmp = { (char *)name, 0, vector};
struct tool tmp = { (char *)name, 0, 0, vector};
struct tool *t = bsearch(&tmp, tool_names, tool_name_count, sizeof(struct tool), tool_name_compare);
if (!t) return 0;
return t->number;
}