Skip to content

Commit

Permalink
z/TPF Backtrace Translation and Processing Fixes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jjohnst-us authored and pdbain-ibm committed Nov 13, 2018
1 parent c7a1210 commit abd36d3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions port/ztpf/omrosbacktrace_impl.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -38,6 +38,8 @@

#include "omrintrospect.h"

#include <atoe.h>

uintptr_t protectedBacktrace(struct OMRPortLibrary *port, void *arg);
uintptr_t backtrace_sigprotect(struct OMRPortLibrary *portLibrary,
J9PlatformThread *threadInfo, void **address_array, int capacity);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = "<unknown>";
short symbol_length = 0;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit abd36d3

Please sign in to comment.