public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: scox@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Add Sysroot.java, SysrootCache.java, TestSysroot.java.
Date: Tue, 11 Mar 2008 15:01:00 -0000	[thread overview]
Message-ID: <20080311150149.18207.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  c25d6b88f051607f5dfcab2c3f55fe295f872a09 (commit)
      from  e14f0e42c16839783728636f5c90c509324044c1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c25d6b88f051607f5dfcab2c3f55fe295f872a09
Author: Stan Cox <scox@redhat.com>
Date:   Tue Mar 11 10:51:58 2008 -0400

    Add Sysroot.java, SysrootCache.java, TestSysroot.java.
    
    * SysrootCache.java: New file.
    (getSysroot): Change all callers of DwflCache.getSysroot to use this.
    * Sysroot.java: New file.
    * TestSysroot.java: New file.
    * DwflCache.java (Mod.sysroot): Remove
    (sysrootMap): Move to Sysroot.java.
    (setSysroot): Likewise.
    (getSysroot): Likewise.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/debuginfo/DebugInfoFrame.java     |    3 +-
 frysk-core/frysk/dwfl/ChangeLog                    |    7 +
 frysk-core/frysk/dwfl/DwflCache.java               |   50 +------
 frysk-core/frysk/hpd/AttachCommand.java            |    4 +-
 frysk-core/frysk/hpd/CoreCommand.java              |    4 +-
 frysk-core/frysk/hpd/ListCommand.java              |    4 +-
 frysk-core/frysk/hpd/LoadCommand.java              |    4 +-
 frysk-core/frysk/sysroot/ChangeLog                 |    7 +
 frysk-core/frysk/sysroot/Sysroot.java              |  165 ++++++++++++++++++++
 .../SysrootCache.java}                             |  114 ++++++++------
 frysk-core/frysk/sysroot/TestSysroot.java          |   94 +++++++++++
 frysk-core/frysk/util/CommandlineParser.java       |    4 +-
 12 files changed, 354 insertions(+), 106 deletions(-)
 create mode 100644 frysk-core/frysk/sysroot/ChangeLog
 create mode 100644 frysk-core/frysk/sysroot/Sysroot.java
 copy frysk-core/frysk/{dwfl/ElfSectionCache.java => sysroot/SysrootCache.java} (52%)
 create mode 100644 frysk-core/frysk/sysroot/TestSysroot.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/debuginfo/DebugInfoFrame.java b/frysk-core/frysk/debuginfo/DebugInfoFrame.java
index 7806be5..b99cfba 100644
--- a/frysk-core/frysk/debuginfo/DebugInfoFrame.java
+++ b/frysk-core/frysk/debuginfo/DebugInfoFrame.java
@@ -56,6 +56,7 @@ import frysk.scopes.Subprogram;
 import frysk.scopes.Subroutine;
 import frysk.stack.Frame;
 import frysk.stack.FrameDecorator;
