* sol-thread.c (GET_LWP, GET_THREAD, BUILD_LWP, BUILD_THREAD):
[deliverable/binutils-gdb.git] / gdb / stop-gdb.c
CommitLineData
c906108c
SS
1/* A client to make GDB return to command level in Mach 3.
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b
JM
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. */
c906108c
SS
20
21/* Authors: Jukka Virtanen <jtv@hut.fi> and Peter Stout <pds@cs.cmu.edu>.
22
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.
c5aa993b 25
c906108c 26 Actions: Lookup the send right to the GDB message port from the
c5aa993b 27 NetMsgServer.
c906108c 28
c5aa993b
JM
29 Send an asynchronous message with msgh_id
30 GDB_MESSAGE_ID_STOP to that port.
31 */
c906108c
SS
32
33#include <stdio.h>
34
35#include "defs.h"
36
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>
42
43void
44main (argc, argv)
45 int argc;
46 char **argv;
47{
48 kern_return_t kr;
49 mach_msg_header_t msg;
50 mach_port_t gdb_port;
51 char *host;
52 char *name;
53
54 if (argc == 1)
55 argv[argc++] = GDB_DEF_NAME;
56
57 if (argc != 2)
58 {
59 fprintf (stderr, "Usage : %s <GDB name>\n", argv[0]);
60 exit (1);
61 }
62
63 /* Allow the user to specify a remote host. */
64 host = strchr (argv[1], '@');
65 if (host)
66 *(host++) = '\0';
67 else
68 host = (char *) "";
69
c5aa993b 70 name = malloc (strlen (argv[1]) + sizeof (GDB_NAME_PREFIX));
c906108c
SS
71 if (name == NULL)
72 {
73 fprintf (stderr, "Unable to allocate memory for name.");
74 exit (1);
75 }
76
77 strcpy (name, GDB_NAME_PREFIX);
78 strcat (name, argv[1]);
79
80 /* Look up the GDB service port. For convenience, add the
81 GDB_NAME_PREFIX the argument before looking up the name.
82 For backwards compatibility, do it without. */
83
84 kr = netname_look_up (name_server_port, host, name, &gdb_port);
85 if (kr == NETNAME_NOT_CHECKED_IN)
86 kr = netname_look_up (name_server_port, host, argv[1], &gdb_port);
87 if (kr != KERN_SUCCESS)
88 {
89 fprintf (stderr, "Unable to lookup the GDB service port: %s.\n",
c5aa993b
JM
90 mach_error_string (kr));
91 exit (1);
c906108c
SS
92 }
93
94 /* Code generated by mig stub generator, with minor cleanups :-)
95
96 simpleroutine stop_inferior(gdb_port : mach_port_t); */
97
98 msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0);
99 msg.msgh_remote_port = gdb_port;
c5aa993b
JM
100 msg.msgh_local_port = MACH_PORT_NULL;
101 msg.msgh_size = sizeof (msg);
102 msg.msgh_seqno = 0;
103 msg.msgh_id = GDB_MESSAGE_ID_STOP;
c906108c
SS
104
105 kr = mach_msg_send (&msg);
106 if (kr != KERN_SUCCESS)
107 fprintf (stderr, "Message not sent, return code %d : %s\n", kr,
108 mach_error_string (kr));
109
110 exit (kr != KERN_SUCCESS);
111}
This page took 0.061438 seconds and 4 git commands to generate.