2 * Convenience functions to handle use of external debugger.
4 * Copyright 1999 Kevin Holbrook
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define DBG_BUFF_SIZE 12
30 #define DBG_EXTERNAL_DEFAULT "gdb"
31 #define DBG_LOCATION_DEFAULT "/usr/local/bin/wine"
32 #define DBG_SLEEPTIME_DEFAULT 120
36 /* DEBUG_ExternalDebugger
38 * This function invokes an external debugger on the current
39 * wine process. The form of the command executed is:
40 * <debugger image> <wine image> <attach process id>
42 * The debugger command is normally invoked by a newly created xterm.
44 * The current calling process is temporarily put to sleep
45 * so that the invoked debugger has time to come up and attach.
47 * The following environment variables may be used:
50 * -------------------------------------------------------------------------------------
51 * WINE_DBG_EXTERNAL debugger command to invoke ("gdb")
52 * WINE_DBG_LOCATION fully qualified location of wine image ("/usr/local/bin/wine")
53 * WINE_DBG_NO_XTERM if set do not invoke xterm with command (not set)
54 * WINE_DBG_SLEEPTIME number of seconds to make process sleep (120)
59 * #include "wine/debug.h"
61 * DEBUG_ExternalDebugger();
64 * Environment Example:
66 * export WINE_DBG_EXTERNAL="ddd"
67 * export WINE_DBG_NO_XTERM=1
68 * export WINE_DBG_SLEEPTIME=60
72 void DEBUG_ExternalDebugger(void)
76 int dbg_sleep_secs
= DBG_SLEEPTIME_DEFAULT
;
80 dbg_sleeptime
= getenv("WINE_DBG_SLEEPTIME");
82 /* convert sleep time string to integer seconds */
85 dbg_sleep_secs
= atoi(dbg_sleeptime
);
87 /* check for conversion error */
88 if (dbg_sleep_secs
== 0)
89 dbg_sleep_secs
= DBG_SLEEPTIME_DEFAULT
;
92 /* get the current process id */
93 attach_pid
= getpid();
95 /* create new process */
98 /* check if we are the child process */
102 const char *dbg_external
;
103 const char *dbg_wine_location
;
104 const char *dbg_no_xterm
;
105 char pid_string
[DBG_BUFF_SIZE
];
108 /* check settings in environment for debugger to use */
109 dbg_external
= getenv("WINE_DBG_EXTERNAL");
110 dbg_wine_location
= getenv("WINE_DBG_LOCATION");
111 dbg_no_xterm
= getenv("WINE_DBG_NO_XTERM");
113 /* if not set in environment, use default */
115 dbg_external
= "gdb";
117 /* if not set in environment, use default */
118 if (!dbg_wine_location
)
119 dbg_wine_location
= "wine";
121 /* check for empty string in WINE_DBG_NO_XTERM */
122 if (dbg_no_xterm
&& (strlen(dbg_no_xterm
) < 1))
125 /* clear the buffer */
126 memset(pid_string
, 0, DBG_BUFF_SIZE
);
128 /* make pid into string */
129 sprintf(pid_string
, "%ld", (long) attach_pid
);
131 /* now exec the debugger to get it's own clean memory space */
133 status
= execlp(dbg_external
, dbg_external
, dbg_wine_location
, pid_string
, NULL
);
135 status
= execlp("xterm", "xterm", "-e", dbg_external
, dbg_wine_location
, pid_string
, NULL
);
140 fprintf(stderr
, "DEBUG_ExternalDebugger failed to execute \"%s %s %s\" (%s)\n",
141 dbg_external
, dbg_wine_location
, pid_string
, strerror(errno
));
143 fprintf(stderr
, "DEBUG_ExternalDebugger failed to execute \"xterm -e %s %s %s\" (%s)\n",
144 dbg_external
, dbg_wine_location
, pid_string
, strerror(errno
));
148 else if (child_pid
!= -1)
150 /* make the parent/caller sleep so the child/debugger can catch it */
151 sleep(dbg_sleep_secs
);
154 fprintf(stderr
, "DEBUG_ExternalDebugger failed.\n");