From abd36d3e2fa5e857278a2b89901cc7591bb75a89 Mon Sep 17 00:00:00 2001 From: James D Johnston Date: Sun, 11 Nov 2018 09:09:15 -0500 Subject: [PATCH] z/TPF Backtrace Translation and Processing Fixes z/TPF Symbol Names and Modules names from dladdr are returned as EBCDIC characters sets. These values need to be translated before being stored in the backtrace frame control structure otherwise they are printed out as garbage characters. Furthermore the top of stack for z/TPF is a dummy invalid frame, and needs to be pruned from the backtrace otherwise unexpected behaviour occurs. Signed-off-by: James D Johnston --- port/ztpf/omrosbacktrace_impl.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/port/ztpf/omrosbacktrace_impl.c b/port/ztpf/omrosbacktrace_impl.c index 6f7c2e42190..50543497d15 100644 --- a/port/ztpf/omrosbacktrace_impl.c +++ b/port/ztpf/omrosbacktrace_impl.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2017 IBM Corp. and others + * Copyright (c) 1991, 2018 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -38,6 +38,8 @@ #include "omrintrospect.h" +#include + uintptr_t protectedBacktrace(struct OMRPortLibrary *port, void *arg); uintptr_t backtrace_sigprotect(struct OMRPortLibrary *portLibrary, J9PlatformThread *threadInfo, void **address_array, int capacity); @@ -149,6 +151,12 @@ omrintrospect_backtrace_thread_raw(struct OMRPortLibrary *portLibrary, ret = backtrace_sigprotect(portLibrary, threadInfo, addresses, sizeof(addresses) / sizeof(void*)); + /* + * z/TPF Stack grows down. The top-of-stack has a dummy frame which should be ignored. + * Therefore reducing stack frame count by one. + */ + ret--; + nextFrame = &threadInfo->callstack; for (i = 0; i < ret; i++) { if (heap != NULL) { @@ -246,6 +254,8 @@ omrintrospect_backtrace_symbols_raw(struct OMRPortLibrary *portLibrary, uintptr_t symbol_offset = 0; uintptr_t module_offset = 0; const char *symbol_name = ""; + char asciiSymbolBuffer[512]; + char asciiModuleBuffer[512]; const char *module_name = ""; short symbol_length = 0; @@ -285,9 +295,10 @@ omrintrospect_backtrace_symbols_raw(struct OMRPortLibrary *portLibrary, /* symbol_name+offset (id, instruction_pointer [module+offset]) */ if (symbol_length > 0) { + e2a_len(symbol_name, asciiSymbolBuffer, symbol_length+1); cursor += omrstr_printf(portLibrary, cursor, sizeof(output_buf) - (cursor - output_buf), "%.*s", - symbol_length, symbol_name); + symbol_length, asciiSymbolBuffer); cursor += omrstr_printf(portLibrary, cursor, sizeof(output_buf) - (cursor - output_buf), "+0x%x ", symbol_offset); @@ -296,9 +307,10 @@ omrintrospect_backtrace_symbols_raw(struct OMRPortLibrary *portLibrary, sizeof(output_buf) - (cursor - output_buf), "(0x%p", frame->instruction_pointer); if (module_name[0] != '\0') { + e2a_len(module_name, asciiModuleBuffer, strlen(module_name)+1); cursor += omrstr_printf(portLibrary, cursor, sizeof(output_buf) - (cursor - output_buf), " [%s+0x%x]", - module_name, module_offset); + asciiModuleBuffer, module_offset); } *(cursor++) = ')'; *cursor = 0;