X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=sim%2Fcommon%2Fcallback.c;h=8f2c76b1e41a15cad10ee29ee13b7cd43fa979ba;hb=1ce22eebea40573551c2db2e7c83951154d14c81;hp=37d42f8559a0529fb4bbbbefeec672ec92f43e3f;hpb=1a8a700e3a6fd88bcd5b3988a1f738da463f5b1b;p=deliverable%2Fbinutils-gdb.git diff --git a/sim/common/callback.c b/sim/common/callback.c index 37d42f8559..8f2c76b1e4 100644 --- a/sim/common/callback.c +++ b/sim/common/callback.c @@ -1,5 +1,5 @@ /* Remote target callback routines. - Copyright 1995-2014 Free Software Foundation, Inc. + Copyright 1995-2020 Free Software Foundation, Inc. Contributed by Cygnus Solutions. This file is part of GDB. @@ -21,9 +21,8 @@ level. */ #ifdef HAVE_CONFIG_H -#include "cconfig.h" -#endif #include "config.h" +#endif #include "ansidecl.h" #include #include @@ -796,6 +795,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]; m->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]; m->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 +828,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 +843,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 +1063,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; +}