public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Feed Dwfl the raw /proc/<pid>/map.
@ 2008-06-03 16:28 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-06-03 16:28 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  93b19c557bbbf3e77df8259633ec034b97ad20de (commit)
       via  d7d0f7c2df759bd04998e1e17ebf1bc3bef626bc (commit)
      from  cef5f5c2faefda16da5a22c96c1cc0ac94286579 (commit)

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

- Log -----------------------------------------------------------------
commit 93b19c557bbbf3e77df8259633ec034b97ad20de
Author: Andrew Cagney <cagney@toil.yyz.redhat.com>
Date:   Tue Jun 3 12:25:48 2008 -0400

    Feed Dwfl the raw /proc/<pid>/map.
    
    The Dwfl class has been extended to accept a raw map and translate it
    into the Module map expected by elfutils.
    
    frysk-core/frysk/dwfl/ChangeLog
    2008-06-03  Andrew Cagney  <cagney@redhat.com>
    
    	* DwflFactory.java (updateDwfl): Simplify by using Dwfl.mapBegin,
    	.mapModule, and .mapEnd.
    
    frysk-sys/lib/dwfl/ChangeLog
    2008-06-03  Andrew Cagney  <cagney@redhat.com>
    
    	* Dwfl.java (mapModule): Fix parameter order.

commit d7d0f7c2df759bd04998e1e17ebf1bc3bef626bc
Author: Andrew Cagney <cagney@toil.yyz.redhat.com>
Date:   Tue Jun 3 12:10:58 2008 -0400

    Eliminate Dwfl.Dwfl(path,pid).
    
    frysk-sys/lib/dwfl/ChangeLog
    2008-06-03  Andrew Cagney  <cagney@redhat.com>
    
    	* Dwfl.java (mapBegin(long), mapEnd(), mapModule): New.
    	(Dwfl(ProcessIdentifier,String)): Delete.
    	(dwflBegin(String,int)): Delete.
    	* jni/Dwfl.cxx: Update.
    	* cni/Dwfl.cxx: Update.
    	* DwflTestbed.java: New.
    	* TestDwarfDie.java: Use DwflTestbed.
    	* TestDwfl.java: Use DwflTestbed.

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

Summary of changes:
 frysk-core/frysk/dwfl/ChangeLog        |    3 +
 frysk-core/frysk/dwfl/DwflFactory.java |  109 +++-----------------------------
 frysk-sys/lib/dwfl/ChangeLog           |   11 +++
 frysk-sys/lib/dwfl/Dwfl.java           |   87 +++++++++++++++++++++++---
 frysk-sys/lib/dwfl/DwflTestbed.java    |  103 ++++++++++++++++++++++++++++++
 frysk-sys/lib/dwfl/TestDwarfDie.java   |   11 ++--
 frysk-sys/lib/dwfl/TestDwfl.java       |   11 ++--
 frysk-sys/lib/dwfl/cni/Dwfl.cxx        |   26 --------
 frysk-sys/lib/dwfl/jni/Dwfl.cxx        |   20 ------
 9 files changed, 216 insertions(+), 165 deletions(-)
 create mode 100644 frysk-sys/lib/dwfl/DwflTestbed.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/dwfl/ChangeLog b/frysk-core/frysk/dwfl/ChangeLog
index 77505f0..542bf50 100644
--- a/frysk-core/frysk/dwfl/ChangeLog
+++ b/frysk-core/frysk/dwfl/ChangeLog
@@ -1,5 +1,8 @@
 2008-06-03  Andrew Cagney  <cagney@redhat.com>
 
+	* DwflFactory.java (updateDwfl): Simplify by using Dwfl.mapBegin,
+	.mapModule, and .mapEnd.
+	
 	* DwflFactory.java: Use Dwfl.reportBegin .reportModule, and
 	.reportEnd.
 
