}
if (KERN_SUCCESS == thread_get_mach_voucher(threadPorts[i], 0, &th_voucher) && th_voucher != IPC_VOUCHER_NULL) {
- char *detail = copy_voucher_detail(mach_task_self(), th_voucher);
+ char *detail = copy_voucher_detail(mach_task_self(), th_voucher, NULL);
taskinfo->threadInfos[i].voucher_detail = strndup(detail, VOUCHER_DETAIL_MAXLEN);
free(detail);
strncat(out_string," GUARD", len);
}
-kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo)
+kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo, JSON_t json)
{
char behavior_string[30];
char mask_string[200];
+ JSON_KEY(json, exception_ports);
+ JSON_ARRAY_BEGIN(json);
+
boolean_t header_required = TRUE;
for (int i = 0; i < taskinfo->exceptionInfo.count; i++) {
if (taskinfo->exceptionInfo.ports[i] != MACH_PORT_NULL) {
}
get_exc_behavior_string(taskinfo->exceptionInfo.behaviors[i], behavior_string, sizeof(behavior_string));
get_exc_mask_string(taskinfo->exceptionInfo.masks[i], mask_string, 200);
+
+ JSON_OBJECT_BEGIN(json);
+ JSON_OBJECT_SET(json, port, "0x%08x", taskinfo->exceptionInfo.ports[i]);
+ JSON_OBJECT_SET(json, flavor, "0x%03x", taskinfo->exceptionInfo.flavors[i]);
+ JSON_OBJECT_SET(json, behavior, "%s", behavior_string);
+ JSON_OBJECT_SET(json, mask, "%s", mask_string);
+ JSON_OBJECT_END(json); // exception port
+
printf(" 0x%08x 0x%03x <%s> %s \n" , taskinfo->exceptionInfo.ports[i], taskinfo->exceptionInfo.flavors[i], behavior_string, mask_string);
}
}
+ JSON_ARRAY_END(json); // exception ports
+
return KERN_SUCCESS;
}
-kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo)
+kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo, JSON_t json)
{
kern_return_t kret = KERN_SUCCESS;
mach_msg_type_number_t threadcount = taskinfo->threadCount;
boolean_t newline_required = TRUE;
struct my_per_thread_info * info = NULL;
+ JSON_KEY(json, threads);
+ JSON_ARRAY_BEGIN(json);
+
for (int i = 0; i < threadcount; i++) {
+ JSON_OBJECT_BEGIN(json);
+
info = &taskinfo->threadInfos[i];
if (header_required) {
printf("Thread_KObject Thread-ID Port Description.");
/* TODO: Should print tid and stuff */
printf("0x%08x ", info->th_kobject);
printf("0x%llx ", info->th_id);
+
+ JSON_OBJECT_SET(json, kobject, "0x%08x", info->th_kobject);
+ JSON_OBJECT_SET(json, tid, "0x%llx", info->th_id);
}
if (info->voucher_detail != NULL) {
+ /* TODO: include voucher detail in JSON */
printf("%s\n", info->voucher_detail);
}
+ JSON_KEY(json, exception_ports);
+ JSON_ARRAY_BEGIN(json);
+
/* print the thread exception ports also */
if (taskinfo->threadExceptionInfos != NULL)
{
if (excinfo->count > 0) {
boolean_t header_required = TRUE;
for (int i = 0; i < excinfo->count; i++) {
+ JSON_OBJECT_BEGIN(json);
+
if (excinfo->ports[i] != MACH_PORT_NULL) {
if (header_required) {
printf("\n exc_port flavor <behaviors> mask -> name owner\n");
}
get_exc_behavior_string(excinfo->behaviors[i], behavior_string, sizeof(behavior_string));
get_exc_mask_string(excinfo->masks[i], mask_string, sizeof(mask_string));
+
+ JSON_OBJECT_SET(json, port, "0x%08x", excinfo->ports[i]);
+ JSON_OBJECT_SET(json, flavor, "0x%03x", excinfo->flavors[i]);
+ JSON_OBJECT_SET(json, behavior, "%s", behavior_string);
+ JSON_OBJECT_SET(json, mask, "%s", mask_string);
+
printf(" 0x%08x 0x%03x <%s> %s " , excinfo->ports[i], excinfo->flavors[i], behavior_string, mask_string);
ipc_info_name_t actual_sendinfo;
my_per_task_info_t *recv_holder_taskinfo;
mach_port_name_t recv_name = MACH_PORT_NULL;
if (KERN_SUCCESS == get_taskinfo_of_receiver_by_send_right(&actual_sendinfo, &recv_holder_taskinfo, &recv_name)) {
+
+ JSON_OBJECT_SET(json, name, "0x%08x", recv_name);
+ JSON_OBJECT_SET(json, ipc-object, "0x%08x", actual_sendinfo.iin_object);
+ JSON_OBJECT_SET(json, pid, %d, recv_holder_taskinfo->pid);
+ JSON_OBJECT_SET(json, process, "%s", recv_holder_taskinfo->processName);
+
printf(" -> 0x%08x 0x%08x (%d) %s\n",
recv_name,
actual_sendinfo.iin_object,
printf("\n");
}
-
+ JSON_OBJECT_END(json); // exception port
}
}
-
}
-
+ JSON_ARRAY_END(json); // exception ports
+ JSON_OBJECT_END(json); // thread
}
+
+ JSON_ARRAY_END(json); // threads
printf("\n");
return kret;
}