+import frysk.sysroot.SysrootCache;
 
 public class DebugInfoFrame extends FrameDecorator {
 
@@ -175,7 +176,7 @@ public class DebugInfoFrame extends FrameDecorator {
   	    // be decremented by one.
   	    DwflLine dwflLine = dwfl.getSourceLine(getAdjustedAddress());
   	    if (dwflLine != null) {
-  		File sysroot = DwflCache.getSysroot(this.getTask());
+  		File sysroot = SysrootCache.getSysroot(this.getTask());
   		File f = new File(dwflLine.getSourceFile());
   		if (! f.isAbsolute()) {
   		    // The file refers to a path relative to the
diff --git a/frysk-core/frysk/dwfl/ChangeLog b/frysk-core/frysk/dwfl/ChangeLog
index 29989c8..061af2d 100644
--- a/frysk-core/frysk/dwfl/ChangeLog
+++ b/frysk-core/frysk/dwfl/ChangeLog
@@ -1,3 +1,10 @@
+2008-03-11  Stan Cox  <scox@redhat.com>
+
+	* DwflCache.java (Mod.sysroot): Remove
+	(sysrootMap): Move to Sysroot.java.
+	(setSysroot): Likewise.
+	(getSysroot): Likewise.
+
 2008-03-03  Andrew Cagney  <cagney@redhat.com>
 
 	* TestElfSectionCache.java: Use frysk.config.
diff --git a/frysk-core/frysk/dwfl/DwflCache.java b/frysk-core/frysk/dwfl/DwflCache.java
index 5a57f98..0b40ecf 100644
--- a/frysk-core/frysk/dwfl/DwflCache.java
+++ b/frysk-core/frysk/dwfl/DwflCache.java
@@ -45,6 +45,7 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.WeakHashMap;
 import frysk.rsl.Log;
+import frysk.sysroot.SysrootCache;
 import lib.dwfl.Dwfl;
 
 /**
@@ -60,11 +61,9 @@ public class DwflCache {
     static private class Mod {
 	final Dwfl dwfl;
 	int count;
-	File sysroot;
-	Mod(Dwfl dwfl, int count, File sysroot) {
+	Mod(Dwfl dwfl, int count) {
 	    this.dwfl = dwfl;
 	    this.count = count;
-	    this.sysroot = sysroot;
 	}
     }
 
@@ -74,11 +73,6 @@ public class DwflCache {
     private static WeakHashMap modMap = new WeakHashMap();
 
     /**
-     * Map from a Task's executable to its sysroot. 
-     */  
-    private static WeakHashMap sysrootMap = new WeakHashMap();
-
-    /**
      * Cache of all Dwfl objects.
      */
     private static WeakHashMap allDwfls = new WeakHashMap();
@@ -136,17 +130,11 @@ public class DwflCache {
 	// If there is no dwfl for this task create one.
 	if (!modMap.containsKey(task)) {
 	    fine.log("creating new dwfl for task", task);
-	    String sysroot = (String)sysrootMap.get(task.getProc().getCommand());
-	    if (sysroot == null) {
-	    	sysroot = (String)sysrootMap.get("default");
-	    	if (sysroot == null)
-	    		sysroot = "/";
-	    }
-	    File sysrootFile = new File(sysroot);
+	    File sysrootFile = (File)SysrootCache.getSysroot(task);
 	    File relativeSysroot = getRelativeSysRoot(task.getProc().getExe(), sysrootFile);
 	    Dwfl dwfl = new Dwfl(relativeSysroot.getPath());
 	    DwflFactory.updateDwfl(dwfl, task);
-	    Mod mod = new Mod(dwfl, task.getMod(), sysrootFile);
+	    Mod mod = new Mod(dwfl, task.getMod());
 	    modMap.put(task, mod);
 
 	    // For cleanup, also save dwfl using Mod as a key (just need a
@@ -167,36 +155,6 @@ public class DwflCache {
 	return mod.dwfl;
     }
 
-    /**
-     * set the sysroot corresponding to a {@link frysk.proc.Task}. 
-     * 
-     * @param task is the task.
-     * @param sysroot is this task's sysroot.
-     */
-    public static void setSysroot(Task task, String sysroot) {
-	sysrootMap.put(task.getProc().getCommand(), sysroot);
-    }
-    
-    /**
-     * set the default sysroot
-     * 
-     * @param sysroot is the default special root directory
-     */
-    public static void setDefaultSysroot(String sysroot) {
-    sysrootMap.put("default", sysroot);
-    }
-    
-    /**
-     * return a sysroot File for a {@link frysk.proc.Task}.
-     * 
-     * @param task is the task.
-     * @return the sysroot file.
-     */
-    public static File getSysroot(Task task) {
-	Mod mod = (Mod) modMap.get(task);
-	return mod.sysroot;
-    }
-
     public static void clear() {
 	modMap.clear();
 	for (Iterator i = allDwfls.values().iterator(); i.hasNext();) {
diff --git a/frysk-core/frysk/hpd/AttachCommand.java b/frysk-core/frysk/hpd/AttachCommand.java
index 684ad8a..94fb335 100644
--- a/frysk-core/frysk/hpd/AttachCommand.java
+++ b/frysk-core/frysk/hpd/AttachCommand.java
@@ -39,7 +39,7 @@
 
 package frysk.hpd;
 
-import frysk.dwfl.DwflCache;
+import frysk.sysroot.SysrootCache;
 import frysk.proc.Proc;
 import frysk.proc.Manager;
 import frysk.proc.FindProc;
@@ -126,7 +126,7 @@ public class AttachCommand extends ParameterizedCommand {
     }
 
     public static void attach(Proc proc, CLI cli, String sysroot) {
-	DwflCache.setSysroot(proc.getMainTask(), sysroot);
+	SysrootCache.setSysroot(proc.getMainTask(), sysroot);
 	cli.doAttach(proc, false);
     }
 
diff --git a/frysk-core/frysk/hpd/CoreCommand.java b/frysk-core/frysk/hpd/CoreCommand.java
index 6d85bb7..74b6535 100644
--- a/frysk-core/frysk/hpd/CoreCommand.java
+++ b/frysk-core/frysk/hpd/CoreCommand.java
@@ -46,7 +46,7 @@ import java.util.List;
 import frysk.debuginfo.DebugInfo;
 import frysk.debuginfo.DebugInfoFrame;
 import frysk.debuginfo.DebugInfoStackFactory;
-import frysk.dwfl.DwflCache;
+import frysk.sysroot.SysrootCache;
 import frysk.proc.Task;
 import frysk.proc.dead.LinuxCoreFactory;
 import java.io.IOException;
@@ -136,7 +136,7 @@ public class CoreCommand extends ParameterizedCommand {
 		.createVirtualStackTrace(task);
 	    cli.setTaskFrame(task, frame);
 	    cli.setTaskDebugInfo(task, new DebugInfo(frame));
-	    DwflCache.setSysroot(task, sysroot);
+	    SysrootCache.setSysroot(task, sysroot);
 	}
 	// Finally, done.
 	synchronized (cli) {
diff --git a/frysk-core/frysk/hpd/ListCommand.java b/frysk-core/frysk/hpd/ListCommand.java
index a0ca68f..4779098 100644
--- a/frysk-core/frysk/hpd/ListCommand.java
+++ b/frysk-core/frysk/hpd/ListCommand.java
@@ -52,7 +52,7 @@ import lib.dwfl.DwarfDie;
 import lib.dwfl.DwTag; 
 import frysk.debuginfo.DebugInfoFrame;
 import frysk.debuginfo.DebugInfo;
-import frysk.dwfl.DwflCache;
+import frysk.sysroot.SysrootCache;
 import frysk.proc.Task;
 
 /**
@@ -122,7 +122,7 @@ class ListCommand extends ParameterizedCommand {
                         }
 			if (funcDie.getTag().hashCode() == DwTag.SUBPROGRAM_) {
 			    line = (int)funcDie.getDeclLine();
-			    File sysroot = DwflCache.getSysroot(frame.getTask());
+			    File sysroot = SysrootCache.getSysroot(frame.getTask());
 			    file = funcDie.getDeclFile();
 			    if (file.isAbsolute()) 
 				file = new File(sysroot.getPath(), file.getPath());
diff --git a/frysk-core/frysk/hpd/LoadCommand.java b/frysk-core/frysk/hpd/LoadCommand.java
index f848295..ffc34e6 100644
--- a/frysk-core/frysk/hpd/LoadCommand.java
+++ b/frysk-core/frysk/hpd/LoadCommand.java
@@ -45,7 +45,7 @@ import frysk.proc.dead.LinuxExeFactory;
 import frysk.debuginfo.DebugInfo;
 import frysk.debuginfo.DebugInfoFrame;
 import frysk.debuginfo.DebugInfoStackFactory;
-import frysk.dwfl.DwflCache;
+import frysk.sysroot.SysrootCache;
 import frysk.proc.Proc;
 import frysk.proc.Task;
 import java.util.List;
@@ -137,7 +137,7 @@ public class LoadCommand extends ParameterizedCommand {
 			.createDebugInfoStackTrace(task);
 		cli.setTaskFrame(task, frame);
 		cli.setTaskDebugInfo(task, new DebugInfo(frame));
-		DwflCache.setSysroot(task, sysroot);
+		SysrootCache.setSysroot(task, sysroot);
 	    }
 	}
 	synchronized (cli) {
diff --git a/frysk-core/frysk/sysroot/ChangeLog b/frysk-core/frysk/sysroot/ChangeLog
new file mode 100644
index 0000000..7e54e33
--- /dev/null
+++ b/frysk-core/frysk/sysroot/ChangeLog
@@ -0,0 +1,7 @@
+2008-03-11  Stan Cox  <scox@redhat.com>
+
+	* SysrootCache.java: New file.
+	(getSysroot): Change all callers of DwflCache.getSysroot
+	to use this.
+	* Sysroot.java: New file.
+	* TestSysroot.java: New file.
diff --git a/frysk-core/frysk/sysroot/Sysroot.java b/frysk-core/frysk/sysroot/Sysroot.java
new file mode 100644
index 0000000..f731d05
--- /dev/null
+++ b/frysk-core/frysk/sysroot/Sysroot.java
@@ -0,0 +1,165 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.sysroot;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Map from a Task's executable to its sysroot special root directory.
+ */  
+
+public class Sysroot {
+    File sysrootFile;
+
+    public Sysroot (File path) {
+	sysrootFile = path;
+    }
+
+    /**
+     * return a pathname of an executable.
+     * 
+     * @param pathname
+     *		is the executable.
+     * @return this executable's pathname, searched for on $PATH
+     */
+    public File getPathViaDefaultRoot (String pathname) {
+        String pathVar = System.getenv("PATH");
+        return findExe(pathVar, "/", pathname);
+    }
+    
+    /**
+     * return a pathname of an executable.  Used only for testing.
+     */
+    File getPathViaDefaultRoot (String pathname, String pathVar) {
+	return findExe(pathVar, "/", pathname);
+    }
+
+    /**
+     * return a pathname of an executable.
+     * 
+     * @param pathname
+     *		is the executable.
+     * @return this executable's pathname, searched for on $PATH in the special 
+     * 		root directory.
+     */
+    public File getPathViaSysroot (String pathname) {
+        String pathVar = System.getenv("PATH");
+        return findExe(pathVar, sysrootFile.getPath(), pathname);
+    }
+    
+    /**
+     * return a pathname of an executable in a sysroot.  Used only for testing.
+     */
+    File getPathViaSysroot (String pathname, String pathVar) {
+        return findExe(pathVar, sysrootFile.getPath(), pathname);
+    }
+
+    /**
+     * return a pathname of an executable's source.
+     * 
+     * @param pathname
+     *		is the executable's compilation directory.
+     * @param file
+     *		this executable's source name.
+     * @return the pathname of the executable's source.
+     */
+    public File getSourcePathViaDefaultRoot (File compilationDir, File f) {
+	try {
+	    if (! f.isAbsolute()) {
+		// The file refers to a path relative to the
+		// compilation directory, so prepend that directory path.
+		return new File(compilationDir.getPath(), f.getPath()).getCanonicalFile();
+	    }
+	    else
+		return new File(f.getPath()).getCanonicalFile();
+	} catch (IOException e) {
+	    return f;
+    	} 
+    }
+
+    /**
+     * return a pathname of an executable's source.
+     * 
+     * @param pathname
+     *		is the executable's compilation directory.
+     * @param file
+     *		this executable's source name.
+     * @return the pathname of the executable's source searched for in the
+     *		special root directory.
+     */
+    public File getSourcePathViaSysroot (File compilationDir, File f) {
+	try {
+	    if (! f.isAbsolute()) {
+		// The file refers to a path relative to the
+		// compilation directory, so prepend that directory path.
+		File parent = new File(sysrootFile.getPath(), compilationDir.getPath());
+		return new File(parent, f.getPath()).getCanonicalFile();
+	    }
+	    else
+		return new File(sysrootFile.getPath(), f.getPath()).getCanonicalFile();
+	} catch (IOException e) {
+	    return f;
+	}
+    }
+
+    private static File findExe(String pathVar, String sysrootFile, String arg0) {
+        if (pathVar == null) {
+            return new File(arg0);
+        }
+
+        if (arg0.startsWith("/")) {
+            return new File(arg0);
+        }
+
+        String[] path = pathVar.split(":");
+        if (path == null) {
+            return new File(arg0);
+        }
+
+        for (int i = 0; i < path.length; i++) {
+            File file = new File(new File(sysrootFile, path[i]), arg0);
+            if (file.exists()) {
+                return file;
+            }
+        }
+        return new File(arg0); // punt
+    }
+}
diff --git a/frysk-core/frysk/dwfl/ElfSectionCache.java b/frysk-core/frysk/sysroot/SysrootCache.java
similarity index 52%
copy from frysk-core/frysk/dwfl/ElfSectionCache.java
copy to frysk-core/frysk/sysroot/SysrootCache.java
index b4d77f5..665bcb2 100644
--- a/frysk-core/frysk/dwfl/ElfSectionCache.java
+++ b/frysk-core/frysk/sysroot/SysrootCache.java
@@ -1,5 +1,4 @@
 // This file is part of the program FRYSK.
-//
 // Copyright 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
@@ -37,67 +36,84 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk.dwfl;
+package frysk.sysroot;
 
+import java.io.File;
 import java.util.WeakHashMap;
 
 import frysk.proc.Task;
-import lib.dwfl.Dwfl;
-import lib.dwfl.DwflModule;
-import lib.dwfl.Elf;
-import lib.dwfl.ElfSection;
-import lib.dwfl.ElfSectionHeader;
-import lib.dwfl.ModuleElfBias;
 
 /**
- * Class to provide and cache requested ElfSectionHeaders based on name.
+ * Map from a Task's executable to its sysroot special root directory.
  */
-public class ElfSectionCache {
-    
-    private Task task;
-    private WeakHashMap sectionMap;
-    
-    public ElfSectionCache (Task task) {
-	this.task = task;
-	this.sectionMap = new WeakHashMap();
-    }
-    
+
+public class SysrootCache {
+
+    private static WeakHashMap sysrootMap = new WeakHashMap();
+
     /**
-     * Returns an ElfSectionHeader representing the ELF header for this class' Task object as
-     * given by the section name and module address in the parameters to this method. Also
-     * caches the headers in a WeakHashMap for later use.
+     * return a sysroot File corresponding to an executable.
      * 
-     * @param name	The name of the section
-     * @param addr	The module address
-     * @return		The corresponding ElfSectionHeader
+     * @param pathname
+     *                is the pathname of the executable.
+     * @return this executable's special root directory.
      */
-    public ElfSectionHeader getSectionHeader(String name, long addr) {
-	
-	if (this.sectionMap.containsKey(name))
-	    return (ElfSectionHeader) this.sectionMap.get(name);
-	
-	Dwfl dwfl = DwflCache.getDwfl(this.task);
-	DwflModule dwflModule = dwfl.getModule(addr);
-	ModuleElfBias elfBias = dwflModule.getElf();
-	Elf elf = elfBias.elf;
-	
-	for (ElfSection section = elf.getSection(0);
-	 section != null;
-	 section = elf.getNextSection(section)) {
-	    
-	    ElfSectionHeader sheader = section.getSectionHeader();
-	    if (sheader.name != null && sheader.name.equals(name)) {
-		
-		this.sectionMap.put(name, sheader);
-		return sheader;
-	    }
+    public static File getSysroot(String pathname) {
+	File sysrootFile = (File)sysrootMap.get(new File(pathname).getName());
+	if (sysrootFile == null) {
+	    sysrootFile = (File) sysrootMap.get("default");
+	    if (sysrootFile == null)
+		sysrootFile = new File("/");
 	}
-	
-	return null;
+	return sysrootFile;
     }
     
-    public Task getTask() {
-	return this.task;
+    public static File getSysroot(Task task) {


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-03-11 15:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080311150149.18207.qmail@sourceware.org \
    --to=scox@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).