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 int gdbtk_load_hash
PARAMS ((char *, unsigned long));
90 int (*ui_load_progress_hook
) PARAMS ((char *, unsigned long));
92 static void null_routine
PARAMS ((int));
93 static void gdbtk_flush
PARAMS ((FILE *));
94 static void gdbtk_fputs
PARAMS ((const char *, FILE *));
95 static int gdbtk_query
PARAMS ((const char *, va_list));
96 static char *gdbtk_readline
PARAMS ((char *));
97 static void gdbtk_init
PARAMS ((char *));
98 static void tk_command_loop
PARAMS ((void));
99 static void gdbtk_call_command
PARAMS ((struct cmd_list_element
*, char *, int));
100 static int gdbtk_wait
PARAMS ((int, struct target_waitstatus
*));
101 static void x_event
PARAMS ((int));
102 static void gdbtk_interactive
PARAMS ((void));
103 static void cleanup_init
PARAMS ((int));
104 static void tk_command
PARAMS ((char *, int));
105 static int gdb_disassemble
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
106 static int compare_lines
PARAMS ((const PTR
, const PTR
));
107 static int gdbtk_dis_asm_read_memory
PARAMS ((bfd_vma
, bfd_byte
*, int, disassemble_info
*));
108 static int gdb_path_conv
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
109 static int gdb_stop
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
110 static int gdb_confirm_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
111 static int gdb_force_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
112 static int gdb_listfiles
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
113 static int gdb_listfuncs
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
114 static int call_wrapper
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
115 static int gdb_cmd
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
116 static int gdb_immediate_command
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 int gdb_get_tracepoint_list
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
146 static void gdbtk_create_tracepoint
PARAMS ((struct tracepoint
*));
147 static void gdbtk_delete_tracepoint
PARAMS ((struct tracepoint
*));
148 static void tracepoint_notify
PARAMS ((struct tracepoint
*, const char *));
150 /* Handle for TCL interpreter */
152 static Tcl_Interp
*interp
= NULL
;
155 static int x_fd
; /* X network socket */
158 /* This variable is true when the inferior is running. Although it's
159 possible to disable most input from widgets and thus prevent
160 attempts to do anything while the inferior is running, any commands
161 that get through - even a simple memory read - are Very Bad, and
162 may cause GDB to crash or behave strangely. So, this variable
163 provides an extra layer of defense. */
165 static int running_now
;
167 /* This variable determines where memory used for disassembly is read from.
168 If > 0, then disassembly comes from the exec file rather than the
169 target (which might be at the other end of a slow serial link). If
170 == 0 then disassembly comes from target. If < 0 disassembly is
171 automatically switched to the target if it's an inferior process,
172 otherwise the exec file is used. */
174 static int disassemble_from_exec
= -1;
178 /* Supply malloc calls for tcl/tk. We do not want to do this on
179 Windows, because Tcl_Alloc is probably in a DLL which will not call
180 the mmalloc routines. */
186 return xmalloc (size
);
190 Tcl_Realloc (ptr
, size
)
194 return xrealloc (ptr
, size
);
204 #endif /* ! _WIN32 */
214 /* On Windows, if we hold a file open, other programs can't write to
215 it. In particular, we don't want to hold the executable open,
216 because it will mean that people have to get out of the debugging
217 session in order to remake their program. So we close it, although
218 this will cost us if and when we need to reopen it. */
228 bfd_cache_close (o
->obfd
);
231 if (exec_bfd
!= NULL
)
232 bfd_cache_close (exec_bfd
);
237 /* The following routines deal with stdout/stderr data, which is created by
238 {f}printf_{un}filtered and friends. gdbtk_fputs and gdbtk_flush are the
239 lowest level of these routines and capture all output from the rest of GDB.
240 Normally they present their data to tcl via callbacks to the following tcl
241 routines: gdbtk_tcl_fputs, gdbtk_tcl_fputs_error, and gdbtk_flush. These
242 in turn call tk routines to update the display.
244 Under some circumstances, you may want to collect the output so that it can
245 be returned as the value of a tcl procedure. This can be done by
246 surrounding the output routines with calls to start_saving_output and
247 finish_saving_output. The saved data can then be retrieved with
248 get_saved_output (but this must be done before the call to
249 finish_saving_output). */
251 /* Dynamic string for output. */
253 static Tcl_DString
*result_ptr
;
255 /* Dynamic string for stderr. This is only used if result_ptr is
258 static Tcl_DString
*error_string_ptr
;
265 /* Force immediate screen update */
267 Tcl_VarEval (interp
, "gdbtk_tcl_flush", NULL
);
272 gdbtk_fputs (ptr
, stream
)
277 Tcl_DStringAppend (result_ptr
, (char *) ptr
, -1);
278 else if (error_string_ptr
!= NULL
&& stream
== gdb_stderr
)
279 Tcl_DStringAppend (error_string_ptr
, (char *) ptr
, -1);
284 Tcl_DStringInit (&str
);
286 Tcl_DStringAppend (&str
, "gdbtk_tcl_fputs", -1);
287 Tcl_DStringAppendElement (&str
, (char *)ptr
);
289 Tcl_Eval (interp
, Tcl_DStringValue (&str
));
290 Tcl_DStringFree (&str
);
295 gdbtk_query (query
, args
)
299 char buf
[200], *merge
[2];
303 vsprintf (buf
, query
, args
);
304 merge
[0] = "gdbtk_tcl_query";
306 command
= Tcl_Merge (2, merge
);
307 Tcl_Eval (interp
, command
);
310 val
= atol (interp
->result
);
316 #ifdef ANSI_PROTOTYPES
317 gdbtk_readline_begin (char *format
, ...)
319 gdbtk_readline_begin (va_alist
)
324 char buf
[200], *merge
[2];
327 #ifdef ANSI_PROTOTYPES
328 va_start (args
, format
);
332 format
= va_arg (args
, char *);
335 vsprintf (buf
, format
, args
);
336 merge
[0] = "gdbtk_tcl_readline_begin";
338 command
= Tcl_Merge (2, merge
);
339 Tcl_Eval (interp
, command
);
344 gdbtk_readline (prompt
)
355 merge
[0] = "gdbtk_tcl_readline";
357 command
= Tcl_Merge (2, merge
);
358 result
= Tcl_Eval (interp
, command
);
360 if (result
== TCL_OK
)
362 return (strdup (interp
-> result
));
366 gdbtk_fputs (interp
-> result
, gdb_stdout
);
367 gdbtk_fputs ("\n", gdb_stdout
);
373 gdbtk_readline_end ()
375 Tcl_Eval (interp
, "gdbtk_tcl_readline_end");
380 #ifdef ANSI_PROTOTYPES
381 dsprintf_append_element (Tcl_DString
*dsp
, char *format
, ...)
383 dsprintf_append_element (va_alist
)
390 #ifdef ANSI_PROTOTYPES
391 va_start (args
, format
);
397 dsp
= va_arg (args
, Tcl_DString
*);
398 format
= va_arg (args
, char *);
401 vsprintf (buf
, format
, args
);
403 Tcl_DStringAppendElement (dsp
, buf
);
407 gdb_path_conv (clientData
, interp
, argc
, argv
)
408 ClientData clientData
;
414 char pathname
[256], *ptr
;
416 error ("wrong # args");
417 cygwin32_conv_to_full_win32_path (argv
[1], pathname
);
418 for (ptr
= pathname
; *ptr
; ptr
++)
424 char *pathname
= argv
[1];
426 Tcl_DStringAppend (result_ptr
, pathname
, strlen(pathname
));
431 gdb_get_breakpoint_list (clientData
, interp
, argc
, argv
)
432 ClientData clientData
;
437 struct breakpoint
*b
;
438 extern struct breakpoint
*breakpoint_chain
;
441 error ("wrong # args");
443 for (b
= breakpoint_chain
; b
; b
= b
->next
)
444 if (b
->type
== bp_breakpoint
)
445 dsprintf_append_element (result_ptr
, "%d", b
->number
);
451 gdb_get_breakpoint_info (clientData
, interp
, argc
, argv
)
452 ClientData clientData
;
457 struct symtab_and_line sal
;
458 static char *bptypes
[] = {"breakpoint", "hardware breakpoint", "until",
459 "finish", "watchpoint", "hardware watchpoint",
460 "read watchpoint", "access watchpoint",
461 "longjmp", "longjmp resume", "step resume",
462 "through sigtramp", "watchpoint scope",
464 static char *bpdisp
[] = {"delete", "delstop", "disable", "donttouch"};
465 struct command_line
*cmd
;
467 struct breakpoint
*b
;
468 extern struct breakpoint
*breakpoint_chain
;
469 char *funcname
, *filename
;
472 error ("wrong # args");
474 bpnum
= atoi (argv
[1]);
476 for (b
= breakpoint_chain
; b
; b
= b
->next
)
477 if (b
->number
== bpnum
)
480 if (!b
|| b
->type
!= bp_breakpoint
)
481 error ("Breakpoint #%d does not exist", bpnum
);
483 sal
= find_pc_line (b
->address
, 0);
485 filename
= symtab_to_filename (sal
.symtab
);
486 if (filename
== NULL
)
488 Tcl_DStringAppendElement (result_ptr
, filename
);
489 find_pc_partial_function (b
->address
, &funcname
, NULL
, NULL
);
490 Tcl_DStringAppendElement (result_ptr
, funcname
);
491 dsprintf_append_element (result_ptr
, "%d", sal
.line
);
492 dsprintf_append_element (result_ptr
, "0x%lx", b
->address
);
493 Tcl_DStringAppendElement (result_ptr
, bptypes
[b
->type
]);
494 Tcl_DStringAppendElement (result_ptr
, b
->enable
== enabled
? "1" : "0");
495 Tcl_DStringAppendElement (result_ptr
, bpdisp
[b
->disposition
]);
496 dsprintf_append_element (result_ptr
, "%d", b
->ignore_count
);
498 Tcl_DStringStartSublist (result_ptr
);
499 for (cmd
= b
->commands
; cmd
; cmd
= cmd
->next
)
500 Tcl_DStringAppendElement (result_ptr
, cmd
->line
);
501 Tcl_DStringEndSublist (result_ptr
);
503 Tcl_DStringAppendElement (result_ptr
, b
->cond_string
);
505 dsprintf_append_element (result_ptr
, "%d", b
->thread
);
506 dsprintf_append_element (result_ptr
, "%d", b
->hit_count
);
512 breakpoint_notify(b
, action
)
513 struct breakpoint
*b
;
518 struct symtab_and_line sal
;
521 if (b
->type
!= bp_breakpoint
)
524 /* We ensure that ACTION contains no special Tcl characters, so we
526 sal
= find_pc_line (b
->address
, 0);
527 filename
= symtab_to_filename (sal
.symtab
);
528 if (filename
== NULL
)
530 sprintf (buf
, "gdbtk_tcl_breakpoint %s %d 0x%lx %d {%s}", action
, b
->number
,
531 (long)b
->address
, sal
.line
, filename
);
533 v
= Tcl_Eval (interp
, buf
);
537 gdbtk_fputs (interp
->result
, gdb_stdout
);
538 gdbtk_fputs ("\n", gdb_stdout
);
543 gdbtk_create_breakpoint(b
)
544 struct breakpoint
*b
;
546 breakpoint_notify (b
, "create");
550 gdbtk_delete_breakpoint(b
)
551 struct breakpoint
*b
;
553 breakpoint_notify (b
, "delete");
557 gdbtk_modify_breakpoint(b
)
558 struct breakpoint
*b
;
560 breakpoint_notify (b
, "modify");
563 /* This implements the TCL command `gdb_loc', which returns a list consisting
564 of the source and line number associated with the current pc. */
567 gdb_loc (clientData
, interp
, argc
, argv
)
568 ClientData clientData
;
574 struct symtab_and_line sal
;
578 if (!have_full_symbols () && !have_partial_symbols ())
580 Tcl_SetResult (interp
, "No symbol table is loaded", TCL_STATIC
);
586 pc
= selected_frame
? selected_frame
->pc
: stop_pc
;
587 sal
= find_pc_line (pc
, 0);
591 struct symtabs_and_lines sals
;
594 sals
= decode_line_spec (argv
[1], 1);
601 error ("Ambiguous line spec");
606 error ("wrong # args");
609 Tcl_DStringAppendElement (result_ptr
, sal
.symtab
->filename
);
611 Tcl_DStringAppendElement (result_ptr
, "");
613 find_pc_partial_function (pc
, &funcname
, NULL
, NULL
);
614 Tcl_DStringAppendElement (result_ptr
, funcname
);
616 filename
= symtab_to_filename (sal
.symtab
);
617 if (filename
== NULL
)
619 Tcl_DStringAppendElement (result_ptr
, filename
);
621 dsprintf_append_element (result_ptr
, "%d", sal
.line
); /* line number */
623 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(pc
)); /* PC in current frame */
625 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(stop_pc
)); /* Real PC */
630 /* This implements the TCL command `gdb_eval'. */
633 gdb_eval (clientData
, interp
, argc
, argv
)
634 ClientData clientData
;
639 struct expression
*expr
;
640 struct cleanup
*old_chain
;
644 error ("wrong # args");
646 expr
= parse_expression (argv
[1]);
648 old_chain
= make_cleanup (free_current_contents
, &expr
);
650 val
= evaluate_expression (expr
);
652 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
653 gdb_stdout
, 0, 0, 0, 0);
655 do_cleanups (old_chain
);
660 /* gdb_get_mem addr form size num aschar*/
661 /* dump a block of memory */
662 /* addr: address of data to dump */
663 /* form: a char indicating format */
664 /* size: size of each element; 1,2,4, or 8 bytes*/
665 /* num: the number of 'size' elements to return */
666 /* acshar: an optional ascii character to use in ASCII dump */
667 /* returns a list of 'num' elements followed by an optional */
670 gdb_get_mem (clientData
, interp
, argc
, argv
)
671 ClientData clientData
;
676 int size
, asize
, num
, i
, j
;
677 CORE_ADDR addr
, saved_addr
, ptr
;
679 struct type
*val_type
;
681 char c
, buff
[128], aschar
;
684 error ("wrong # args");
686 addr
= (CORE_ADDR
)strtoul(argv
[1],(char **)NULL
,0);
689 size
= (int)strtoul(argv
[3],(char **)NULL
,0);
690 num
= (int)strtoul(argv
[4],(char **)NULL
,0);
695 val_type
= builtin_type_char
;
699 val_type
= builtin_type_short
;
703 val_type
= builtin_type_int
;
707 val_type
= builtin_type_long_long
;
711 val_type
= builtin_type_char
;
715 for (i
=0; i
< num
; i
++)
717 vptr
= value_at (val_type
, addr
, (asection
*)NULL
);
718 print_scalar_formatted (VALUE_CONTENTS(vptr
), val_type
, format
, asize
, gdb_stdout
);
719 fputs_unfiltered (" ", gdb_stdout
);
725 val_type
= builtin_type_char
;
729 for (j
=0; j
< num
*size
; j
++)
731 c
= *(char *)VALUE_CONTENTS(value_at (val_type
, ptr
, (asection
*)NULL
));
732 if (c
< 32 || c
> 126)
741 fputs_unfiltered (buff
, gdb_stdout
);
748 /* This implements the TCL command `gdb_sourcelines', which returns a list of
749 all of the lines containing executable code for the specified source file
750 (ie: lines where you can put breakpoints). */
753 gdb_sourcelines (clientData
, interp
, argc
, argv
)
754 ClientData clientData
;
759 struct symtab
*symtab
;
760 struct linetable_entry
*le
;
764 error ("wrong # args");
766 symtab
= lookup_symtab (argv
[1]);
769 error ("No such file");
771 /* If there's no linetable, or no entries, then we are done. */
773 if (!symtab
->linetable
774 || symtab
->linetable
->nitems
== 0)
776 Tcl_DStringAppendElement (result_ptr
, "");
780 le
= symtab
->linetable
->item
;
781 nlines
= symtab
->linetable
->nitems
;
783 for (;nlines
> 0; nlines
--, le
++)
785 /* If the pc of this line is the same as the pc of the next line, then
788 && le
->pc
== (le
+ 1)->pc
)
791 dsprintf_append_element (result_ptr
, "%d", le
->line
);
798 map_arg_registers (argc
, argv
, func
, argp
)
801 void (*func
) PARAMS ((int regnum
, void *argp
));
806 /* Note that the test for a valid register must include checking the
807 reg_names array because NUM_REGS may be allocated for the union of the
808 register sets within a family of related processors. In this case, the
809 trailing entries of reg_names will change depending upon the particular
810 processor being debugged. */
812 if (argc
== 0) /* No args, just do all the regs */
816 && reg_names
[regnum
] != NULL
817 && *reg_names
[regnum
] != '\000';
824 /* Else, list of register #s, just do listed regs */
825 for (; argc
> 0; argc
--, argv
++)
827 regnum
= atoi (*argv
);
831 && reg_names
[regnum
] != NULL
832 && *reg_names
[regnum
] != '\000')
835 error ("bad register number");
842 get_register_name (regnum
, argp
)
844 void *argp
; /* Ignored */
846 Tcl_DStringAppendElement (result_ptr
, reg_names
[regnum
]);
849 /* This implements the TCL command `gdb_regnames', which returns a list of
850 all of the register names. */
853 gdb_regnames (clientData
, interp
, argc
, argv
)
854 ClientData clientData
;
862 return map_arg_registers (argc
, argv
, get_register_name
, NULL
);
865 #ifndef REGISTER_CONVERTIBLE
866 #define REGISTER_CONVERTIBLE(x) (0 != 0)
869 #ifndef REGISTER_CONVERT_TO_VIRTUAL
870 #define REGISTER_CONVERT_TO_VIRTUAL(x, y, z, a)
873 #ifndef INVALID_FLOAT
874 #define INVALID_FLOAT(x, y) (0 != 0)
878 get_register (regnum
, fp
)
882 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
883 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
884 int format
= (int)fp
;
886 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
888 Tcl_DStringAppendElement (result_ptr
, "Optimized out");
892 /* Convert raw data to virtual format if necessary. */
894 if (REGISTER_CONVERTIBLE (regnum
))
896 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
897 raw_buffer
, virtual_buffer
);
900 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
905 printf_filtered ("0x");
906 for (j
= 0; j
< REGISTER_RAW_SIZE (regnum
); j
++)
908 register int idx
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? j
909 : REGISTER_RAW_SIZE (regnum
) - 1 - j
;
910 printf_filtered ("%02x", (unsigned char)raw_buffer
[idx
]);
914 val_print (REGISTER_VIRTUAL_TYPE (regnum
), virtual_buffer
, 0,
915 gdb_stdout
, format
, 1, 0, Val_pretty_default
);
917 Tcl_DStringAppend (result_ptr
, " ", -1);
921 gdb_fetch_registers (clientData
, interp
, argc
, argv
)
922 ClientData clientData
;
930 error ("wrong # args");
938 return map_arg_registers (argc
, argv
, get_register
, (void *) format
);
941 /* This contains the previous values of the registers, since the last call to
942 gdb_changed_register_list. */
944 static char old_regs
[REGISTER_BYTES
];
947 register_changed_p (regnum
, argp
)
949 void *argp
; /* Ignored */
951 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
953 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
956 if (memcmp (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
957 REGISTER_RAW_SIZE (regnum
)) == 0)
960 /* Found a changed register. Save new value and return its number. */
962 memcpy (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
963 REGISTER_RAW_SIZE (regnum
));
965 dsprintf_append_element (result_ptr
, "%d", regnum
);
969 gdb_changed_register_list (clientData
, interp
, argc
, argv
)
970 ClientData clientData
;
978 return map_arg_registers (argc
, argv
, register_changed_p
, NULL
);
981 /* This implements the tcl command "gdb_immediate", which does exactly
982 the same thing as gdb_cmd, except NONE of its outut is buffered. */
984 gdb_immediate_command (clientData
, interp
, argc
, argv
)
985 ClientData clientData
;
990 Tcl_DString
*save_ptr
= NULL
;
993 error ("wrong # args");
998 Tcl_DStringAppend (result_ptr
, "", -1);
999 save_ptr
= result_ptr
;
1002 execute_command (argv
[1], 1);
1004 bpstat_do_actions (&stop_bpstat
);
1006 result_ptr
= save_ptr
;
1011 /* This implements the TCL command `gdb_cmd', which sends its argument into
1012 the GDB command scanner. */
1015 gdb_cmd (clientData
, interp
, argc
, argv
)
1016 ClientData clientData
;
1021 Tcl_DString
*save_ptr
= NULL
;
1024 error ("wrong # args");
1029 /* for the load instruction (and possibly others later) we
1030 set result_ptr to NULL so gdbtk_fputs() will not buffer
1031 all the data until the command is finished. */
1033 if (strncmp ("load ", argv
[1], 5) == 0
1034 || strncmp ("while ", argv
[1], 6) == 0)
1036 Tcl_DStringAppend (result_ptr
, "", -1);
1037 save_ptr
= result_ptr
;
1041 execute_command (argv
[1], 1);
1043 bpstat_do_actions (&stop_bpstat
);
1046 result_ptr
= save_ptr
;
1051 /* Client of call_wrapper - this routine performs the actual call to
1052 the client function. */
1054 struct wrapped_call_args
1065 struct wrapped_call_args
*args
;
1067 args
->val
= (*args
->func
) (args
->func
, args
->interp
, args
->argc
, args
->argv
);
1071 /* This routine acts as a top-level for all GDB code called by tcl/Tk. It
1072 handles cleanups, and calls to return_to_top_level (usually via error).
1073 This is necessary in order to prevent a longjmp out of the bowels of Tk,
1074 possibly leaving things in a bad state. Since this routine can be called
1075 recursively, it needs to save and restore the contents of the jmp_buf as
1079 call_wrapper (clientData
, interp
, argc
, argv
)
1080 ClientData clientData
;
1085 struct wrapped_call_args wrapped_args
;
1086 Tcl_DString result
, *old_result_ptr
;
1087 Tcl_DString error_string
, *old_error_string_ptr
;
1089 Tcl_DStringInit (&result
);
1090 old_result_ptr
= result_ptr
;
1091 result_ptr
= &result
;
1093 Tcl_DStringInit (&error_string
);
1094 old_error_string_ptr
= error_string_ptr
;
1095 error_string_ptr
= &error_string
;
1097 wrapped_args
.func
= (Tcl_CmdProc
*)clientData
;
1098 wrapped_args
.interp
= interp
;
1099 wrapped_args
.argc
= argc
;
1100 wrapped_args
.argv
= argv
;
1101 wrapped_args
.val
= 0;
1103 if (!catch_errors (wrapped_call
, &wrapped_args
, "", RETURN_MASK_ALL
))
1105 wrapped_args
.val
= TCL_ERROR
; /* Flag an error for TCL */
1107 gdb_flush (gdb_stderr
); /* Flush error output */
1109 gdb_flush (gdb_stdout
); /* Sometimes error output comes here as well */
1111 /* In case of an error, we may need to force the GUI into idle
1112 mode because gdbtk_call_command may have bombed out while in
1113 the command routine. */
1116 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1119 if (Tcl_DStringLength (&error_string
) == 0)
1121 Tcl_DStringResult (interp
, &result
);
1122 Tcl_DStringFree (&error_string
);
1124 else if (Tcl_DStringLength (&result
) == 0)
1126 Tcl_DStringResult (interp
, &error_string
);
1127 Tcl_DStringFree (&result
);
1131 Tcl_ResetResult (interp
);
1132 Tcl_AppendResult (interp
, Tcl_DStringValue (&result
),
1133 Tcl_DStringValue (&error_string
), (char *) NULL
);
1134 Tcl_DStringFree (&result
);
1135 Tcl_DStringFree (&error_string
);
1138 result_ptr
= old_result_ptr
;
1139 error_string_ptr
= old_error_string_ptr
;
1145 return wrapped_args
.val
;
1149 gdb_listfiles (clientData
, interp
, argc
, argv
)
1150 ClientData clientData
;
1155 struct objfile
*objfile
;
1156 struct partial_symtab
*psymtab
;
1157 struct symtab
*symtab
;
1159 ALL_PSYMTABS (objfile
, psymtab
)
1160 Tcl_DStringAppendElement (result_ptr
, psymtab
->filename
);
1162 ALL_SYMTABS (objfile
, symtab
)
1163 Tcl_DStringAppendElement (result_ptr
, symtab
->filename
);
1169 gdb_listfuncs (clientData
, interp
, argc
, argv
)
1170 ClientData clientData
;
1175 struct symtab
*symtab
;
1176 struct blockvector
*bv
;
1182 error ("wrong # args");
1184 symtab
= lookup_symtab (argv
[1]);
1187 error ("No such file");
1189 bv
= BLOCKVECTOR (symtab
);
1190 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
1192 b
= BLOCKVECTOR_BLOCK (bv
, i
);
1193 /* Skip the sort if this block is always sorted. */
1194 if (!BLOCK_SHOULD_SORT (b
))
1195 sort_block_syms (b
);
1196 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
1198 sym
= BLOCK_SYM (b
, j
);
1199 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1201 Tcl_DStringAppendElement (result_ptr
, SYMBOL_NAME(sym
));
1209 gdb_stop (clientData
, interp
, argc
, argv
)
1210 ClientData clientData
;
1218 quit_flag
= 1; /* hope something sees this */
1223 /* Prepare to accept a new executable file. This is called when we
1224 want to clear away everything we know about the old file, without
1225 asking the user. The Tcl code will have already asked the user if
1226 necessary. After this is called, we should be able to run the
1227 `file' command without getting any questions. */
1230 gdb_clear_file (clientData
, interp
, argc
, argv
)
1231 ClientData clientData
;
1236 if (inferior_pid
!= 0 && target_has_execution
)
1239 target_detach (NULL
, 0);
1244 if (target_has_execution
)
1247 symbol_file_command (NULL
, 0);
1252 /* Ask the user to confirm an exit request. */
1255 gdb_confirm_quit (clientData
, interp
, argc
, argv
)
1256 ClientData clientData
;
1263 ret
= quit_confirm ();
1264 Tcl_DStringAppendElement (result_ptr
, ret
? "1" : "0");
1268 /* Quit without asking for confirmation. */
1271 gdb_force_quit (clientData
, interp
, argc
, argv
)
1272 ClientData clientData
;
1277 quit_force ((char *) NULL
, 1);
1281 /* This implements the TCL command `gdb_disassemble'. */
1284 gdbtk_dis_asm_read_memory (memaddr
, myaddr
, len
, info
)
1288 disassemble_info
*info
;
1290 extern struct target_ops exec_ops
;
1294 res
= xfer_memory (memaddr
, myaddr
, len
, 0, &exec_ops
);
1305 /* We need a different sort of line table from the normal one cuz we can't
1306 depend upon implicit line-end pc's for lines. This is because of the
1307 reordering we are about to do. */
1309 struct my_line_entry
{
1316 compare_lines (mle1p
, mle2p
)
1320 struct my_line_entry
*mle1
, *mle2
;
1323 mle1
= (struct my_line_entry
*) mle1p
;
1324 mle2
= (struct my_line_entry
*) mle2p
;
1326 val
= mle1
->line
- mle2
->line
;
1331 return mle1
->start_pc
- mle2
->start_pc
;
1335 gdb_disassemble (clientData
, interp
, argc
, argv
)
1336 ClientData clientData
;
1341 CORE_ADDR pc
, low
, high
;
1342 int mixed_source_and_assembly
;
1343 static disassemble_info di
;
1344 static int di_initialized
;
1346 if (! di_initialized
)
1348 INIT_DISASSEMBLE_INFO_NO_ARCH (di
, gdb_stdout
,
1349 (fprintf_ftype
) fprintf_unfiltered
);
1350 di
.flavour
= bfd_target_unknown_flavour
;
1351 di
.memory_error_func
= dis_asm_memory_error
;
1352 di
.print_address_func
= dis_asm_print_address
;
1356 di
.mach
= tm_print_insn_info
.mach
;
1357 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1358 di
.endian
= BFD_ENDIAN_BIG
;
1360 di
.endian
= BFD_ENDIAN_LITTLE
;
1362 if (argc
!= 3 && argc
!= 4)
1363 error ("wrong # args");
1365 if (strcmp (argv
[1], "source") == 0)
1366 mixed_source_and_assembly
= 1;
1367 else if (strcmp (argv
[1], "nosource") == 0)
1368 mixed_source_and_assembly
= 0;
1370 error ("First arg must be 'source' or 'nosource'");
1372 low
= parse_and_eval_address (argv
[2]);
1376 if (find_pc_partial_function (low
, NULL
, &low
, &high
) == 0)
1377 error ("No function contains specified address");
1380 high
= parse_and_eval_address (argv
[3]);
1382 /* If disassemble_from_exec == -1, then we use the following heuristic to
1383 determine whether or not to do disassembly from target memory or from the
1386 If we're debugging a local process, read target memory, instead of the
1387 exec file. This makes disassembly of functions in shared libs work
1390 Else, we're debugging a remote process, and should disassemble from the
1391 exec file for speed. However, this is no good if the target modifies its
1392 code (for relocation, or whatever).
1395 if (disassemble_from_exec
== -1)
1396 if (strcmp (target_shortname
, "child") == 0
1397 || strcmp (target_shortname
, "procfs") == 0
1398 || strcmp (target_shortname
, "vxprocess") == 0)
1399 disassemble_from_exec
= 0; /* It's a child process, read inferior mem */
1401 disassemble_from_exec
= 1; /* It's remote, read the exec file */
1403 if (disassemble_from_exec
)
1404 di
.read_memory_func
= gdbtk_dis_asm_read_memory
;
1406 di
.read_memory_func
= dis_asm_read_memory
;
1408 /* If just doing straight assembly, all we need to do is disassemble
1409 everything between low and high. If doing mixed source/assembly, we've
1410 got a totally different path to follow. */
1412 if (mixed_source_and_assembly
)
1413 { /* Come here for mixed source/assembly */
1414 /* The idea here is to present a source-O-centric view of a function to
1415 the user. This means that things are presented in source order, with
1416 (possibly) out of order assembly immediately following. */
1417 struct symtab
*symtab
;
1418 struct linetable_entry
*le
;
1421 struct my_line_entry
*mle
;
1422 struct symtab_and_line sal
;
1427 symtab
= find_pc_symtab (low
); /* Assume symtab is valid for whole PC range */
1432 /* First, convert the linetable to a bunch of my_line_entry's. */
1434 le
= symtab
->linetable
->item
;
1435 nlines
= symtab
->linetable
->nitems
;
1440 mle
= (struct my_line_entry
*) alloca (nlines
* sizeof (struct my_line_entry
));
1444 /* Copy linetable entries for this function into our data structure, creating
1445 end_pc's and setting out_of_order as appropriate. */
1447 /* First, skip all the preceding functions. */
1449 for (i
= 0; i
< nlines
- 1 && le
[i
].pc
< low
; i
++) ;
1451 /* Now, copy all entries before the end of this function. */
1454 for (; i
< nlines
- 1 && le
[i
].pc
< high
; i
++)
1456 if (le
[i
].line
== le
[i
+ 1].line
1457 && le
[i
].pc
== le
[i
+ 1].pc
)
1458 continue; /* Ignore duplicates */
1460 mle
[newlines
].line
= le
[i
].line
;
1461 if (le
[i
].line
> le
[i
+ 1].line
)
1463 mle
[newlines
].start_pc
= le
[i
].pc
;
1464 mle
[newlines
].end_pc
= le
[i
+ 1].pc
;
1468 /* If we're on the last line, and it's part of the function, then we need to
1469 get the end pc in a special way. */
1474 mle
[newlines
].line
= le
[i
].line
;
1475 mle
[newlines
].start_pc
= le
[i
].pc
;
1476 sal
= find_pc_line (le
[i
].pc
, 0);
1477 mle
[newlines
].end_pc
= sal
.end
;
1481 /* Now, sort mle by line #s (and, then by addresses within lines). */
1484 qsort (mle
, newlines
, sizeof (struct my_line_entry
), compare_lines
);
1486 /* Now, for each line entry, emit the specified lines (unless they have been
1487 emitted before), followed by the assembly code for that line. */
1489 next_line
= 0; /* Force out first line */
1490 for (i
= 0; i
< newlines
; i
++)
1492 /* Print out everything from next_line to the current line. */
1494 if (mle
[i
].line
>= next_line
)
1497 print_source_lines (symtab
, next_line
, mle
[i
].line
+ 1, 0);
1499 print_source_lines (symtab
, mle
[i
].line
, mle
[i
].line
+ 1, 0);
1501 next_line
= mle
[i
].line
+ 1;
1504 for (pc
= mle
[i
].start_pc
; pc
< mle
[i
].end_pc
; )
1507 fputs_unfiltered (" ", gdb_stdout
);
1508 print_address (pc
, gdb_stdout
);
1509 fputs_unfiltered (":\t ", gdb_stdout
);
1510 pc
+= (*tm_print_insn
) (pc
, &di
);
1511 fputs_unfiltered ("\n", gdb_stdout
);
1518 for (pc
= low
; pc
< high
; )
1521 fputs_unfiltered (" ", gdb_stdout
);
1522 print_address (pc
, gdb_stdout
);
1523 fputs_unfiltered (":\t ", gdb_stdout
);
1524 pc
+= (*tm_print_insn
) (pc
, &di
);
1525 fputs_unfiltered ("\n", gdb_stdout
);
1529 gdb_flush (gdb_stdout
);
1535 tk_command (cmd
, from_tty
)
1541 struct cleanup
*old_chain
;
1543 /* Catch case of no argument, since this will make the tcl interpreter dump core. */
1545 error_no_arg ("tcl command to interpret");
1547 retval
= Tcl_Eval (interp
, cmd
);
1549 result
= strdup (interp
->result
);
1551 old_chain
= make_cleanup (free
, result
);
1553 if (retval
!= TCL_OK
)
1556 printf_unfiltered ("%s\n", result
);
1558 do_cleanups (old_chain
);
1562 cleanup_init (ignored
)
1566 Tcl_DeleteInterp (interp
);
1570 /* Come here during long calculations to check for GUI events. Usually invoked
1571 via the QUIT macro. */
1574 gdbtk_interactive ()
1576 /* Tk_DoOneEvent (TK_DONT_WAIT|TK_IDLE_EVENTS); */
1579 /* Come here when there is activity on the X file descriptor. */
1585 /* Process pending events */
1587 while (Tcl_DoOneEvent (TCL_DONT_WAIT
|TCL_ALL_EVENTS
) != 0);
1592 /* For Cygwin32, we use a timer to periodically check for Windows
1593 messages. FIXME: It would be better to not poll, but to instead
1594 rewrite the target_wait routines to serve as input sources.
1595 Unfortunately, that will be a lot of work. */
1598 gdbtk_start_timer ()
1600 sigset_t nullsigmask
;
1601 struct sigaction action
;
1602 struct itimerval it
;
1604 sigemptyset (&nullsigmask
);
1606 action
.sa_handler
= x_event
;
1607 action
.sa_mask
= nullsigmask
;
1608 action
.sa_flags
= 0;
1609 sigaction (SIGALRM
, &action
, NULL
);
1611 it
.it_interval
.tv_sec
= 0;
1612 /* Check for messages twice a second. */
1613 it
.it_interval
.tv_usec
= 500 * 1000;
1614 it
.it_value
.tv_sec
= 0;
1615 it
.it_value
.tv_usec
= 500 * 1000;
1617 setitimer (ITIMER_REAL
, &it
, NULL
);
1623 sigset_t nullsigmask
;
1624 struct sigaction action
;
1625 struct itimerval it
;
1627 sigemptyset (&nullsigmask
);
1629 action
.sa_handler
= SIG_IGN
;
1630 action
.sa_mask
= nullsigmask
;
1631 action
.sa_flags
= 0;
1632 sigaction (SIGALRM
, &action
, NULL
);
1634 it
.it_interval
.tv_sec
= 0;
1635 it
.it_interval
.tv_usec
= 0;
1636 it
.it_value
.tv_sec
= 0;
1637 it
.it_value
.tv_usec
= 0;
1638 setitimer (ITIMER_REAL
, &it
, NULL
);
1643 /* This hook function is called whenever we want to wait for the
1647 gdbtk_wait (pid
, ourstatus
)
1649 struct target_waitstatus
*ourstatus
;
1652 struct sigaction action
;
1653 static sigset_t nullsigmask
= {0};
1657 /* Needed for SunOS 4.1.x */
1658 #define SA_RESTART 0
1661 action
.sa_handler
= x_event
;
1662 action
.sa_mask
= nullsigmask
;
1663 action
.sa_flags
= SA_RESTART
;
1664 sigaction(SIGIO
, &action
, NULL
);
1668 gdbtk_start_timer ();
1671 pid
= target_wait (pid
, ourstatus
);
1674 gdbtk_stop_timer ();
1678 action
.sa_handler
= SIG_IGN
;
1679 sigaction(SIGIO
, &action
, NULL
);
1685 /* This is called from execute_command, and provides a wrapper around
1686 various command routines in a place where both protocol messages and
1687 user input both flow through. Mostly this is used for indicating whether
1688 the target process is running or not.
1692 gdbtk_call_command (cmdblk
, arg
, from_tty
)
1693 struct cmd_list_element
*cmdblk
;
1698 if (cmdblk
->class == class_run
|| cmdblk
->class == class_trace
)
1701 Tcl_Eval (interp
, "gdbtk_tcl_busy");
1702 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1704 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1707 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1710 /* This function is called instead of gdb's internal command loop. This is the
1711 last chance to do anything before entering the main Tk event loop. */
1716 extern GDB_FILE
*instream
;
1718 /* We no longer want to use stdin as the command input stream */
1721 if (Tcl_Eval (interp
, "gdbtk_tcl_preloop") != TCL_OK
)
1725 /* Force errorInfo to be set up propertly. */
1726 Tcl_AddErrorInfo (interp
, "");
1728 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
1730 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
1732 fputs_unfiltered (msg
, gdb_stderr
);
1743 /* gdbtk_init installs this function as a final cleanup. */
1746 gdbtk_cleanup (dummy
)
1752 /* Initialize gdbtk. */
1755 gdbtk_init ( argv0
)
1758 struct cleanup
*old_chain
;
1759 char *lib
, *gdbtk_lib
, *gdbtk_lib_tmp
, *gdbtk_file
;
1762 struct sigaction action
;
1763 static sigset_t nullsigmask
= {0};
1766 /* start-sanitize-ide */
1767 struct ide_event_handle
*h
;
1770 /* end-sanitize-ide */
1773 /* If there is no DISPLAY environment variable, Tk_Init below will fail,
1774 causing gdb to abort. If instead we simply return here, gdb will
1775 gracefully degrade to using the command line interface. */
1778 if (getenv ("DISPLAY") == NULL
)
1782 old_chain
= make_cleanup (cleanup_init
, 0);
1784 /* First init tcl and tk. */
1785 Tcl_FindExecutable (argv0
);
1786 interp
= Tcl_CreateInterp ();
1789 error ("Tcl_CreateInterp failed");
1791 if (Tcl_Init(interp
) != TCL_OK
)
1792 error ("Tcl_Init failed: %s", interp
->result
);
1794 make_final_cleanup (gdbtk_cleanup
, NULL
);
1796 /* Initialize the Paths variable. */
1797 if (ide_initialize_paths (interp
, "gdbtcl") != TCL_OK
)
1798 error ("ide_initialize_paths failed: %s", interp
->result
);
1801 /* start-sanitize-ide */
1802 /* Find the directory where we expect to find idemanager. We ignore
1803 errors since it doesn't really matter if this fails. */
1804 libexecdir
= Tcl_GetVar2 (interp
, "Paths", "libexecdir", TCL_GLOBAL_ONLY
);
1808 h
= ide_event_init_from_environment (&errmsg
, libexecdir
);
1811 Tcl_AppendResult (interp
, "can't initialize event system: ", errmsg
,
1813 fprintf(stderr
, "WARNING: ide_event_init_client failed: %s\n", interp
->result
);
1815 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1819 if (ide_create_tclevent_command (interp
, h
) != TCL_OK
)
1820 error ("ide_create_tclevent_command failed: %s", interp
->result
);
1822 if (ide_create_edit_command (interp
, h
) != TCL_OK
)
1823 error ("ide_create_edit_command failed: %s", interp
->result
);
1825 if (ide_create_property_command (interp
, h
) != TCL_OK
)
1826 error ("ide_create_property_command failed: %s", interp
->result
);
1828 if (ide_create_build_command (interp
, h
) != TCL_OK
)
1829 error ("ide_create_build_command failed: %s", interp
->result
);
1831 if (ide_create_window_register_command (interp
, h
, "gdb-restore")
1833 error ("ide_create_window_register_command failed: %s",
1836 if (ide_create_window_command (interp
, h
) != TCL_OK
)
1837 error ("ide_create_window_command failed: %s", interp
->result
);
1839 if (ide_create_exit_command (interp
, h
) != TCL_OK
)
1840 error ("ide_create_exit_command failed: %s", interp
->result
);
1842 if (ide_create_help_command (interp
) != TCL_OK
)
1843 error ("ide_create_help_command failed: %s", interp
->result
);
1846 if (ide_initialize (interp, "gdb") != TCL_OK)
1847 error ("ide_initialize failed: %s", interp->result);
1850 Tcl_SetVar (interp
, "GDBTK_IDE", "1", 0);
1851 Tcl_SetVar (interp
, "IDE", "1", TCL_GLOBAL_ONLY
);
1853 /* end-sanitize-ide */
1855 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1858 /* We don't want to open the X connection until we've done all the
1859 IDE initialization. Otherwise, goofy looking unfinished windows
1860 pop up when ILU drops into the TCL event loop. */
1862 if (Tk_Init(interp
) != TCL_OK
)
1863 error ("Tk_Init failed: %s", interp
->result
);
1865 if (Itcl_Init(interp
) == TCL_ERROR
)
1866 error ("Itcl_Init failed: %s", interp
->result
);
1868 if (Tix_Init(interp
) != TCL_OK
)
1869 error ("Tix_Init failed: %s", interp
->result
);
1872 /* On Windows, create a sizebox widget command */
1873 if (ide_create_sizebox_command (interp
) != TCL_OK
)
1874 error ("sizebox creation failed");
1875 if (ide_create_winprint_command (interp
) != TCL_OK
)
1876 error ("windows print code initialization failed");
1877 /* start-sanitize-ide */
1878 /* An interface to ShellExecute. */
1879 if (ide_create_shell_execute_command (interp
) != TCL_OK
)
1880 error ("shell execute command initialization failed");
1881 /* end-sanitize-ide */
1884 Tcl_CreateCommand (interp
, "gdb_cmd", call_wrapper
, gdb_cmd
, NULL
);
1885 Tcl_CreateCommand (interp
, "gdb_immediate", call_wrapper
,
1886 gdb_immediate_command
, NULL
);
1887 Tcl_CreateCommand (interp
, "gdb_loc", call_wrapper
, gdb_loc
, NULL
);
1888 Tcl_CreateCommand (interp
, "gdb_path_conv", call_wrapper
, gdb_path_conv
, NULL
);
1889 Tcl_CreateCommand (interp
, "gdb_sourcelines", call_wrapper
, gdb_sourcelines
,
1891 Tcl_CreateCommand (interp
, "gdb_listfiles", call_wrapper
, gdb_listfiles
,
1893 Tcl_CreateCommand (interp
, "gdb_listfuncs", call_wrapper
, gdb_listfuncs
,
1895 Tcl_CreateCommand (interp
, "gdb_get_mem", call_wrapper
, gdb_get_mem
,
1897 Tcl_CreateCommand (interp
, "gdb_stop", call_wrapper
, gdb_stop
, NULL
);
1898 Tcl_CreateCommand (interp
, "gdb_regnames", call_wrapper
, gdb_regnames
, NULL
);
1899 Tcl_CreateCommand (interp
, "gdb_fetch_registers", call_wrapper
,
1900 gdb_fetch_registers
, NULL
);
1901 Tcl_CreateCommand (interp
, "gdb_changed_register_list", call_wrapper
,
1902 gdb_changed_register_list
, NULL
);
1903 Tcl_CreateCommand (interp
, "gdb_disassemble", call_wrapper
,
1904 gdb_disassemble
, NULL
);
1905 Tcl_CreateCommand (interp
, "gdb_eval", call_wrapper
, gdb_eval
, NULL
);
1906 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_list", call_wrapper
,
1907 gdb_get_breakpoint_list
, NULL
);
1908 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_info", call_wrapper
,
1909 gdb_get_breakpoint_info
, NULL
);
1910 Tcl_CreateCommand (interp
, "gdb_clear_file", call_wrapper
,
1911 gdb_clear_file
, NULL
);
1912 Tcl_CreateCommand (interp
, "gdb_confirm_quit", call_wrapper
,
1913 gdb_confirm_quit
, NULL
);
1914 Tcl_CreateCommand (interp
, "gdb_force_quit", call_wrapper
,
1915 gdb_force_quit
, NULL
);
1916 Tcl_CreateCommand (interp
, "gdb_target_has_execution",
1917 gdb_target_has_execution_command
,
1919 Tcl_CreateObjCommand (interp
, "gdb_load_info", gdb_load_info
, NULL
, NULL
);
1920 Tcl_CreateObjCommand (interp
, "gdb_get_locals", gdb_get_vars_command
,
1921 (ClientData
) 0, NULL
);
1922 Tcl_CreateObjCommand (interp
, "gdb_get_args", gdb_get_vars_command
,
1923 (ClientData
) 1, NULL
);
1924 Tcl_CreateObjCommand (interp
, "gdb_get_function", gdb_get_function_command
,
1926 Tcl_CreateObjCommand (interp
, "gdb_get_line", gdb_get_line_command
,
1928 Tcl_CreateObjCommand (interp
, "gdb_get_file", gdb_get_file_command
,
1930 Tcl_CreateObjCommand (interp
, "gdb_tracepoint_exists",
1931 gdb_tracepoint_exists_command
, NULL
, NULL
);
1932 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_info",
1933 gdb_get_tracepoint_info
, NULL
, NULL
);
1934 Tcl_CreateObjCommand (interp
, "gdb_actions",
1935 gdb_actions_command
, NULL
, NULL
);
1936 Tcl_CreateObjCommand (interp
, "gdb_prompt",
1937 gdb_prompt_command
, NULL
, NULL
);
1938 Tcl_CreateObjCommand (interp
, "gdb_find_file",
1939 gdb_find_file_command
, NULL
, NULL
);
1940 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_list",
1941 gdb_get_tracepoint_list
, NULL
, NULL
);
1943 command_loop_hook
= tk_command_loop
;
1944 print_frame_info_listing_hook
=
1945 (void (*) PARAMS ((struct symtab
*, int, int, int))) null_routine
;
1946 query_hook
= gdbtk_query
;
1947 flush_hook
= gdbtk_flush
;
1948 create_breakpoint_hook
= gdbtk_create_breakpoint
;
1949 delete_breakpoint_hook
= gdbtk_delete_breakpoint
;
1950 modify_breakpoint_hook
= gdbtk_modify_breakpoint
;
1951 interactive_hook
= gdbtk_interactive
;
1952 target_wait_hook
= gdbtk_wait
;
1953 call_command_hook
= gdbtk_call_command
;
1954 readline_begin_hook
= gdbtk_readline_begin
;
1955 readline_hook
= gdbtk_readline
;
1956 readline_end_hook
= gdbtk_readline_end
;
1957 ui_load_progress_hook
= gdbtk_load_hash
;
1958 create_tracepoint_hook
= gdbtk_create_tracepoint
;
1959 delete_tracepoint_hook
= gdbtk_delete_tracepoint
;
1962 /* Get the file descriptor for the X server */
1964 x_fd
= ConnectionNumber (Tk_Display (Tk_MainWindow (interp
)));
1966 /* Setup for I/O interrupts */
1968 action
.sa_mask
= nullsigmask
;
1969 action
.sa_flags
= 0;
1970 action
.sa_handler
= SIG_IGN
;
1971 sigaction(SIGIO
, &action
, NULL
);
1975 if (ioctl (x_fd
, FIOASYNC
, &i
))
1976 perror_with_name ("gdbtk_init: ioctl FIOASYNC failed");
1980 if (ioctl (x_fd
, SIOCSPGRP
, &i
))
1981 perror_with_name ("gdbtk_init: ioctl SIOCSPGRP failed");
1986 if (fcntl (x_fd
, F_SETOWN
, i
))
1987 perror_with_name ("gdbtk_init: fcntl F_SETOWN failed");
1988 #endif /* F_SETOWN */
1989 #endif /* !SIOCSPGRP */
1992 if (ioctl (x_fd
, I_SETSIG
, S_INPUT
|S_RDNORM
) < 0)
1993 perror_with_name ("gdbtk_init: ioctl I_SETSIG failed");
1996 #endif /* ifndef FIOASYNC */
1999 add_com ("tk", class_obscure
, tk_command
,
2000 "Send a command directly into tk.");
2002 Tcl_LinkVar (interp
, "disassemble-from-exec", (char *)&disassemble_from_exec
,
2005 /* find the gdb tcl library and source main.tcl */
2007 gdbtk_lib
= getenv ("GDBTK_LIBRARY");
2009 if (access ("gdbtcl/main.tcl", R_OK
) == 0)
2010 gdbtk_lib
= "gdbtcl";
2012 gdbtk_lib
= GDBTK_LIBRARY
;
2014 gdbtk_lib_tmp
= xstrdup (gdbtk_lib
);
2017 /* see if GDBTK_LIBRARY is a path list */
2018 lib
= strtok (gdbtk_lib_tmp
, GDBTK_PATH_SEP
);
2021 if (Tcl_VarEval (interp
, "lappend auto_path ", lib
, NULL
) != TCL_OK
)
2023 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
2028 gdbtk_file
= concat (lib
, "/main.tcl", (char *) NULL
);
2029 if (access (gdbtk_file
, R_OK
) == 0)
2032 Tcl_SetVar (interp
, "GDBTK_LIBRARY", lib
, 0);
2036 while ((lib
= strtok (NULL
, ":")) != NULL
);
2038 free (gdbtk_lib_tmp
);
2042 /* Try finding it with the auto path. */
2044 static const char script
[] ="\
2045 proc gdbtk_find_main {} {\n\
2046 global auto_path GDBTK_LIBRARY\n\
2047 foreach dir $auto_path {\n\
2048 set f [file join $dir main.tcl]\n\
2049 if {[file exists $f]} then {\n\
2050 set GDBTK_LIBRARY $dir\n\
2058 if (Tcl_GlobalEval (interp
, (char *) script
) != TCL_OK
)
2060 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
2064 if (interp
->result
[0] != '\0')
2066 gdbtk_file
= xstrdup (interp
->result
);
2073 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2074 if (getenv("GDBTK_LIBRARY"))
2076 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n",getenv("GDBTK_LIBRARY"));
2077 fprintf_unfiltered (stderr
,
2078 "Please set GDBTK_LIBRARY to a path that includes the GDB tcl files.\n");
2082 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n", GDBTK_LIBRARY
);
2083 fprintf_unfiltered (stderr
, "You might want to set GDBTK_LIBRARY\n");
2088 /* Defer setup of fputs_unfiltered_hook to near the end so that error messages
2089 prior to this point go to stdout/stderr. */
2091 fputs_unfiltered_hook
= gdbtk_fputs
;
2093 if (Tcl_EvalFile (interp
, gdbtk_file
) != TCL_OK
)
2097 /* Force errorInfo to be set up propertly. */
2098 Tcl_AddErrorInfo (interp
, "");
2100 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
2102 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2105 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
2107 fputs_unfiltered (msg
, gdb_stderr
);
2114 /* start-sanitize-ide */
2115 /* Don't do this until we have initialized. Otherwise, we may get a
2116 run command before we are ready for one. */
2117 if (ide_run_server_init (interp
, h
) != TCL_OK
)
2118 error ("ide_run_server_init failed: %s", interp
->result
);
2119 /* end-sanitize-ide */
2124 discard_cleanups (old_chain
);
2128 gdb_target_has_execution_command (clientData
, interp
, argc
, argv
)
2129 ClientData clientData
;
2136 if (target_has_execution
&& inferior_pid
!= 0)
2139 Tcl_SetIntObj (Tcl_GetObjResult (interp
), result
);
2143 /* gdb_load_info - returns information about the file about to be downloaded */
2146 gdb_load_info (clientData
, interp
, objc
, objv
)
2147 ClientData clientData
;
2150 Tcl_Obj
*CONST objv
[];
2153 struct cleanup
*old_cleanups
;
2159 char *filename
= Tcl_GetStringFromObj (objv
[1], NULL
);
2161 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
2162 if (loadfile_bfd
== NULL
)
2164 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Open failed", -1));
2167 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
2169 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
2171 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Bad Object File", -1));
2175 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
2177 if (s
->flags
& SEC_LOAD
)
2179 bfd_size_type size
= bfd_get_section_size_before_reloc (s
);
2182 ob
[0] = Tcl_NewStringObj((char *)bfd_get_section_name(loadfile_bfd
, s
), -1);
2183 ob
[1] = Tcl_NewLongObj ((long)size
);
2184 res
[i
++] = Tcl_NewListObj (2, ob
);
2189 Tcl_SetObjResult (interp
, Tcl_NewListObj (i
, res
));
2190 do_cleanups (old_cleanups
);
2196 gdbtk_load_hash (section
, num
)
2202 sprintf (buf
, "download_hash %s %ld", section
, num
);
2203 result
= Tcl_Eval (interp
, buf
);
2207 /* gdb_get_vars_command -
2209 * Implements the "gdb_get_locals" and "gdb_get_args" tcl commands. This
2210 * function sets the Tcl interpreter's result to a list of variable names
2211 * depending on clientData. If clientData is one, the result is a list of
2212 * arguments; zero returns a list of locals -- all relative to the block
2213 * specified as an argument to the command. Valid commands include
2214 * anything decode_line_1 can handle (like "main.c:2", "*0x02020202",
2218 gdb_get_vars_command (clientData
, interp
, objc
, objv
)
2219 ClientData clientData
;
2222 Tcl_Obj
*CONST objv
[];
2225 struct symtabs_and_lines sals
;
2227 struct block
*block
;
2228 char **canonical
, *args
;
2229 int i
, nsyms
, arguments
;
2233 Tcl_AppendResult (interp
,
2234 "wrong # of args: should be \"",
2235 Tcl_GetStringFromObj (objv
[0], NULL
),
2236 " function:line|function|line|*addr\"");
2240 arguments
= (int) clientData
;
2241 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2242 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2243 if (sals
.nelts
== 0)
2245 Tcl_AppendResult (interp
,
2246 "error decoding line", NULL
);
2250 /* Initialize a list that will hold the results */
2251 result
= Tcl_NewListObj (0, NULL
);
2253 /* Resolve all line numbers to PC's */
2254 for (i
= 0; i
< sals
.nelts
; i
++)
2255 resolve_sal_pc (&sals
.sals
[i
]);
2257 block
= block_for_pc (sals
.sals
[0].pc
);
2260 nsyms
= BLOCK_NSYMS (block
);
2261 for (i
= 0; i
< nsyms
; i
++)
2263 sym
= BLOCK_SYM (block
, i
);
2264 switch (SYMBOL_CLASS (sym
)) {
2266 case LOC_UNDEF
: /* catches errors */
2267 case LOC_CONST
: /* constant */
2268 case LOC_STATIC
: /* static */
2269 case LOC_REGISTER
: /* register */
2270 case LOC_TYPEDEF
: /* local typedef */
2271 case LOC_LABEL
: /* local label */
2272 case LOC_BLOCK
: /* local function */
2273 case LOC_CONST_BYTES
: /* loc. byte seq. */
2274 case LOC_UNRESOLVED
: /* unresolved static */
2275 case LOC_OPTIMIZED_OUT
: /* optimized out */
2277 case LOC_ARG
: /* argument */
2278 case LOC_REF_ARG
: /* reference arg */
2279 case LOC_REGPARM
: /* register arg */
2280 case LOC_REGPARM_ADDR
: /* indirect register arg */
2281 case LOC_LOCAL_ARG
: /* stack arg */
2282 case LOC_BASEREG_ARG
: /* basereg arg */
2284 Tcl_ListObjAppendElement (interp
, result
,
2285 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2287 case LOC_LOCAL
: /* stack local */
2288 case LOC_BASEREG
: /* basereg local */
2290 Tcl_ListObjAppendElement (interp
, result
,
2291 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2295 if (BLOCK_FUNCTION (block
))
2298 block
= BLOCK_SUPERBLOCK (block
);
2301 Tcl_SetObjResult (interp
, result
);
2306 gdb_get_line_command (clientData
, interp
, objc
, objv
)
2307 ClientData clientData
;
2310 Tcl_Obj
*CONST objv
[];
2313 struct symtabs_and_lines sals
;
2314 char *args
, **canonical
;
2318 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2319 Tcl_GetStringFromObj (objv
[0], NULL
),
2324 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2325 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2326 if (sals
.nelts
== 1)
2328 Tcl_SetObjResult (interp
, Tcl_NewIntObj (sals
.sals
[0].line
));
2332 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2337 gdb_get_file_command (clientData
, interp
, objc
, objv
)
2338 ClientData clientData
;
2341 Tcl_Obj
*CONST objv
[];
2344 struct symtabs_and_lines sals
;
2345 char *args
, **canonical
;
2349 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2350 Tcl_GetStringFromObj (objv
[0], NULL
),
2355 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2356 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2357 if (sals
.nelts
== 1)
2359 Tcl_SetResult (interp
, sals
.sals
[0].symtab
->filename
, TCL_VOLATILE
);
2363 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2368 gdb_get_function_command (clientData
, interp
, objc
, objv
)
2369 ClientData clientData
;
2372 Tcl_Obj
*CONST objv
[];
2376 struct symtabs_and_lines sals
;
2377 char *args
, **canonical
;
2381 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2382 Tcl_GetStringFromObj (objv
[0], NULL
),
2387 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2388 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2389 if (sals
.nelts
== 1)
2391 resolve_sal_pc (&sals
.sals
[0]);
2392 find_pc_partial_function (sals
.sals
[0].pc
, &function
, NULL
, NULL
);
2393 if (function
!= NULL
)
2395 Tcl_SetResult (interp
, function
, TCL_VOLATILE
);
2400 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2405 gdb_get_tracepoint_info (clientData
, interp
, objc
, objv
)
2406 ClientData clientData
;
2409 Tcl_Obj
*CONST objv
[];
2411 struct symtab_and_line sal
;
2413 struct tracepoint
*tp
;
2414 struct action_line
*al
;
2415 Tcl_Obj
*list
, *action_list
;
2416 char *filename
, *funcname
;
2420 error ("wrong # args");
2422 Tcl_GetIntFromObj (NULL
, objv
[1], &tpnum
);
2424 ALL_TRACEPOINTS (tp
)
2425 if (tp
->number
== tpnum
)
2429 error ("Tracepoint #%d does not exist", tpnum
);
2431 list
= Tcl_NewListObj (0, NULL
);
2432 sal
= find_pc_line (tp
->address
, 0);
2433 filename
= symtab_to_filename (sal
.symtab
);
2434 if (filename
== NULL
)
2436 Tcl_ListObjAppendElement (interp
, list
,
2437 Tcl_NewStringObj (filename
, -1));
2438 find_pc_partial_function (tp
->address
, &funcname
, NULL
, NULL
);
2439 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (funcname
, -1));
2440 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (sal
.line
));
2441 sprintf (tmp
, "0x%08x", tp
->address
);
2442 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (tmp
, -1));
2443 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->enabled
));
2444 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->pass_count
));
2445 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->step_count
));
2446 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->thread
));
2447 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->hit_count
));
2449 /* Append a list of actions */
2450 action_list
= Tcl_NewListObj (0, NULL
);
2451 for (al
= tp
->actions
; al
!= NULL
; al
= al
->next
)
2453 Tcl_ListObjAppendElement (interp
, action_list
,
2454 Tcl_NewStringObj (al
->action
, -1));
2456 Tcl_ListObjAppendElement (interp
, list
, action_list
);
2458 Tcl_SetObjResult (interp
, list
);
2463 gdbtk_create_tracepoint (tp
)
2464 struct tracepoint
*tp
;
2466 tracepoint_notify (tp
, "create");
2470 gdbtk_delete_tracepoint (tp
)
2471 struct tracepoint
*tp
;
2473 tracepoint_notify (tp
, "delete");
2477 tracepoint_notify(tp
, action
)
2478 struct tracepoint
*tp
;
2483 struct symtab_and_line sal
;
2486 /* We ensure that ACTION contains no special Tcl characters, so we
2488 sal
= find_pc_line (tp
->address
, 0);
2490 filename
= symtab_to_filename (sal
.symtab
);
2491 if (filename
== NULL
)
2493 sprintf (buf
, "gdbtk_tcl_tracepoint %s %d 0x%lx %d {%s}", action
, tp
->number
,
2494 (long)tp
->address
, sal
.line
, filename
);
2496 v
= Tcl_Eval (interp
, buf
);
2500 gdbtk_fputs (interp
->result
, gdb_stdout
);
2501 gdbtk_fputs ("\n", gdb_stdout
);
2505 /* returns -1 if not found, tracepoint # if found */
2507 tracepoint_exists (char * args
)
2509 struct tracepoint
*tp
;
2511 struct symtabs_and_lines sals
;
2515 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2516 if (sals
.nelts
== 1)
2518 resolve_sal_pc (&sals
.sals
[0]);
2519 file
= xmalloc (strlen (sals
.sals
[0].symtab
->dirname
)
2520 + strlen (sals
.sals
[0].symtab
->filename
) + 1);
2523 strcpy (file
, sals
.sals
[0].symtab
->dirname
);
2524 strcat (file
, sals
.sals
[0].symtab
->filename
);
2526 ALL_TRACEPOINTS (tp
)
2528 if (tp
->address
== sals
.sals
[0].pc
)
2529 result
= tp
->number
;
2530 else if (tp
->source_file
!= NULL
2531 && strcmp (tp
->source_file
, file
) == 0
2532 && sals
.sals
[0].line
== tp
->line_number
)
2534 result
= tp
->number
;
2544 gdb_actions_command (clientData
, interp
, objc
, objv
)
2545 ClientData clientData
;
2548 Tcl_Obj
*CONST objv
[];
2550 struct tracepoint
*tp
;
2552 int nactions
, i
, len
;
2553 char *number
, *args
, *action
;
2555 struct action_line
*next
= NULL
, *temp
;
2559 Tcl_AppendResult (interp
, "wrong # args: should be: \"",
2560 Tcl_GetStringFromObj (objv
[0], NULL
),
2561 " number actions\"");
2565 args
= number
= Tcl_GetStringFromObj (objv
[1], NULL
);
2566 tp
= get_tracepoint_by_number (&args
);
2569 Tcl_AppendResult (interp
, "Tracepoint \"", number
, "\" does not exist");
2573 /* Free any existing actions */
2574 for (temp
= tp
->actions
; temp
!= NULL
; temp
= temp
->next
)
2577 free (temp
->action
);
2582 Tcl_ListObjGetElements (interp
, objv
[2], &nactions
, &actions
);
2583 for (i
= 0; i
< nactions
; i
++)
2585 temp
= xmalloc (sizeof (struct action_line
));
2587 action
= Tcl_GetStringFromObj (actions
[i
], &len
);
2588 temp
->action
= savestring (action
, len
);
2589 if (sscanf (temp
->action
, "while-stepping %d", &step_count
) !=0)
2590 tp
->step_count
= step_count
;
2607 gdb_tracepoint_exists_command (clientData
, interp
, objc
, objv
)
2608 ClientData clientData
;
2611 Tcl_Obj
*CONST objv
[];
2617 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2618 Tcl_GetStringFromObj (objv
[0], NULL
),
2619 " function:line|function|line|*addr\"");
2623 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2625 Tcl_SetObjResult (interp
, Tcl_NewIntObj (tracepoint_exists (args
)));
2629 /* Return the prompt to the interpreter */
2631 gdb_prompt_command (clientData
, interp
, objc
, objv
)
2632 ClientData clientData
;
2635 Tcl_Obj
*CONST objv
[];
2637 Tcl_SetResult (interp
, get_prompt (), TCL_VOLATILE
);
2641 /* return a list of all tracepoint numbers in interpreter */
2643 gdb_get_tracepoint_list (clientData
, interp
, objc
, objv
)
2644 ClientData clientData
;
2647 Tcl_Obj
*CONST objv
[];
2650 struct tracepoint
*tp
;
2652 list
= Tcl_NewListObj (0, NULL
);
2654 ALL_TRACEPOINTS (tp
)
2655 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->number
));
2657 Tcl_SetObjResult (interp
, list
);
2661 /* This is stolen from source.c */
2662 #ifdef CRLF_SOURCE_FILES
2664 /* Define CRLF_SOURCE_FILES in an xm-*.h file if source files on the
2665 host use \r\n rather than just \n. Defining CRLF_SOURCE_FILES is
2666 much faster than defining LSEEK_NOT_LINEAR. */
2672 #define OPEN_MODE (O_RDONLY | O_BINARY)
2674 #else /* ! defined (CRLF_SOURCE_FILES) */
2676 #define OPEN_MODE O_RDONLY
2678 #endif /* ! defined (CRLF_SOURCE_FILES) */
2680 /* Find the pathname to a file, searching the source_dir */
2681 /* we may actually need to use openp to find the the full pathname
2682 so we don't have any "../" et al in it. */
2684 gdb_find_file_command (clientData
, interp
, objc
, objv
)
2685 ClientData clientData
;
2688 Tcl_Obj
*CONST objv
[];
2690 char *file
, *filename
;
2691 struct symtab
*st
= NULL
;
2695 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2696 Tcl_GetStringFromObj (objv
[0], NULL
),
2701 /* try something simple first */
2702 file
= Tcl_GetStringFromObj (objv
[1], NULL
);
2703 if (access (file
, R_OK
) == 0)
2705 Tcl_SetObjResult (interp
, Tcl_NewStringObj (file
, -1));
2709 /* We really need a symtab for this to work... */
2710 st
= lookup_symtab (file
);
2713 filename
= symtab_to_filename (st
);
2714 if (filename
!= NULL
)
2716 Tcl_SetObjResult (interp
, Tcl_NewStringObj (filename
, -1));
2721 Tcl_SetResult (interp
, "", TCL_STATIC
);
2725 /* Come here during initialize_all_files () */
2728 _initialize_gdbtk ()
2732 /* Tell the rest of the world that Gdbtk is now set up. */
2734 init_ui_hook
= gdbtk_init
;