Constify add_info
[deliverable/binutils-gdb.git] / gdb / darwin-nat-info.c
CommitLineData
a80b95ba 1/* Darwin support for GDB, the GNU debugger.
61baf725 2 Copyright (C) 1997-2017 Free Software Foundation, Inc.
a80b95ba
TG
3
4 Contributed by Apple Computer, Inc.
5
6 This file is part of GDB.
7
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
dcf7800b 10 the Free Software Foundation; either version 3 of the License, or
a80b95ba
TG
11 (at your option) any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
dcf7800b 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
a80b95ba
TG
20
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. */
29
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
a80b95ba
TG
38#include <sys/sysctl.h>
39
40#include "darwin-nat.h"
41
42#include <mach/thread_info.h>
43#include <mach/thread_act.h>
44#include <mach/task.h>
45#include <mach/vm_map.h>
46#include <mach/mach_port.h>
47#include <mach/mach_init.h>
48#include <mach/mach_vm.h>
49
50#define CHECK_ARGS(what, args) do { \
51 if ((NULL == args) || ((args[0] != '0') && (args[1] != 'x'))) \
7ea6d463 52 error(_("%s must be specified with 0x..."), what); \
a80b95ba
TG
53} while (0)
54
55#define PRINT_FIELD(structure, field) \
56 printf_unfiltered(_(#field":\t%#lx\n"), (unsigned long) (structure)->field)
57
58#define PRINT_TV_FIELD(structure, field) \
59 printf_unfiltered(_(#field":\t%u.%06u sec\n"), \
60 (unsigned) (structure)->field.seconds, \
61 (unsigned) (structure)->field.microseconds)
62
63#define task_self mach_task_self
64#define task_by_unix_pid task_for_pid
65#define port_name_array_t mach_port_array_t
66#define port_type_array_t mach_port_array_t
67
68static void
1d12d88f 69info_mach_tasks_command (const char *args, int from_tty)
a80b95ba
TG
70{
71 int sysControl[4];
72 int count, index;
73 size_t length;
74 struct kinfo_proc *procInfo;
75
76 sysControl[0] = CTL_KERN;
77 sysControl[1] = KERN_PROC;
78 sysControl[2] = KERN_PROC_ALL;
79
80 sysctl (sysControl, 3, NULL, &length, NULL, 0);
81 procInfo = (struct kinfo_proc *) xmalloc (length);
82 sysctl (sysControl, 3, procInfo, &length, NULL, 0);
83
84 count = (length / sizeof (struct kinfo_proc));
85 printf_unfiltered (_("%d processes:\n"), count);
86 for (index = 0; index < count; ++index)
87 {
88 kern_return_t result;
89 mach_port_t taskPort;
90
91 result =
92 task_by_unix_pid (mach_task_self (), procInfo[index].kp_proc.p_pid,
93 &taskPort);
94 if (KERN_SUCCESS == result)
95 {
96 printf_unfiltered (_(" %s is %d has task %#x\n"),
97 procInfo[index].kp_proc.p_comm,
98 procInfo[index].kp_proc.p_pid, taskPort);
99 }
100 else
101 {
102 printf_unfiltered (_(" %s is %d unknown task port\n"),
103 procInfo[index].kp_proc.p_comm,
104 procInfo[index].kp_proc.p_pid);
105 }
106 }
107
108 xfree (procInfo);
109}
110
111static task_t
1d12d88f 112get_task_from_args (const char *args)
a80b95ba
TG
113{
114 task_t task;
115 char *eptr;
116
117 if (args == NULL || *args == 0)
118 {
bb00b29d 119 if (ptid_equal (inferior_ptid, null_ptid))
a80b95ba 120 printf_unfiltered (_("No inferior running\n"));
fe978cb0 121 return current_inferior ()->priv->task;
a80b95ba
TG
122 }
123 if (strcmp (args, "gdb") == 0)
124 return mach_task_self ();
125 task = strtoul (args, &eptr, 0);
126 if (*eptr)
127 {
128 printf_unfiltered (_("cannot parse task id '%s'\n"), args);
129 return TASK_NULL;
130 }
131 return task;
132}
133
134static void
1d12d88f 135info_mach_task_command (const char *args, int from_tty)
a80b95ba
TG
136{
137 union
138 {
139 struct task_basic_info basic;
140 struct task_events_info events;
141 struct task_thread_times_info thread_times;
142 } task_info_data;
143
144 kern_return_t result;
145 unsigned int info_count;
146 task_t task;
147
148 task = get_task_from_args (args);
149 if (task == TASK_NULL)
150 return;
151
152 printf_unfiltered (_("TASK_BASIC_INFO for 0x%x:\n"), task);
153 info_count = TASK_BASIC_INFO_COUNT;
154 result = task_info (task,
155 TASK_BASIC_INFO,
156 (task_info_t) & task_info_data.basic, &info_count);
157 MACH_CHECK_ERROR (result);
158
159 PRINT_FIELD (&task_info_data.basic, suspend_count);
160 PRINT_FIELD (&task_info_data.basic, virtual_size);
161 PRINT_FIELD (&task_info_data.basic, resident_size);
162 PRINT_TV_FIELD (&task_info_data.basic, user_time);
163 PRINT_TV_FIELD (&task_info_data.basic, system_time);
164 printf_unfiltered (_("\nTASK_EVENTS_INFO:\n"));
165 info_count = TASK_EVENTS_INFO_COUNT;
166 result = task_info (task,
167 TASK_EVENTS_INFO,
168 (task_info_t) & task_info_data.events, &info_count);
169 MACH_CHECK_ERROR (result);
170
171 PRINT_FIELD (&task_info_data.events, faults);
172#if 0
173 PRINT_FIELD (&task_info_data.events, zero_fills);
174 PRINT_FIELD (&task_info_data.events, reactivations);
175#endif
176 PRINT_FIELD (&task_info_data.events, pageins);
177 PRINT_FIELD (&task_info_data.events, cow_faults);
178 PRINT_FIELD (&task_info_data.events, messages_sent);
179 PRINT_FIELD (&task_info_data.events, messages_received);
180 printf_unfiltered (_("\nTASK_THREAD_TIMES_INFO:\n"));
181 info_count = TASK_THREAD_TIMES_INFO_COUNT;
182 result = task_info (task,
183 TASK_THREAD_TIMES_INFO,
184 (task_info_t) & task_info_data.thread_times,
185 &info_count);
186 MACH_CHECK_ERROR (result);
187 PRINT_TV_FIELD (&task_info_data.thread_times, user_time);
188 PRINT_TV_FIELD (&task_info_data.thread_times, system_time);
189}
190
191static void
1d12d88f 192info_mach_ports_command (const char *args, int from_tty)
a80b95ba
TG
193{
194 port_name_array_t names;
195 port_type_array_t types;
196 unsigned int name_count, type_count;
197 kern_return_t result;
198 int index;
199 task_t task;
200
201 task = get_task_from_args (args);
202 if (task == TASK_NULL)
203 return;
204
205 result = mach_port_names (task, &names, &name_count, &types, &type_count);
206 MACH_CHECK_ERROR (result);
207
208 gdb_assert (name_count == type_count);
209
210 printf_unfiltered (_("Ports for task 0x%x:\n"), task);
211 printf_unfiltered (_("port type\n"));
212 for (index = 0; index < name_count; ++index)
213 {
214 mach_port_t port = names[index];
215 unsigned int j;
216 struct type_descr
217 {
218 mach_port_type_t type;
219 const char *name;
220 mach_port_right_t right;
221 };
222 static struct type_descr descrs[] =
223 {
224 {MACH_PORT_TYPE_SEND, "send", MACH_PORT_RIGHT_SEND},
225 {MACH_PORT_TYPE_SEND_ONCE, "send-once", MACH_PORT_RIGHT_SEND_ONCE},
226 {MACH_PORT_TYPE_RECEIVE, "receive", MACH_PORT_RIGHT_RECEIVE},
227 {MACH_PORT_TYPE_PORT_SET, "port-set", MACH_PORT_RIGHT_PORT_SET},
228 {MACH_PORT_TYPE_DEAD_NAME, "dead", MACH_PORT_RIGHT_DEAD_NAME}
229 };
230
231 printf_unfiltered (_("%04x: %08x "), port, types[index]);
232 for (j = 0; j < sizeof(descrs) / sizeof(*descrs); j++)
233 if (types[index] & descrs[j].type)
234 {
235 mach_port_urefs_t ref;
236 kern_return_t ret;
237
238 printf_unfiltered (_(" %s("), descrs[j].name);
239 ret = mach_port_get_refs (task, port, descrs[j].right, &ref);
240 if (ret != KERN_SUCCESS)
241 printf_unfiltered (_("??"));
242 else
243 printf_unfiltered (_("%u"), ref);
244 printf_unfiltered (_(" refs)"));
245 }
246
247 if (task == task_self ())
248 {
249 if (port == task_self())
250 printf_unfiltered (_(" gdb-task"));
251 else if (port == darwin_host_self)
252 printf_unfiltered (_(" host-self"));
a80b95ba
TG
253 else if (port == darwin_ex_port)
254 printf_unfiltered (_(" gdb-exception"));
255 else if (port == darwin_port_set)
256 printf_unfiltered (_(" gdb-port_set"));
bb00b29d 257 else if (!ptid_equal (inferior_ptid, null_ptid))
a80b95ba 258 {
bb00b29d
TG
259 struct inferior *inf = current_inferior ();
260
fe978cb0 261 if (port == inf->priv->task)
bb00b29d 262 printf_unfiltered (_(" inferior-task"));
fe978cb0 263 else if (port == inf->priv->notify_port)
bb00b29d
TG
264 printf_unfiltered (_(" inferior-notify"));
265 else
266 {
267 int k;
268 darwin_thread_t *t;
269
fe978cb0
PA
270 for (k = 0; k < inf->priv->exception_info.count; k++)
271 if (port == inf->priv->exception_info.ports[k])
bb00b29d
TG
272 {
273 printf_unfiltered (_(" inferior-excp-port"));
274 break;
275 }
276
fe978cb0 277 if (inf->priv->threads)
bb00b29d
TG
278 {
279 for (k = 0;
280 VEC_iterate(darwin_thread_t,
fe978cb0 281 inf->priv->threads, k, t);
bb00b29d
TG
282 k++)
283 if (port == t->gdb_port)
284 {
285 printf_unfiltered (_(" inferior-thread for 0x%x"),
fe978cb0 286 inf->priv->task);
bb00b29d
TG
287 break;
288 }
289 }
290 }
a80b95ba
TG
291 }
292 }
293 printf_unfiltered (_("\n"));
294 }
295
296 vm_deallocate (task_self (), (vm_address_t) names,
297 (name_count * sizeof (mach_port_t)));
298 vm_deallocate (task_self (), (vm_address_t) types,
299 (type_count * sizeof (mach_port_type_t)));
300}
301
302
c381a3f6 303static void
a80b95ba
TG
304darwin_debug_port_info (task_t task, mach_port_t port)
305{
306 kern_return_t kret;
307 mach_port_status_t status;
308 mach_msg_type_number_t len = sizeof (status);
309
310 kret = mach_port_get_attributes
311 (task, port, MACH_PORT_RECEIVE_STATUS, (mach_port_info_t)&status, &len);
312 MACH_CHECK_ERROR (kret);
313
314 printf_unfiltered (_("Port 0x%lx in task 0x%lx:\n"), (unsigned long) port,
315 (unsigned long) task);
316 printf_unfiltered (_(" port set: 0x%x\n"), status.mps_pset);
317 printf_unfiltered (_(" seqno: 0x%x\n"), status.mps_seqno);
318 printf_unfiltered (_(" mscount: 0x%x\n"), status.mps_mscount);
319 printf_unfiltered (_(" qlimit: 0x%x\n"), status.mps_qlimit);
320 printf_unfiltered (_(" msgcount: 0x%x\n"), status.mps_msgcount);
321 printf_unfiltered (_(" sorights: 0x%x\n"), status.mps_sorights);
322 printf_unfiltered (_(" srights: 0x%x\n"), status.mps_srights);
323 printf_unfiltered (_(" pdrequest: 0x%x\n"), status.mps_pdrequest);
324 printf_unfiltered (_(" nsrequest: 0x%x\n"), status.mps_nsrequest);
325 printf_unfiltered (_(" flags: 0x%x\n"), status.mps_flags);
326}
327
328static void
1d12d88f 329info_mach_port_command (const char *args, int from_tty)
a80b95ba
TG
330{
331 task_t task;
332 mach_port_t port;
333
334 CHECK_ARGS (_("Task and port"), args);
335 sscanf (args, "0x%x 0x%x", &task, &port);
336
337 darwin_debug_port_info (task, port);
338}
339
340static void
1d12d88f 341info_mach_threads_command (const char *args, int from_tty)
a80b95ba
TG
342{
343 thread_array_t threads;
344 unsigned int thread_count;
345 kern_return_t result;
346 task_t task;
347 int i;
348
349 task = get_task_from_args (args);
350 if (task == TASK_NULL)
351 return;
352
353 result = task_threads (task, &threads, &thread_count);
354 MACH_CHECK_ERROR (result);
355
356 printf_unfiltered (_("Threads in task %#x:\n"), task);
357 for (i = 0; i < thread_count; ++i)
358 {
359 printf_unfiltered (_(" %#x\n"), threads[i]);
360 mach_port_deallocate (task_self (), threads[i]);
361 }
362
363 vm_deallocate (task_self (), (vm_address_t) threads,
364 (thread_count * sizeof (thread_t)));
365}
366
367static void
1d12d88f 368info_mach_thread_command (const char *args, int from_tty)
a80b95ba
TG
369{
370 union
371 {
372 struct thread_basic_info basic;
373 } thread_info_data;
374
375 thread_t thread;
376 kern_return_t result;
377 unsigned int info_count;
378
379 CHECK_ARGS (_("Thread"), args);
380 sscanf (args, "0x%x", &thread);
381
382 printf_unfiltered (_("THREAD_BASIC_INFO\n"));
383 info_count = THREAD_BASIC_INFO_COUNT;
384 result = thread_info (thread,
385 THREAD_BASIC_INFO,
386 (thread_info_t) & thread_info_data.basic,
387 &info_count);
388 MACH_CHECK_ERROR (result);
389
390#if 0
391 PRINT_FIELD (&thread_info_data.basic, user_time);
392 PRINT_FIELD (&thread_info_data.basic, system_time);
393#endif
394 PRINT_FIELD (&thread_info_data.basic, cpu_usage);
395 PRINT_FIELD (&thread_info_data.basic, run_state);
396 PRINT_FIELD (&thread_info_data.basic, flags);
397 PRINT_FIELD (&thread_info_data.basic, suspend_count);
398 PRINT_FIELD (&thread_info_data.basic, sleep_time);
399}
400
401static const char *
402unparse_protection (vm_prot_t p)
403{
404 switch (p)
405 {
406 case VM_PROT_NONE:
407 return "---";
408 case VM_PROT_READ:
409 return "r--";
410 case VM_PROT_WRITE:
411 return "-w-";
412 case VM_PROT_READ | VM_PROT_WRITE:
413 return "rw-";
414 case VM_PROT_EXECUTE:
415 return "--x";
416 case VM_PROT_EXECUTE | VM_PROT_READ:
417 return "r-x";
418 case VM_PROT_EXECUTE | VM_PROT_WRITE:
419 return "-wx";
420 case VM_PROT_EXECUTE | VM_PROT_WRITE | VM_PROT_READ:
421 return "rwx";
422 default:
423 return "???";
424 }
425}
426
427static const char *
428unparse_inheritance (vm_inherit_t i)
429{
430 switch (i)
431 {
432 case VM_INHERIT_SHARE:
433 return _("share");
434 case VM_INHERIT_COPY:
435 return _("copy ");
436 case VM_INHERIT_NONE:
437 return _("none ");
438 default:
439 return _("??? ");
440 }
441}
442
443static const char *
444unparse_share_mode (unsigned char p)
445{
446 switch (p)
447 {
448 case SM_COW:
449 return _("cow");
450 case SM_PRIVATE:
451 return _("private");
452 case SM_EMPTY:
453 return _("empty");
454 case SM_SHARED:
455 return _("shared");
456 case SM_TRUESHARED:
457 return _("true-shrd");
458 case SM_PRIVATE_ALIASED:
459 return _("prv-alias");
460 case SM_SHARED_ALIASED:
461 return _("shr-alias");
462 default:
463 return _("???");
464 }
465}
466
467static const char *
468unparse_user_tag (unsigned int tag)
469{
470 switch (tag)
471 {
472 case 0:
473 return _("default");
474 case VM_MEMORY_MALLOC:
475 return _("malloc");
476 case VM_MEMORY_MALLOC_SMALL:
477 return _("malloc_small");
478 case VM_MEMORY_MALLOC_LARGE:
479 return _("malloc_large");
480 case VM_MEMORY_MALLOC_HUGE:
481 return _("malloc_huge");
482 case VM_MEMORY_SBRK:
483 return _("sbrk");
484 case VM_MEMORY_REALLOC:
485 return _("realloc");
486 case VM_MEMORY_MALLOC_TINY:
487 return _("malloc_tiny");
488 case VM_MEMORY_ANALYSIS_TOOL:
489 return _("analysis_tool");
490 case VM_MEMORY_MACH_MSG:
491 return _("mach_msg");
492 case VM_MEMORY_IOKIT:
493 return _("iokit");
494 case VM_MEMORY_STACK:
495 return _("stack");
496 case VM_MEMORY_GUARD:
497 return _("guard");
498 case VM_MEMORY_SHARED_PMAP:
499 return _("shared_pmap");
500 case VM_MEMORY_DYLIB:
501 return _("dylib");
502 case VM_MEMORY_APPKIT:
503 return _("appkit");
504 case VM_MEMORY_FOUNDATION:
505 return _("foundation");
506 default:
507 return NULL;
508 }
509}
510
511static void
512darwin_debug_regions (task_t task, mach_vm_address_t address, int max)
513{
514 kern_return_t kret;
515 vm_region_basic_info_data_64_t info, prev_info;
516 mach_vm_address_t prev_address;
517 mach_vm_size_t size, prev_size;
518
519 mach_port_t object_name;
520 mach_msg_type_number_t count;
521
522 int nsubregions = 0;
523 int num_printed = 0;
524
525 count = VM_REGION_BASIC_INFO_COUNT_64;
526 kret = mach_vm_region (task, &address, &size, VM_REGION_BASIC_INFO_64,
527 (vm_region_info_t) &info, &count, &object_name);
528 if (kret != KERN_SUCCESS)
529 {
530 printf_filtered (_("No memory regions."));
531 return;
532 }
533 memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t));
534 prev_address = address;
535 prev_size = size;
536 nsubregions = 1;
537
538 for (;;)
539 {
540 int print = 0;
541 int done = 0;
542
543 address = prev_address + prev_size;
544
0963b4bd 545 /* Check to see if address space has wrapped around. */
a80b95ba
TG
546 if (address == 0)
547 print = done = 1;
548
549 if (!done)
550 {
551 count = VM_REGION_BASIC_INFO_COUNT_64;
552 kret =
553 mach_vm_region (task, &address, &size, VM_REGION_BASIC_INFO_64,
554 (vm_region_info_t) &info, &count, &object_name);
555 if (kret != KERN_SUCCESS)
556 {
557 size = 0;
558 print = done = 1;
559 }
560 }
561
562 if (address != prev_address + prev_size)
563 print = 1;
564
565 if ((info.protection != prev_info.protection)
566 || (info.max_protection != prev_info.max_protection)
567 || (info.inheritance != prev_info.inheritance)
568 || (info.shared != prev_info.reserved)
569 || (info.reserved != prev_info.reserved))
570 print = 1;
571
572 if (print)
573 {
574 printf_filtered (_("%s-%s %s/%s %s %s %s"),
f5656ead
TT
575 paddress (target_gdbarch (), prev_address),
576 paddress (target_gdbarch (), prev_address + prev_size),
a80b95ba
TG
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"));
582
583 if (nsubregions > 1)
584 printf_filtered (_(" (%d sub-rgn)"), nsubregions);
585
586 printf_filtered (_("\n"));
587
588 prev_address = address;
589 prev_size = size;
590 memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t));
591 nsubregions = 1;
592
593 num_printed++;
594 }
595 else
596 {
597 prev_size += size;
598 nsubregions++;
599 }
600
601 if ((max > 0) && (num_printed >= max))
602 done = 1;
603
604 if (done)
605 break;
606 }
607}
608
609static void
610darwin_debug_regions_recurse (task_t task)
611{
612 mach_vm_address_t r_addr;
613 mach_vm_address_t r_start;
614 mach_vm_size_t r_size;
615 natural_t r_depth;
616 mach_msg_type_number_t r_info_size;
617 vm_region_submap_short_info_data_64_t r_info;
618 kern_return_t kret;
619 int ret;
6e2f5b22 620 struct ui_out *uiout = current_uiout;
bb00b29d 621
dc9fe180 622 ui_out_emit_table table_emitter (uiout, 9, -1, "regions");
bb00b29d 623
f5656ead 624 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
bb00b29d 625 {
112e8700
SM
626 uiout->table_header (10, ui_left, "start", "Start");
627 uiout->table_header (10, ui_left, "end", "End");
bb00b29d
TG
628 }
629 else
630 {
112e8700
SM
631 uiout->table_header (18, ui_left, "start", "Start");
632 uiout->table_header (18, ui_left, "end", "End");
bb00b29d 633 }
112e8700
SM
634 uiout->table_header (3, ui_left, "min-prot", "Min");
635 uiout->table_header (3, ui_left, "max-prot", "Max");
636 uiout->table_header (5, ui_left, "inheritence", "Inh");
637 uiout->table_header (9, ui_left, "share-mode", "Shr");
638 uiout->table_header (1, ui_left, "depth", "D");
639 uiout->table_header (3, ui_left, "submap", "Sm");
640 uiout->table_header (0, ui_noalign, "tag", "Tag");
bb00b29d 641
112e8700 642 uiout->table_body ();
a80b95ba
TG
643
644 r_start = 0;
645 r_depth = 0;
646 while (1)
647 {
648 const char *tag;
649
650 r_info_size = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64;
651 r_size = -1;
652 kret = mach_vm_region_recurse (task, &r_start, &r_size, &r_depth,
653 (vm_region_recurse_info_t) &r_info,
654 &r_info_size);
655 if (kret != KERN_SUCCESS)
656 break;
bb00b29d 657
dc9fe180
TT
658 {
659 ui_out_emit_tuple tuple_emitter (uiout, "regions-row");
660
661 uiout->field_core_addr ("start", target_gdbarch (), r_start);
662 uiout->field_core_addr ("end", target_gdbarch (), r_start + r_size);
663 uiout->field_string ("min-prot",
664 unparse_protection (r_info.protection));
665 uiout->field_string ("max-prot",
666 unparse_protection (r_info.max_protection));
667 uiout->field_string ("inheritence",
668 unparse_inheritance (r_info.inheritance));
669 uiout->field_string ("share-mode",
670 unparse_share_mode (r_info.share_mode));
671 uiout->field_int ("depth", r_depth);
672 uiout->field_string ("submap",
673 r_info.is_submap ? _("sm ") : _("obj"));
674 tag = unparse_user_tag (r_info.user_tag);
675 if (tag)
676 uiout->field_string ("tag", tag);
677 else
678 uiout->field_int ("tag", r_info.user_tag);
679 }
bb00b29d 680
112e8700
SM
681 if (!uiout->is_mi_like_p ())
682 uiout->text ("\n");
bb00b29d 683
a80b95ba
TG
684 if (r_info.is_submap)
685 r_depth++;
686 else
687 r_start += r_size;
688 }
689}
690
691
692static void
693darwin_debug_region (task_t task, mach_vm_address_t address)
694{
695 darwin_debug_regions (task, address, 1);
696}
697
698static void
1d12d88f 699info_mach_regions_command (const char *args, int from_tty)
a80b95ba
TG
700{
701 task_t task;
702
703 task = get_task_from_args (args);
704 if (task == TASK_NULL)
705 return;
706
707 darwin_debug_regions (task, 0, -1);
708}
709
710static void
1d12d88f 711info_mach_regions_recurse_command (const char *args, int from_tty)
a80b95ba
TG
712{
713 task_t task;
714
715 task = get_task_from_args (args);
716 if (task == TASK_NULL)
717 return;
718
719 darwin_debug_regions_recurse (task);
720}
721
722static void
1d12d88f 723info_mach_region_command (const char *exp, int from_tty)
a80b95ba 724{
a80b95ba
TG
725 struct value *val;
726 mach_vm_address_t address;
bb00b29d 727 struct inferior *inf;
a80b95ba 728
97f00e36
BH
729 expression_up expr = parse_expression (exp);
730 val = evaluate_expression (expr.get ());
aa006118 731 if (TYPE_IS_REFERENCE (value_type (val)))
a80b95ba
TG
732 {
733 val = value_ind (val);
734 }
bb00b29d 735 address = value_as_address (val);
a80b95ba 736
bb00b29d 737 if (ptid_equal (inferior_ptid, null_ptid))
a80b95ba
TG
738 error (_("Inferior not available"));
739
bb00b29d 740 inf = current_inferior ();
fe978cb0 741 darwin_debug_region (inf->priv->task, address);
a80b95ba
TG
742}
743
744static void
745disp_exception (const darwin_exception_info *info)
746{
747 int i;
748
749 printf_filtered (_("%d exceptions:\n"), info->count);
750 for (i = 0; i < info->count; i++)
751 {
752 exception_mask_t mask = info->masks[i];
753
754 printf_filtered (_("port 0x%04x, behavior: "), info->ports[i]);
755 switch (info->behaviors[i])
756 {
757 case EXCEPTION_DEFAULT:
758 printf_unfiltered (_("default"));
759 break;
760 case EXCEPTION_STATE:
761 printf_unfiltered (_("state"));
762 break;
763 case EXCEPTION_STATE_IDENTITY:
764 printf_unfiltered (_("state-identity"));
765 break;
766 default:
767 printf_unfiltered (_("0x%x"), info->behaviors[i]);
768 }
769 printf_unfiltered (_(", masks:"));
770 if (mask & EXC_MASK_BAD_ACCESS)
771 printf_unfiltered (_(" BAD_ACCESS"));
772 if (mask & EXC_MASK_BAD_INSTRUCTION)
773 printf_unfiltered (_(" BAD_INSTRUCTION"));
774 if (mask & EXC_MASK_ARITHMETIC)
775 printf_unfiltered (_(" ARITHMETIC"));
776 if (mask & EXC_MASK_EMULATION)
777 printf_unfiltered (_(" EMULATION"));
778 if (mask & EXC_MASK_SOFTWARE)
779 printf_unfiltered (_(" SOFTWARE"));
780 if (mask & EXC_MASK_BREAKPOINT)
781 printf_unfiltered (_(" BREAKPOINT"));
782 if (mask & EXC_MASK_SYSCALL)
783 printf_unfiltered (_(" SYSCALL"));
784 if (mask & EXC_MASK_MACH_SYSCALL)
785 printf_unfiltered (_(" MACH_SYSCALL"));
786 if (mask & EXC_MASK_RPC_ALERT)
787 printf_unfiltered (_(" RPC_ALERT"));
788 if (mask & EXC_MASK_CRASH)
789 printf_unfiltered (_(" CRASH"));
790 printf_unfiltered (_("\n"));
791 }
792}
793
794static void
1d12d88f 795info_mach_exceptions_command (const char *args, int from_tty)
a80b95ba
TG
796{
797 int i;
798 task_t task;
799 kern_return_t kret;
800 darwin_exception_info info;
801
802 info.count = sizeof (info.ports) / sizeof (info.ports[0]);
803
804 if (args != NULL)
805 {
806 if (strcmp (args, "saved") == 0)
807 {
bb00b29d
TG
808 if (ptid_equal (inferior_ptid, null_ptid))
809 printf_unfiltered (_("No inferior running\n"));
fe978cb0 810 disp_exception (&current_inferior ()->priv->exception_info);
a80b95ba
TG
811 return;
812 }
813 else if (strcmp (args, "host") == 0)
814 {
766062f6 815 /* FIXME: This need a privilegied host port! */
a80b95ba
TG
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);
821 }
822 else
823 error (_("Parameter is saved, host or none"));
824 }
825 else
826 {
bb00b29d
TG
827 struct inferior *inf;
828
829 if (ptid_equal (inferior_ptid, null_ptid))
830 printf_unfiltered (_("No inferior running\n"));
831 inf = current_inferior ();
a80b95ba
TG
832
833 kret = task_get_exception_ports
fe978cb0 834 (inf->priv->task, EXC_MASK_ALL, info.masks,
a80b95ba
TG
835 &info.count, info.ports, info.behaviors, info.flavors);
836 MACH_CHECK_ERROR (kret);
837 disp_exception (&info);
838 }
839}
840
a80b95ba
TG
841void
842_initialize_darwin_info_commands (void)
843{
844 add_info ("mach-tasks", info_mach_tasks_command,
845 _("Get list of tasks in system."));
846 add_info ("mach-ports", info_mach_ports_command,
847 _("Get list of ports in a task."));
848 add_info ("mach-port", info_mach_port_command,
849 _("Get info on a specific port."));
850 add_info ("mach-task", info_mach_task_command,
851 _("Get info on a specific task."));
852 add_info ("mach-threads", info_mach_threads_command,
853 _("Get list of threads in a task."));
854 add_info ("mach-thread", info_mach_thread_command,
855 _("Get info on a specific thread."));
856
857 add_info ("mach-regions", info_mach_regions_command,
858 _("Get information on all mach region for the task."));
859 add_info ("mach-regions-rec", info_mach_regions_recurse_command,
860 _("Get information on all mach sub region for the task."));
861 add_info ("mach-region", info_mach_region_command,
862 _("Get information on mach region at given address."));
863
864 add_info ("mach-exceptions", info_mach_exceptions_command,
865 _("Disp mach exceptions."));
866}
This page took 0.767413 seconds and 4 git commands to generate.