Regenerate AArch64 opcodes files
[binutils-gdb.git] / gdb / darwin-nat-info.c
blob48868c8115ec8e6b361c23f2be049e1706d29ad3
1 /* Darwin support for GDB, the GNU debugger.
2 Copyright (C) 1997-2024 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 gdb_printf(_(#field":\t%#lx\n"), (unsigned long) (structure)->field)
59 #define PRINT_TV_FIELD(structure, field) \
60 gdb_printf(_(#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 gdb_printf (_("%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 gdb_printf (_(" %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 gdb_printf (_(" %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 gdb_printf (_("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 gdb_printf (_("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 gdb_printf (_("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 gdb_printf (_("\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 gdb_printf (_("\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 gdb_printf (_("Ports for task 0x%x:\n"), task);
215 gdb_printf (_("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 gdb_printf (_("%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 gdb_printf (_(" %s("), descrs[j].name);
243 ret = mach_port_get_refs (task, port, descrs[j].right, &ref);
244 if (ret != KERN_SUCCESS)
245 gdb_printf (_("??"));
246 else
247 gdb_printf (_("%u"), ref);
248 gdb_printf (_(" refs)"));
251 if (task == task_self ())
253 if (port == task_self())
254 gdb_printf (_(" gdb-task"));
255 else if (port == darwin_host_self)
256 gdb_printf (_(" host-self"));
257 else if (port == darwin_ex_port)
258 gdb_printf (_(" gdb-exception"));
259 else if (port == darwin_port_set)
260 gdb_printf (_(" 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 gdb_printf (_(" inferior-task"));
268 else if (port == priv->notify_port)
269 gdb_printf (_(" inferior-notify"));
270 else
272 for (int k = 0; k < priv->exception_info.count; k++)
273 if (port == priv->exception_info.ports[k])
275 gdb_printf (_(" inferior-excp-port"));
276 break;
279 for (darwin_thread_t *t : priv->threads)
281 if (port == t->gdb_port)
283 gdb_printf (_(" inferior-thread for 0x%x"),
284 priv->task);
285 break;
292 gdb_printf (_("\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 gdb_printf (_("Port 0x%lx in task 0x%lx:\n"), (unsigned long) port,
314 (unsigned long) task);
315 gdb_printf (_(" port set: 0x%x\n"), status.mps_pset);
316 gdb_printf (_(" seqno: 0x%x\n"), status.mps_seqno);
317 gdb_printf (_(" mscount: 0x%x\n"), status.mps_mscount);
318 gdb_printf (_(" qlimit: 0x%x\n"), status.mps_qlimit);
319 gdb_printf (_(" msgcount: 0x%x\n"), status.mps_msgcount);
320 gdb_printf (_(" sorights: 0x%x\n"), status.mps_sorights);
321 gdb_printf (_(" srights: 0x%x\n"), status.mps_srights);
322 gdb_printf (_(" pdrequest: 0x%x\n"), status.mps_pdrequest);
323 gdb_printf (_(" nsrequest: 0x%x\n"), status.mps_nsrequest);
324 gdb_printf (_(" 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 gdb_printf (_("Threads in task %#x:\n"), task);
356 for (i = 0; i < thread_count; ++i)
358 gdb_printf (_(" %#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 gdb_printf (_("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 gdb_printf (_("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 gdbarch *arch = current_inferior ()->arch ();
574 gdb_printf (_("%s-%s %s/%s %s %s %s"),
575 paddress (arch, prev_address),
576 paddress (arch, prev_address + prev_size),
577 unparse_protection (prev_info.protection),
578 unparse_protection (prev_info.max_protection),
579 unparse_inheritance (prev_info.inheritance),
580 prev_info.shared ? _("shrd") : _("priv"),
581 prev_info.reserved ? _("reserved") : _("not-rsvd"));
583 if (nsubregions > 1)
584 gdb_printf (_(" (%d sub-rgn)"), nsubregions);
586 gdb_printf (_("\n"));
588 prev_address = address;
589 prev_size = size;
590 memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t));
591 nsubregions = 1;
593 num_printed++;
595 else
597 prev_size += size;
598 nsubregions++;
601 if ((max > 0) && (num_printed >= max))
602 done = 1;
604 if (done)
605 break;
609 static void
610 darwin_debug_regions_recurse (task_t task)
612 mach_vm_address_t r_start;
613 mach_vm_size_t r_size;
614 natural_t r_depth;
615 mach_msg_type_number_t r_info_size;
616 vm_region_submap_short_info_data_64_t r_info;
617 kern_return_t kret;
618 struct ui_out *uiout = current_uiout;
620 ui_out_emit_table table_emitter (uiout, 9, -1, "regions");
622 if (gdbarch_addr_bit (current_inferior ()->arch ()) <= 32)
624 uiout->table_header (10, ui_left, "start", "Start");
625 uiout->table_header (10, ui_left, "end", "End");
627 else
629 uiout->table_header (18, ui_left, "start", "Start");
630 uiout->table_header (18, ui_left, "end", "End");
632 uiout->table_header (3, ui_left, "min-prot", "Min");
633 uiout->table_header (3, ui_left, "max-prot", "Max");
634 uiout->table_header (5, ui_left, "inheritence", "Inh");
635 uiout->table_header (9, ui_left, "share-mode", "Shr");
636 uiout->table_header (1, ui_left, "depth", "D");
637 uiout->table_header (3, ui_left, "submap", "Sm");
638 uiout->table_header (0, ui_noalign, "tag", "Tag");
640 uiout->table_body ();
642 r_start = 0;
643 r_depth = 0;
644 while (1)
646 const char *tag;
648 r_info_size = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64;
649 r_size = -1;
650 kret = mach_vm_region_recurse (task, &r_start, &r_size, &r_depth,
651 (vm_region_recurse_info_t) &r_info,
652 &r_info_size);
653 if (kret != KERN_SUCCESS)
654 break;
657 ui_out_emit_tuple tuple_emitter (uiout, "regions-row");
658 gdbarch *arch = current_inferior ()->arch ();
660 uiout->field_core_addr ("start", arch, r_start);
661 uiout->field_core_addr ("end", arch, r_start + r_size);
662 uiout->field_string ("min-prot",
663 unparse_protection (r_info.protection));
664 uiout->field_string ("max-prot",
665 unparse_protection (r_info.max_protection));
666 uiout->field_string ("inheritence",
667 unparse_inheritance (r_info.inheritance));
668 uiout->field_string ("share-mode",
669 unparse_share_mode (r_info.share_mode));
670 uiout->field_signed ("depth", r_depth);
671 uiout->field_string ("submap",
672 r_info.is_submap ? _("sm ") : _("obj"));
673 tag = unparse_user_tag (r_info.user_tag);
674 if (tag)
675 uiout->field_string ("tag", tag);
676 else
677 uiout->field_signed ("tag", r_info.user_tag);
680 uiout->text ("\n");
682 if (r_info.is_submap)
683 r_depth++;
684 else
685 r_start += r_size;
690 static void
691 darwin_debug_region (task_t task, mach_vm_address_t address)
693 darwin_debug_regions (task, address, 1);
696 static void
697 info_mach_regions_command (const char *args, int from_tty)
699 task_t task;
701 task = get_task_from_args (args);
702 if (task == TASK_NULL)
703 return;
705 darwin_debug_regions (task, 0, -1);
708 static void
709 info_mach_regions_recurse_command (const char *args, int from_tty)
711 task_t task;
713 task = get_task_from_args (args);
714 if (task == TASK_NULL)
715 return;
717 darwin_debug_regions_recurse (task);
720 static void
721 info_mach_region_command (const char *exp, int from_tty)
723 struct value *val;
724 mach_vm_address_t address;
725 struct inferior *inf;
727 expression_up expr = parse_expression (exp);
728 val = expr->evaluate ();
729 if (TYPE_IS_REFERENCE (val->type ()))
731 val = value_ind (val);
733 address = value_as_address (val);
735 if (inferior_ptid == null_ptid)
736 error (_("Inferior not available"));
738 inf = current_inferior ();
739 darwin_inferior *priv = get_darwin_inferior (inf);
740 darwin_debug_region (priv->task, address);
743 static void
744 disp_exception (const darwin_exception_info *info)
746 int i;
748 gdb_printf (_("%d exceptions:\n"), info->count);
749 for (i = 0; i < info->count; i++)
751 exception_mask_t mask = info->masks[i];
753 gdb_printf (_("port 0x%04x, behavior: "), info->ports[i]);
754 switch (info->behaviors[i])
756 case EXCEPTION_DEFAULT:
757 gdb_printf (_("default"));
758 break;
759 case EXCEPTION_STATE:
760 gdb_printf (_("state"));
761 break;
762 case EXCEPTION_STATE_IDENTITY:
763 gdb_printf (_("state-identity"));
764 break;
765 default:
766 gdb_printf (_("0x%x"), info->behaviors[i]);
768 gdb_printf (_(", masks:"));
769 if (mask & EXC_MASK_BAD_ACCESS)
770 gdb_printf (_(" BAD_ACCESS"));
771 if (mask & EXC_MASK_BAD_INSTRUCTION)
772 gdb_printf (_(" BAD_INSTRUCTION"));
773 if (mask & EXC_MASK_ARITHMETIC)
774 gdb_printf (_(" ARITHMETIC"));
775 if (mask & EXC_MASK_EMULATION)
776 gdb_printf (_(" EMULATION"));
777 if (mask & EXC_MASK_SOFTWARE)
778 gdb_printf (_(" SOFTWARE"));
779 if (mask & EXC_MASK_BREAKPOINT)
780 gdb_printf (_(" BREAKPOINT"));
781 if (mask & EXC_MASK_SYSCALL)
782 gdb_printf (_(" SYSCALL"));
783 if (mask & EXC_MASK_MACH_SYSCALL)
784 gdb_printf (_(" MACH_SYSCALL"));
785 if (mask & EXC_MASK_RPC_ALERT)
786 gdb_printf (_(" RPC_ALERT"));
787 if (mask & EXC_MASK_CRASH)
788 gdb_printf (_(" CRASH"));
789 gdb_printf (_("\n"));
793 static void
794 info_mach_exceptions_command (const char *args, int from_tty)
796 kern_return_t kret;
797 darwin_exception_info info;
799 info.count = sizeof (info.ports) / sizeof (info.ports[0]);
801 if (args != NULL)
803 if (strcmp (args, "saved") == 0)
805 if (inferior_ptid == null_ptid)
806 gdb_printf (_("No inferior running\n"));
808 darwin_inferior *priv = get_darwin_inferior (current_inferior ());
810 disp_exception (&priv->exception_info);
811 return;
813 else if (strcmp (args, "host") == 0)
815 /* FIXME: This needs a privileged host port! */
816 kret = host_get_exception_ports
817 (darwin_host_self, EXC_MASK_ALL, info.masks,
818 &info.count, info.ports, info.behaviors, info.flavors);
819 MACH_CHECK_ERROR (kret);
820 disp_exception (&info);
822 else
823 error (_("Parameter is saved, host or none"));
825 else
827 struct inferior *inf;
829 if (inferior_ptid == null_ptid)
830 gdb_printf (_("No inferior running\n"));
831 inf = current_inferior ();
833 darwin_inferior *priv = get_darwin_inferior (inf);
835 kret = task_get_exception_ports
836 (priv->task, EXC_MASK_ALL, info.masks,
837 &info.count, info.ports, info.behaviors, info.flavors);
838 MACH_CHECK_ERROR (kret);
839 disp_exception (&info);
843 void _initialize_darwin_info_commands ();
844 void
845 _initialize_darwin_info_commands ()
847 add_info ("mach-tasks", info_mach_tasks_command,
848 _("Get list of tasks in system."));
849 add_info ("mach-ports", info_mach_ports_command,
850 _("Get list of ports in a task."));
851 add_info ("mach-port", info_mach_port_command,
852 _("Get info on a specific port."));
853 add_info ("mach-task", info_mach_task_command,
854 _("Get info on a specific task."));
855 add_info ("mach-threads", info_mach_threads_command,
856 _("Get list of threads in a task."));
857 add_info ("mach-thread", info_mach_thread_command,
858 _("Get info on a specific thread."));
860 add_info ("mach-regions", info_mach_regions_command,
861 _("Get information on all mach region for the task."));
862 add_info ("mach-regions-rec", info_mach_regions_recurse_command,
863 _("Get information on all mach sub region for the task."));
864 add_info ("mach-region", info_mach_region_command,
865 _("Get information on mach region at given address."));
867 add_info ("mach-exceptions", info_mach_exceptions_command,
868 _("Disp mach exceptions."));