]>
Commit | Line | Data |
---|---|---|
9f8219f1 SS |
1 | /* A client to make GDB return to command level in Mach 3. |
2 | Copyright (C) 1992, 1993 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
6c9638b4 | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
9f8219f1 SS |
19 | |
20 | /* Authors: Jukka Virtanen <[email protected]> and Peter Stout <[email protected]>. | |
21 | ||
22 | A simple client to make GDB (versions 4.4 and later) on Mach 3 return | |
23 | to the command level when it is waiting for the inferior to stop. | |
24 | ||
25 | Actions: Lookup the send right to the GDB message port from the | |
26 | NetMsgServer. | |
27 | ||
28 | Send an asynchronous message with msgh_id | |
29 | GDB_MESSAGE_ID_STOP to that port. | |
30 | */ | |
31 | ||
32 | #include <stdio.h> | |
33 | ||
34 | #include "defs.h" | |
35 | ||
36 | #include <mach.h> | |
37 | #include <mach/message.h> | |
38 | #include <mach_error.h> | |
39 | #include <servers/netname.h> | |
40 | #include <servers/netname_defs.h> | |
41 | ||
42 | void | |
43 | main (argc, argv) | |
44 | int argc; | |
45 | char **argv; | |
46 | { | |
47 | kern_return_t kr; | |
48 | mach_msg_header_t msg; | |
49 | mach_port_t gdb_port; | |
50 | char *host; | |
51 | char *name; | |
52 | ||
53 | if (argc == 1) | |
54 | argv[argc++] = GDB_DEF_NAME; | |
55 | ||
56 | if (argc != 2) | |
57 | { | |
58 | fprintf (stderr, "Usage : %s <GDB name>\n", argv[0]); | |
59 | exit (1); | |
60 | } | |
61 | ||
62 | /* Allow the user to specify a remote host. */ | |
63 | host = strchr (argv[1], '@'); | |
64 | if (host) | |
65 | *(host++) = '\0'; | |
66 | else | |
67 | host = (char *) ""; | |
68 | ||
69 | name = malloc (strlen (argv[1]) + sizeof(GDB_NAME_PREFIX)); | |
70 | if (name == NULL) | |
71 | { | |
72 | fprintf (stderr, "Unable to allocate memory for name."); | |
73 | exit (1); | |
74 | } | |
75 | ||
76 | strcpy (name, GDB_NAME_PREFIX); | |
77 | strcat (name, argv[1]); | |
78 | ||
79 | /* Look up the GDB service port. For convenience, add the | |
80 | GDB_NAME_PREFIX the argument before looking up the name. | |
81 | For backwards compatibility, do it without. */ | |
82 | ||
83 | kr = netname_look_up (name_server_port, host, name, &gdb_port); | |
84 | if (kr == NETNAME_NOT_CHECKED_IN) | |
85 | kr = netname_look_up (name_server_port, host, argv[1], &gdb_port); | |
86 | if (kr != KERN_SUCCESS) | |
87 | { | |
88 | fprintf (stderr, "Unable to lookup the GDB service port: %s.\n", | |
89 | mach_error_string(kr)); | |
90 | exit(1); | |
91 | } | |
92 | ||
93 | /* Code generated by mig stub generator, with minor cleanups :-) | |
94 | ||
95 | simpleroutine stop_inferior(gdb_port : mach_port_t); */ | |
96 | ||
97 | msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0); | |
98 | msg.msgh_remote_port = gdb_port; | |
99 | msg.msgh_local_port = MACH_PORT_NULL; | |
100 | msg.msgh_size = sizeof(msg); | |
101 | msg.msgh_seqno = 0; | |
102 | msg.msgh_id = GDB_MESSAGE_ID_STOP; | |
103 | ||
104 | kr = mach_msg_send (&msg); | |
105 | if (kr != KERN_SUCCESS) | |
106 | fprintf (stderr, "Message not sent, return code %d : %s\n", kr, | |
107 | mach_error_string (kr)); | |
108 | ||
109 | exit (kr != KERN_SUCCESS); | |
110 | } |