From c0fdf4b185cd2dca8d3f9b7026c839144e5acfeb Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Tue, 19 Nov 2024 14:28:35 -0500 Subject: [PATCH] Print actual string arguments with -Xtrace (part 1) The changes reflect the feature request #16416. Print the actual string instead of address at max of 32 characters. Subsequent PRs: cmdline option for length (part 2) and tests (part 3). Signed-off-by: Nick Kamal Print actual string arguments with -Xtrace (part 1) The changes reflect the feature request #16416. Print the actual string instead of address at max of 32 characters. Subsequent PRs: cmdline option for length (part 2) and tests (part 3). Signed-off-by: Nick Kamal Print actual String arguments with Xtrace part 1 The changes reflect the feature request #16416. Print the actual string instead of address at max of 32 characters. Subsequent PRs: cmdline option for length (Part 2) and tests (Part 3). Signed-off-by: Nick Kamal --- runtime/rastrace/method_trace.c | 41 +++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index 81b2ae446a2..82b3eb207d5 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -474,13 +474,44 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) if (object == NULL) { j9str_printf(PORTLIB, cursor, length, "null"); } else { - J9Class* clazz = J9OBJECT_CLAZZ(thr, object); - J9ROMClass * romClass = clazz->romClass; - J9UTF8* className = J9ROMCLASS_CLASSNAME(romClass); + J9Class *clazz = J9OBJECT_CLAZZ(thr, object); + J9JavaVM *vm = thr->javaVM; + + if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm)) { + /* string argument */ +#define DEFAULT_STRING_LENGTH 32 + char utf8Buffer[128]; + UDATA utf8Length = 0; + + char *utf8String = vm->internalVMFunctions->copyStringToUTF8WithMemAlloc( + thr, + object, + 0, + "", + 0, + utf8Buffer, + sizeof(utf8Buffer), + &utf8Length); + + if (NULL == utf8String) { + j9str_printf(PORTLIB, cursor, length, "(String)"); + } else if (utf8Length > DEFAULT_STRING_LENGTH) { + j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)DEFAULT_STRING_LENGTH, utf8String); + } else { + j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String); + } - /* TODO: handle arrays */ + if (utf8Buffer != utf8String) { + j9mem_free_memory(utf8String); + } +#undef DEFAULT_STRING_LENGTH + } else { + /* TODO: handle arrays */ - j9str_printf(PORTLIB, cursor, length, "%.*s@%p", (U_32)J9UTF8_LENGTH(className), J9UTF8_DATA(className), object); + J9ROMClass *romClass = clazz->romClass; + J9UTF8 *className = J9ROMCLASS_CLASSNAME(romClass); + j9str_printf(PORTLIB, cursor, length, "%.*s@%p", (U_32)J9UTF8_LENGTH(className), J9UTF8_DATA(className), object); + } } }