diff --git a/frysk-core/frysk/dwfl/DwflFactory.java b/frysk-core/frysk/dwfl/DwflFactory.java
index 8fdf031..0f17713 100644
--- a/frysk-core/frysk/dwfl/DwflFactory.java
+++ b/frysk-core/frysk/dwfl/DwflFactory.java
@@ -90,109 +90,21 @@ public class DwflFactory {
     }
 
     /**
-     * Check if a given {@link frysk.proc.MemoryMap} does not refer to
-     * an elf image.
-     * 
-     * @param map the given {@link frysk.proc.MemoryMap}.
-     * @return true if the map section does not refer to an elf image.
-     */
-    private static boolean isEmptyMap (MemoryMap map) {
-	return map.name.equals("")
-	    || (map.inode == 0 && map.devMinor == 0 && map.devMajor == 0);
-    }
-    
-    /**
-     * Refresh an existing dwfl. Package private, use DwflCache.getDwfl().
+     * Refresh an existing dwfl.  Package private, use
+     * DwflCache.getDwfl().
      */
     static Dwfl updateDwfl(Dwfl dwfl, Task task) {
-	
 	Proc proc = task.getProc();
 	MemoryMap[] maps = proc.getMaps();
-	dwfl.reportBegin();
-
-	int count = 0;
-	String name = null;
-	long low = 0, high = 0, devMinor = 0, devMajor = 0;
-	int inode = 0;
-
-	// Creating Dwfl_Modules for each elf image and the vdso section.
-	// Condensing elf mappings into a single Dwfl_Module per elf image.
-
-	// Base case:
-	// While the map is empty skip
-
-	// XXX: Add an explicit if count == maps.length -1 break. What is the 
-	// failure case for not finding a [vdso]?
-        while (! isVDSO(proc, maps[count]) && isEmptyMap(maps[count]))
-        {
-            if (count == (maps.length-1))
-                break;
-            count++;
-        }
-
-	// If map represents the vdso section, report vdso.
-	if (isVDSO(proc, maps[count])) {
-	    fine.log("Found the vdso!");
-	    dwfl.reportModule(maps[count].name, maps[count].addressLow,
-			      maps[count].addressHigh);
-	} else {
-	    // If map represents an elf mapping store its data..
-	    name = maps[count].name;
-	    low = maps[count].addressLow;
-	    high = maps[count].addressHigh;
-	    inode = maps[count].inode;
-	    devMinor = maps[count].devMinor;
-	    devMajor = maps[count].devMajor;
+	long vdso = VDSOAddressLow(proc);
+	dwfl.mapBegin(vdso);
+	for (int i = 0; i < maps.length; i++) {
+	    MemoryMap map = maps[i];
+	    dwfl.mapModule(map.name, map.addressLow, map.addressHigh,
+			   map.devMajor, map.devMinor, map.inode);
 	}
-
-	// Induction Step:
-	while (++count < maps.length) {
-	    
-	    // if vdso report old (if old), flush old, then report vdso.
-	    if (isVDSO(proc, maps[count])) {
-		if (name != null)
-		    dwfl.reportModule(name, low, high);
-		
-		name = null;
-		dwfl.reportModule(maps[count].name, maps[count].addressLow,
-				  maps[count].addressHigh);
-		continue;
-	    } else if (isEmptyMap(maps[count])) {
-		// if empty, report old (if old), flush old.
-		if (name != null)
-		    dwfl.reportModule(name, low, high);
-		
-		name = null;
-		continue;
-	    } else if (maps[count].name.equals(name)
-		       && maps[count].inode == inode
-		       && maps[count].devMinor == devMinor
-		       && maps[count].devMajor == devMajor) {
-		// if old elf, increase highAddress.
-		high = maps[count].addressHigh;
-	    } else {
-		// if new elf, report old, store new
-		if (name != null) {
-		    dwfl.reportModule(name, low, high);
-		}
-		name = maps[count].name;
-		low = maps[count].addressLow;
-		high = maps[count].addressHigh;
-		inode = maps[count].inode;
-		devMinor = maps[count].devMinor;
-		devMajor = maps[count].devMajor;
-	    }
-	}
-
-	// if last is elf, report elf.
-	if (! isEmptyMap(maps[maps.length - 1])
-	    && ! isVDSO(proc, maps[maps.length - 1])) {
-	    dwfl.reportModule(name, low, high);
-	}
-
-	dwfl.reportEnd();
-	DwflModule module = dwfl.getModule(VDSOAddressLow(proc));
-
+	dwfl.mapEnd();
+	DwflModule module = dwfl.getModule(vdso);
 	fine.log("updateDwfl main task", proc.getMainTask(),
 		 "memory", proc.getMainTask().getMemory(),
 		 "dwfl module", module);
@@ -201,7 +113,6 @@ public class DwflFactory {
 	if (module != null) {
 	    module.setUserData(task.getMemory());
 	}
-
 	return dwfl;
     }
 }
diff --git a/frysk-sys/lib/dwfl/ChangeLog b/frysk-sys/lib/dwfl/ChangeLog
index 7ee8a3b..e1e448f 100644
--- a/frysk-sys/lib/dwfl/ChangeLog
+++ b/frysk-sys/lib/dwfl/ChangeLog
@@ -1,5 +1,16 @@
 2008-06-03  Andrew Cagney  <cagney@redhat.com>
 
+	* Dwfl.java (mapModule): Fix parameter order.
+
+	* Dwfl.java (mapBegin(long), mapEnd(), mapModule): New.
+	(Dwfl(ProcessIdentifier,String)): Delete.
+	(dwflBegin(String,int)): Delete.
+	* jni/Dwfl.cxx: Update.
+	* cni/Dwfl.cxx: Update.
+	* DwflTestbed.java: New.
+	* TestDwarfDie.java: Use DwflTestbed.
+	* TestDwfl.java: Use DwflTestbed.
+
 	* DwarfDie.java: Make non-abstract.
 	(accept(DieVisitor)): Delete.
 	* DwarfDieFactory.java: Simplify.
diff --git a/frysk-sys/lib/dwfl/Dwfl.java b/frysk-sys/lib/dwfl/Dwfl.java
index eee3384..85f1ffd 100644
--- a/frysk-sys/lib/dwfl/Dwfl.java
+++ b/frysk-sys/lib/dwfl/Dwfl.java
@@ -40,9 +40,10 @@
 package lib.dwfl;
 
 import java.util.LinkedList;
-import frysk.sys.ProcessIdentifier;
+import frysk.rsl.Log;
 
 public class Dwfl {
+    private static final Log fine = Log.fine(Dwfl.class);
 
     private long pointer;
 
@@ -54,10 +55,6 @@ public class Dwfl {
 	pointer = dwflBegin(sysroot);
     }
 
-    Dwfl(ProcessIdentifier pid, String sysroot) {
-	pointer = dwflBegin(sysroot, pid.intValue());
-    }
-
     /**
      * Get all the DwflModule objects associated with this Dwfl. Use a
      * cached array if possible.
@@ -175,24 +172,98 @@ public class Dwfl {
     }
   
     private static native long dwflBegin (String s);
-    private static native long dwflBegin(String s, int pid);
   
+    /**
+     * Start a refresh of the address map.
+     */
     public void reportBegin() {
+	fine.log(this, "reportBegin");
 	reportBegin(pointer);
     }
     private static native void reportBegin(long pointer);
-
+    /**
+     * Finish a refresh of the address map.
+     */
     public void reportEnd() {
+	fine.log(this, "reportEnd");
 	reportEnd(pointer);
     }
     private static native void reportEnd(long pointer);
-
+    /**
+     * Report a mapped component.
+     */
     public void reportModule(String moduleName, long low, long high) {
+	fine.log(this, "reportModule", moduleName, "low", low, "high", high);
 	reportModule(pointer, moduleName, low, high);
     }
     private static native void reportModule(long pointer, String moduleName,
 					    long low, long high);
 
+
+    private String name;
+    private long low;
+    private long high;
+    private int devMajor;
+    private int devMinor;
+    private int inode;
+    private long vdso;
+    /**
+     * Start refreshing the address map using raw information
+     * extracted from /proc/pid/maps.
+     */
+    public void mapBegin(long vdso) {
+	reportBegin();
+	this.vdso = vdso;
+	name = null;
+    }
+    /**
+     * Report a single raw line from /proc/pid/maps.
+     */
+    public void mapModule(String name, long low, long high,
+			  int devMajor, int devMinor, int inode) {
+	if (this.name != null && this.name.equals(name)
+	    && this.devMajor == devMajor
+	    && this.devMinor == devMinor
+	    && this.inode == inode
+	    ) {
+	    // A repeat of a previous map (but with more addresses)
+	    // extend the address range.
+	    this.high = high;
+	} else {
+	    if (this.name != null) {
+		// There's a previous map, report and flush it.
+		reportModule(this.name, this.low, this.high);
+		this.name = null;
+	    }
+	    if (name.equals("")
+		|| (devMajor == 0 && devMinor == 0 && inode == 0)) {
+		// An empty map, do nothing.
+	    } else if (this.vdso == low) {
+		// A vdso, report it immediatly.
+		reportModule(name, low, high);
+	    } else {
+		// A new map, save it.
+		this.name = name;
+		this.low = low;
+		this.high = high;
+		this.inode = inode;
+		this.devMajor = devMajor;
+		this.devMinor = devMinor;
+	    }
+	}
+    }
+    /**
+     * Finish reporting a raw address map.
+     */
+    public void mapEnd() {
+	if (this.name != null) {
+	    // Report any dangling old map.
+	    reportModule(this.name, this.low, this.high);
+	    this.name = null;
+	}
+	reportEnd();
+    }
+
     protected native void dwfl_end ();
 
     // protected native long[] dwfl_get_modules();
diff --git a/frysk-sys/lib/dwfl/DwflTestbed.java b/frysk-sys/lib/dwfl/DwflTestbed.java
new file mode 100644
index 0000000..80aed86
--- /dev/null
+++ b/frysk-sys/lib/dwfl/DwflTestbed.java
@@ -0,0 +1,103 @@
+// 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 lib.dwfl;
+
+import frysk.sys.proc.MapsBuilder;
+import frysk.sys.Pid;
+import frysk.sys.proc.AuxvBuilder;
+
+public class DwflTestbed {
+
+    private static class VdsoBuilder extends AuxvBuilder {
+	long address;
+	public void buildBuffer(byte[] auxv) {
+	}
+	public void buildDimensions(int wordSize, boolean bigEndian,
+				    int numberElements) {
+	}
+	public void buildAuxiliary(int index, int type, long value) {
+	    if (type == inua.elf.AT.SYSINFO_EHDR) {
+		address = value;
+	    }
+	}
+    }
+
+    private static class ModuleBuilder extends MapsBuilder {
+	private final Dwfl dwfl;
+	ModuleBuilder(Dwfl dwfl) {
+	    this.dwfl = dwfl;
+	}
+	private byte[] maps;
+	private String name(int offset, int length) {
+	    byte[] byteName = new byte[length];
+	    System.arraycopy(maps, offset, byteName, 0, length);
+	    return new String(byteName);
+	}
+	public void buildBuffer(byte[] maps) {
+	    this.maps = maps;
+	}
+	public void buildMap(long addressLow, long addressHigh,
+			     boolean permRead, boolean permWrite,
+			     boolean permExecute, boolean shared,
+			     long offset,
+			     int devMajor, int devMinor,
+			     int inode,
+			     int pathnameOffset, int pathnameLength) {
+	    dwfl.mapModule(name(pathnameOffset, pathnameLength),
+			   addressLow, addressHigh,
+			   devMajor, devMinor, inode);
+	}
+    }
+
+    /**
+     * Create a dwfl from this process.
+     */
+    static Dwfl createFromSelf() {
+	Dwfl dwfl = new Dwfl("");
+	ModuleBuilder maps = new ModuleBuilder(dwfl);
+	VdsoBuilder vdso = new VdsoBuilder();
+	vdso.construct(Pid.get());
+	dwfl.mapBegin(vdso.address);
+	maps.construct(Pid.get());
+	dwfl.mapEnd();
+	return dwfl;
+    }
+
+}
diff --git a/frysk-sys/lib/dwfl/TestDwarfDie.java b/frysk-sys/lib/dwfl/TestDwarfDie.java
index 64cb89b..35342e4 100644
--- a/frysk-sys/lib/dwfl/TestDwarfDie.java
+++ b/frysk-sys/lib/dwfl/TestDwarfDie.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2006, 2007, Red Hat Inc.
+// Copyright 2005, 2006, 2007, 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
@@ -40,14 +40,13 @@
 package lib.dwfl;
 
 import frysk.junit.TestCase;
-import frysk.sys.Pid;
 import frysk.testbed.LocalMemory;
 
 public class TestDwarfDie extends TestCase {
 
     
     public void testHasAttribute() {
-	Dwfl dwfl = new Dwfl(Pid.get(), "");
+	Dwfl dwfl = DwflTestbed.createFromSelf();
 	assertNotNull(dwfl);
 
 	// get CUDIE
@@ -65,7 +64,7 @@ public class TestDwarfDie extends TestCase {
     
     public void testGetCompilationUnit(){
 	long pc = LocalMemory.getCodeAddr();
-	Dwfl dwfl = new Dwfl(Pid.get(), "");
+	Dwfl dwfl = DwflTestbed.createFromSelf();
 	assertNotNull(dwfl);
 
 	// get CUDIE
@@ -87,7 +86,7 @@ public class TestDwarfDie extends TestCase {
 
     public void testGetModule(){
 	
-	Dwfl dwfl = new Dwfl(Pid.get(), "");
+	Dwfl dwfl = DwflTestbed.createFromSelf();
 	assertNotNull(dwfl);
 	long addr = LocalMemory.getCodeAddr();
 
@@ -103,7 +102,7 @@ public class TestDwarfDie extends TestCase {
 
     public void testGetOffset(){
 
-	Dwfl dwfl = new Dwfl(Pid.get(), "");
+	Dwfl dwfl = DwflTestbed.createFromSelf();
 	assertNotNull(dwfl);
 	long addr = LocalMemory.getCodeAddr();
 
diff --git a/frysk-sys/lib/dwfl/TestDwfl.java b/frysk-sys/lib/dwfl/TestDwfl.java
index 0d17541..dbc881f 100644
--- a/frysk-sys/lib/dwfl/TestDwfl.java
+++ b/frysk-sys/lib/dwfl/TestDwfl.java
@@ -45,7 +45,6 @@ import java.util.List;
 
 import frysk.junit.Runner;
 import frysk.junit.TestCase;
-import frysk.sys.Pid;
 import frysk.testbed.LocalMemory;
 
 public class TestDwfl
@@ -116,7 +115,7 @@ public class TestDwfl
   
   public void testGetLine ()
   {
-    Dwfl dwfl = new Dwfl(Pid.get(), "");
+    Dwfl dwfl = DwflTestbed.createFromSelf();
     assertNotNull("dwfl", dwfl);
     DwflLine line = dwfl.getSourceLine(LocalMemory.getCodeAddr());
     assertNotNull("line", line);
@@ -131,7 +130,7 @@ public class TestDwfl
 
   public void testGetDie ()
   {
-    Dwfl dwfl = new Dwfl(Pid.get(), "");
+    Dwfl dwfl = DwflTestbed.createFromSelf();
     assertNotNull(dwfl);
     
     DwflDieBias bias = dwfl.getCompilationUnit(LocalMemory.getCodeAddr());
@@ -172,7 +171,7 @@ public class TestDwfl
   // should be there. 
   public void testGetModules() 
   {
-    Dwfl dwfl = new Dwfl(Pid.get(), "");
+    Dwfl dwfl = DwflTestbed.createFromSelf();
     DwflModule[] modules = dwfl.getModules();
     assertNotNull(modules);
     // Look for some modules that should be there.
@@ -196,7 +195,7 @@ public class TestDwfl
   // in the DwflLine records returned for a line.


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-03 16:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-03 16:28 [SCM] master: Feed Dwfl the raw /proc/<pid>/map cagney

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).