1 /* Tcl/Tk interface routines.
2 Copyright 1994, 1995, 1996 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
32 #ifdef ANSI_PROTOTYPES
42 #include <sys/ioctl.h>
43 #include "gdb_string.h"
49 #include <sys/stropts.h>
52 /* Handle for TCL interpreter */
53 static Tcl_Interp *interp = NULL;
55 /* Handle for TK main window */
56 static Tk_Window mainWindow = NULL;
58 static int x_fd; /* X network socket */
60 /* This variable determines where memory used for disassembly is read from.
62 If > 0, then disassembly comes from the exec file rather than the target
63 (which might be at the other end of a slow serial link). If == 0 then
64 disassembly comes from target. If < 0 disassembly is automatically switched
65 to the target if it's an inferior process, otherwise the exec file is
69 static int disassemble_from_exec = -1;
71 /* Supply malloc calls for tcl/tk. */
77 return xmalloc (size);
81 Tcl_Realloc (ptr, size)
85 return xrealloc (ptr, size);
101 /* The following routines deal with stdout/stderr data, which is created by
102 {f}printf_{un}filtered and friends. gdbtk_fputs and gdbtk_flush are the
103 lowest level of these routines and capture all output from the rest of GDB.
104 Normally they present their data to tcl via callbacks to the following tcl
105 routines: gdbtk_tcl_fputs, gdbtk_tcl_fputs_error, and gdbtk_flush. These
106 in turn call tk routines to update the display.
108 Under some circumstances, you may want to collect the output so that it can
109 be returned as the value of a tcl procedure. This can be done by
110 surrounding the output routines with calls to start_saving_output and
111 finish_saving_output. The saved data can then be retrieved with
112 get_saved_output (but this must be done before the call to
113 finish_saving_output). */
115 /* Dynamic string header for stdout. */
117 static Tcl_DString *result_ptr;
124 /* Force immediate screen update */
126 Tcl_VarEval (interp, "gdbtk_tcl_flush", NULL);
131 gdbtk_fputs (ptr, stream)
136 Tcl_DStringAppend (result_ptr, (char *)ptr, -1);
141 Tcl_DStringInit (&str);
143 Tcl_DStringAppend (&str, "gdbtk_tcl_fputs", -1);
144 Tcl_DStringAppendElement (&str, (char *)ptr);
146 Tcl_Eval (interp, Tcl_DStringValue (&str));
147 Tcl_DStringFree (&str);
152 gdbtk_query (query, args)
156 char buf[200], *merge[2];
160 vsprintf (buf, query, args);
161 merge[0] = "gdbtk_tcl_query";
163 command = Tcl_Merge (2, merge);
164 Tcl_Eval (interp, command);
167 val = atol (interp->result);
172 #ifdef ANSI_PROTOTYPES
173 dsprintf_append_element (Tcl_DString *dsp, char *format, ...)
175 dsprintf_append_element (va_alist)
182 #ifdef ANSI_PROTOTYPES
183 va_start (args, format);
189 dsp = va_arg (args, Tcl_DString *);
190 format = va_arg (args, char *);
193 vsprintf (buf, format, args);
195 Tcl_DStringAppendElement (dsp, buf);
199 gdb_get_breakpoint_list (clientData, interp, argc, argv)
200 ClientData clientData;
205 struct breakpoint *b;
206 extern struct breakpoint *breakpoint_chain;
209 error ("wrong # args");
211 for (b = breakpoint_chain; b; b = b->next)
212 if (b->type == bp_breakpoint)
213 dsprintf_append_element (result_ptr, "%d", b->number);
219 gdb_get_breakpoint_info (clientData, interp, argc, argv)
220 ClientData clientData;
225 struct symtab_and_line sal;
226 static char *bptypes[] = {"breakpoint", "hardware breakpoint", "until",
227 "finish", "watchpoint", "hardware watchpoint",
228 "read watchpoint", "access watchpoint",
229 "longjmp", "longjmp resume", "step resume",
230 "through sigtramp", "watchpoint scope",
232 static char *bpdisp[] = {"delete", "disable", "donttouch"};
233 struct command_line *cmd;
235 struct breakpoint *b;
236 extern struct breakpoint *breakpoint_chain;
239 error ("wrong # args");
241 bpnum = atoi (argv[1]);
243 for (b = breakpoint_chain; b; b = b->next)
244 if (b->number == bpnum)
247 if (!b || b->type != bp_breakpoint)
248 error ("Breakpoint #%d does not exist", bpnum);
250 sal = find_pc_line (b->address, 0);
252 Tcl_DStringAppendElement (result_ptr, symtab_to_filename (sal.symtab));
253 dsprintf_append_element (result_ptr, "%d", sal.line);
254 dsprintf_append_element (result_ptr, "0x%lx", b->address);
255 Tcl_DStringAppendElement (result_ptr, bptypes[b->type]);
256 Tcl_DStringAppendElement (result_ptr, b->enable == enabled ? "1" : "0");
257 Tcl_DStringAppendElement (result_ptr, bpdisp[b->disposition]);
258 dsprintf_append_element (result_ptr, "%d", b->silent);
259 dsprintf_append_element (result_ptr, "%d", b->ignore_count);
261 Tcl_DStringStartSublist (result_ptr);
262 for (cmd = b->commands; cmd; cmd = cmd->next)
263 Tcl_DStringAppendElement (result_ptr, cmd->line);
264 Tcl_DStringEndSublist (result_ptr);
266 Tcl_DStringAppendElement (result_ptr, b->cond_string);
268 dsprintf_append_element (result_ptr, "%d", b->thread);
269 dsprintf_append_element (result_ptr, "%d", b->hit_count);
275 breakpoint_notify(b, action)
276 struct breakpoint *b;
282 if (b->type != bp_breakpoint)
285 /* We ensure that ACTION contains no special Tcl characters, so we
287 sprintf (buf, "gdbtk_tcl_breakpoint %s %d", action, b->number);
289 v = Tcl_Eval (interp, buf);
293 gdbtk_fputs (interp->result, gdb_stdout);
294 gdbtk_fputs ("\n", gdb_stdout);
299 gdbtk_create_breakpoint(b)
300 struct breakpoint *b;
302 breakpoint_notify (b, "create");
306 gdbtk_delete_breakpoint(b)
307 struct breakpoint *b;
309 breakpoint_notify (b, "delete");
313 gdbtk_modify_breakpoint(b)
314 struct breakpoint *b;
316 breakpoint_notify (b, "modify");
319 /* This implements the TCL command `gdb_loc', which returns a list consisting
320 of the source and line number associated with the current pc. */
323 gdb_loc (clientData, interp, argc, argv)
324 ClientData clientData;
330 struct symtab_and_line sal;
336 pc = selected_frame ? selected_frame->pc : stop_pc;
337 sal = find_pc_line (pc, 0);
341 struct symtabs_and_lines sals;
344 sals = decode_line_spec (argv[1], 1);
351 error ("Ambiguous line spec");
356 error ("wrong # args");
359 Tcl_DStringAppendElement (result_ptr, sal.symtab->filename);
361 Tcl_DStringAppendElement (result_ptr, "");
363 find_pc_partial_function (pc, &funcname, NULL, NULL);
364 Tcl_DStringAppendElement (result_ptr, funcname);
366 filename = symtab_to_filename (sal.symtab);
367 Tcl_DStringAppendElement (result_ptr, filename);
369 dsprintf_append_element (result_ptr, "%d", sal.line); /* line number */
371 dsprintf_append_element (result_ptr, "0x%lx", pc); /* PC */
376 /* This implements the TCL command `gdb_eval'. */
379 gdb_eval (clientData, interp, argc, argv)
380 ClientData clientData;
385 struct expression *expr;
386 struct cleanup *old_chain;
390 error ("wrong # args");
392 expr = parse_expression (argv[1]);
394 old_chain = make_cleanup (free_current_contents, &expr);
396 val = evaluate_expression (expr);
398 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
399 gdb_stdout, 0, 0, 0, 0);
401 do_cleanups (old_chain);
406 /* This implements the TCL command `gdb_sourcelines', which returns a list of
407 all of the lines containing executable code for the specified source file
408 (ie: lines where you can put breakpoints). */
411 gdb_sourcelines (clientData, interp, argc, argv)
412 ClientData clientData;
417 struct symtab *symtab;
418 struct linetable_entry *le;
422 error ("wrong # args");
424 symtab = lookup_symtab (argv[1]);
427 error ("No such file");
429 /* If there's no linetable, or no entries, then we are done. */
431 if (!symtab->linetable
432 || symtab->linetable->nitems == 0)
434 Tcl_DStringAppendElement (result_ptr, "");
438 le = symtab->linetable->item;
439 nlines = symtab->linetable->nitems;
441 for (;nlines > 0; nlines--, le++)
443 /* If the pc of this line is the same as the pc of the next line, then
446 && le->pc == (le + 1)->pc)
449 dsprintf_append_element (result_ptr, "%d", le->line);
456 map_arg_registers (argc, argv, func, argp)
459 void (*func) PARAMS ((int regnum, void *argp));
464 /* Note that the test for a valid register must include checking the
465 reg_names array because NUM_REGS may be allocated for the union of the
466 register sets within a family of related processors. In this case, the
467 trailing entries of reg_names will change depending upon the particular
468 processor being debugged. */
470 if (argc == 0) /* No args, just do all the regs */
474 && reg_names[regnum] != NULL
475 && *reg_names[regnum] != '\000';
482 /* Else, list of register #s, just do listed regs */
483 for (; argc > 0; argc--, argv++)
485 regnum = atoi (*argv);
489 && reg_names[regnum] != NULL
490 && *reg_names[regnum] != '\000')
493 error ("bad register number");
500 get_register_name (regnum, argp)
502 void *argp; /* Ignored */
504 Tcl_DStringAppendElement (result_ptr, reg_names[regnum]);
507 /* This implements the TCL command `gdb_regnames', which returns a list of
508 all of the register names. */
511 gdb_regnames (clientData, interp, argc, argv)
512 ClientData clientData;
520 return map_arg_registers (argc, argv, get_register_name, 0);
523 #ifndef REGISTER_CONVERTIBLE
524 #define REGISTER_CONVERTIBLE(x) (0 != 0)
527 #ifndef REGISTER_CONVERT_TO_VIRTUAL
528 #define REGISTER_CONVERT_TO_VIRTUAL(x, y, z, a)
531 #ifndef INVALID_FLOAT
532 #define INVALID_FLOAT(x, y) (0 != 0)
536 get_register (regnum, fp)
540 char raw_buffer[MAX_REGISTER_RAW_SIZE];
541 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
542 int format = (int)fp;
544 if (read_relative_register_raw_bytes (regnum, raw_buffer))
546 Tcl_DStringAppendElement (result_ptr, "Optimized out");
550 /* Convert raw data to virtual format if necessary. */
552 if (REGISTER_CONVERTIBLE (regnum))
554 REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum),
555 raw_buffer, virtual_buffer);
558 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
560 val_print (REGISTER_VIRTUAL_TYPE (regnum), virtual_buffer, 0,
561 gdb_stdout, format, 1, 0, Val_pretty_default);
563 Tcl_DStringAppend (result_ptr, " ", -1);
567 gdb_fetch_registers (clientData, interp, argc, argv)
568 ClientData clientData;
576 error ("wrong # args");
584 return map_arg_registers (argc, argv, get_register, format);
587 /* This contains the previous values of the registers, since the last call to
588 gdb_changed_register_list. */
590 static char old_regs[REGISTER_BYTES];
593 register_changed_p (regnum, argp)
595 void *argp; /* Ignored */
597 char raw_buffer[MAX_REGISTER_RAW_SIZE];
600 if (read_relative_register_raw_bytes (regnum, raw_buffer))
603 if (memcmp (&old_regs[REGISTER_BYTE (regnum)], raw_buffer,
604 REGISTER_RAW_SIZE (regnum)) == 0)
607 /* Found a changed register. Save new value and return it's number. */
609 memcpy (&old_regs[REGISTER_BYTE (regnum)], raw_buffer,
610 REGISTER_RAW_SIZE (regnum));
612 dsprintf_append_element (result_ptr, "%d", regnum);
616 gdb_changed_register_list (clientData, interp, argc, argv)
617 ClientData clientData;
625 return map_arg_registers (argc, argv, register_changed_p, NULL);
628 /* This implements the TCL command `gdb_cmd', which sends it's argument into
629 the GDB command scanner. */
632 gdb_cmd (clientData, interp, argc, argv)
633 ClientData clientData;
639 error ("wrong # args");
641 execute_command (argv[1], 1);
643 bpstat_do_actions (&stop_bpstat);
648 /* This routine acts as a top-level for all GDB code called by tcl/Tk. It
649 handles cleanups, and calls to return_to_top_level (usually via error).
650 This is necessary in order to prevent a longjmp out of the bowels of Tk,
651 possibly leaving things in a bad state. Since this routine can be called
652 recursively, it needs to save and restore the contents of the jmp_buf as
656 call_wrapper (clientData, interp, argc, argv)
657 ClientData clientData;
663 struct cleanup *saved_cleanup_chain;
665 jmp_buf saved_error_return;
666 Tcl_DString result, *old_result_ptr;
668 Tcl_DStringInit (&result);
669 old_result_ptr = result_ptr;
670 result_ptr = &result;
672 func = (Tcl_CmdProc *)clientData;
673 memcpy (saved_error_return, error_return, sizeof (jmp_buf));
675 saved_cleanup_chain = save_cleanups ();
677 if (!setjmp (error_return))
678 val = func (clientData, interp, argc, argv);
681 val = TCL_ERROR; /* Flag an error for TCL */
683 gdb_flush (gdb_stderr); /* Flush error output */
685 gdb_flush (gdb_stdout); /* Sometimes error output comes here as well */
687 /* In case of an error, we may need to force the GUI into idle mode because
688 gdbtk_call_command may have bombed out while in the command routine. */
690 Tcl_Eval (interp, "gdbtk_tcl_idle");
693 do_cleanups (ALL_CLEANUPS);
695 restore_cleanups (saved_cleanup_chain);
697 memcpy (error_return, saved_error_return, sizeof (jmp_buf));
699 Tcl_DStringResult (interp, &result);
700 result_ptr = old_result_ptr;
706 gdb_listfiles (clientData, interp, argc, argv)
707 ClientData clientData;
712 struct objfile *objfile;
713 struct partial_symtab *psymtab;
714 struct symtab *symtab;
716 ALL_PSYMTABS (objfile, psymtab)
717 Tcl_DStringAppendElement (result_ptr, psymtab->filename);
719 ALL_SYMTABS (objfile, symtab)
720 Tcl_DStringAppendElement (result_ptr, symtab->filename);
726 gdb_stop (clientData, interp, argc, argv)
727 ClientData clientData;
737 /* This implements the TCL command `gdb_disassemble'. */
740 gdbtk_dis_asm_read_memory (memaddr, myaddr, len, info)
744 disassemble_info *info;
746 extern struct target_ops exec_ops;
750 res = xfer_memory (memaddr, myaddr, len, 0, &exec_ops);
761 /* We need a different sort of line table from the normal one cuz we can't
762 depend upon implicit line-end pc's for lines. This is because of the
763 reordering we are about to do. */
765 struct my_line_entry {
772 compare_lines (mle1p, mle2p)
776 struct my_line_entry *mle1, *mle2;
779 mle1 = (struct my_line_entry *) mle1p;
780 mle2 = (struct my_line_entry *) mle2p;
782 val = mle1->line - mle2->line;
787 return mle1->start_pc - mle2->start_pc;
791 gdb_disassemble (clientData, interp, argc, argv)
792 ClientData clientData;
797 CORE_ADDR pc, low, high;
798 int mixed_source_and_assembly;
799 static disassemble_info di;
800 static int di_initialized;
802 if (! di_initialized)
804 INIT_DISASSEMBLE_INFO (di, gdb_stdout,
805 (fprintf_ftype) fprintf_unfiltered);
806 di.memory_error_func = dis_asm_memory_error;
807 di.print_address_func = dis_asm_print_address;
811 if (argc != 3 && argc != 4)
812 error ("wrong # args");
814 if (strcmp (argv[1], "source") == 0)
815 mixed_source_and_assembly = 1;
816 else if (strcmp (argv[1], "nosource") == 0)
817 mixed_source_and_assembly = 0;
819 error ("First arg must be 'source' or 'nosource'");
821 low = parse_and_eval_address (argv[2]);
825 if (find_pc_partial_function (low, NULL, &low, &high) == 0)
826 error ("No function contains specified address");
829 high = parse_and_eval_address (argv[3]);
831 /* If disassemble_from_exec == -1, then we use the following heuristic to
832 determine whether or not to do disassembly from target memory or from the
835 If we're debugging a local process, read target memory, instead of the
836 exec file. This makes disassembly of functions in shared libs work
839 Else, we're debugging a remote process, and should disassemble from the
840 exec file for speed. However, this is no good if the target modifies it's
841 code (for relocation, or whatever).
844 if (disassemble_from_exec == -1)
845 if (strcmp (target_shortname, "child") == 0
846 || strcmp (target_shortname, "procfs") == 0
847 || strcmp (target_shortname, "vxprocess") == 0)
848 disassemble_from_exec = 0; /* It's a child process, read inferior mem */
850 disassemble_from_exec = 1; /* It's remote, read the exec file */
852 if (disassemble_from_exec)
853 di.read_memory_func = gdbtk_dis_asm_read_memory;
855 di.read_memory_func = dis_asm_read_memory;
857 /* If just doing straight assembly, all we need to do is disassemble
858 everything between low and high. If doing mixed source/assembly, we've
859 got a totally different path to follow. */
861 if (mixed_source_and_assembly)
862 { /* Come here for mixed source/assembly */
863 /* The idea here is to present a source-O-centric view of a function to
864 the user. This means that things are presented in source order, with
865 (possibly) out of order assembly immediately following. */
866 struct symtab *symtab;
867 struct linetable_entry *le;
870 struct my_line_entry *mle;
871 struct symtab_and_line sal;
876 symtab = find_pc_symtab (low); /* Assume symtab is valid for whole PC range */
881 /* First, convert the linetable to a bunch of my_line_entry's. */
883 le = symtab->linetable->item;
884 nlines = symtab->linetable->nitems;
889 mle = (struct my_line_entry *) alloca (nlines * sizeof (struct my_line_entry));
893 /* Copy linetable entries for this function into our data structure, creating
894 end_pc's and setting out_of_order as appropriate. */
896 /* First, skip all the preceding functions. */
898 for (i = 0; i < nlines - 1 && le[i].pc < low; i++) ;
900 /* Now, copy all entries before the end of this function. */
903 for (; i < nlines - 1 && le[i].pc < high; i++)
905 if (le[i].line == le[i + 1].line
906 && le[i].pc == le[i + 1].pc)
907 continue; /* Ignore duplicates */
909 mle[newlines].line = le[i].line;
910 if (le[i].line > le[i + 1].line)
912 mle[newlines].start_pc = le[i].pc;
913 mle[newlines].end_pc = le[i + 1].pc;
917 /* If we're on the last line, and it's part of the function, then we need to
918 get the end pc in a special way. */
923 mle[newlines].line = le[i].line;
924 mle[newlines].start_pc = le[i].pc;
925 sal = find_pc_line (le[i].pc, 0);
926 mle[newlines].end_pc = sal.end;
930 /* Now, sort mle by line #s (and, then by addresses within lines). */
933 qsort (mle, newlines, sizeof (struct my_line_entry), compare_lines);
935 /* Now, for each line entry, emit the specified lines (unless they have been
936 emitted before), followed by the assembly code for that line. */
938 next_line = 0; /* Force out first line */
939 for (i = 0; i < newlines; i++)
941 /* Print out everything from next_line to the current line. */
943 if (mle[i].line >= next_line)
946 print_source_lines (symtab, next_line, mle[i].line + 1, 0);
948 print_source_lines (symtab, mle[i].line, mle[i].line + 1, 0);
950 next_line = mle[i].line + 1;
953 for (pc = mle[i].start_pc; pc < mle[i].end_pc; )
956 fputs_unfiltered (" ", gdb_stdout);
957 print_address (pc, gdb_stdout);
958 fputs_unfiltered (":\t ", gdb_stdout);
959 pc += (*tm_print_insn) (pc, &di);
960 fputs_unfiltered ("\n", gdb_stdout);
967 for (pc = low; pc < high; )
970 fputs_unfiltered (" ", gdb_stdout);
971 print_address (pc, gdb_stdout);
972 fputs_unfiltered (":\t ", gdb_stdout);
973 pc += (*tm_print_insn) (pc, &di);
974 fputs_unfiltered ("\n", gdb_stdout);
978 gdb_flush (gdb_stdout);
984 tk_command (cmd, from_tty)
990 struct cleanup *old_chain;
992 retval = Tcl_Eval (interp, cmd);
994 result = strdup (interp->result);
996 old_chain = make_cleanup (free, result);
998 if (retval != TCL_OK)
1001 printf_unfiltered ("%s\n", result);
1003 do_cleanups (old_chain);
1007 cleanup_init (ignored)
1010 if (mainWindow != NULL)
1011 Tk_DestroyWindow (mainWindow);
1015 Tcl_DeleteInterp (interp);
1019 /* Come here during long calculations to check for GUI events. Usually invoked
1020 via the QUIT macro. */
1023 gdbtk_interactive ()
1025 /* Tk_DoOneEvent (TK_DONT_WAIT|TK_IDLE_EVENTS); */
1028 /* Come here when there is activity on the X file descriptor. */
1034 /* Process pending events */
1036 while (Tk_DoOneEvent (TK_DONT_WAIT|TK_ALL_EVENTS) != 0);
1040 gdbtk_wait (pid, ourstatus)
1042 struct target_waitstatus *ourstatus;
1044 struct sigaction action;
1045 static sigset_t nullsigmask = {0};
1048 /* Needed for SunOS 4.1.x */
1049 #define SA_RESTART 0
1052 action.sa_handler = x_event;
1053 action.sa_mask = nullsigmask;
1054 action.sa_flags = SA_RESTART;
1055 sigaction(SIGIO, &action, NULL);
1057 pid = target_wait (pid, ourstatus);
1059 action.sa_handler = SIG_IGN;
1060 sigaction(SIGIO, &action, NULL);
1065 /* This is called from execute_command, and provides a wrapper around
1066 various command routines in a place where both protocol messages and
1067 user input both flow through. Mostly this is used for indicating whether
1068 the target process is running or not.
1072 gdbtk_call_command (cmdblk, arg, from_tty)
1073 struct cmd_list_element *cmdblk;
1077 if (cmdblk->class == class_run)
1079 Tcl_Eval (interp, "gdbtk_tcl_busy");
1080 (*cmdblk->function.cfunc)(arg, from_tty);
1081 Tcl_Eval (interp, "gdbtk_tcl_idle");
1084 (*cmdblk->function.cfunc)(arg, from_tty);
1090 struct cleanup *old_chain;
1091 char *gdbtk_filename;
1093 struct sigaction action;
1094 static sigset_t nullsigmask = {0};
1096 old_chain = make_cleanup (cleanup_init, 0);
1098 /* First init tcl and tk. */
1100 interp = Tcl_CreateInterp ();
1103 error ("Tcl_CreateInterp failed");
1105 mainWindow = Tk_CreateMainWindow (interp, NULL, "gdb", "Gdb");
1108 return; /* DISPLAY probably not set */
1110 if (Tcl_Init(interp) != TCL_OK)
1111 error ("Tcl_Init failed: %s", interp->result);
1113 if (Tk_Init(interp) != TCL_OK)
1114 error ("Tk_Init failed: %s", interp->result);
1116 Tcl_CreateCommand (interp, "gdb_cmd", call_wrapper, gdb_cmd, NULL);
1117 Tcl_CreateCommand (interp, "gdb_loc", call_wrapper, gdb_loc, NULL);
1118 Tcl_CreateCommand (interp, "gdb_sourcelines", call_wrapper, gdb_sourcelines,
1120 Tcl_CreateCommand (interp, "gdb_listfiles", call_wrapper, gdb_listfiles,
1122 Tcl_CreateCommand (interp, "gdb_stop", call_wrapper, gdb_stop, NULL);
1123 Tcl_CreateCommand (interp, "gdb_regnames", call_wrapper, gdb_regnames, NULL);
1124 Tcl_CreateCommand (interp, "gdb_fetch_registers", call_wrapper,
1125 gdb_fetch_registers, NULL);
1126 Tcl_CreateCommand (interp, "gdb_changed_register_list", call_wrapper,
1127 gdb_changed_register_list, NULL);
1128 Tcl_CreateCommand (interp, "gdb_disassemble", call_wrapper,
1129 gdb_disassemble, NULL);
1130 Tcl_CreateCommand (interp, "gdb_eval", call_wrapper, gdb_eval, NULL);
1131 Tcl_CreateCommand (interp, "gdb_get_breakpoint_list", call_wrapper,
1132 gdb_get_breakpoint_list, NULL);
1133 Tcl_CreateCommand (interp, "gdb_get_breakpoint_info", call_wrapper,
1134 gdb_get_breakpoint_info, NULL);
1136 command_loop_hook = Tk_MainLoop;
1137 print_frame_info_listing_hook = null_routine;
1138 query_hook = gdbtk_query;
1139 flush_hook = gdbtk_flush;
1140 create_breakpoint_hook = gdbtk_create_breakpoint;
1141 delete_breakpoint_hook = gdbtk_delete_breakpoint;
1142 modify_breakpoint_hook = gdbtk_modify_breakpoint;
1143 interactive_hook = gdbtk_interactive;
1144 target_wait_hook = gdbtk_wait;
1145 call_command_hook = gdbtk_call_command;
1147 /* Get the file descriptor for the X server */
1149 x_fd = ConnectionNumber (Tk_Display (mainWindow));
1151 /* Setup for I/O interrupts */
1153 action.sa_mask = nullsigmask;
1154 action.sa_flags = 0;
1155 action.sa_handler = SIG_IGN;
1156 sigaction(SIGIO, &action, NULL);
1160 if (ioctl (x_fd, FIOASYNC, &i))
1161 perror_with_name ("gdbtk_init: ioctl FIOASYNC failed");
1165 if (ioctl (x_fd, SIOCSPGRP, &i))
1166 perror_with_name ("gdbtk_init: ioctl SIOCSPGRP failed");
1171 if (fcntl (x_fd, F_SETOWN, i))
1172 perror_with_name ("gdbtk_init: fcntl F_SETOWN failed");
1173 #endif /* F_SETOWN */
1174 #endif /* !SIOCSPGRP */
1176 if (ioctl (x_fd, I_SETSIG, S_INPUT|S_RDNORM) < 0)
1177 perror_with_name ("gdbtk_init: ioctl I_SETSIG failed");
1178 #endif /* ifndef FIOASYNC */
1180 add_com ("tk", class_obscure, tk_command,
1181 "Send a command directly into tk.");
1183 Tcl_LinkVar (interp, "disassemble-from-exec", (char *)&disassemble_from_exec,
1186 /* Load up gdbtk.tcl after all the environment stuff has been setup. */
1188 gdbtk_filename = getenv ("GDBTK_FILENAME");
1189 if (!gdbtk_filename)
1190 if (access ("gdbtk.tcl", R_OK) == 0)
1191 gdbtk_filename = "gdbtk.tcl";
1193 gdbtk_filename = GDBTK_FILENAME;
1195 /* Defer setup of fputs_unfiltered_hook to near the end so that error messages
1196 prior to this point go to stdout/stderr. */
1198 fputs_unfiltered_hook = gdbtk_fputs;
1200 if (Tcl_EvalFile (interp, gdbtk_filename) != TCL_OK)
1202 fputs_unfiltered_hook = NULL; /* Force errors to stdout/stderr */
1204 fprintf_unfiltered (stderr, "%s:%d: %s\n", gdbtk_filename,
1205 interp->errorLine, interp->result);
1207 fputs_unfiltered ("Stack trace:\n", gdb_stderr);
1208 fputs_unfiltered (Tcl_GetVar (interp, "errorInfo", 0), gdb_stderr);
1212 discard_cleanups (old_chain);
1215 /* Come here during initialze_all_files () */
1218 _initialize_gdbtk ()
1222 /* Tell the rest of the world that Gdbtk is now set up. */
1224 init_ui_hook = gdbtk_init;