* gdbtk.c (gdbtk_init): add gdb_find_file to interpreter
authorKeith Seitz <keiths@cygnus>
Fri, 5 Dec 1997 20:17:13 +0000 (20:17 +0000)
committerKeith Seitz <keiths@cygnus>
Fri, 5 Dec 1997 20:17:13 +0000 (20:17 +0000)
        (gdb_find_file_command): new function searches source_path to
        find real full filename

gdb/ChangeLog
gdb/gdbtk.c

index 3acdea328b979f707e32eb6dd49afe216baeb9f6..f4f1a32ec4229a7fd12134b6f9cc8c923a25fb97 100644 (file)
@@ -1,3 +1,9 @@
+Fri Dec  5 10:31:23 1997  Keith Seitz  <keiths@pizza.cygnus.com>
+
+       * gdbtk.c (gdbtk_init): add gdb_find_file to interpreter
+       (gdb_find_file_command): new function searches source_path to
+       find real full filename
+
 Fri Dec  5 09:22:35 1997  Nick Clifton  <nickc@cygnus.com>
 
        * config/v850/tm-v850.h (BREAKPOINT): Reverted back to old value...
index 5ec9c408fd3c446be08a60fe539debd519f1a871..2a29a7476f3e3ea40dfe0c9294322dc6bb567ca8 100644 (file)
@@ -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
This page took 0.028758 seconds and 4 git commands to generate.