1 /* Tcl/Tk interface routines.
2 Copyright 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.
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. */
31 #include "tracepoint.h"
44 /* start-sanitize-ide */
48 /* end-sanitize-ide */
51 #ifdef ANSI_PROTOTYPES
61 #include <sys/ioctl.h>
62 #include "gdb_string.h"
69 #include <sys/stropts.h>
78 #define GDBTK_PATH_SEP ";"
80 #define GDBTK_PATH_SEP ":"
83 /* Some versions (1.3.79, 1.3.81) of Linux don't support SIOCSPGRP the way
84 gdbtk wants to use it... */
89 extern char *source_path
; /* from source.c */
90 int gdbtk_load_hash
PARAMS ((char *, unsigned long));
91 int (*ui_load_progress_hook
) PARAMS ((char *, unsigned long));
93 static void null_routine
PARAMS ((int));
94 static void gdbtk_flush
PARAMS ((FILE *));
95 static void gdbtk_fputs
PARAMS ((const char *, FILE *));
96 static int gdbtk_query
PARAMS ((const char *, va_list));
97 static char *gdbtk_readline
PARAMS ((char *));
98 static void gdbtk_init
PARAMS ((char *));
99 static void tk_command_loop
PARAMS ((void));
100 static void gdbtk_call_command
PARAMS ((struct cmd_list_element
*, char *, int));
101 static int gdbtk_wait
PARAMS ((int, struct target_waitstatus
*));
102 static void x_event
PARAMS ((int));
103 static void gdbtk_interactive
PARAMS ((void));
104 static void cleanup_init
PARAMS ((int));
105 static void tk_command
PARAMS ((char *, int));
106 static int gdb_disassemble
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
107 static int compare_lines
PARAMS ((const PTR
, const PTR
));
108 static int gdbtk_dis_asm_read_memory
PARAMS ((bfd_vma
, bfd_byte
*, int, disassemble_info
*));
109 static int gdb_path_conv
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
110 static int gdb_stop
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
111 static int gdb_confirm_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
112 static int gdb_force_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
113 static int gdb_listfiles
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
114 static int gdb_listfuncs
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
115 static int call_wrapper
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
116 static int gdb_cmd
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
117 static int gdb_fetch_registers
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
118 static void gdbtk_readline_end
PARAMS ((void));
119 static int gdb_changed_register_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
120 static void register_changed_p
PARAMS ((int, void *));
121 static int gdb_get_breakpoint_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
122 static int gdb_get_breakpoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
123 static void breakpoint_notify
PARAMS ((struct breakpoint
*, const char *));
124 static void gdbtk_create_breakpoint
PARAMS ((struct breakpoint
*));
125 static void gdbtk_delete_breakpoint
PARAMS ((struct breakpoint
*));
126 static void gdbtk_modify_breakpoint
PARAMS ((struct breakpoint
*));
127 static int gdb_loc
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
128 static int gdb_eval
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
129 static int gdb_sourcelines
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
130 static int map_arg_registers
PARAMS ((int, char *[], void (*) (int, void *), void *));
131 static void get_register_name
PARAMS ((int, void *));
132 static int gdb_regnames
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
133 static void get_register
PARAMS ((int, void *));
134 static int gdb_target_has_execution_command
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
135 static int gdb_load_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
136 static int gdb_get_vars_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
137 static int gdb_get_function_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
138 static int gdb_get_line_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
139 static int gdb_get_file_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
140 static int gdb_tracepoint_exists_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
141 static int gdb_get_tracepoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
142 static int gdb_actions_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
143 static int gdb_prompt_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
144 static int gdb_find_file_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
145 static void gdbtk_create_tracepoint
PARAMS ((struct tracepoint
*));
146 static void gdbtk_delete_tracepoint
PARAMS ((struct tracepoint
*));
147 static void tracepoint_notify
PARAMS ((struct tracepoint
*, const char *));
149 /* Handle for TCL interpreter */
151 static Tcl_Interp
*interp
= NULL
;
154 static int x_fd
; /* X network socket */
157 /* This variable is true when the inferior is running. Although it's
158 possible to disable most input from widgets and thus prevent
159 attempts to do anything while the inferior is running, any commands
160 that get through - even a simple memory read - are Very Bad, and
161 may cause GDB to crash or behave strangely. So, this variable
162 provides an extra layer of defense. */
164 static int running_now
;
166 /* This variable determines where memory used for disassembly is read from.
167 If > 0, then disassembly comes from the exec file rather than the
168 target (which might be at the other end of a slow serial link). If
169 == 0 then disassembly comes from target. If < 0 disassembly is
170 automatically switched to the target if it's an inferior process,
171 otherwise the exec file is used. */
173 static int disassemble_from_exec
= -1;
177 /* Supply malloc calls for tcl/tk. We do not want to do this on
178 Windows, because Tcl_Alloc is probably in a DLL which will not call
179 the mmalloc routines. */
185 return xmalloc (size
);
189 Tcl_Realloc (ptr
, size
)
193 return xrealloc (ptr
, size
);
203 #endif /* ! _WIN32 */
213 /* On Windows, if we hold a file open, other programs can't write to
214 it. In particular, we don't want to hold the executable open,
215 because it will mean that people have to get out of the debugging
216 session in order to remake their program. So we close it, although
217 this will cost us if and when we need to reopen it. */
227 bfd_cache_close (o
->obfd
);
230 if (exec_bfd
!= NULL
)
231 bfd_cache_close (exec_bfd
);
236 /* The following routines deal with stdout/stderr data, which is created by
237 {f}printf_{un}filtered and friends. gdbtk_fputs and gdbtk_flush are the
238 lowest level of these routines and capture all output from the rest of GDB.
239 Normally they present their data to tcl via callbacks to the following tcl
240 routines: gdbtk_tcl_fputs, gdbtk_tcl_fputs_error, and gdbtk_flush. These
241 in turn call tk routines to update the display.
243 Under some circumstances, you may want to collect the output so that it can
244 be returned as the value of a tcl procedure. This can be done by
245 surrounding the output routines with calls to start_saving_output and
246 finish_saving_output. The saved data can then be retrieved with
247 get_saved_output (but this must be done before the call to
248 finish_saving_output). */
250 /* Dynamic string for output. */
252 static Tcl_DString
*result_ptr
;
254 /* Dynamic string for stderr. This is only used if result_ptr is
257 static Tcl_DString
*error_string_ptr
;
264 /* Force immediate screen update */
266 Tcl_VarEval (interp
, "gdbtk_tcl_flush", NULL
);
271 gdbtk_fputs (ptr
, stream
)
276 Tcl_DStringAppend (result_ptr
, (char *) ptr
, -1);
277 else if (error_string_ptr
!= NULL
&& stream
== gdb_stderr
)
278 Tcl_DStringAppend (error_string_ptr
, (char *) ptr
, -1);
283 Tcl_DStringInit (&str
);
285 Tcl_DStringAppend (&str
, "gdbtk_tcl_fputs", -1);
286 Tcl_DStringAppendElement (&str
, (char *)ptr
);
288 Tcl_Eval (interp
, Tcl_DStringValue (&str
));
289 Tcl_DStringFree (&str
);
294 gdbtk_query (query
, args
)
298 char buf
[200], *merge
[2];
302 vsprintf (buf
, query
, args
);
303 merge
[0] = "gdbtk_tcl_query";
305 command
= Tcl_Merge (2, merge
);
306 Tcl_Eval (interp
, command
);
309 val
= atol (interp
->result
);
315 #ifdef ANSI_PROTOTYPES
316 gdbtk_readline_begin (char *format
, ...)
318 gdbtk_readline_begin (va_alist
)
323 char buf
[200], *merge
[2];
326 #ifdef ANSI_PROTOTYPES
327 va_start (args
, format
);
331 format
= va_arg (args
, char *);
334 vsprintf (buf
, format
, args
);
335 merge
[0] = "gdbtk_tcl_readline_begin";
337 command
= Tcl_Merge (2, merge
);
338 Tcl_Eval (interp
, command
);
343 gdbtk_readline (prompt
)
354 merge
[0] = "gdbtk_tcl_readline";
356 command
= Tcl_Merge (2, merge
);
357 result
= Tcl_Eval (interp
, command
);
359 if (result
== TCL_OK
)
361 return (strdup (interp
-> result
));
365 gdbtk_fputs (interp
-> result
, gdb_stdout
);
366 gdbtk_fputs ("\n", gdb_stdout
);
372 gdbtk_readline_end ()
374 Tcl_Eval (interp
, "gdbtk_tcl_readline_end");
379 #ifdef ANSI_PROTOTYPES
380 dsprintf_append_element (Tcl_DString
*dsp
, char *format
, ...)
382 dsprintf_append_element (va_alist
)
389 #ifdef ANSI_PROTOTYPES
390 va_start (args
, format
);
396 dsp
= va_arg (args
, Tcl_DString
*);
397 format
= va_arg (args
, char *);
400 vsprintf (buf
, format
, args
);
402 Tcl_DStringAppendElement (dsp
, buf
);
406 gdb_path_conv (clientData
, interp
, argc
, argv
)
407 ClientData clientData
;
413 char pathname
[256], *ptr
;
415 error ("wrong # args");
416 cygwin32_conv_to_full_win32_path (argv
[1], pathname
);
417 for (ptr
= pathname
; *ptr
; ptr
++)
423 char *pathname
= argv
[1];
425 Tcl_DStringAppend (result_ptr
, pathname
, strlen(pathname
));
430 gdb_get_breakpoint_list (clientData
, interp
, argc
, argv
)
431 ClientData clientData
;
436 struct breakpoint
*b
;
437 extern struct breakpoint
*breakpoint_chain
;
440 error ("wrong # args");
442 for (b
= breakpoint_chain
; b
; b
= b
->next
)
443 if (b
->type
== bp_breakpoint
)
444 dsprintf_append_element (result_ptr
, "%d", b
->number
);
450 gdb_get_breakpoint_info (clientData
, interp
, argc
, argv
)
451 ClientData clientData
;
456 struct symtab_and_line sal
;
457 static char *bptypes
[] = {"breakpoint", "hardware breakpoint", "until",
458 "finish", "watchpoint", "hardware watchpoint",
459 "read watchpoint", "access watchpoint",
460 "longjmp", "longjmp resume", "step resume",
461 "through sigtramp", "watchpoint scope",
463 static char *bpdisp
[] = {"delete", "delstop", "disable", "donttouch"};
464 struct command_line
*cmd
;
466 struct breakpoint
*b
;
467 extern struct breakpoint
*breakpoint_chain
;
468 char *funcname
, *filename
;
471 error ("wrong # args");
473 bpnum
= atoi (argv
[1]);
475 for (b
= breakpoint_chain
; b
; b
= b
->next
)
476 if (b
->number
== bpnum
)
479 if (!b
|| b
->type
!= bp_breakpoint
)
480 error ("Breakpoint #%d does not exist", bpnum
);
482 sal
= find_pc_line (b
->address
, 0);
484 filename
= symtab_to_filename (sal
.symtab
);
485 if (filename
== NULL
)
487 Tcl_DStringAppendElement (result_ptr
, filename
);
488 find_pc_partial_function (b
->address
, &funcname
, NULL
, NULL
);
489 Tcl_DStringAppendElement (result_ptr
, funcname
);
490 dsprintf_append_element (result_ptr
, "%d", sal
.line
);
491 dsprintf_append_element (result_ptr
, "0x%lx", b
->address
);
492 Tcl_DStringAppendElement (result_ptr
, bptypes
[b
->type
]);
493 Tcl_DStringAppendElement (result_ptr
, b
->enable
== enabled
? "1" : "0");
494 Tcl_DStringAppendElement (result_ptr
, bpdisp
[b
->disposition
]);
495 dsprintf_append_element (result_ptr
, "%d", b
->ignore_count
);
497 Tcl_DStringStartSublist (result_ptr
);
498 for (cmd
= b
->commands
; cmd
; cmd
= cmd
->next
)
499 Tcl_DStringAppendElement (result_ptr
, cmd
->line
);
500 Tcl_DStringEndSublist (result_ptr
);
502 Tcl_DStringAppendElement (result_ptr
, b
->cond_string
);
504 dsprintf_append_element (result_ptr
, "%d", b
->thread
);
505 dsprintf_append_element (result_ptr
, "%d", b
->hit_count
);
511 breakpoint_notify(b
, action
)
512 struct breakpoint
*b
;
517 struct symtab_and_line sal
;
520 if (b
->type
!= bp_breakpoint
)
523 /* We ensure that ACTION contains no special Tcl characters, so we
525 sal
= find_pc_line (b
->address
, 0);
526 filename
= symtab_to_filename (sal
.symtab
);
527 if (filename
== NULL
)
529 sprintf (buf
, "gdbtk_tcl_breakpoint %s %d 0x%lx %d {%s}", action
, b
->number
,
530 (long)b
->address
, sal
.line
, filename
);
532 v
= Tcl_Eval (interp
, buf
);
536 gdbtk_fputs (interp
->result
, gdb_stdout
);
537 gdbtk_fputs ("\n", gdb_stdout
);
542 gdbtk_create_breakpoint(b
)
543 struct breakpoint
*b
;
545 breakpoint_notify (b
, "create");
549 gdbtk_delete_breakpoint(b
)
550 struct breakpoint
*b
;
552 breakpoint_notify (b
, "delete");
556 gdbtk_modify_breakpoint(b
)
557 struct breakpoint
*b
;
559 breakpoint_notify (b
, "modify");
562 /* This implements the TCL command `gdb_loc', which returns a list consisting
563 of the source and line number associated with the current pc. */
566 gdb_loc (clientData
, interp
, argc
, argv
)
567 ClientData clientData
;
573 struct symtab_and_line sal
;
577 if (!have_full_symbols () && !have_partial_symbols ())
579 Tcl_SetResult (interp
, "No symbol table is loaded", TCL_STATIC
);
585 pc
= selected_frame
? selected_frame
->pc
: stop_pc
;
586 sal
= find_pc_line (pc
, 0);
590 struct symtabs_and_lines sals
;
593 sals
= decode_line_spec (argv
[1], 1);
600 error ("Ambiguous line spec");
605 error ("wrong # args");
608 Tcl_DStringAppendElement (result_ptr
, sal
.symtab
->filename
);
610 Tcl_DStringAppendElement (result_ptr
, "");
612 find_pc_partial_function (pc
, &funcname
, NULL
, NULL
);
613 Tcl_DStringAppendElement (result_ptr
, funcname
);
615 filename
= symtab_to_filename (sal
.symtab
);
616 if (filename
== NULL
)
618 Tcl_DStringAppendElement (result_ptr
, filename
);
620 dsprintf_append_element (result_ptr
, "%d", sal
.line
); /* line number */
622 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(pc
)); /* PC in current frame */
624 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(stop_pc
)); /* Real PC */
629 /* This implements the TCL command `gdb_eval'. */
632 gdb_eval (clientData
, interp
, argc
, argv
)
633 ClientData clientData
;
638 struct expression
*expr
;
639 struct cleanup
*old_chain
;
643 error ("wrong # args");
645 expr
= parse_expression (argv
[1]);
647 old_chain
= make_cleanup (free_current_contents
, &expr
);
649 val
= evaluate_expression (expr
);
651 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
652 gdb_stdout
, 0, 0, 0, 0);
654 do_cleanups (old_chain
);
659 /* gdb_get_mem addr form size num aschar*/
660 /* dump a block of memory */
661 /* addr: address of data to dump */
662 /* form: a char indicating format */
663 /* size: size of each element; 1,2,4, or 8 bytes*/
664 /* num: the number of 'size' elements to return */
665 /* acshar: an optional ascii character to use in ASCII dump */
666 /* returns a list of 'num' elements followed by an optional */
669 gdb_get_mem (clientData
, interp
, argc
, argv
)
670 ClientData clientData
;
675 int size
, asize
, num
, i
, j
;
676 CORE_ADDR addr
, saved_addr
, ptr
;
678 struct type
*val_type
;
680 char c
, buff
[128], aschar
;
683 error ("wrong # args");
685 addr
= (CORE_ADDR
)strtoul(argv
[1],(char **)NULL
,0);
688 size
= (int)strtoul(argv
[3],(char **)NULL
,0);
689 num
= (int)strtoul(argv
[4],(char **)NULL
,0);
694 val_type
= builtin_type_char
;
698 val_type
= builtin_type_short
;
702 val_type
= builtin_type_int
;
706 val_type
= builtin_type_long_long
;
710 val_type
= builtin_type_char
;
714 for (i
=0; i
< num
; i
++)
716 vptr
= value_at (val_type
, addr
, (asection
*)NULL
);
717 print_scalar_formatted (VALUE_CONTENTS(vptr
), val_type
, format
, asize
, gdb_stdout
);
718 fputs_unfiltered (" ", gdb_stdout
);
724 val_type
= builtin_type_char
;
728 for (j
=0; j
< num
*size
; j
++)
730 c
= *(char *)VALUE_CONTENTS(value_at (val_type
, ptr
, (asection
*)NULL
));
731 if (c
< 32 || c
> 126)
740 fputs_unfiltered (buff
, gdb_stdout
);
747 /* This implements the TCL command `gdb_sourcelines', which returns a list of
748 all of the lines containing executable code for the specified source file
749 (ie: lines where you can put breakpoints). */
752 gdb_sourcelines (clientData
, interp
, argc
, argv
)
753 ClientData clientData
;
758 struct symtab
*symtab
;
759 struct linetable_entry
*le
;
763 error ("wrong # args");
765 symtab
= lookup_symtab (argv
[1]);
768 error ("No such file");
770 /* If there's no linetable, or no entries, then we are done. */
772 if (!symtab
->linetable
773 || symtab
->linetable
->nitems
== 0)
775 Tcl_DStringAppendElement (result_ptr
, "");
779 le
= symtab
->linetable
->item
;
780 nlines
= symtab
->linetable
->nitems
;
782 for (;nlines
> 0; nlines
--, le
++)
784 /* If the pc of this line is the same as the pc of the next line, then
787 && le
->pc
== (le
+ 1)->pc
)
790 dsprintf_append_element (result_ptr
, "%d", le
->line
);
797 map_arg_registers (argc
, argv
, func
, argp
)
800 void (*func
) PARAMS ((int regnum
, void *argp
));
805 /* Note that the test for a valid register must include checking the
806 reg_names array because NUM_REGS may be allocated for the union of the
807 register sets within a family of related processors. In this case, the
808 trailing entries of reg_names will change depending upon the particular
809 processor being debugged. */
811 if (argc
== 0) /* No args, just do all the regs */
815 && reg_names
[regnum
] != NULL
816 && *reg_names
[regnum
] != '\000';
823 /* Else, list of register #s, just do listed regs */
824 for (; argc
> 0; argc
--, argv
++)
826 regnum
= atoi (*argv
);
830 && reg_names
[regnum
] != NULL
831 && *reg_names
[regnum
] != '\000')
834 error ("bad register number");
841 get_register_name (regnum
, argp
)
843 void *argp
; /* Ignored */
845 Tcl_DStringAppendElement (result_ptr
, reg_names
[regnum
]);
848 /* This implements the TCL command `gdb_regnames', which returns a list of
849 all of the register names. */
852 gdb_regnames (clientData
, interp
, argc
, argv
)
853 ClientData clientData
;
861 return map_arg_registers (argc
, argv
, get_register_name
, NULL
);
864 #ifndef REGISTER_CONVERTIBLE
865 #define REGISTER_CONVERTIBLE(x) (0 != 0)
868 #ifndef REGISTER_CONVERT_TO_VIRTUAL
869 #define REGISTER_CONVERT_TO_VIRTUAL(x, y, z, a)
872 #ifndef INVALID_FLOAT
873 #define INVALID_FLOAT(x, y) (0 != 0)
877 get_register (regnum
, fp
)
881 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
882 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
883 int format
= (int)fp
;
885 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
887 Tcl_DStringAppendElement (result_ptr
, "Optimized out");
891 /* Convert raw data to virtual format if necessary. */
893 if (REGISTER_CONVERTIBLE (regnum
))
895 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
896 raw_buffer
, virtual_buffer
);
899 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
904 printf_filtered ("0x");
905 for (j
= 0; j
< REGISTER_RAW_SIZE (regnum
); j
++)
907 register int idx
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? j
908 : REGISTER_RAW_SIZE (regnum
) - 1 - j
;
909 printf_filtered ("%02x", (unsigned char)raw_buffer
[idx
]);
913 val_print (REGISTER_VIRTUAL_TYPE (regnum
), virtual_buffer
, 0,
914 gdb_stdout
, format
, 1, 0, Val_pretty_default
);
916 Tcl_DStringAppend (result_ptr
, " ", -1);
920 gdb_fetch_registers (clientData
, interp
, argc
, argv
)
921 ClientData clientData
;
929 error ("wrong # args");
937 return map_arg_registers (argc
, argv
, get_register
, (void *) format
);
940 /* This contains the previous values of the registers, since the last call to
941 gdb_changed_register_list. */
943 static char old_regs
[REGISTER_BYTES
];
946 register_changed_p (regnum
, argp
)
948 void *argp
; /* Ignored */
950 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
952 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
955 if (memcmp (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
956 REGISTER_RAW_SIZE (regnum
)) == 0)
959 /* Found a changed register. Save new value and return its number. */
961 memcpy (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
962 REGISTER_RAW_SIZE (regnum
));
964 dsprintf_append_element (result_ptr
, "%d", regnum
);
968 gdb_changed_register_list (clientData
, interp
, argc
, argv
)
969 ClientData clientData
;
977 return map_arg_registers (argc
, argv
, register_changed_p
, NULL
);
980 /* This implements the TCL command `gdb_cmd', which sends its argument into
981 the GDB command scanner. */
984 gdb_cmd (clientData
, interp
, argc
, argv
)
985 ClientData clientData
;
990 Tcl_DString
*save_ptr
= NULL
;
993 error ("wrong # args");
998 /* for the load instruction (and possibly others later) we
999 set result_ptr to NULL so gdbtk_fputs() will not buffer
1000 all the data until the command is finished. */
1002 if (strncmp("load ",argv
[1],5) == 0) {
1003 Tcl_DStringAppend (result_ptr
, "", -1);
1004 save_ptr
= result_ptr
;
1008 execute_command (argv
[1], 1);
1010 bpstat_do_actions (&stop_bpstat
);
1013 result_ptr
= save_ptr
;
1018 /* Client of call_wrapper - this routine performs the actual call to
1019 the client function. */
1021 struct wrapped_call_args
1032 struct wrapped_call_args
*args
;
1034 args
->val
= (*args
->func
) (args
->func
, args
->interp
, args
->argc
, args
->argv
);
1038 /* This routine acts as a top-level for all GDB code called by tcl/Tk. It
1039 handles cleanups, and calls to return_to_top_level (usually via error).
1040 This is necessary in order to prevent a longjmp out of the bowels of Tk,
1041 possibly leaving things in a bad state. Since this routine can be called
1042 recursively, it needs to save and restore the contents of the jmp_buf as
1046 call_wrapper (clientData
, interp
, argc
, argv
)
1047 ClientData clientData
;
1052 struct wrapped_call_args wrapped_args
;
1053 Tcl_DString result
, *old_result_ptr
;
1054 Tcl_DString error_string
, *old_error_string_ptr
;
1056 Tcl_DStringInit (&result
);
1057 old_result_ptr
= result_ptr
;
1058 result_ptr
= &result
;
1060 Tcl_DStringInit (&error_string
);
1061 old_error_string_ptr
= error_string_ptr
;
1062 error_string_ptr
= &error_string
;
1064 wrapped_args
.func
= (Tcl_CmdProc
*)clientData
;
1065 wrapped_args
.interp
= interp
;
1066 wrapped_args
.argc
= argc
;
1067 wrapped_args
.argv
= argv
;
1068 wrapped_args
.val
= 0;
1070 if (!catch_errors (wrapped_call
, &wrapped_args
, "", RETURN_MASK_ALL
))
1072 wrapped_args
.val
= TCL_ERROR
; /* Flag an error for TCL */
1074 gdb_flush (gdb_stderr
); /* Flush error output */
1076 gdb_flush (gdb_stdout
); /* Sometimes error output comes here as well */
1078 /* In case of an error, we may need to force the GUI into idle
1079 mode because gdbtk_call_command may have bombed out while in
1080 the command routine. */
1083 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1086 if (Tcl_DStringLength (&error_string
) == 0)
1088 Tcl_DStringResult (interp
, &result
);
1089 Tcl_DStringFree (&error_string
);
1091 else if (Tcl_DStringLength (&result
) == 0)
1093 Tcl_DStringResult (interp
, &error_string
);
1094 Tcl_DStringFree (&result
);
1098 Tcl_ResetResult (interp
);
1099 Tcl_AppendResult (interp
, Tcl_DStringValue (&result
),
1100 Tcl_DStringValue (&error_string
), (char *) NULL
);
1101 Tcl_DStringFree (&result
);
1102 Tcl_DStringFree (&error_string
);
1105 result_ptr
= old_result_ptr
;
1106 error_string_ptr
= old_error_string_ptr
;
1112 return wrapped_args
.val
;
1116 gdb_listfiles (clientData
, interp
, argc
, argv
)
1117 ClientData clientData
;
1122 struct objfile
*objfile
;
1123 struct partial_symtab
*psymtab
;
1124 struct symtab
*symtab
;
1126 ALL_PSYMTABS (objfile
, psymtab
)
1127 Tcl_DStringAppendElement (result_ptr
, psymtab
->filename
);
1129 ALL_SYMTABS (objfile
, symtab
)
1130 Tcl_DStringAppendElement (result_ptr
, symtab
->filename
);
1136 gdb_listfuncs (clientData
, interp
, argc
, argv
)
1137 ClientData clientData
;
1142 struct symtab
*symtab
;
1143 struct blockvector
*bv
;
1149 error ("wrong # args");
1151 symtab
= lookup_symtab (argv
[1]);
1154 error ("No such file");
1156 bv
= BLOCKVECTOR (symtab
);
1157 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
1159 b
= BLOCKVECTOR_BLOCK (bv
, i
);
1160 /* Skip the sort if this block is always sorted. */
1161 if (!BLOCK_SHOULD_SORT (b
))
1162 sort_block_syms (b
);
1163 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
1165 sym
= BLOCK_SYM (b
, j
);
1166 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1168 Tcl_DStringAppendElement (result_ptr
, SYMBOL_NAME(sym
));
1176 gdb_stop (clientData
, interp
, argc
, argv
)
1177 ClientData clientData
;
1185 quit_flag
= 1; /* hope something sees this */
1190 /* Prepare to accept a new executable file. This is called when we
1191 want to clear away everything we know about the old file, without
1192 asking the user. The Tcl code will have already asked the user if
1193 necessary. After this is called, we should be able to run the
1194 `file' command without getting any questions. */
1197 gdb_clear_file (clientData
, interp
, argc
, argv
)
1198 ClientData clientData
;
1203 if (inferior_pid
!= 0 && target_has_execution
)
1206 target_detach (NULL
, 0);
1211 if (target_has_execution
)
1214 symbol_file_command (NULL
, 0);
1219 /* Ask the user to confirm an exit request. */
1222 gdb_confirm_quit (clientData
, interp
, argc
, argv
)
1223 ClientData clientData
;
1230 ret
= quit_confirm ();
1231 Tcl_DStringAppendElement (result_ptr
, ret
? "1" : "0");
1235 /* Quit without asking for confirmation. */
1238 gdb_force_quit (clientData
, interp
, argc
, argv
)
1239 ClientData clientData
;
1244 quit_force ((char *) NULL
, 1);
1248 /* This implements the TCL command `gdb_disassemble'. */
1251 gdbtk_dis_asm_read_memory (memaddr
, myaddr
, len
, info
)
1255 disassemble_info
*info
;
1257 extern struct target_ops exec_ops
;
1261 res
= xfer_memory (memaddr
, myaddr
, len
, 0, &exec_ops
);
1272 /* We need a different sort of line table from the normal one cuz we can't
1273 depend upon implicit line-end pc's for lines. This is because of the
1274 reordering we are about to do. */
1276 struct my_line_entry
{
1283 compare_lines (mle1p
, mle2p
)
1287 struct my_line_entry
*mle1
, *mle2
;
1290 mle1
= (struct my_line_entry
*) mle1p
;
1291 mle2
= (struct my_line_entry
*) mle2p
;
1293 val
= mle1
->line
- mle2
->line
;
1298 return mle1
->start_pc
- mle2
->start_pc
;
1302 gdb_disassemble (clientData
, interp
, argc
, argv
)
1303 ClientData clientData
;
1308 CORE_ADDR pc
, low
, high
;
1309 int mixed_source_and_assembly
;
1310 static disassemble_info di
;
1311 static int di_initialized
;
1313 if (! di_initialized
)
1315 INIT_DISASSEMBLE_INFO_NO_ARCH (di
, gdb_stdout
,
1316 (fprintf_ftype
) fprintf_unfiltered
);
1317 di
.flavour
= bfd_target_unknown_flavour
;
1318 di
.memory_error_func
= dis_asm_memory_error
;
1319 di
.print_address_func
= dis_asm_print_address
;
1323 di
.mach
= tm_print_insn_info
.mach
;
1324 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1325 di
.endian
= BFD_ENDIAN_BIG
;
1327 di
.endian
= BFD_ENDIAN_LITTLE
;
1329 if (argc
!= 3 && argc
!= 4)
1330 error ("wrong # args");
1332 if (strcmp (argv
[1], "source") == 0)
1333 mixed_source_and_assembly
= 1;
1334 else if (strcmp (argv
[1], "nosource") == 0)
1335 mixed_source_and_assembly
= 0;
1337 error ("First arg must be 'source' or 'nosource'");
1339 low
= parse_and_eval_address (argv
[2]);
1343 if (find_pc_partial_function (low
, NULL
, &low
, &high
) == 0)
1344 error ("No function contains specified address");
1347 high
= parse_and_eval_address (argv
[3]);
1349 /* If disassemble_from_exec == -1, then we use the following heuristic to
1350 determine whether or not to do disassembly from target memory or from the
1353 If we're debugging a local process, read target memory, instead of the
1354 exec file. This makes disassembly of functions in shared libs work
1357 Else, we're debugging a remote process, and should disassemble from the
1358 exec file for speed. However, this is no good if the target modifies its
1359 code (for relocation, or whatever).
1362 if (disassemble_from_exec
== -1)
1363 if (strcmp (target_shortname
, "child") == 0
1364 || strcmp (target_shortname
, "procfs") == 0
1365 || strcmp (target_shortname
, "vxprocess") == 0)
1366 disassemble_from_exec
= 0; /* It's a child process, read inferior mem */
1368 disassemble_from_exec
= 1; /* It's remote, read the exec file */
1370 if (disassemble_from_exec
)
1371 di
.read_memory_func
= gdbtk_dis_asm_read_memory
;
1373 di
.read_memory_func
= dis_asm_read_memory
;
1375 /* If just doing straight assembly, all we need to do is disassemble
1376 everything between low and high. If doing mixed source/assembly, we've
1377 got a totally different path to follow. */
1379 if (mixed_source_and_assembly
)
1380 { /* Come here for mixed source/assembly */
1381 /* The idea here is to present a source-O-centric view of a function to
1382 the user. This means that things are presented in source order, with
1383 (possibly) out of order assembly immediately following. */
1384 struct symtab
*symtab
;
1385 struct linetable_entry
*le
;
1388 struct my_line_entry
*mle
;
1389 struct symtab_and_line sal
;
1394 symtab
= find_pc_symtab (low
); /* Assume symtab is valid for whole PC range */
1399 /* First, convert the linetable to a bunch of my_line_entry's. */
1401 le
= symtab
->linetable
->item
;
1402 nlines
= symtab
->linetable
->nitems
;
1407 mle
= (struct my_line_entry
*) alloca (nlines
* sizeof (struct my_line_entry
));
1411 /* Copy linetable entries for this function into our data structure, creating
1412 end_pc's and setting out_of_order as appropriate. */
1414 /* First, skip all the preceding functions. */
1416 for (i
= 0; i
< nlines
- 1 && le
[i
].pc
< low
; i
++) ;
1418 /* Now, copy all entries before the end of this function. */
1421 for (; i
< nlines
- 1 && le
[i
].pc
< high
; i
++)
1423 if (le
[i
].line
== le
[i
+ 1].line
1424 && le
[i
].pc
== le
[i
+ 1].pc
)
1425 continue; /* Ignore duplicates */
1427 mle
[newlines
].line
= le
[i
].line
;
1428 if (le
[i
].line
> le
[i
+ 1].line
)
1430 mle
[newlines
].start_pc
= le
[i
].pc
;
1431 mle
[newlines
].end_pc
= le
[i
+ 1].pc
;
1435 /* If we're on the last line, and it's part of the function, then we need to
1436 get the end pc in a special way. */
1441 mle
[newlines
].line
= le
[i
].line
;
1442 mle
[newlines
].start_pc
= le
[i
].pc
;
1443 sal
= find_pc_line (le
[i
].pc
, 0);
1444 mle
[newlines
].end_pc
= sal
.end
;
1448 /* Now, sort mle by line #s (and, then by addresses within lines). */
1451 qsort (mle
, newlines
, sizeof (struct my_line_entry
), compare_lines
);
1453 /* Now, for each line entry, emit the specified lines (unless they have been
1454 emitted before), followed by the assembly code for that line. */
1456 next_line
= 0; /* Force out first line */
1457 for (i
= 0; i
< newlines
; i
++)
1459 /* Print out everything from next_line to the current line. */
1461 if (mle
[i
].line
>= next_line
)
1464 print_source_lines (symtab
, next_line
, mle
[i
].line
+ 1, 0);
1466 print_source_lines (symtab
, mle
[i
].line
, mle
[i
].line
+ 1, 0);
1468 next_line
= mle
[i
].line
+ 1;
1471 for (pc
= mle
[i
].start_pc
; pc
< mle
[i
].end_pc
; )
1474 fputs_unfiltered (" ", gdb_stdout
);
1475 print_address (pc
, gdb_stdout
);
1476 fputs_unfiltered (":\t ", gdb_stdout
);
1477 pc
+= (*tm_print_insn
) (pc
, &di
);
1478 fputs_unfiltered ("\n", gdb_stdout
);
1485 for (pc
= low
; pc
< high
; )
1488 fputs_unfiltered (" ", gdb_stdout
);
1489 print_address (pc
, gdb_stdout
);
1490 fputs_unfiltered (":\t ", gdb_stdout
);
1491 pc
+= (*tm_print_insn
) (pc
, &di
);
1492 fputs_unfiltered ("\n", gdb_stdout
);
1496 gdb_flush (gdb_stdout
);
1502 tk_command (cmd
, from_tty
)
1508 struct cleanup
*old_chain
;
1510 /* Catch case of no argument, since this will make the tcl interpreter dump core. */
1512 error_no_arg ("tcl command to interpret");
1514 retval
= Tcl_Eval (interp
, cmd
);
1516 result
= strdup (interp
->result
);
1518 old_chain
= make_cleanup (free
, result
);
1520 if (retval
!= TCL_OK
)
1523 printf_unfiltered ("%s\n", result
);
1525 do_cleanups (old_chain
);
1529 cleanup_init (ignored
)
1533 Tcl_DeleteInterp (interp
);
1537 /* Come here during long calculations to check for GUI events. Usually invoked
1538 via the QUIT macro. */
1541 gdbtk_interactive ()
1543 /* Tk_DoOneEvent (TK_DONT_WAIT|TK_IDLE_EVENTS); */
1546 /* Come here when there is activity on the X file descriptor. */
1552 /* Process pending events */
1554 while (Tcl_DoOneEvent (TCL_DONT_WAIT
|TCL_ALL_EVENTS
) != 0);
1559 /* For Cygwin32, we use a timer to periodically check for Windows
1560 messages. FIXME: It would be better to not poll, but to instead
1561 rewrite the target_wait routines to serve as input sources.
1562 Unfortunately, that will be a lot of work. */
1565 gdbtk_start_timer ()
1567 sigset_t nullsigmask
;
1568 struct sigaction action
;
1569 struct itimerval it
;
1571 sigemptyset (&nullsigmask
);
1573 action
.sa_handler
= x_event
;
1574 action
.sa_mask
= nullsigmask
;
1575 action
.sa_flags
= 0;
1576 sigaction (SIGALRM
, &action
, NULL
);
1578 it
.it_interval
.tv_sec
= 0;
1579 /* Check for messages twice a second. */
1580 it
.it_interval
.tv_usec
= 500 * 1000;
1581 it
.it_value
.tv_sec
= 0;
1582 it
.it_value
.tv_usec
= 500 * 1000;
1584 setitimer (ITIMER_REAL
, &it
, NULL
);
1590 sigset_t nullsigmask
;
1591 struct sigaction action
;
1592 struct itimerval it
;
1594 sigemptyset (&nullsigmask
);
1596 action
.sa_handler
= SIG_IGN
;
1597 action
.sa_mask
= nullsigmask
;
1598 action
.sa_flags
= 0;
1599 sigaction (SIGALRM
, &action
, NULL
);
1601 it
.it_interval
.tv_sec
= 0;
1602 it
.it_interval
.tv_usec
= 0;
1603 it
.it_value
.tv_sec
= 0;
1604 it
.it_value
.tv_usec
= 0;
1605 setitimer (ITIMER_REAL
, &it
, NULL
);
1610 /* This hook function is called whenever we want to wait for the
1614 gdbtk_wait (pid
, ourstatus
)
1616 struct target_waitstatus
*ourstatus
;
1619 struct sigaction action
;
1620 static sigset_t nullsigmask
= {0};
1624 /* Needed for SunOS 4.1.x */
1625 #define SA_RESTART 0
1628 action
.sa_handler
= x_event
;
1629 action
.sa_mask
= nullsigmask
;
1630 action
.sa_flags
= SA_RESTART
;
1631 sigaction(SIGIO
, &action
, NULL
);
1635 gdbtk_start_timer ();
1638 pid
= target_wait (pid
, ourstatus
);
1641 gdbtk_stop_timer ();
1645 action
.sa_handler
= SIG_IGN
;
1646 sigaction(SIGIO
, &action
, NULL
);
1652 /* This is called from execute_command, and provides a wrapper around
1653 various command routines in a place where both protocol messages and
1654 user input both flow through. Mostly this is used for indicating whether
1655 the target process is running or not.
1659 gdbtk_call_command (cmdblk
, arg
, from_tty
)
1660 struct cmd_list_element
*cmdblk
;
1665 if (cmdblk
->class == class_run
|| cmdblk
->class == class_trace
)
1668 Tcl_Eval (interp
, "gdbtk_tcl_busy");
1669 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1671 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1674 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1677 /* This function is called instead of gdb's internal command loop. This is the
1678 last chance to do anything before entering the main Tk event loop. */
1683 extern GDB_FILE
*instream
;
1685 /* We no longer want to use stdin as the command input stream */
1688 if (Tcl_Eval (interp
, "gdbtk_tcl_preloop") != TCL_OK
)
1692 /* Force errorInfo to be set up propertly. */
1693 Tcl_AddErrorInfo (interp
, "");
1695 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
1697 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
1699 fputs_unfiltered (msg
, gdb_stderr
);
1710 /* gdbtk_init installs this function as a final cleanup. */
1713 gdbtk_cleanup (dummy
)
1719 /* Initialize gdbtk. */
1722 gdbtk_init ( argv0
)
1725 struct cleanup
*old_chain
;
1726 char *lib
, *gdbtk_lib
, *gdbtk_lib_tmp
, *gdbtk_file
;
1729 struct sigaction action
;
1730 static sigset_t nullsigmask
= {0};
1733 /* start-sanitize-ide */
1734 struct ide_event_handle
*h
;
1737 /* end-sanitize-ide */
1740 /* If there is no DISPLAY environment variable, Tk_Init below will fail,
1741 causing gdb to abort. If instead we simply return here, gdb will
1742 gracefully degrade to using the command line interface. */
1745 if (getenv ("DISPLAY") == NULL
)
1749 old_chain
= make_cleanup (cleanup_init
, 0);
1751 /* First init tcl and tk. */
1752 Tcl_FindExecutable (argv0
);
1753 interp
= Tcl_CreateInterp ();
1756 error ("Tcl_CreateInterp failed");
1758 if (Tcl_Init(interp
) != TCL_OK
)
1759 error ("Tcl_Init failed: %s", interp
->result
);
1761 make_final_cleanup (gdbtk_cleanup
, NULL
);
1763 /* Initialize the Paths variable. */
1764 if (ide_initialize_paths (interp
, "gdbtcl") != TCL_OK
)
1765 error ("ide_initialize_paths failed: %s", interp
->result
);
1768 /* start-sanitize-ide */
1769 /* Find the directory where we expect to find idemanager. We ignore
1770 errors since it doesn't really matter if this fails. */
1771 libexecdir
= Tcl_GetVar2 (interp
, "Paths", "libexecdir", TCL_GLOBAL_ONLY
);
1775 h
= ide_event_init_from_environment (&errmsg
, libexecdir
);
1778 Tcl_AppendResult (interp
, "can't initialize event system: ", errmsg
,
1780 fprintf(stderr
, "WARNING: ide_event_init_client failed: %s\n", interp
->result
);
1782 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1786 if (ide_create_tclevent_command (interp
, h
) != TCL_OK
)
1787 error ("ide_create_tclevent_command failed: %s", interp
->result
);
1789 if (ide_create_edit_command (interp
, h
) != TCL_OK
)
1790 error ("ide_create_edit_command failed: %s", interp
->result
);
1792 if (ide_create_property_command (interp
, h
) != TCL_OK
)
1793 error ("ide_create_property_command failed: %s", interp
->result
);
1795 if (ide_create_build_command (interp
, h
) != TCL_OK
)
1796 error ("ide_create_build_command failed: %s", interp
->result
);
1798 if (ide_create_window_register_command (interp
, h
, "gdb-restore")
1800 error ("ide_create_window_register_command failed: %s",
1803 if (ide_create_window_command (interp
, h
) != TCL_OK
)
1804 error ("ide_create_window_command failed: %s", interp
->result
);
1806 if (ide_create_exit_command (interp
, h
) != TCL_OK
)
1807 error ("ide_create_exit_command failed: %s", interp
->result
);
1809 if (ide_create_help_command (interp
) != TCL_OK
)
1810 error ("ide_create_help_command failed: %s", interp
->result
);
1813 if (ide_initialize (interp, "gdb") != TCL_OK)
1814 error ("ide_initialize failed: %s", interp->result);
1817 Tcl_SetVar (interp
, "GDBTK_IDE", "1", 0);
1818 Tcl_SetVar (interp
, "IDE", "1", TCL_GLOBAL_ONLY
);
1820 /* end-sanitize-ide */
1822 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1825 /* We don't want to open the X connection until we've done all the
1826 IDE initialization. Otherwise, goofy looking unfinished windows
1827 pop up when ILU drops into the TCL event loop. */
1829 if (Tk_Init(interp
) != TCL_OK
)
1830 error ("Tk_Init failed: %s", interp
->result
);
1832 if (Itcl_Init(interp
) == TCL_ERROR
)
1833 error ("Itcl_Init failed: %s", interp
->result
);
1835 if (Tix_Init(interp
) != TCL_OK
)
1836 error ("Tix_Init failed: %s", interp
->result
);
1839 /* On Windows, create a sizebox widget command */
1840 if (ide_create_sizebox_command (interp
) != TCL_OK
)
1841 error ("sizebox creation failed");
1842 if (ide_create_winprint_command (interp
) != TCL_OK
)
1843 error ("windows print code initialization failed");
1844 /* start-sanitize-ide */
1845 /* An interface to ShellExecute. */
1846 if (ide_create_shell_execute_command (interp
) != TCL_OK
)
1847 error ("shell execute command initialization failed");
1850 Tcl_CreateCommand (interp
, "gdb_cmd", call_wrapper
, gdb_cmd
, NULL
);
1851 Tcl_CreateCommand (interp
, "gdb_loc", call_wrapper
, gdb_loc
, NULL
);
1852 Tcl_CreateCommand (interp
, "gdb_path_conv", call_wrapper
, gdb_path_conv
, NULL
);
1853 Tcl_CreateCommand (interp
, "gdb_sourcelines", call_wrapper
, gdb_sourcelines
,
1855 Tcl_CreateCommand (interp
, "gdb_listfiles", call_wrapper
, gdb_listfiles
,
1857 Tcl_CreateCommand (interp
, "gdb_listfuncs", call_wrapper
, gdb_listfuncs
,
1859 Tcl_CreateCommand (interp
, "gdb_get_mem", call_wrapper
, gdb_get_mem
,
1861 Tcl_CreateCommand (interp
, "gdb_stop", call_wrapper
, gdb_stop
, NULL
);
1862 Tcl_CreateCommand (interp
, "gdb_regnames", call_wrapper
, gdb_regnames
, NULL
);
1863 Tcl_CreateCommand (interp
, "gdb_fetch_registers", call_wrapper
,
1864 gdb_fetch_registers
, NULL
);
1865 Tcl_CreateCommand (interp
, "gdb_changed_register_list", call_wrapper
,
1866 gdb_changed_register_list
, NULL
);
1867 Tcl_CreateCommand (interp
, "gdb_disassemble", call_wrapper
,
1868 gdb_disassemble
, NULL
);
1869 Tcl_CreateCommand (interp
, "gdb_eval", call_wrapper
, gdb_eval
, NULL
);
1870 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_list", call_wrapper
,
1871 gdb_get_breakpoint_list
, NULL
);
1872 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_info", call_wrapper
,
1873 gdb_get_breakpoint_info
, NULL
);
1874 Tcl_CreateCommand (interp
, "gdb_clear_file", call_wrapper
,
1875 gdb_clear_file
, NULL
);
1876 Tcl_CreateCommand (interp
, "gdb_confirm_quit", call_wrapper
,
1877 gdb_confirm_quit
, NULL
);
1878 Tcl_CreateCommand (interp
, "gdb_force_quit", call_wrapper
,
1879 gdb_force_quit
, NULL
);
1880 Tcl_CreateCommand (interp
, "gdb_target_has_execution",
1881 gdb_target_has_execution_command
,
1883 Tcl_CreateObjCommand (interp
, "gdb_load_info", gdb_load_info
, NULL
, NULL
);
1884 Tcl_CreateObjCommand (interp
, "gdb_get_locals", gdb_get_vars_command
,
1885 (ClientData
) 0, NULL
);
1886 Tcl_CreateObjCommand (interp
, "gdb_get_args", gdb_get_vars_command
,
1887 (ClientData
) 1, NULL
);
1888 Tcl_CreateObjCommand (interp
, "gdb_get_function", gdb_get_function_command
,
1890 Tcl_CreateObjCommand (interp
, "gdb_get_line", gdb_get_line_command
,
1892 Tcl_CreateObjCommand (interp
, "gdb_get_file", gdb_get_file_command
,
1894 Tcl_CreateObjCommand (interp
, "gdb_tracepoint_exists",
1895 gdb_tracepoint_exists_command
, NULL
, NULL
);
1896 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_info",
1897 gdb_get_tracepoint_info
, NULL
, NULL
);
1898 Tcl_CreateObjCommand (interp
, "gdb_actions",
1899 gdb_actions_command
, NULL
, NULL
);
1900 Tcl_CreateObjCommand (interp
, "gdb_prompt",
1901 gdb_prompt_command
, NULL
, NULL
);
1902 Tcl_CreateObjCommand (interp
, "gdb_find_file",
1903 gdb_find_file_command
, NULL
, NULL
);
1905 command_loop_hook
= tk_command_loop
;
1906 print_frame_info_listing_hook
=
1907 (void (*) PARAMS ((struct symtab
*, int, int, int))) null_routine
;
1908 query_hook
= gdbtk_query
;
1909 flush_hook
= gdbtk_flush
;
1910 create_breakpoint_hook
= gdbtk_create_breakpoint
;
1911 delete_breakpoint_hook
= gdbtk_delete_breakpoint
;
1912 modify_breakpoint_hook
= gdbtk_modify_breakpoint
;
1913 interactive_hook
= gdbtk_interactive
;
1914 target_wait_hook
= gdbtk_wait
;
1915 call_command_hook
= gdbtk_call_command
;
1916 readline_begin_hook
= gdbtk_readline_begin
;
1917 readline_hook
= gdbtk_readline
;
1918 readline_end_hook
= gdbtk_readline_end
;
1919 ui_load_progress_hook
= gdbtk_load_hash
;
1920 create_tracepoint_hook
= gdbtk_create_tracepoint
;
1921 delete_tracepoint_hook
= gdbtk_delete_tracepoint
;
1924 /* Get the file descriptor for the X server */
1926 x_fd
= ConnectionNumber (Tk_Display (Tk_MainWindow (interp
)));
1928 /* Setup for I/O interrupts */
1930 action
.sa_mask
= nullsigmask
;
1931 action
.sa_flags
= 0;
1932 action
.sa_handler
= SIG_IGN
;
1933 sigaction(SIGIO
, &action
, NULL
);
1937 if (ioctl (x_fd
, FIOASYNC
, &i
))
1938 perror_with_name ("gdbtk_init: ioctl FIOASYNC failed");
1942 if (ioctl (x_fd
, SIOCSPGRP
, &i
))
1943 perror_with_name ("gdbtk_init: ioctl SIOCSPGRP failed");
1948 if (fcntl (x_fd
, F_SETOWN
, i
))
1949 perror_with_name ("gdbtk_init: fcntl F_SETOWN failed");
1950 #endif /* F_SETOWN */
1951 #endif /* !SIOCSPGRP */
1954 if (ioctl (x_fd
, I_SETSIG
, S_INPUT
|S_RDNORM
) < 0)
1955 perror_with_name ("gdbtk_init: ioctl I_SETSIG failed");
1958 #endif /* ifndef FIOASYNC */
1961 add_com ("tk", class_obscure
, tk_command
,
1962 "Send a command directly into tk.");
1964 Tcl_LinkVar (interp
, "disassemble-from-exec", (char *)&disassemble_from_exec
,
1967 /* find the gdb tcl library and source main.tcl */
1969 gdbtk_lib
= getenv ("GDBTK_LIBRARY");
1971 if (access ("gdbtcl/main.tcl", R_OK
) == 0)
1972 gdbtk_lib
= "gdbtcl";
1974 gdbtk_lib
= GDBTK_LIBRARY
;
1976 gdbtk_lib_tmp
= xstrdup (gdbtk_lib
);
1979 /* see if GDBTK_LIBRARY is a path list */
1980 lib
= strtok (gdbtk_lib_tmp
, GDBTK_PATH_SEP
);
1983 if (Tcl_VarEval (interp
, "lappend auto_path ", lib
, NULL
) != TCL_OK
)
1985 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
1990 gdbtk_file
= concat (lib
, "/main.tcl", (char *) NULL
);
1991 if (access (gdbtk_file
, R_OK
) == 0)
1994 Tcl_SetVar (interp
, "GDBTK_LIBRARY", lib
, 0);
1998 while ((lib
= strtok (NULL
, ":")) != NULL
);
2000 free (gdbtk_lib_tmp
);
2004 /* Try finding it with the auto path. */
2006 static const char script
[] ="\
2007 proc gdbtk_find_main {} {\n\
2008 global auto_path GDBTK_LIBRARY\n\
2009 foreach dir $auto_path {\n\
2010 set f [file join $dir main.tcl]\n\
2011 if {[file exists $f]} then {\n\
2012 set GDBTK_LIBRARY $dir\n\
2020 if (Tcl_GlobalEval (interp
, (char *) script
) != TCL_OK
)
2022 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
2026 if (interp
->result
[0] != '\0')
2028 gdbtk_file
= xstrdup (interp
->result
);
2035 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2036 if (getenv("GDBTK_LIBRARY"))
2038 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n",getenv("GDBTK_LIBRARY"));
2039 fprintf_unfiltered (stderr
,
2040 "Please set GDBTK_LIBRARY to a path that includes the GDB tcl files.\n");
2044 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n", GDBTK_LIBRARY
);
2045 fprintf_unfiltered (stderr
, "You might want to set GDBTK_LIBRARY\n");
2050 /* Defer setup of fputs_unfiltered_hook to near the end so that error messages
2051 prior to this point go to stdout/stderr. */
2053 fputs_unfiltered_hook
= gdbtk_fputs
;
2055 if (Tcl_EvalFile (interp
, gdbtk_file
) != TCL_OK
)
2059 /* Force errorInfo to be set up propertly. */
2060 Tcl_AddErrorInfo (interp
, "");
2062 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
2064 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2067 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
2069 fputs_unfiltered (msg
, gdb_stderr
);
2076 /* start-sanitize-ide */
2077 /* Don't do this until we have initialized. Otherwise, we may get a
2078 run command before we are ready for one. */
2079 if (ide_run_server_init (interp
, h
) != TCL_OK
)
2080 error ("ide_run_server_init failed: %s", interp
->result
);
2081 /* end-sanitize-ide */
2086 discard_cleanups (old_chain
);
2090 gdb_target_has_execution_command (clientData
, interp
, argc
, argv
)
2091 ClientData clientData
;
2098 if (target_has_execution
&& inferior_pid
!= 0)
2101 Tcl_SetIntObj (Tcl_GetObjResult (interp
), result
);
2105 /* gdb_load_info - returns information about the file about to be downloaded */
2108 gdb_load_info (clientData
, interp
, objc
, objv
)
2109 ClientData clientData
;
2112 Tcl_Obj
*CONST objv
[];
2115 struct cleanup
*old_cleanups
;
2121 char *filename
= Tcl_GetStringFromObj (objv
[1], NULL
);
2123 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
2124 if (loadfile_bfd
== NULL
)
2126 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Open failed", -1));
2129 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
2131 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
2133 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Bad Object File", -1));
2137 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
2139 if (s
->flags
& SEC_LOAD
)
2141 bfd_size_type size
= bfd_get_section_size_before_reloc (s
);
2144 ob
[0] = Tcl_NewStringObj((char *)bfd_get_section_name(loadfile_bfd
, s
), -1);
2145 ob
[1] = Tcl_NewLongObj ((long)size
);
2146 res
[i
++] = Tcl_NewListObj (2, ob
);
2151 Tcl_SetObjResult (interp
, Tcl_NewListObj (i
, res
));
2152 do_cleanups (old_cleanups
);
2158 gdbtk_load_hash (section
, num
)
2164 sprintf (buf
, "download_hash %s %ld", section
, num
);
2165 result
= Tcl_Eval (interp
, buf
);
2169 /* gdb_get_vars_command -
2171 * Implements the "gdb_get_locals" and "gdb_get_args" tcl commands. This
2172 * function sets the Tcl interpreter's result to a list of variable names
2173 * depending on clientData. If clientData is one, the result is a list of
2174 * arguments; zero returns a list of locals -- all relative to the block
2175 * specified as an argument to the command. Valid commands include
2176 * anything decode_line_1 can handle (like "main.c:2", "*0x02020202",
2180 gdb_get_vars_command (clientData
, interp
, objc
, objv
)
2181 ClientData clientData
;
2184 Tcl_Obj
*CONST objv
[];
2187 struct symtabs_and_lines sals
;
2189 struct block
*block
;
2190 char **canonical
, *args
;
2191 int i
, nsyms
, arguments
;
2195 Tcl_AppendResult (interp
,
2196 "wrong # of args: should be \"",
2197 Tcl_GetStringFromObj (objv
[0], NULL
),
2198 " function:line|function|line|*addr\"");
2202 arguments
= (int) clientData
;
2203 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2204 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2205 if (sals
.nelts
== 0)
2207 Tcl_AppendResult (interp
,
2208 "error decoding line", NULL
);
2212 /* Initialize a list that will hold the results */
2213 result
= Tcl_NewListObj (0, NULL
);
2215 /* Resolve all line numbers to PC's */
2216 for (i
= 0; i
< sals
.nelts
; i
++)
2217 resolve_sal_pc (&sals
.sals
[i
]);
2219 block
= block_for_pc (sals
.sals
[0].pc
);
2222 nsyms
= BLOCK_NSYMS (block
);
2223 for (i
= 0; i
< nsyms
; i
++)
2225 sym
= BLOCK_SYM (block
, i
);
2226 switch (SYMBOL_CLASS (sym
)) {
2228 case LOC_UNDEF
: /* catches errors */
2229 case LOC_CONST
: /* constant */
2230 case LOC_STATIC
: /* static */
2231 case LOC_REGISTER
: /* register */
2232 case LOC_TYPEDEF
: /* local typedef */
2233 case LOC_LABEL
: /* local label */
2234 case LOC_BLOCK
: /* local function */
2235 case LOC_CONST_BYTES
: /* loc. byte seq. */
2236 case LOC_UNRESOLVED
: /* unresolved static */
2237 case LOC_OPTIMIZED_OUT
: /* optimized out */
2239 case LOC_ARG
: /* argument */
2240 case LOC_REF_ARG
: /* reference arg */
2241 case LOC_REGPARM
: /* register arg */
2242 case LOC_REGPARM_ADDR
: /* indirect register arg */
2243 case LOC_LOCAL_ARG
: /* stack arg */
2244 case LOC_BASEREG_ARG
: /* basereg arg */
2246 Tcl_ListObjAppendElement (interp
, result
,
2247 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2249 case LOC_LOCAL
: /* stack local */
2250 case LOC_BASEREG
: /* basereg local */
2252 Tcl_ListObjAppendElement (interp
, result
,
2253 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2257 if (BLOCK_FUNCTION (block
))
2260 block
= BLOCK_SUPERBLOCK (block
);
2263 Tcl_SetObjResult (interp
, result
);
2268 gdb_get_line_command (clientData
, interp
, objc
, objv
)
2269 ClientData clientData
;
2272 Tcl_Obj
*CONST objv
[];
2275 struct symtabs_and_lines sals
;
2276 char *args
, **canonical
;
2280 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2281 Tcl_GetStringFromObj (objv
[0], NULL
),
2286 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2287 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2288 if (sals
.nelts
== 1)
2290 Tcl_SetObjResult (interp
, Tcl_NewIntObj (sals
.sals
[0].line
));
2294 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2299 gdb_get_file_command (clientData
, interp
, objc
, objv
)
2300 ClientData clientData
;
2303 Tcl_Obj
*CONST objv
[];
2306 struct symtabs_and_lines sals
;
2307 char *args
, **canonical
;
2311 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2312 Tcl_GetStringFromObj (objv
[0], NULL
),
2317 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2318 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2319 if (sals
.nelts
== 1)
2321 Tcl_SetResult (interp
, sals
.sals
[0].symtab
->filename
, TCL_VOLATILE
);
2325 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2330 gdb_get_function_command (clientData
, interp
, objc
, objv
)
2331 ClientData clientData
;
2334 Tcl_Obj
*CONST objv
[];
2338 struct symtabs_and_lines sals
;
2339 char *args
, **canonical
;
2343 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2344 Tcl_GetStringFromObj (objv
[0], NULL
),
2349 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2350 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2351 if (sals
.nelts
== 1)
2353 resolve_sal_pc (&sals
.sals
[0]);
2354 find_pc_partial_function (sals
.sals
[0].pc
, &function
, NULL
, NULL
);
2355 if (function
!= NULL
)
2357 Tcl_SetResult (interp
, function
, TCL_VOLATILE
);
2362 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2367 gdb_get_tracepoint_info (clientData
, interp
, objc
, objv
)
2368 ClientData clientData
;
2371 Tcl_Obj
*CONST objv
[];
2373 struct symtab_and_line sal
;
2374 struct command_line
*cmd
;
2376 struct tracepoint
*tp
;
2377 struct action_line
*al
;
2378 Tcl_Obj
*list
, *action_list
;
2382 error ("wrong # args");
2384 Tcl_GetIntFromObj (NULL
, objv
[1], &tpnum
);
2386 ALL_TRACEPOINTS (tp
)
2387 if (tp
->number
== tpnum
)
2391 error ("Tracepoint #%d does not exist", tpnum
);
2393 list
= Tcl_NewListObj (0, NULL
);
2394 if (tp
->source_file
!= NULL
)
2395 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (tp
->source_file
, -1));
2397 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj ("N/A", -1));
2398 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->line_number
));
2399 /* the function part is not currently used by the frontend */
2400 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj ("function", -1));
2401 sprintf (tmp
, "0x%08x", tp
->address
);
2402 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (tmp
, -1));
2403 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->enabled
));
2404 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->pass_count
));
2405 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->step_count
));
2406 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->thread
));
2407 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->hit_count
));
2409 /* Append a list of actions */
2410 action_list
= Tcl_NewListObj (0, NULL
);
2411 for (al
= tp
->actions
; al
!= NULL
; al
= al
->next
)
2413 Tcl_ListObjAppendElement (interp
, action_list
,
2414 Tcl_NewStringObj (al
->action
, -1));
2416 Tcl_ListObjAppendElement (interp
, list
, action_list
);
2418 Tcl_SetObjResult (interp
, list
);
2423 gdbtk_create_tracepoint (tp
)
2424 struct tracepoint
*tp
;
2426 tracepoint_notify (tp
, "create");
2430 gdbtk_delete_tracepoint (tp
)
2431 struct tracepoint
*tp
;
2433 tracepoint_notify (tp
, "delete");
2437 tracepoint_notify(tp
, action
)
2438 struct tracepoint
*tp
;
2445 /* We ensure that ACTION contains no special Tcl characters, so we
2447 if (tp
->source_file
!= NULL
)
2448 source
= tp
->source_file
;
2451 sprintf (buf
, "gdbtk_tcl_tracepoint %s %d 0x%lx %d {%s}", action
, tp
->number
,
2452 (long)tp
->address
, tp
->line_number
, source
);
2454 v
= Tcl_Eval (interp
, buf
);
2458 gdbtk_fputs (interp
->result
, gdb_stdout
);
2459 gdbtk_fputs ("\n", gdb_stdout
);
2463 /* returns -1 if not found, tracepoint # if found */
2465 tracepoint_exists (char * args
)
2467 struct tracepoint
*tp
;
2469 struct symtabs_and_lines sals
;
2473 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2474 if (sals
.nelts
== 1)
2476 resolve_sal_pc (&sals
.sals
[0]);
2477 file
= xmalloc (strlen (sals
.sals
[0].symtab
->dirname
)
2478 + strlen (sals
.sals
[0].symtab
->filename
) + 1);
2481 strcpy (file
, sals
.sals
[0].symtab
->dirname
);
2482 strcat (file
, sals
.sals
[0].symtab
->filename
);
2484 ALL_TRACEPOINTS (tp
)
2486 if (tp
->address
== sals
.sals
[0].pc
)
2487 result
= tp
->number
;
2488 else if (tp
->source_file
!= NULL
2489 && strcmp (tp
->source_file
, file
) == 0
2490 && sals
.sals
[0].line
== tp
->line_number
)
2492 result
= tp
->number
;
2502 gdb_actions_command (clientData
, interp
, objc
, objv
)
2503 ClientData clientData
;
2506 Tcl_Obj
*CONST objv
[];
2508 struct tracepoint
*tp
;
2510 int nactions
, i
, len
;
2511 char *number
, *args
, *action
;
2512 struct action_line
*next
= NULL
, *temp
;
2516 Tcl_AppendResult (interp
, "wrong # args: should be: \"",
2517 Tcl_GetStringFromObj (objv
[0], NULL
),
2518 " number actions\"");
2522 args
= number
= Tcl_GetStringFromObj (objv
[1], NULL
);
2523 tp
= get_tracepoint_by_number (&args
);
2526 Tcl_AppendResult (interp
, "Tracepoint \"", number
, "\" does not exist");
2530 /* Free any existing actions */
2531 for (temp
= tp
->actions
; temp
!= NULL
; temp
= temp
->next
)
2534 free (temp
->action
);
2538 Tcl_ListObjGetElements (interp
, objv
[2], &nactions
, &actions
);
2539 for (i
= 0; i
< nactions
; i
++)
2541 temp
= xmalloc (sizeof (struct action_line
));
2543 action
= Tcl_GetStringFromObj (actions
[i
], &len
);
2544 temp
->action
= savestring (action
, len
);
2561 gdb_tracepoint_exists_command (clientData
, interp
, objc
, objv
)
2562 ClientData clientData
;
2565 Tcl_Obj
*CONST objv
[];
2571 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2572 Tcl_GetStringFromObj (objv
[0], NULL
),
2573 " function:line|function|line|*addr\"");
2577 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2579 Tcl_SetObjResult (interp
, Tcl_NewIntObj (tracepoint_exists (args
)));
2583 /* Return the prompt to the interpreter */
2585 gdb_prompt_command (clientData
, interp
, objc
, objv
)
2586 ClientData clientData
;
2589 Tcl_Obj
*CONST objv
[];
2591 Tcl_SetResult (interp
, get_prompt (), TCL_VOLATILE
);
2596 /* This is stolen from source.c */
2597 #ifdef CRLF_SOURCE_FILES
2599 /* Define CRLF_SOURCE_FILES in an xm-*.h file if source files on the
2600 host use \r\n rather than just \n. Defining CRLF_SOURCE_FILES is
2601 much faster than defining LSEEK_NOT_LINEAR. */
2607 #define OPEN_MODE (O_RDONLY | O_BINARY)
2609 #else /* ! defined (CRLF_SOURCE_FILES) */
2611 #define OPEN_MODE O_RDONLY
2613 #endif /* ! defined (CRLF_SOURCE_FILES) */
2615 /* Find the pathname to a file, searching the source_dir */
2616 /* we may actually need to use openp to find the the full pathname
2617 so we don't have any "../" et al in it. */
2619 gdb_find_file_command (clientData
, interp
, objc
, objv
)
2620 ClientData clientData
;
2623 Tcl_Obj
*CONST objv
[];
2625 char *file
, *filename
;
2631 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2632 Tcl_GetStringFromObj (objv
[0], NULL
),
2637 /* try something simple first */
2638 file
= Tcl_GetStringFromObj (objv
[1], NULL
);
2639 if (access (file
, R_OK
) == 0)
2641 Tcl_SetObjResult (interp
, Tcl_NewStringObj (file
, -1));
2645 /* Search the path -- do NOT search CWD first -- be consistent with source.c */
2646 found
= openp (source_path
, 0, file
, OPEN_MODE
, 0, &filename
);
2649 /* Did not work -- try just the base filename */
2650 p
= basename (file
);
2652 found
= openp (source_path
, 0, p
, OPEN_MODE
, 0, &filename
);
2657 Tcl_SetObjResult (interp
, Tcl_NewStringObj (filename
, -1));
2661 Tcl_SetResult (interp
, "", TCL_STATIC
);
2666 /* Come here during initialize_all_files () */
2669 _initialize_gdbtk ()
2673 /* Tell the rest of the world that Gdbtk is now set up. */
2675 init_ui_hook
= gdbtk_init
;