]> git.saurik.com Git - apple/system_cmds.git/blobdiff - lsmp.tproj/task_details.c
system_cmds-790.tar.gz
[apple/system_cmds.git] / lsmp.tproj / task_details.c
index aeaa1602885f68e0cb0c936959cbe93bb09dec0e..e8b1ffe818b9344c4b832cea43f958ba7876953a 100644 (file)
@@ -191,7 +191,7 @@ kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_t target_
             }
 
             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);
 
@@ -288,12 +288,15 @@ void get_exc_mask_string(exception_mask_t m, char *out_string, size_t len)
         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) {
@@ -304,16 +307,26 @@ kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo)
             }
             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;
@@ -321,7 +334,12 @@ kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo)
     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.");
@@ -337,12 +355,19 @@ kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo)
             /* 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)
         {
@@ -354,6 +379,8 @@ kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo)
             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");
@@ -361,6 +388,12 @@ kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo)
                         }
                         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;
@@ -368,6 +401,12 @@ kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo)
                             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,
@@ -382,13 +421,15 @@ kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo)
                         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;
 }