From f44ec114149146d616c262933f61583f572129ae Mon Sep 17 00:00:00 2001 From: Peter Seebach Date: Fri, 4 Sep 2015 16:14:17 -0500 Subject: Add return value printing to wrappers I never did this because how could you do it generically, then a friend who is better at Python gave me an idea for a way to do it, and now wrapper debugging prints return values, not just errno values, in most-to-all cases. Signed-off-by: Peter Seebach --- ChangeLog.txt | 3 +++ makewrappers | 28 ++++++++++++++++++++++++++++ templates/wrapfuncs.c | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index e2bd123..9b39838 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +2015-09-04: + * (seebs) add return value printing to wrapper debug! + 2015-09-03: * (seebs) Use original mode, not 0600, for the chmods used to ensure that an 0700 umask didn't prevent writing. diff --git a/makewrappers b/makewrappers index 15b4274..e9191ed 100755 --- a/makewrappers +++ b/makewrappers @@ -195,6 +195,26 @@ class Argument: def __repr__(self): return self.decl() +typedata = { + 'char *': { 'format': '%s', 'value': 'rc ? rc : ""' }, + 'const char *': { 'format': '%s', 'value': 'rc ? rc : ""' }, + 'DIR *': { 'format': '%p', 'value': '(void *) rc' }, + 'FILE *': { 'format': '%p', 'value': '(void *) rc' }, + 'FTS *': { 'format': '%p', 'value': '(void *) rc' }, + 'gid_t': { 'format': '%ld', 'value': ' (long) rc' }, + 'int': { 'format': '%d', 'value': 'rc' }, + 'long': { 'format': '%ld', 'value': 'rc' }, + 'mode_t': { 'format': '0%lo', 'value': '(long) rc' }, + 'off_t': { 'format': '%lld', 'value': '(long long) rc' }, + 'size_t': { 'format': '%lu', 'value': '(unsigned long) rc' }, + 'ssize_t': { 'format': '%ld', 'value': '(long) rc' }, + 'struct group *': { 'format': '%p', 'value': '(void *) rc' }, + 'struct passwd *': { 'format': '%p', 'value': '(void *) rc' }, + 'uid_t': { 'format': '%ld', 'value': ' (long) rc' }, + 'void *': { 'format': '%p', 'value': 'rc' }, + 'void': { 'format': 'void%s', 'value': '""' }, +} + class Function: """A function signature and additional data about how the function works""" def __init__(self, port, line): @@ -371,6 +391,14 @@ class Function: else: return "return rc;" + def rc_format(self): + """the format string to use for the return value""" + return typedata.get(self.type, { 'format': '[%s]', 'value': '"' + self.type + '"' })['format'] + + def rc_value(self): + """the value to pass for the format string for the return value""" + return typedata.get(self.type, { 'format': '[%s]', 'value': '"' + self.type + '"' })['value'] + def rc_decl(self): """declare rc (if needed)""" if self.type == 'void': diff --git a/templates/wrapfuncs.c b/templates/wrapfuncs.c index 2d13031..3859183 100644 --- a/templates/wrapfuncs.c +++ b/templates/wrapfuncs.c @@ -73,9 +73,9 @@ ${maybe_async_skip} /* This can cause hangs on some recentish systems which use locale * stuff for strerror... */ - pseudo_debug(PDBGF_WRAPPER, "wrapper completed: ${name} (maybe: %s)\n", strerror(save_errno)); + pseudo_debug(PDBGF_WRAPPER, "wrapper completed: ${name} returns ${rc_format} (errno: %s)\n", ${rc_value}, strerror(save_errno)); #endif - pseudo_debug(PDBGF_WRAPPER, "wrapper completed: ${name} (errno: %d)\n", save_errno); + pseudo_debug(PDBGF_WRAPPER, "wrapper completed: ${name} returns ${rc_format} (errno: %d)\n", ${rc_value}, save_errno); errno = save_errno; PROFILE_DONE; ${rc_return} -- cgit v1.2.3