First version committed to git
[zpugcc/jano.git] / toolchain / gdb / gdb / stop-gdb.c
blobee84609664c51c04b43df8652193eb410c0b2924
1 /* A client to make GDB return to command level in Mach 3.
2 Copyright 1992, 1993, 1994, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Authors: Jukka Virtanen <jtv@hut.fi> and Peter Stout <pds@cs.cmu.edu>.
23 A simple client to make GDB (versions 4.4 and later) on Mach 3 return
24 to the command level when it is waiting for the inferior to stop.
26 Actions: Lookup the send right to the GDB message port from the
27 NetMsgServer.
29 Send an asynchronous message with msgh_id
30 GDB_MESSAGE_ID_STOP to that port.
33 #include <stdio.h>
35 #include "defs.h"
37 #include <mach.h>
38 #include <mach/message.h>
39 #include <mach_error.h>
40 #include <servers/netname.h>
41 #include <servers/netname_defs.h>
43 void
44 main (int argc, char **argv)
46 kern_return_t kr;
47 mach_msg_header_t msg;
48 mach_port_t gdb_port;
49 char *host;
50 char *name;
52 if (argc == 1)
53 argv[argc++] = GDB_DEF_NAME;
55 if (argc != 2)
57 fprintf (stderr, "Usage : %s <GDB name>\n", argv[0]);
58 exit (1);
61 /* Allow the user to specify a remote host. */
62 host = strchr (argv[1], '@');
63 if (host)
64 *(host++) = '\0';
65 else
66 host = (char *) "";
68 name = malloc (strlen (argv[1]) + sizeof (GDB_NAME_PREFIX));
69 if (name == NULL)
71 fprintf (stderr, "Unable to allocate memory for name.");
72 exit (1);
75 strcpy (name, GDB_NAME_PREFIX);
76 strcat (name, argv[1]);
78 /* Look up the GDB service port. For convenience, add the
79 GDB_NAME_PREFIX the argument before looking up the name.
80 For backwards compatibility, do it without. */
82 kr = netname_look_up (name_server_port, host, name, &gdb_port);
83 if (kr == NETNAME_NOT_CHECKED_IN)
84 kr = netname_look_up (name_server_port, host, argv[1], &gdb_port);
85 if (kr != KERN_SUCCESS)
87 fprintf (stderr, "Unable to lookup the GDB service port: %s.\n",
88 mach_error_string (kr));
89 exit (1);
92 /* Code generated by mig stub generator, with minor cleanups :-)
94 simpleroutine stop_inferior(gdb_port : mach_port_t); */
96 msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0);
97 msg.msgh_remote_port = gdb_port;
98 msg.msgh_local_port = MACH_PORT_NULL;
99 msg.msgh_size = sizeof (msg);
100 msg.msgh_seqno = 0;
101 msg.msgh_id = GDB_MESSAGE_ID_STOP;
103 kr = mach_msg_send (&msg);
104 if (kr != KERN_SUCCESS)
105 fprintf (stderr, "Message not sent, return code %d : %s\n", kr,
106 mach_error_string (kr));
108 exit (kr != KERN_SUCCESS);