Rename gdb/ChangeLog to gdb/ChangeLog-2021
[binutils-gdb.git] / gdb / darwin-nat-info.c
blob5852e9bf01404b1a5e1cbf7c31c6b254c8d5449b
1 /* Darwin support for GDB, the GNU debugger.
2 Copyright (C) 1997-2021 Free Software Foundation, Inc.
4 Contributed by Apple Computer, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* The name of the ppc_thread_state structure, and the names of its
22 members, have been changed for Unix conformance reasons. The easiest
23 way to have gdb build on systems with the older names and systems
24 with the newer names is to build this compilation unit with the
25 non-conformant define below. This doesn't seem to cause the resulting
26 binary any problems but it seems like it could cause us problems in
27 the future. It'd be good to remove this at some point when compiling on
28 Tiger is no longer important. */
30 #include "defs.h"
31 #include "symtab.h"
32 #include "gdbtypes.h"
33 #include "gdbcore.h"
34 #include "value.h"
35 #include "gdbcmd.h"
36 #include "inferior.h"
37 #include "gdbarch.h"
39 #include <sys/sysctl.h>
41 #include "darwin-nat.h"
43 #include <mach/thread_info.h>
44 #include <mach/thread_act.h>
45 #include <mach/task.h>
46 #include <mach/vm_map.h>
47 #include <mach/mach_port.h>
48 #include <mach/mach_init.h>
49 #include <mach/mach_vm.h>
51 #define CHECK_ARGS(what, args) do { \
52 if ((NULL == args) || ((args[0] != '0') && (args[1] != 'x'))) \
53 error(_("%s must be specified with 0x..."), what); \
54 } while (0)
56 #define PRINT_FIELD(structure, field) \
57 printf_unfiltered(_(#field":\t%#lx\n"), (unsigned long) (structure)->field)
59 #define PRINT_TV_FIELD(structure, field) \
60 printf_unfiltered(_(#field":\t%u.%06u sec\n"), \
61 (unsigned) (structure)->field.seconds, \
62 (unsigned) (structure)->field.microseconds)
64 #define task_self mach_task_self
65 #define task_by_unix_pid task_for_pid
66 #define port_name_array_t mach_port_array_t
67 #define port_type_array_t mach_port_array_t
69 static void
70 info_mach_tasks_command (const char *args, int from_tty)
72 int sysControl[4];
73 int count, index;
74 size_t length;
75 struct kinfo_proc *procInfo;
77 sysControl[0] = CTL_KERN;
78 sysControl[1] = KERN_PROC;
79 sysControl[2] = KERN_PROC_ALL;
81 sysctl (sysControl, 3, NULL, &length, NULL, 0);
82 procInfo = (struct kinfo_proc *) xmalloc (length);
83 sysctl (sysControl, 3, procInfo, &length, NULL, 0);
85 count = (length / sizeof (struct kinfo_proc));
86 printf_unfiltered (_("%d processes:\n"), count);
87 for (index = 0; index < count; ++index)
89 kern_return_t result;
90 mach_port_t taskPort;
92 result =
93 task_by_unix_pid (mach_task_self (), procInfo[index].kp_proc.p_pid,
94 &taskPort);
95 if (KERN_SUCCESS == result)
97 printf_unfiltered (_(" %s is %d has task %#x\n"),
98 procInfo[index].kp_proc.p_comm,
99 procInfo[index].kp_proc.p_pid, taskPort);
101 else
103 printf_unfiltered (_(" %s is %d unknown task port\n"),
104 procInfo[index].kp_proc.p_comm,
105 procInfo[index].kp_proc.p_pid);
109 xfree (procInfo);
112 static task_t
113 get_task_from_args (const char *args)
115 task_t task;
116 char *eptr;
118 if (args == NULL || *args == 0)
120 if (inferior_ptid == null_ptid)
121 printf_unfiltered (_("No inferior running\n"));
123 darwin_inferior *priv = get_darwin_inferior (current_inferior ());
125 return priv->task;
127 if (strcmp (args, "gdb") == 0)
128 return mach_task_self ();
129 task = strtoul (args, &eptr, 0);
130 if (*eptr)
132 printf_unfiltered (_("cannot parse task id '%s'\n"), args);
133 return TASK_NULL;
135 return task;
138 static void
139 info_mach_task_command (const char *args, int from_tty)
141 union
143 struct task_basic_info basic;
144 struct task_events_info events;
145 struct task_thread_times_info thread_times;
146 } task_info_data;
148 kern_return_t result;
149 unsigned int info_count;
150 task_t task;
152 task = get_task_from_args (args);
153 if (task == TASK_NULL)
154 return;
156 printf_unfiltered (_("TASK_BASIC_INFO for 0x%x:\n"), task);
157 info_count = TASK_BASIC_INFO_COUNT;
158 result = task_info (task,
159 TASK_BASIC_INFO,
160 (task_info_t) & task_info_data.basic, &info_count);
161 MACH_CHECK_ERROR (result);
163 PRINT_FIELD (&task_info_data.basic, suspend_count);
164 PRINT_FIELD (&task_info_data.basic, virtual_size);
165 PRINT_FIELD (&task_info_data.basic, resident_size);
166 PRINT_TV_FIELD (&task_info_data.basic, user_time);
167 PRINT_TV_FIELD (&task_info_data.basic, system_time);
168 printf_unfiltered (_("\nTASK_EVENTS_INFO:\n"));
169 info_count = TASK_EVENTS_INFO_COUNT;
170 result = task_info (task,
171 TASK_EVENTS_INFO,
172 (task_info_t) & task_info_data.events, &info_count);
173 MACH_CHECK_ERROR (result);
175 PRINT_FIELD (&task_info_data.events, faults);
176 #if 0
177 PRINT_FIELD (&task_info_data.events, zero_fills);
178 PRINT_FIELD (&task_info_data.events, reactivations);
179 #endif
180 PRINT_FIELD (&task_info_data.events, pageins);
181 PRINT_FIELD (&task_info_data.events, cow_faults);
182 PRINT_FIELD (&task_info_data.events, messages_sent);
183 PRINT_FIELD (&task_info_data.events, messages_received);
184 printf_unfiltered (_("\nTASK_THREAD_TIMES_INFO:\n"));
185 info_count = TASK_THREAD_TIMES_INFO_COUNT;
186 result = task_info (task,
187 TASK_THREAD_TIMES_INFO,
188 (task_info_t) & task_info_data.thread_times,
189 &info_count);
190 MACH_CHECK_ERROR (result);
191 PRINT_TV_FIELD (&task_info_data.thread_times, user_time);
192 PRINT_TV_FIELD (&task_info_data.thread_times, system_time);
195 static void
196 info_mach_ports_command (const char *args, int from_tty)
198 port_name_array_t names;
199 port_type_array_t types;
200 unsigned int name_count, type_count;
201 kern_return_t result;
202 int index;
203 task_t task;
205 task = get_task_from_args (args);
206 if (task == TASK_NULL)
207 return;
209 result = mach_port_names (task, &names, &name_count, &types, &type_count);
210 MACH_CHECK_ERROR (result);
212 gdb_assert (name_count == type_count);
214 printf_unfiltered (_("Ports for task 0x%x:\n"), task);
215 printf_unfiltered (_("port type\n"));
216 for (index = 0; index < name_count; ++index)
218 mach_port_t port = names[index];
219 unsigned int j;
220 struct type_descr
222 mach_port_type_t type;
223 const char *name;
224 mach_port_right_t right;
226 static struct type_descr descrs[] =
228 {MACH_PORT_TYPE_SEND, "send", MACH_PORT_RIGHT_SEND},
229 {MACH_PORT_TYPE_SEND_ONCE, "send-once", MACH_PORT_RIGHT_SEND_ONCE},
230 {MACH_PORT_TYPE_RECEIVE, "receive", MACH_PORT_RIGHT_RECEIVE},
231 {MACH_PORT_TYPE_PORT_SET, "port-set", MACH_PORT_RIGHT_PORT_SET},
232 {MACH_PORT_TYPE_DEAD_NAME, "dead", MACH_PORT_RIGHT_DEAD_NAME}
235 printf_unfiltered (_("%04x: %08x "), port, types[index]);
236 for (j = 0; j < sizeof(descrs) / sizeof(*descrs); j++)
237 if (types[index] & descrs[j].type)
239 mach_port_urefs_t ref;
240 kern_return_t ret;
242 printf_unfiltered (_(" %s("), descrs[j].name);
243 ret = mach_port_get_refs (task, port, descrs[j].right, &ref);
244 if (ret != KERN_SUCCESS)
245 printf_unfiltered (_("??"));
246 else
247 printf_unfiltered (_("%u"), ref);
248 printf_unfiltered (_(" refs)"));
251 if (task == task_self ())
253 if (port == task_self())
254 printf_unfiltered (_(" gdb-task"));
255 else if (port == darwin_host_self)
256 printf_unfiltered (_(" host-self"));
257 else if (port == darwin_ex_port)
258 printf_unfiltered (_(" gdb-exception"));
259 else if (port == darwin_port_set)
260 printf_unfiltered (_(" gdb-port_set"));
261 else if (inferior_ptid != null_ptid)
263 struct inferior *inf = current_inferior ();
264 darwin_inferior *priv = get_darwin_inferior (inf);
266 if (port == priv->task)
267 printf_unfiltered (_(" inferior-task"));
268 else if (port == priv->notify_port)
269 printf_unfiltered (_(" inferior-notify"));
270 else
272 for (int k = 0; k < priv->exception_info.count; k++)
273 if (port == priv->exception_info.ports[k])
275 printf_unfiltered (_(" inferior-excp-port"));
276 break;
279 for (darwin_thread_t *t : priv->threads)
281 if (port == t->gdb_port)
283 printf_unfiltered (_(" inferior-thread for 0x%x"),
284 priv->task);
285 break;
292 printf_unfiltered (_("\n"));
295 vm_deallocate (task_self (), (vm_address_t) names,
296 (name_count * sizeof (mach_port_t)));
297 vm_deallocate (task_self (), (vm_address_t) types,
298 (type_count * sizeof (mach_port_type_t)));
302 static void
303 darwin_debug_port_info (task_t task, mach_port_t port)
305 kern_return_t kret;
306 mach_port_status_t status;
307 mach_msg_type_number_t len = sizeof (status);
309 kret = mach_port_get_attributes
310 (task, port, MACH_PORT_RECEIVE_STATUS, (mach_port_info_t)&status, &len);
311 MACH_CHECK_ERROR (kret);
313 printf_unfiltered (_("Port 0x%lx in task 0x%lx:\n"), (unsigned long) port,
314 (unsigned long) task);
315 printf_unfiltered (_(" port set: 0x%x\n"), status.mps_pset);
316 printf_unfiltered (_(" seqno: 0x%x\n"), status.mps_seqno);
317 printf_unfiltered (_(" mscount: 0x%x\n"), status.mps_mscount);
318 printf_unfiltered (_(" qlimit: 0x%x\n"), status.mps_qlimit);
319 printf_unfiltered (_(" msgcount: 0x%x\n"), status.mps_msgcount);
320 printf_unfiltered (_(" sorights: 0x%x\n"), status.mps_sorights);
321 printf_unfiltered (_(" srights: 0x%x\n"), status.mps_srights);
322 printf_unfiltered (_(" pdrequest: 0x%x\n"), status.mps_pdrequest);
323 printf_unfiltered (_(" nsrequest: 0x%x\n"), status.mps_nsrequest);
324 printf_unfiltered (_(" flags: 0x%x\n"), status.mps_flags);
327 static void
328 info_mach_port_command (const char *args, int from_tty)
330 task_t task;
331 mach_port_t port;
333 CHECK_ARGS (_("Task and port"), args);
334 sscanf (args, "0x%x 0x%x", &task, &port);
336 darwin_debug_port_info (task, port);
339 static void
340 info_mach_threads_command (const char *args, int from_tty)
342 thread_array_t threads;
343 unsigned int thread_count;
344 kern_return_t result;
345 task_t task;
346 int i;
348 task = get_task_from_args (args);
349 if (task == TASK_NULL)
350 return;
352 result = task_threads (task, &threads, &thread_count);
353 MACH_CHECK_ERROR (result);
355 printf_unfiltered (_("Threads in task %#x:\n"), task);
356 for (i = 0; i < thread_count; ++i)
358 printf_unfiltered (_(" %#x\n"), threads[i]);
359 mach_port_deallocate (task_self (), threads[i]);
362 vm_deallocate (task_self (), (vm_address_t) threads,
363 (thread_count * sizeof (thread_t)));
366 static void
367 info_mach_thread_command (const char *args, int from_tty)
369 union
371 struct thread_basic_info basic;
372 } thread_info_data;
374 thread_t thread;
375 kern_return_t result;
376 unsigned int info_count;
378 CHECK_ARGS (_("Thread"), args);
379 sscanf (args, "0x%x", &thread);
381 printf_unfiltered (_("THREAD_BASIC_INFO\n"));
382 info_count = THREAD_BASIC_INFO_COUNT;
383 result = thread_info (thread,
384 THREAD_BASIC_INFO,
385 (thread_info_t) & thread_info_data.basic,
386 &info_count);
387 MACH_CHECK_ERROR (result);
389 #if 0
390 PRINT_FIELD (&thread_info_data.basic, user_time);
391 PRINT_FIELD (&thread_info_data.basic, system_time);
392 #endif
393 PRINT_FIELD (&thread_info_data.basic, cpu_usage);
394 PRINT_FIELD (&thread_info_data.basic, run_state);
395 PRINT_FIELD (&thread_info_data.basic, flags);
396 PRINT_FIELD (&thread_info_data.basic, suspend_count);
397 PRINT_FIELD (&thread_info_data.basic, sleep_time);
400 static const char *
401 unparse_protection (vm_prot_t p)
403 switch (p)
405 case VM_PROT_NONE:
406 return "---";
407 case VM_PROT_READ:
408 return "r--";
409 case VM_PROT_WRITE:
410 return "-w-";
411 case VM_PROT_READ | VM_PROT_WRITE:
412 return "rw-";
413 case VM_PROT_EXECUTE:
414 return "--x";
415 case VM_PROT_EXECUTE | VM_PROT_READ:
416 return "r-x";
417 case VM_PROT_EXECUTE | VM_PROT_WRITE:
418 return "-wx";
419 case VM_PROT_EXECUTE | VM_PROT_WRITE | VM_PROT_READ:
420 return "rwx";
421 default:
422 return "???";
426 static const char *
427 unparse_inheritance (vm_inherit_t i)
429 switch (i)
431 case VM_INHERIT_SHARE:
432 return _("share");
433 case VM_INHERIT_COPY:
434 return _("copy ");
435 case VM_INHERIT_NONE:
436 return _("none ");
437 default:
438 return _("??? ");
442 static const char *
443 unparse_share_mode (unsigned char p)
445 switch (p)
447 case SM_COW:
448 return _("cow");
449 case SM_PRIVATE:
450 return _("private");
451 case SM_EMPTY:
452 return _("empty");
453 case SM_SHARED:
454 return _("shared");
455 case SM_TRUESHARED:
456 return _("true-shrd");
457 case SM_PRIVATE_ALIASED:
458 return _("prv-alias");
459 case SM_SHARED_ALIASED:
460 return _("shr-alias");
461 default:
462 return _("???");
466 static const char *
467 unparse_user_tag (unsigned int tag)
469 switch (tag)
471 case 0:
472 return _("default");
473 case VM_MEMORY_MALLOC:
474 return _("malloc");
475 case VM_MEMORY_MALLOC_SMALL:
476 return _("malloc_small");
477 case VM_MEMORY_MALLOC_LARGE:
478 return _("malloc_large");
479 case VM_MEMORY_MALLOC_HUGE:
480 return _("malloc_huge");
481 case VM_MEMORY_SBRK:
482 return _("sbrk");
483 case VM_MEMORY_REALLOC:
484 return _("realloc");
485 case VM_MEMORY_MALLOC_TINY:
486 return _("malloc_tiny");
487 case VM_MEMORY_ANALYSIS_TOOL:
488 return _("analysis_tool");
489 case VM_MEMORY_MACH_MSG:
490 return _("mach_msg");
491 case VM_MEMORY_IOKIT:
492 return _("iokit");
493 case VM_MEMORY_STACK:
494 return _("stack");
495 case VM_MEMORY_GUARD:
496 return _("guard");
497 case VM_MEMORY_SHARED_PMAP:
498 return _("shared_pmap");
499 case VM_MEMORY_DYLIB:
500 return _("dylib");
501 case VM_MEMORY_APPKIT:
502 return _("appkit");
503 case VM_MEMORY_FOUNDATION:
504 return _("foundation");
505 default:
506 return NULL;
510 static void
511 darwin_debug_regions (task_t task, mach_vm_address_t address, int max)
513 kern_return_t kret;
514 vm_region_basic_info_data_64_t info, prev_info;
515 mach_vm_address_t prev_address;
516 mach_vm_size_t size, prev_size;
518 mach_port_t object_name;
519 mach_msg_type_number_t count;
521 int nsubregions = 0;
522 int num_printed = 0;
524 count = VM_REGION_BASIC_INFO_COUNT_64;
525 kret = mach_vm_region (task, &address, &size, VM_REGION_BASIC_INFO_64,
526 (vm_region_info_t) &info, &count, &object_name);
527 if (kret != KERN_SUCCESS)
529 printf_filtered (_("No memory regions."));
530 return;
532 memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t));
533 prev_address = address;
534 prev_size = size;
535 nsubregions = 1;
537 for (;;)
539 int print = 0;
540 int done = 0;
542 address = prev_address + prev_size;
544 /* Check to see if address space has wrapped around. */
545 if (address == 0)
546 print = done = 1;
548 if (!done)
550 count = VM_REGION_BASIC_INFO_COUNT_64;
551 kret =
552 mach_vm_region (task, &address, &size, VM_REGION_BASIC_INFO_64,
553 (vm_region_info_t) &info, &count, &object_name);
554 if (kret != KERN_SUCCESS)
556 size = 0;
557 print = done = 1;
561 if (address != prev_address + prev_size)
562 print = 1;
564 if ((info.protection != prev_info.protection)
565 || (info.max_protection != prev_info.max_protection)
566 || (info.inheritance != prev_info.inheritance)
567 || (info.shared != prev_info.reserved)
568 || (info.reserved != prev_info.reserved))
569 print = 1;
571 if (print)
573 printf_filtered (_("%s-%s %s/%s %s %s %s"),
574 paddress (target_gdbarch (), prev_address),
575 paddress (target_gdbarch (), prev_address + prev_size),
576 unparse_protection (prev_info.protection),
577 unparse_protection (prev_info.max_protection),
578 unparse_inheritance (prev_info.inheritance),
579 prev_info.shared ? _("shrd") : _("priv"),
580 prev_info.reserved ? _("reserved") : _("not-rsvd"));
582 if (nsubregions > 1)
583 printf_filtered (_(" (%d sub-rgn)"), nsubregions);
585 printf_filtered (_("\n"));
587 prev_address = address;
588 prev_size = size;
589 memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t));
590 nsubregions = 1;
592 num_printed++;
594 else
596 prev_size += size;
597 nsubregions++;
600 if ((max > 0) && (num_printed >= max))
601 done = 1;
603 if (done)
604 break;
608 static void
609 darwin_debug_regions_recurse (task_t task)
611 mach_vm_address_t r_start;
612 mach_vm_size_t r_size;
613 natural_t r_depth;
614 mach_msg_type_number_t r_info_size;
615 vm_region_submap_short_info_data_64_t r_info;
616 kern_return_t kret;
617 struct ui_out *uiout = current_uiout;
619 ui_out_emit_table table_emitter (uiout, 9, -1, "regions");
621 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
623 uiout->table_header (10, ui_left, "start", "Start");
624 uiout->table_header (10, ui_left, "end", "End");
626 else
628 uiout->table_header (18, ui_left, "start", "Start");
629 uiout->table_header (18, ui_left, "end", "End");
631 uiout->table_header (3, ui_left, "min-prot", "Min");
632 uiout->table_header (3, ui_left, "max-prot", "Max");
633 uiout->table_header (5, ui_left, "inheritence", "Inh");
634 uiout->table_header (9, ui_left, "share-mode", "Shr");
635 uiout->table_header (1, ui_left, "depth", "D");
636 uiout->table_header (3, ui_left, "submap", "Sm");
637 uiout->table_header (0, ui_noalign, "tag", "Tag");
639 uiout->table_body ();
641 r_start = 0;
642 r_depth = 0;
643 while (1)
645 const char *tag;
647 r_info_size = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64;
648 r_size = -1;
649 kret = mach_vm_region_recurse (task, &r_start, &r_size, &r_depth,
650 (vm_region_recurse_info_t) &r_info,
651 &r_info_size);
652 if (kret != KERN_SUCCESS)
653 break;
656 ui_out_emit_tuple tuple_emitter (uiout, "regions-row");
658 uiout->field_core_addr ("start", target_gdbarch (), r_start);
659 uiout->field_core_addr ("end", target_gdbarch (), r_start + r_size);
660 uiout->field_string ("min-prot",
661 unparse_protection (r_info.protection));
662 uiout->field_string ("max-prot",
663 unparse_protection (r_info.max_protection));
664 uiout->field_string ("inheritence",
665 unparse_inheritance (r_info.inheritance));
666 uiout->field_string ("share-mode",
667 unparse_share_mode (r_info.share_mode));
668 uiout->field_signed ("depth", r_depth);
669 uiout->field_string ("submap",
670 r_info.is_submap ? _("sm ") : _("obj"));
671 tag = unparse_user_tag (r_info.user_tag);
672 if (tag)
673 uiout->field_string ("tag", tag);
674 else
675 uiout->field_signed ("tag", r_info.user_tag);
678 uiout->text ("\n");
680 if (r_info.is_submap)
681 r_depth++;
682 else
683 r_start += r_size;
688 static void
689 darwin_debug_region (task_t task, mach_vm_address_t address)
691 darwin_debug_regions (task, address, 1);
694 static void
695 info_mach_regions_command (const char *args, int from_tty)
697 task_t task;
699 task = get_task_from_args (args);
700 if (task == TASK_NULL)
701 return;
703 darwin_debug_regions (task, 0, -1);
706 static void
707 info_mach_regions_recurse_command (const char *args, int from_tty)
709 task_t task;
711 task = get_task_from_args (args);
712 if (task == TASK_NULL)
713 return;
715 darwin_debug_regions_recurse (task);
718 static void
719 info_mach_region_command (const char *exp, int from_tty)
721 struct value *val;
722 mach_vm_address_t address;
723 struct inferior *inf;
725 expression_up expr = parse_expression (exp);
726 val = evaluate_expression (expr.get ());
727 if (TYPE_IS_REFERENCE (value_type (val)))
729 val = value_ind (val);
731 address = value_as_address (val);
733 if (inferior_ptid == null_ptid)
734 error (_("Inferior not available"));
736 inf = current_inferior ();
737 darwin_inferior *priv = get_darwin_inferior (inf);
738 darwin_debug_region (priv->task, address);
741 static void
742 disp_exception (const darwin_exception_info *info)
744 int i;
746 printf_filtered (_("%d exceptions:\n"), info->count);
747 for (i = 0; i < info->count; i++)
749 exception_mask_t mask = info->masks[i];
751 printf_filtered (_("port 0x%04x, behavior: "), info->ports[i]);
752 switch (info->behaviors[i])
754 case EXCEPTION_DEFAULT:
755 printf_unfiltered (_("default"));
756 break;
757 case EXCEPTION_STATE:
758 printf_unfiltered (_("state"));
759 break;
760 case EXCEPTION_STATE_IDENTITY:
761 printf_unfiltered (_("state-identity"));
762 break;
763 default:
764 printf_unfiltered (_("0x%x"), info->behaviors[i]);
766 printf_unfiltered (_(", masks:"));
767 if (mask & EXC_MASK_BAD_ACCESS)
768 printf_unfiltered (_(" BAD_ACCESS"));
769 if (mask & EXC_MASK_BAD_INSTRUCTION)
770 printf_unfiltered (_(" BAD_INSTRUCTION"));
771 if (mask & EXC_MASK_ARITHMETIC)
772 printf_unfiltered (_(" ARITHMETIC"));
773 if (mask & EXC_MASK_EMULATION)
774 printf_unfiltered (_(" EMULATION"));
775 if (mask & EXC_MASK_SOFTWARE)
776 printf_unfiltered (_(" SOFTWARE"));
777 if (mask & EXC_MASK_BREAKPOINT)
778 printf_unfiltered (_(" BREAKPOINT"));
779 if (mask & EXC_MASK_SYSCALL)
780 printf_unfiltered (_(" SYSCALL"));
781 if (mask & EXC_MASK_MACH_SYSCALL)
782 printf_unfiltered (_(" MACH_SYSCALL"));
783 if (mask & EXC_MASK_RPC_ALERT)
784 printf_unfiltered (_(" RPC_ALERT"));
785 if (mask & EXC_MASK_CRASH)
786 printf_unfiltered (_(" CRASH"));
787 printf_unfiltered (_("\n"));
791 static void
792 info_mach_exceptions_command (const char *args, int from_tty)
794 kern_return_t kret;
795 darwin_exception_info info;
797 info.count = sizeof (info.ports) / sizeof (info.ports[0]);
799 if (args != NULL)
801 if (strcmp (args, "saved") == 0)
803 if (inferior_ptid == null_ptid)
804 printf_unfiltered (_("No inferior running\n"));
806 darwin_inferior *priv = get_darwin_inferior (current_inferior ());
808 disp_exception (&priv->exception_info);
809 return;
811 else if (strcmp (args, "host") == 0)
813 /* FIXME: This needs a privileged host port! */
814 kret = host_get_exception_ports
815 (darwin_host_self, EXC_MASK_ALL, info.masks,
816 &info.count, info.ports, info.behaviors, info.flavors);
817 MACH_CHECK_ERROR (kret);
818 disp_exception (&info);
820 else
821 error (_("Parameter is saved, host or none"));
823 else
825 struct inferior *inf;
827 if (inferior_ptid == null_ptid)
828 printf_unfiltered (_("No inferior running\n"));
829 inf = current_inferior ();
831 darwin_inferior *priv = get_darwin_inferior (inf);
833 kret = task_get_exception_ports
834 (priv->task, EXC_MASK_ALL, info.masks,
835 &info.count, info.ports, info.behaviors, info.flavors);
836 MACH_CHECK_ERROR (kret);
837 disp_exception (&info);
841 void _initialize_darwin_info_commands ();
842 void
843 _initialize_darwin_info_commands ()
845 add_info ("mach-tasks", info_mach_tasks_command,
846 _("Get list of tasks in system."));
847 add_info ("mach-ports", info_mach_ports_command,
848 _("Get list of ports in a task."));
849 add_info ("mach-port", info_mach_port_command,
850 _("Get info on a specific port."));
851 add_info ("mach-task", info_mach_task_command,
852 _("Get info on a specific task."));
853 add_info ("mach-threads", info_mach_threads_command,
854 _("Get list of threads in a task."));
855 add_info ("mach-thread", info_mach_thread_command,
856 _("Get info on a specific thread."));
858 add_info ("mach-regions", info_mach_regions_command,
859 _("Get information on all mach region for the task."));
860 add_info ("mach-regions-rec", info_mach_regions_recurse_command,
861 _("Get information on all mach sub region for the task."));
862 add_info ("mach-region", info_mach_region_command,
863 _("Get information on mach region at given address."));
865 add_info ("mach-exceptions", info_mach_exceptions_command,
866 _("Disp mach exceptions."));