3 * Author : Kevin Holbrook
4 * Created : July 18, 1999
6 * Convenience functions to handle use of external debugger.
19 #define DBG_BUFF_SIZE 12
21 #define DBG_EXTERNAL_DEFAULT "gdb"
22 #define DBG_LOCATION_DEFAULT "/usr/local/bin/wine"
23 #define DBG_SLEEPTIME_DEFAULT 120
27 /* DEBUG_ExternalDebugger
29 * This function invokes an external debugger on the current
30 * wine process. The form of the command executed is:
31 * <debugger image> <wine image> <attach process id>
33 * The debugger command is normally invoked by a newly created xterm.
35 * The current calling process is temporarily put to sleep
36 * so that the invoked debugger has time to come up and attach.
38 * The following environment variables may be used:
41 * -------------------------------------------------------------------------------------
42 * WINE_DBG_EXTERNAL debugger command to invoke ("gdb")
43 * WINE_DBG_LOCATION fully qualified location of wine image ("/usr/local/bin/wine")
44 * WINE_DBG_NO_XTERM if set do not invoke xterm with command (not set)
45 * WINE_DBG_SLEEPTIME number of seconds to make process sleep (120)
50 * #include "debugtools.h"
52 * DEBUG_ExternalDebugger();
55 * Environment Example:
57 * export WINE_DBG_EXTERNAL="ddd"
58 * export WINE_DBG_NO_XTERM=1
59 * export WINE_DBG_SLEEPTIME=60
63 void DEBUG_ExternalDebugger(void)
67 int dbg_sleep_secs
= DBG_SLEEPTIME_DEFAULT
;
71 dbg_sleeptime
= getenv("WINE_DBG_SLEEPTIME");
73 /* convert sleep time string to integer seconds */
76 dbg_sleep_secs
= atoi(dbg_sleeptime
);
78 /* check for conversion error */
79 if (dbg_sleep_secs
== 0)
80 dbg_sleep_secs
= DBG_SLEEPTIME_DEFAULT
;
83 /* get the curent process id */
84 attach_pid
= getpid();
86 /* create new process */
89 /* check if we are the child process */
93 const char *dbg_external
;
94 const char *dbg_wine_location
;
95 const char *dbg_no_xterm
;
96 char pid_string
[DBG_BUFF_SIZE
];
99 /* check settings in environment for debugger to use */
100 dbg_external
= getenv("WINE_DBG_EXTERNAL");
101 dbg_wine_location
= getenv("WINE_DBG_LOCATION");
102 dbg_no_xterm
= getenv("WINE_DBG_NO_XTERM");
104 /* if not set in environment, use default */
106 dbg_external
= "gdb";
108 /* if not set in environment, use default */
109 if (!dbg_wine_location
)
110 dbg_wine_location
= argv0
;
112 /* check for empty string in WINE_DBG_NO_XTERM */
113 if (dbg_no_xterm
&& (strlen(dbg_no_xterm
) < 1))
116 /* clear the buffer */
117 memset(pid_string
, 0, DBG_BUFF_SIZE
);
119 /* make pid into string */
120 sprintf(pid_string
, "%ld", (long) attach_pid
);
122 /* now exec the debugger to get it's own clean memory space */
124 status
= execlp(dbg_external
, dbg_external
, dbg_wine_location
, pid_string
, NULL
);
126 status
= execlp("xterm", "xterm", "-e", dbg_external
, dbg_wine_location
, pid_string
, NULL
);
131 fprintf(stderr
, "DEBUG_ExternalDebugger failed to execute \"%s %s %s\" (%s)\n",
132 dbg_external
, dbg_wine_location
, pid_string
, strerror(errno
));
134 fprintf(stderr
, "DEBUG_ExternalDebugger failed to execute \"xterm -e %s %s %s\" (%s)\n",
135 dbg_external
, dbg_wine_location
, pid_string
, strerror(errno
));
139 else if (child_pid
!= -1)
141 /* make the parent/caller sleep so the child/debugger can catch it */
142 sleep(dbg_sleep_secs
);
145 fprintf(stderr
, "DEBUG_ExternalDebugger failed.\n");