Replacing a bogus file with a semi-bogus one (sharing through devo).
[deliverable/binutils-gdb.git] / gdb / gdbtk.c
CommitLineData
ca4e7e14 1/* Startup code for gdbtk.
a5f4fbff 2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4604b34c
SG
3
4 Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.
754e5da2
SG
5
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
6c9638b4 20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
754e5da2
SG
21
22#include "defs.h"
23#include "symtab.h"
24#include "inferior.h"
25#include "command.h"
26#include "bfd.h"
27#include "symfile.h"
28#include "objfiles.h"
29#include "target.h"
018d76dd
KS
30#include "gdbcore.h"
31#include "tracepoint.h"
929db6e5 32#include "demangle.h"
018d76dd
KS
33
34#ifdef _WIN32
35#include <winuser.h>
36#endif
37
e6e9507d
EZ
38#include <sys/stat.h>
39
754e5da2
SG
40#include <tcl.h>
41#include <tk.h>
2476848a
MH
42#include <itcl.h>
43#include <tix.h>
dd3dd918 44#include "guitcl.h"
ca4e7e14 45#include "gdbtk.h"
2476848a
MH
46
47#ifdef IDE
018d76dd 48/* start-sanitize-ide */
2476848a
MH
49#include "event.h"
50#include "idetcl.h"
018d76dd
KS
51#include "ilutk.h"
52/* end-sanitize-ide */
2476848a
MH
53#endif
54
73d3dbd4 55#ifdef ANSI_PROTOTYPES
85c613aa
C
56#include <stdarg.h>
57#else
cd2df226 58#include <varargs.h>
85c613aa 59#endif
cd2df226
SG
60#include <signal.h>
61#include <fcntl.h>
8532893d 62#include <unistd.h>
86db943c
SG
63#include <setjmp.h>
64#include "top.h"
736a82e7 65#include <sys/ioctl.h>
2b576293 66#include "gdb_string.h"
09722039 67#include "dis-asm.h"
6131622e
SG
68#include <stdio.h>
69#include "gdbcmd.h"
736a82e7 70
929db6e5 71#include "annotate.h"
018d76dd 72#include <sys/time.h>
018d76dd 73
1798621b
GN
74#ifdef __CYGWIN__
75#include <sys/cygwin.h> /* for cygwin32_attach_handle_to_fd */
76#endif
77
d836385e 78/* For Cygwin, we use a timer to periodically check for Windows
ca4e7e14
JI
79 messages. FIXME: It would be better to not poll, but to instead
80 rewrite the target_wait routines to serve as input sources.
81 Unfortunately, that will be a lot of work. */
82static sigset_t nullsigmask;
83static struct sigaction act1, act2;
84static struct itimerval it_on, it_off;
8b3f9ed6 85
94a6f14f
MH
86extern int Tktable_Init PARAMS ((Tcl_Interp *interp));
87
2476848a 88static void gdbtk_init PARAMS ((char *));
ca4e7e14 89void gdbtk_interactive PARAMS ((void));
b607efe7
FF
90static void cleanup_init PARAMS ((int));
91static void tk_command PARAMS ((char *, int));
ca4e7e14 92
6f5af15b 93void gdbtk_add_hooks PARAMS ((void));
ca4e7e14
JI
94int gdbtk_test PARAMS ((char *));
95
96/*
97 * gdbtk_fputs is defined in the gdbtk_hooks.c, but we need it here
98 * because we delay adding this hook till all the setup is done. That
99 * way errors will go to stdout.
100 */
101
102extern void gdbtk_fputs PARAMS ((const char *, FILE *));
b607efe7 103
754e5da2 104/* Handle for TCL interpreter */
7f6cb62e 105Tcl_Interp *gdbtk_interp = NULL;
754e5da2 106
0776b0b0 107static int gdbtk_timer_going = 0;
0776b0b0 108
4ff5d55a
MH
109/* linked variable used to tell tcl what the current thread is */
110int gdb_context = 0;
111
ca4e7e14
JI
112/* This variable is true when the inferior is running. See note in
113 * gdbtk.h for details.
114 */
ca4e7e14 115int running_now;
fda6fadc 116
7f6cb62e
KS
117/* This variable holds the name of a Tcl file which should be sourced by the
118 interpreter when it goes idle at startup. Used with the testsuite. */
ca4e7e14
JI
119static char *gdbtk_source_filename = NULL;
120\f
9b119644
ILT
121#ifndef _WIN32
122
123/* Supply malloc calls for tcl/tk. We do not want to do this on
124 Windows, because Tcl_Alloc is probably in a DLL which will not call
125 the mmalloc routines. */
8c19daa1
SG
126
127char *
a5a6e3bd 128Tcl_Alloc (size)
8c19daa1
SG
129 unsigned int size;
130{
131 return xmalloc (size);
132}
133
134char *
135Tcl_Realloc (ptr, size)
136 char *ptr;
137 unsigned int size;
138{
139 return xrealloc (ptr, size);
140}
141
142void
143Tcl_Free(ptr)
144 char *ptr;
145{
146 free (ptr);
147}
148
018d76dd 149#endif /* ! _WIN32 */
9b119644 150
018d76dd
KS
151#ifdef _WIN32
152
153/* On Windows, if we hold a file open, other programs can't write to
ca4e7e14
JI
154 * it. In particular, we don't want to hold the executable open,
155 * because it will mean that people have to get out of the debugging
156 * session in order to remake their program. So we close it, although
157 * this will cost us if and when we need to reopen it.
158 */
018d76dd 159
ca4e7e14 160void
018d76dd
KS
161close_bfds ()
162{
163 struct objfile *o;
164
165 ALL_OBJFILES (o)
166 {
167 if (o->obfd != NULL)
168 bfd_cache_close (o->obfd);
169 }
170
171 if (exec_bfd != NULL)
172 bfd_cache_close (exec_bfd);
173}
174
175#endif /* _WIN32 */
176
754e5da2 177\f
ca4e7e14
JI
178/* TclDebug (const char *fmt, ...) works just like printf() but
179 * sends the output to the GDB TK debug window.
180 * Not for normal use; just a convenient tool for debugging
181 */
41756e56 182
ca4e7e14 183void
41756e56 184#ifdef ANSI_PROTOTYPES
ca4e7e14 185TclDebug (const char *fmt, ...)
41756e56 186#else
ca4e7e14 187TclDebug (va_alist)
41756e56
FF
188 va_dcl
189#endif
190{
191 va_list args;
ca4e7e14 192 char buf[512], *v[2], *merge;
41756e56
FF
193
194#ifdef ANSI_PROTOTYPES
ca4e7e14 195 va_start (args, fmt);
41756e56 196#else
ca4e7e14 197 char *fmt;
41756e56 198 va_start (args);
ca4e7e14 199 fmt = va_arg (args, char *);
41756e56
FF
200#endif
201
ca4e7e14
JI
202 v[0] = "debug";
203 v[1] = buf;
41756e56 204
ca4e7e14
JI
205 vsprintf (buf, fmt, args);
206 va_end (args);
018d76dd 207
ca4e7e14
JI
208 merge = Tcl_Merge (2, v);
209 Tcl_Eval (gdbtk_interp, merge);
210 Tcl_Free (merge);
41756e56
FF
211}
212
ca4e7e14
JI
213\f
214/*
215 * The rest of this file contains the start-up, and event handling code for gdbtk.
216 */
217
218/*
219 * This cleanup function is added to the cleanup list that surrounds the Tk
220 * main in gdbtk_init. It deletes the Tcl interpreter.
221 */
222
41756e56 223static void
ca4e7e14
JI
224cleanup_init (ignored)
225 int ignored;
41756e56 226{
ca4e7e14
JI
227 if (gdbtk_interp != NULL)
228 Tcl_DeleteInterp (gdbtk_interp);
229 gdbtk_interp = NULL;
41756e56
FF
230}
231
ca4e7e14
JI
232/* Come here during long calculations to check for GUI events. Usually invoked
233 via the QUIT macro. */
234
235void
236gdbtk_interactive ()
929db6e5 237{
ca4e7e14 238 /* Tk_DoOneEvent (TK_DONT_WAIT|TK_IDLE_EVENTS); */
929db6e5
EZ
239}
240
ca4e7e14
JI
241
242void
243gdbtk_start_timer ()
6131622e 244{
ca4e7e14
JI
245 static int first = 1;
246 /*TclDebug ("Starting timer....");*/
247 if (first)
248 {
249 /* first time called, set up all the structs */
250 first = 0;
251 sigemptyset (&nullsigmask);
85c613aa 252
ca4e7e14
JI
253 act1.sa_handler = x_event;
254 act1.sa_mask = nullsigmask;
255 act1.sa_flags = 0;
6131622e 256
ca4e7e14
JI
257 act2.sa_handler = SIG_IGN;
258 act2.sa_mask = nullsigmask;
259 act2.sa_flags = 0;
6131622e 260
ca4e7e14
JI
261 it_on.it_interval.tv_sec = 0;
262 it_on.it_interval.tv_usec = 250000; /* .25 sec */
263 it_on.it_value.tv_sec = 0;
264 it_on.it_value.tv_usec = 250000;
6131622e 265
ca4e7e14
JI
266 it_off.it_interval.tv_sec = 0;
267 it_off.it_interval.tv_usec = 0;
268 it_off.it_value.tv_sec = 0;
269 it_off.it_value.tv_usec = 0;
270 }
271
272 if (!gdbtk_timer_going)
273 {
274 sigaction (SIGALRM, &act1, NULL);
275 setitimer (ITIMER_REAL, &it_on, NULL);
276 gdbtk_timer_going = 1;
277 }
6131622e
SG
278}
279
ca4e7e14
JI
280void
281gdbtk_stop_timer ()
8a19b35a 282{
ca4e7e14 283 if (gdbtk_timer_going)
8a19b35a 284 {
ca4e7e14
JI
285 gdbtk_timer_going = 0;
286 /*TclDebug ("Stopping timer.");*/
287 setitimer (ITIMER_REAL, &it_off, NULL);
288 sigaction (SIGALRM, &act2, NULL);
8a19b35a 289 }
8a19b35a
MH
290}
291
ca4e7e14 292/* gdbtk_init installs this function as a final cleanup. */
6131622e 293
ca4e7e14
JI
294static void
295gdbtk_cleanup (dummy)
296 PTR dummy;
297{
4d14b252 298 Tcl_Eval (gdbtk_interp, "gdbtk_cleanup");
ca4e7e14 299#ifdef IDE
1dd251f9
DM
300 {
301 struct ide_event_handle *h = (struct ide_event_handle *) dummy;
302 ide_interface_deregister_all (h);
303 }
ca4e7e14
JI
304#endif
305 Tcl_Finalize ();
6131622e
SG
306}
307
ca4e7e14
JI
308/* Initialize gdbtk. This involves creating a Tcl interpreter,
309 * defining all the Tcl commands that the GUI will use, pointing
310 * all the gdb "hooks" to the correct functions,
311 * and setting the Tcl auto loading environment so that we can find all
312 * the Tcl based library files.
313 */
314
754e5da2 315static void
ca4e7e14
JI
316gdbtk_init ( argv0 )
317 char *argv0;
754e5da2 318{
ca4e7e14
JI
319 struct cleanup *old_chain;
320 char *lib, *gdbtk_lib, *gdbtk_lib_tmp, *gdbtk_file;
6f5af15b 321 int found_main;
ca4e7e14 322 Tcl_Obj *auto_path_elem, *auto_path_name;
6f5af15b 323
ca4e7e14
JI
324#ifdef IDE
325 /* start-sanitize-ide */
326 struct ide_event_handle *h;
327 const char *errmsg;
328 char *libexecdir;
329 /* end-sanitize-ide */
330#endif
331
332 /* If there is no DISPLAY environment variable, Tk_Init below will fail,
333 causing gdb to abort. If instead we simply return here, gdb will
334 gracefully degrade to using the command line interface. */
754e5da2 335
d836385e 336#ifndef _WIN32
ca4e7e14 337 if (getenv ("DISPLAY") == NULL)
754e5da2 338 return;
ca4e7e14 339#endif
754e5da2 340
ad3b8c4a 341 old_chain = make_cleanup ((make_cleanup_func) cleanup_init, 0);
929db6e5 342
ca4e7e14
JI
343 /* First init tcl and tk. */
344 Tcl_FindExecutable (argv0);
345 gdbtk_interp = Tcl_CreateInterp ();
754e5da2 346
ca4e7e14
JI
347#ifdef TCL_MEM_DEBUG
348 Tcl_InitMemory (gdbtk_interp);
349#endif
754e5da2 350
ca4e7e14
JI
351 if (!gdbtk_interp)
352 error ("Tcl_CreateInterp failed");
754e5da2 353
ca4e7e14
JI
354 if (Tcl_Init(gdbtk_interp) != TCL_OK)
355 error ("Tcl_Init failed: %s", gdbtk_interp->result);
754e5da2 356
ca4e7e14
JI
357#ifndef IDE
358 /* For the IDE we register the cleanup later, after we've
359 initialized events. */
360 make_final_cleanup (gdbtk_cleanup, NULL);
746d1df4
SG
361#endif
362
ca4e7e14
JI
363 /* Initialize the Paths variable. */
364 if (ide_initialize_paths (gdbtk_interp, "gdbtcl") != TCL_OK)
365 error ("ide_initialize_paths failed: %s", gdbtk_interp->result);
746d1df4 366
ca4e7e14
JI
367#ifdef IDE
368 /* start-sanitize-ide */
369 /* Find the directory where we expect to find idemanager. We ignore
370 errors since it doesn't really matter if this fails. */
371 libexecdir = Tcl_GetVar2 (gdbtk_interp, "Paths", "libexecdir", TCL_GLOBAL_ONLY);
746d1df4 372
ca4e7e14 373 IluTk_Init ();
929db6e5 374
ca4e7e14
JI
375 h = ide_event_init_from_environment (&errmsg, libexecdir);
376 make_final_cleanup (gdbtk_cleanup, h);
377 if (h == NULL)
746d1df4 378 {
ca4e7e14
JI
379 Tcl_AppendResult (gdbtk_interp, "can't initialize event system: ", errmsg,
380 (char *) NULL);
381 fprintf(stderr, "WARNING: ide_event_init_client failed: %s\n", gdbtk_interp->result);
746d1df4 382
ca4e7e14 383 Tcl_SetVar (gdbtk_interp, "IDE_ENABLED", "0", 0);
746d1df4 384 }
ca4e7e14 385 else
3d9f68c0 386 {
ca4e7e14
JI
387 if (ide_create_tclevent_command (gdbtk_interp, h) != TCL_OK)
388 error ("ide_create_tclevent_command failed: %s", gdbtk_interp->result);
0422b59e 389
ca4e7e14
JI
390 if (ide_create_edit_command (gdbtk_interp, h) != TCL_OK)
391 error ("ide_create_edit_command failed: %s", gdbtk_interp->result);
392
393 if (ide_create_property_command (gdbtk_interp, h) != TCL_OK)
394 error ("ide_create_property_command failed: %s", gdbtk_interp->result);
018d76dd 395
ca4e7e14
JI
396 if (ide_create_build_command (gdbtk_interp, h) != TCL_OK)
397 error ("ide_create_build_command failed: %s", gdbtk_interp->result);
754e5da2 398
ca4e7e14
JI
399 if (ide_create_window_register_command (gdbtk_interp, h, "gdb-restore")
400 != TCL_OK)
401 error ("ide_create_window_register_command failed: %s",
402 gdbtk_interp->result);
fda6fadc 403
ca4e7e14
JI
404 if (ide_create_window_command (gdbtk_interp, h) != TCL_OK)
405 error ("ide_create_window_command failed: %s", gdbtk_interp->result);
0b7148e4 406
ca4e7e14
JI
407 if (ide_create_exit_command (gdbtk_interp, h) != TCL_OK)
408 error ("ide_create_exit_command failed: %s", gdbtk_interp->result);
018d76dd 409
ca4e7e14
JI
410 if (ide_create_help_command (gdbtk_interp) != TCL_OK)
411 error ("ide_create_help_command failed: %s", gdbtk_interp->result);
018d76dd 412
ca4e7e14
JI
413 /*
414 if (ide_initialize (gdbtk_interp, "gdb") != TCL_OK)
415 error ("ide_initialize failed: %s", gdbtk_interp->result);
416 */
479f0f18 417
ca4e7e14 418 Tcl_SetVar (gdbtk_interp, "IDE_ENABLED", "1", 0);
7234efcb 419 }
ca4e7e14
JI
420 /* end-sanitize-ide */
421#else
422 Tcl_SetVar (gdbtk_interp, "IDE_ENABLED", "0", 0);
423#endif /* IDE */
0776b0b0 424
ca4e7e14
JI
425 /* We don't want to open the X connection until we've done all the
426 IDE initialization. Otherwise, goofy looking unfinished windows
427 pop up when ILU drops into the TCL event loop. */
86db943c 428
ca4e7e14
JI
429 if (Tk_Init(gdbtk_interp) != TCL_OK)
430 error ("Tk_Init failed: %s", gdbtk_interp->result);
86db943c 431
ca4e7e14
JI
432 if (Itcl_Init(gdbtk_interp) == TCL_ERROR)
433 error ("Itcl_Init failed: %s", gdbtk_interp->result);
434 Tcl_StaticPackage(gdbtk_interp, "Tktable", Tktable_Init,
435 (Tcl_PackageInitProc *) NULL);
09722039 436
ca4e7e14
JI
437 if (Tix_Init(gdbtk_interp) != TCL_OK)
438 error ("Tix_Init failed: %s", gdbtk_interp->result);
439 Tcl_StaticPackage(gdbtk_interp, "Tktable", Tktable_Init,
440 (Tcl_PackageInitProc *) NULL);
86db943c 441
ca4e7e14
JI
442 if (Tktable_Init(gdbtk_interp) != TCL_OK)
443 error ("Tktable_Init failed: %s", gdbtk_interp->result);
929db6e5 444
ca4e7e14
JI
445 Tcl_StaticPackage(gdbtk_interp, "Tktable", Tktable_Init,
446 (Tcl_PackageInitProc *) NULL);
447 /*
448 * These are the commands to do some Windows Specific stuff...
449 */
018d76dd 450
d836385e 451#ifdef __CYGWIN__
ca4e7e14
JI
452 if (ide_create_messagebox_command (gdbtk_interp) != TCL_OK)
453 error ("messagebox command initialization failed");
454 /* On Windows, create a sizebox widget command */
455 if (ide_create_sizebox_command (gdbtk_interp) != TCL_OK)
456 error ("sizebox creation failed");
457 if (ide_create_winprint_command (gdbtk_interp) != TCL_OK)
458 error ("windows print code initialization failed");
018d76dd 459 /* start-sanitize-ide */
ca4e7e14
JI
460 /* An interface to ShellExecute. */
461 if (ide_create_shell_execute_command (gdbtk_interp) != TCL_OK)
462 error ("shell execute command initialization failed");
018d76dd 463 /* end-sanitize-ide */
ca4e7e14
JI
464 if (ide_create_win_grab_command (gdbtk_interp) != TCL_OK)
465 error ("grab support command initialization failed");
466 /* Path conversion functions. */
467 if (ide_create_cygwin_path_command (gdbtk_interp) != TCL_OK)
468 error ("cygwin path command initialization failed");
469#endif
018d76dd 470
ca4e7e14
JI
471 /*
472 * This adds all the Gdbtk commands.
473 */
474
475 if (Gdbtk_Init(gdbtk_interp) != TCL_OK)
018d76dd 476 {
ca4e7e14 477 error("Gdbtk_Init failed: %s", gdbtk_interp->result);
018d76dd 478 }
4f17e6eb 479
ca4e7e14
JI
480 Tcl_StaticPackage(gdbtk_interp, "Gdbtk", Gdbtk_Init, NULL);
481
482 /* This adds all the hooks that call up from the bowels of gdb
483 * back into Tcl-land...
484 */
e0f7db02 485
ca4e7e14
JI
486 gdbtk_add_hooks();
487
488 /* Add a back door to Tk from the gdb console... */
e0f7db02 489
ca4e7e14
JI
490 add_com ("tk", class_obscure, tk_command,
491 "Send a command directly into tk.");
e0f7db02 492
ca4e7e14 493 /* find the gdb tcl library and source main.tcl */
929db6e5 494
ca4e7e14
JI
495 gdbtk_lib = getenv ("GDBTK_LIBRARY");
496 if (!gdbtk_lib)
6f5af15b
MH
497 {
498 if (access ("gdbtcl/main.tcl", R_OK) == 0)
499 gdbtk_lib = "gdbtcl";
500 else
501 gdbtk_lib = GDBTK_LIBRARY;
502 }
503
ca4e7e14 504 gdbtk_lib_tmp = xstrdup (gdbtk_lib);
929db6e5 505
ca4e7e14
JI
506 found_main = 0;
507 /* see if GDBTK_LIBRARY is a path list */
508 lib = strtok (gdbtk_lib_tmp, GDBTK_PATH_SEP);
929db6e5 509
ca4e7e14 510 auto_path_name = Tcl_NewStringObj ("auto_path", -1);
929db6e5 511
ca4e7e14 512 do
929db6e5 513 {
ca4e7e14
JI
514 auto_path_elem = Tcl_NewStringObj (lib, -1);
515 if (Tcl_ObjSetVar2 (gdbtk_interp, auto_path_name, NULL, auto_path_elem,
516 TCL_GLOBAL_ONLY | TCL_APPEND_VALUE | TCL_LIST_ELEMENT ) == NULL)
929db6e5 517 {
ca4e7e14
JI
518 fputs_unfiltered (Tcl_GetVar (gdbtk_interp, "errorInfo", 0), gdb_stderr);
519 error ("");
929db6e5 520 }
ca4e7e14 521 if (!found_main)
929db6e5 522 {
ca4e7e14
JI
523 gdbtk_file = concat (lib, "/main.tcl", (char *) NULL);
524 if (access (gdbtk_file, R_OK) == 0)
929db6e5 525 {
ca4e7e14
JI
526 found_main++;
527 Tcl_SetVar (gdbtk_interp, "GDBTK_LIBRARY", lib, 0);
929db6e5
EZ
528 }
529 }
ca4e7e14
JI
530 }
531 while ((lib = strtok (NULL, ":")) != NULL);
929db6e5 532
ca4e7e14
JI
533 free (gdbtk_lib_tmp);
534 Tcl_DecrRefCount(auto_path_name);
e0f7db02 535
ca4e7e14 536 if (!found_main)
e6e9507d 537 {
ca4e7e14 538 /* Try finding it with the auto path. */
929db6e5 539
ca4e7e14
JI
540 static const char script[] ="\
541proc gdbtk_find_main {} {\n\
542 global auto_path GDBTK_LIBRARY\n\
543 foreach dir $auto_path {\n\
544 set f [file join $dir main.tcl]\n\
545 if {[file exists $f]} then {\n\
546 set GDBTK_LIBRARY $dir\n\
547 return $f\n\
548 }\n\
549 }\n\
550 return ""\n\
551}\n\
552gdbtk_find_main";
929db6e5 553
ca4e7e14
JI
554 if (Tcl_GlobalEval (gdbtk_interp, (char *) script) != TCL_OK)
555 {
556 fputs_unfiltered (Tcl_GetVar (gdbtk_interp, "errorInfo", 0), gdb_stderr);
557 error ("");
558 }
929db6e5 559
ca4e7e14 560 if (gdbtk_interp->result[0] != '\0')
929db6e5 561 {
ca4e7e14
JI
562 gdbtk_file = xstrdup (gdbtk_interp->result);
563 found_main++;
929db6e5
EZ
564 }
565 }
11f91b2b 566
ca4e7e14 567 if (!found_main)
929db6e5 568 {
ca4e7e14
JI
569 fputs_unfiltered_hook = NULL; /* Force errors to stdout/stderr */
570 if (getenv("GDBTK_LIBRARY"))
929db6e5 571 {
ca4e7e14
JI
572 fprintf_unfiltered (stderr, "Unable to find main.tcl in %s\n",getenv("GDBTK_LIBRARY"));
573 fprintf_unfiltered (stderr,
574 "Please set GDBTK_LIBRARY to a path that includes the GDB tcl files.\n");
929db6e5
EZ
575 }
576 else
577 {
ca4e7e14
JI
578 fprintf_unfiltered (stderr, "Unable to find main.tcl in %s\n", GDBTK_LIBRARY);
579 fprintf_unfiltered (stderr, "You might want to set GDBTK_LIBRARY\n");
929db6e5 580 }
ca4e7e14 581 error("");
929db6e5 582 }
11f91b2b 583
ca4e7e14
JI
584/* Defer setup of fputs_unfiltered_hook to near the end so that error messages
585 prior to this point go to stdout/stderr. */
929db6e5 586
ca4e7e14 587 fputs_unfiltered_hook = gdbtk_fputs;
929db6e5 588
ca4e7e14
JI
589/* start-sanitize-tclpro */
590#ifdef TCLPRO_DEBUGGER
591 {
592 Tcl_DString source_cmd;
929db6e5 593
ca4e7e14
JI
594 Tcl_DStringInit (&source_cmd);
595 Tcl_DStringAppend (&source_cmd,
596 "if {[info exists env(DEBUG_STUB)]} {source $env(DEBUG_STUB); " -1);
597 Tcl_DStringAppend (&source_cmd, "debugger_init; debugger_eval {source {", -1);
598 Tcl_DStringAppend (&source_cmd, gdbtk_file, -1);
599 Tcl_DStringAppend (&source_cmd, "}}} else {source {", -1);
600 Tcl_DStringAppend (&source_cmd, gdbtk_file, -1);
601 Tcl_DStringAppend (&source_cmd, "}}", -1);
602 if (Tcl_GlobalEval (gdbtk_interp, Tcl_DStringValue (&source_cmd)) != TCL_OK)
603#else
604/* end-sanitize-tclpro */
605 if (Tcl_EvalFile (gdbtk_interp, gdbtk_file) != TCL_OK)
606/* start-sanitize-tclpro */
607#endif
608/* end-sanitize-tclpro */
609 {
610 char *msg;
929db6e5 611
ca4e7e14
JI
612 /* Force errorInfo to be set up propertly. */
613 Tcl_AddErrorInfo (gdbtk_interp, "");
e0f7db02 614
ca4e7e14 615 msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY);
4f17e6eb 616
ca4e7e14 617 fputs_unfiltered_hook = NULL; /* Force errors to stdout/stderr */
7f6cb62e 618
ca4e7e14
JI
619#ifdef _WIN32
620 MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
621#else
622 fputs_unfiltered (msg, gdb_stderr);
623#endif
7f6cb62e 624
ca4e7e14 625 error ("");
7f6cb62e 626 }
ca4e7e14
JI
627/* start-sanitize-tclpro */
628#ifdef TCLPRO_DEBUGGER
629 Tcl_DStringFree(&source_cmd);
7f6cb62e 630 }
ca4e7e14
JI
631#endif
632/* end-sanitize-tclpro */
7f6cb62e 633
ca4e7e14
JI
634#ifdef IDE
635 /* start-sanitize-ide */
636 /* Don't do this until we have initialized. Otherwise, we may get a
637 run command before we are ready for one. */
638 if (ide_run_server_init (gdbtk_interp, h) != TCL_OK)
639 error ("ide_run_server_init failed: %s", gdbtk_interp->result);
640 /* end-sanitize-ide */
641#endif
7f6cb62e 642
ca4e7e14 643 free (gdbtk_file);
7f6cb62e 644
ca4e7e14
JI
645 /* Now source in the filename provided by the --tclcommand option.
646 This is mostly used for the gdbtk testsuite... */
7f6cb62e 647
ca4e7e14
JI
648 if (gdbtk_source_filename != NULL)
649 {
650 char *s = "after idle source ";
651 char *script = concat (s, gdbtk_source_filename, (char *) NULL);
652 Tcl_Eval (gdbtk_interp, script);
653 free (gdbtk_source_filename);
654 free (script);
655 }
656
657
658 discard_cleanups (old_chain);
7f6cb62e
KS
659}
660
ca4e7e14
JI
661/* gdbtk_test is used in main.c to validate the -tclcommand option to
662 gdb, which sources in a file of tcl code after idle during the
663 startup procedure. */
664
7f6cb62e
KS
665int
666gdbtk_test (filename)
667 char *filename;
668{
669 if (access (filename, R_OK) != 0)
670 return 0;
671 else
672 gdbtk_source_filename = xstrdup (filename);
673 return 1;
674}
ca4e7e14 675
3f37b696 676/* Come here during initialize_all_files () */
754e5da2
SG
677
678void
679_initialize_gdbtk ()
680{
c5197511
SG
681 if (use_windows)
682 {
683 /* Tell the rest of the world that Gdbtk is now set up. */
754e5da2 684
c5197511 685 init_ui_hook = gdbtk_init;
d836385e 686#ifdef __CYGWIN__
47792960
KS
687 (void) FreeConsole ();
688#endif
c5197511 689 }
d836385e 690#ifdef __CYGWIN__
cb432079
EZ
691 else
692 {
693 DWORD ft = GetFileType (GetStdHandle (STD_INPUT_HANDLE));
cb432079
EZ
694
695 switch (ft)
696 {
697 case FILE_TYPE_DISK:
698 case FILE_TYPE_CHAR:
699 case FILE_TYPE_PIPE:
700 break;
701 default:
702 AllocConsole();
1798621b
GN
703 cygwin32_attach_handle_to_fd ("/dev/conin", 0,
704 GetStdHandle (STD_INPUT_HANDLE),
705 1, GENERIC_READ);
706 cygwin32_attach_handle_to_fd ("/dev/conout", 1,
707 GetStdHandle (STD_OUTPUT_HANDLE),
708 0, GENERIC_WRITE);
709 cygwin32_attach_handle_to_fd ("/dev/conout", 2,
710 GetStdHandle (STD_ERROR_HANDLE),
711 0, GENERIC_WRITE);
cb432079
EZ
712 break;
713 }
714 }
715#endif
754e5da2 716}
ca4e7e14
JI
717
718static void
719tk_command (cmd, from_tty)
720 char *cmd;
721 int from_tty;
722{
723 int retval;
724 char *result;
725 struct cleanup *old_chain;
726
727 /* Catch case of no argument, since this will make the tcl interpreter dump core. */
728 if (cmd == NULL)
729 error_no_arg ("tcl command to interpret");
730
731 retval = Tcl_Eval (gdbtk_interp, cmd);
732
733 result = strdup (gdbtk_interp->result);
734
735 old_chain = make_cleanup (free, result);
736
737 if (retval != TCL_OK)
738 error (result);
739
740 printf_unfiltered ("%s\n", result);
741
742 do_cleanups (old_chain);
743}
744
This page took 0.250631 seconds and 4 git commands to generate.