diff options
author | Keith Seitz <keiths@cygnus> | 1997-12-05 20:17:13 +0000 |
---|---|---|
committer | Keith Seitz <keiths@cygnus> | 1997-12-05 20:17:13 +0000 |
commit | e0f7db023dab750e868be6d3fd101b65d5dd7fdc (patch) | |
tree | 93a51e4e9df7f53bd49f8a833bf78ab1abb08304 /gdb/gdbtk.c | |
parent | 22a9f052deffaa5d712b42f3d620382be9dfa5f4 (diff) | |
download | gdb-e0f7db023dab750e868be6d3fd101b65d5dd7fdc.zip gdb-e0f7db023dab750e868be6d3fd101b65d5dd7fdc.tar.gz gdb-e0f7db023dab750e868be6d3fd101b65d5dd7fdc.tar.bz2 |
* gdbtk.c (gdbtk_init): add gdb_find_file to interpreter
(gdb_find_file_command): new function searches source_path to
find real full filename
Diffstat (limited to 'gdb/gdbtk.c')
-rw-r--r-- | gdb/gdbtk.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/gdb/gdbtk.c b/gdb/gdbtk.c index 5ec9c40..2a29a74 100644 --- a/gdb/gdbtk.c +++ b/gdb/gdbtk.c @@ -86,6 +86,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #undef SIOCSPGRP #endif +extern char *source_path; /* from source.c */ int gdbtk_load_hash PARAMS ((char *, unsigned long)); int (*ui_load_progress_hook) PARAMS ((char *, unsigned long)); @@ -140,6 +141,7 @@ static int gdb_tracepoint_exists_command PARAMS ((ClientData, Tcl_Interp *, int, static int gdb_get_tracepoint_info PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); static int gdb_actions_command PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); static int gdb_prompt_command PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); +static int gdb_find_file_command PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); static void gdbtk_create_tracepoint PARAMS ((struct tracepoint *)); static void gdbtk_delete_tracepoint PARAMS ((struct tracepoint *)); static void tracepoint_notify PARAMS ((struct tracepoint *, const char *)); @@ -1897,6 +1899,8 @@ gdbtk_init ( argv0 ) gdb_actions_command, NULL, NULL); Tcl_CreateObjCommand (interp, "gdb_prompt", gdb_prompt_command, NULL, NULL); + Tcl_CreateObjCommand (interp, "gdb_find_file", + gdb_find_file_command, NULL, NULL); command_loop_hook = tk_command_loop; print_frame_info_listing_hook = @@ -2588,6 +2592,77 @@ gdb_prompt_command (clientData, interp, objc, objv) return TCL_OK; } + +/* This is stolen from source.c */ +#ifdef CRLF_SOURCE_FILES + +/* Define CRLF_SOURCE_FILES in an xm-*.h file if source files on the + host use \r\n rather than just \n. Defining CRLF_SOURCE_FILES is + much faster than defining LSEEK_NOT_LINEAR. */ + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#define OPEN_MODE (O_RDONLY | O_BINARY) + +#else /* ! defined (CRLF_SOURCE_FILES) */ + +#define OPEN_MODE O_RDONLY + +#endif /* ! defined (CRLF_SOURCE_FILES) */ + +/* Find the pathname to a file, searching the source_dir */ +/* we may actually need to use openp to find the the full pathname + so we don't have any "../" et al in it. */ +static int +gdb_find_file_command (clientData, interp, objc, objv) + ClientData clientData; + Tcl_Interp *interp; + int objc; + Tcl_Obj *CONST objv[]; +{ + char *file, *filename; + char *p; + int found; + + if (objc != 2) + { + Tcl_AppendResult (interp, "wrong # of args: should be \"", + Tcl_GetStringFromObj (objv[0], NULL), + " filename\""); + return TCL_ERROR; + } + + /* try something simple first */ + file = Tcl_GetStringFromObj (objv[1], NULL); + if (access (file, R_OK) == 0) + { + Tcl_SetObjResult (interp, Tcl_NewStringObj (file, -1)); + return TCL_OK; + } + + /* Search the path -- do NOT search CWD first -- be consistent with source.c */ + found = openp (source_path, 0, file, OPEN_MODE, 0, &filename); + if (found < 0) + { + /* Did not work -- try just the base filename */ + p = basename (file); + if (p != file) + found = openp (source_path, 0, p, OPEN_MODE, 0, &filename); + } + + if (found >= 0) + { + Tcl_SetObjResult (interp, Tcl_NewStringObj (filename, -1)); + close (found); + } + else + Tcl_SetResult (interp, "", TCL_STATIC); + + return TCL_OK; +} + /* Come here during initialize_all_files () */ void |