aboutsummaryrefslogtreecommitdiff
path: root/sim/common
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2015-06-15 19:17:16 +0545
committerMike Frysinger <vapier@gentoo.org>2015-06-17 13:19:51 -0400
commit6362a3f8757bfce133b724df2077573433823ad4 (patch)
tree681f10063e77d5ed43b862eb7be12d4c860e790e /sim/common
parent920467912a594a3e5af1d779487ffe3e5c550aef (diff)
downloadgdb-6362a3f8757bfce133b724df2077573433823ad4.zip
gdb-6362a3f8757bfce133b724df2077573433823ad4.tar.gz
gdb-6362a3f8757bfce133b724df2077573433823ad4.tar.bz2
sim: callback: add human readable strings for debugging to maps
When tracing, we often want to display the human readable name for the various syscall/errno values. Rather than make each target duplicate the lookup, extend the existing maps to include the string directly, and add helper functions to look up the constants. While most targets are autogenerated (from libgloss), the bfin/cris targets have custom maps for the Linux ABI which need to be updated by hand.
Diffstat (limited to 'sim/common')
-rw-r--r--sim/common/ChangeLog10
-rw-r--r--sim/common/callback.c94
-rw-r--r--sim/common/gentmap.c13
3 files changed, 99 insertions, 18 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index a8be420..0478f2c 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,13 @@
+2015-06-17 Mike Frysinger <vapier@gentoo.org>
+
+ * callback.c (cb_target_map_entry, cb_host_map_entry): Define.
+ (cb_target_to_host_syscall): Rewrite to use cb_target_map_entry.
+ (cb_host_to_target_errno): Rewrite to use cb_host_map_entry.
+ (cb_host_str_syscall, cb_host_str_errno, cb_host_str_signal,
+ cb_target_str_syscall, cb_target_str_errno, cb_target_str_signal):
+ Define.
+ * gentmap.c (gen_targ_map_c): Output name field.
+
2015-06-12 Mike Frysinger <vapier@gentoo.org>
* acinclude.m4: Change configure.in to configure.ac.
diff --git a/sim/common/callback.c b/sim/common/callback.c
index f295641..9b42536 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -796,6 +796,32 @@ cb_read_target_syscall_maps (host_callback *cb, const char *file)
return CB_RC_OK;
}
+/* General utility functions to search a map for a value. */
+
+static const CB_TARGET_DEFS_MAP *
+cb_target_map_entry (const CB_TARGET_DEFS_MAP map[], int target_val)
+{
+ const CB_TARGET_DEFS_MAP *m;
+
+ for (m = &map[0]; map->target_val != -1; ++m)
+ if (m->target_val == target_val)
+ return m;
+
+ return NULL;
+}
+
+static const CB_TARGET_DEFS_MAP *
+cb_host_map_entry (const CB_TARGET_DEFS_MAP map[], int host_val)
+{
+ const CB_TARGET_DEFS_MAP *m;
+
+ for (m = &map[0]; map->host_val != -1; ++m)
+ if (m->host_val == host_val)
+ return m;
+
+ return NULL;
+}
+
/* Translate the target's version of a syscall number to the host's.
This isn't actually the host's version, rather a canonical form.
??? Perhaps this should be renamed to ..._canon_syscall. */
@@ -803,13 +829,10 @@ cb_read_target_syscall_maps (host_callback *cb, const char *file)
int
cb_target_to_host_syscall (host_callback *cb, int target_val)
{
- CB_TARGET_DEFS_MAP *m;
-
- for (m = &cb->syscall_map[0]; m->target_val != -1; ++m)
- if (m->target_val == target_val)
- return m->host_val;
+ const CB_TARGET_DEFS_MAP *m =
+ cb_target_map_entry (cb->syscall_map, target_val);
- return -1;
+ return m ? m->host_val : -1;
}
/* FIXME: sort tables if large.
@@ -821,16 +844,12 @@ cb_target_to_host_syscall (host_callback *cb, int target_val)
int
cb_host_to_target_errno (host_callback *cb, int host_val)
{
- CB_TARGET_DEFS_MAP *m;
-
- for (m = &cb->errno_map[0]; m->host_val; ++m)
- if (m->host_val == host_val)
- return m->target_val;
+ const CB_TARGET_DEFS_MAP *m = cb_host_map_entry (cb->errno_map, host_val);
/* ??? Which error to return in this case is up for grabs.
Note that some missing values may have standard alternatives.
For now return 0 and require caller to deal with it. */
- return 0;
+ return m ? m->target_val : 0;
}
/* Given a set of target bitmasks for the open system call,
@@ -1045,3 +1064,54 @@ cb_is_stderr (host_callback *cb, int fd)
{
return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 2;
}
+
+const char *
+cb_host_str_syscall (host_callback *cb, int host_val)
+{
+ const CB_TARGET_DEFS_MAP *m = cb_host_map_entry (cb->syscall_map, host_val);
+
+ return m ? m->name : NULL;
+}
+
+const char *
+cb_host_str_errno (host_callback *cb, int host_val)
+{
+ const CB_TARGET_DEFS_MAP *m = cb_host_map_entry (cb->errno_map, host_val);
+
+ return m ? m->name : NULL;
+}
+
+const char *
+cb_host_str_signal (host_callback *cb, int host_val)
+{
+ const CB_TARGET_DEFS_MAP *m = cb_host_map_entry (cb->signal_map, host_val);
+
+ return m ? m->name : NULL;
+}
+
+const char *
+cb_target_str_syscall (host_callback *cb, int target_val)
+{
+ const CB_TARGET_DEFS_MAP *m =
+ cb_target_map_entry (cb->syscall_map, target_val);
+
+ return m ? m->name : NULL;
+}
+
+const char *
+cb_target_str_errno (host_callback *cb, int target_val)
+{
+ const CB_TARGET_DEFS_MAP *m =
+ cb_target_map_entry (cb->errno_map, target_val);
+
+ return m ? m->name : NULL;
+}
+
+const char *
+cb_target_str_signal (host_callback *cb, int target_val)
+{
+ const CB_TARGET_DEFS_MAP *m =
+ cb_target_map_entry (cb->signal_map, target_val);
+
+ return m ? m->name : NULL;
+}
diff --git a/sim/common/gentmap.c b/sim/common/gentmap.c
index fbc09a2..669a7e5 100644
--- a/sim/common/gentmap.c
+++ b/sim/common/gentmap.c
@@ -80,10 +80,11 @@ gen_targ_map_c (void)
for (t = &sys_tdefs[0]; t->symbol; ++t)
{
printf ("#ifdef CB_%s\n", t->symbol);
- printf (" { CB_%s, TARGET_%s },\n", t->symbol, t->symbol);
+ /* Skip the "SYS_" prefix for the name. */
+ printf (" { \"%s\", CB_%s, TARGET_%s },\n", t->symbol + 4, t->symbol, t->symbol);
printf ("#endif\n");
}
- printf (" { -1, -1 }\n");
+ printf (" { 0, -1, -1 }\n");
printf ("};\n\n");
printf ("/* errno mapping table */\n");
@@ -91,10 +92,10 @@ gen_targ_map_c (void)
for (t = &errno_tdefs[0]; t->symbol; ++t)
{
printf ("#ifdef %s\n", t->symbol);
- printf (" { %s, TARGET_%s },\n", t->symbol, t->symbol);
+ printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
printf ("#endif\n");
}
- printf (" { 0, 0 }\n");
+ printf (" { 0, 0, 0 }\n");
printf ("};\n\n");
printf ("/* open flags mapping table */\n");
@@ -102,10 +103,10 @@ gen_targ_map_c (void)
for (t = &open_tdefs[0]; t->symbol; ++t)
{
printf ("#ifdef %s\n", t->symbol);
- printf (" { %s, TARGET_%s },\n", t->symbol, t->symbol);
+ printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
printf ("#endif\n");
}
- printf (" { -1, -1 }\n");
+ printf (" { 0, -1, -1 }\n");
printf ("};\n\n");
}