Skip to content

Commit

Permalink
Print actual string arguments with -Xtrace (part 1)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
h3110n3rv3 committed Nov 27, 2024
1 parent 4772a09 commit eea476f
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions runtime/rastrace/method_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,26 +474,24 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)
if (object == NULL) {
j9str_printf(PORTLIB, cursor, length, "null");
} else {
/* string arg */
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);
thr,
object,
0,
"",
0,
utf8Buffer,
sizeof(utf8Buffer),
&utf8Length);

if (NULL == utf8String) {
j9str_printf(PORTLIB, cursor, length, "(String)<Memory allocation error>");
Expand All @@ -506,9 +504,7 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)
if (utf8Buffer != utf8String) {
j9mem_free_memory(utf8String);
}

#undef DEFAULT_STRING_LENGTH

} else {
/* TODO: handle arrays */

Expand Down

0 comments on commit eea476f

Please sign in to comment.