This is the mail archive of the frysk@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fcore status


On Mon, 2006-10-16 at 08:17 -0500, Phil Muldoon wrote:

> I do all my operations on the header via gelf which is arch dependent, 
> so we are arch dependent on all elf operations?
> Yes, I totally agree on PT_NOTE arch dependent information if that is 
> what you mean.

Yes, fcore do all operations on the header via gelf. But some
information, such as little-endian, big-endian, including PT_NOTE
section we need to fill is still arch depentent! So it's necessary for
us to refactor fcore code in order to dump out PT_NOTE and further
operations on core file. So I write one small patch to show how we could
refactor fcore codes. Its main purpose is for our discussion, not for
checking in, so I just write one general code framework.

Best regards

Yong Zheng


Index: frysk-core/frysk/util/FCore.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/util/FCore.java,v
retrieving revision 1.5
diff -u -r1.5 FCore.java
--- frysk-core/frysk/util/FCore.java	16 Oct 2006 21:27:28 -0000	1.5
+++ frysk-core/frysk/util/FCore.java	17 Oct 2006 02:17:36 -0000
@@ -75,6 +75,8 @@
 import frysk.proc.Task;
 import frysk.proc.TaskException;
 import frysk.sys.proc.MapsBuilder;
+import frysk.util.core.LinuxElfCoreFiller;
+import frysk.util.core.LinuxElfCoreFillerFactory;
 import gnu.classpath.tools.getopt.FileArgumentCallback;
 import gnu.classpath.tools.getopt.Option;
 import gnu.classpath.tools.getopt.OptionException;
@@ -238,49 +240,9 @@
 		local_elf = new Elf(System.getProperty("user.dir") + "/fcore."
 				+ proc.getPid(), ElfCommand.ELF_C_WRITE, true);
 
-		// Create the elf header
-		local_elf.createNewEHeader();
-		ElfEHeader elf_header = local_elf.getEHeader();
-		
-		Isa arch = proc.getMainTask().getIsa();		
-		ByteOrder order = arch.getByteOrder();
-		
-		if (order == inua.eio.ByteOrder.BIG_ENDIAN)
-			elf_header.ident[5] = ElfEHeader.PHEADER_ELFDATA2MSB;
-		else
-			elf_header.ident[5] = ElfEHeader.PHEADER_ELFDATA2LSB;
-		
-		// Version
-		elf_header.ident[6] = (byte) local_elf.getElfVersion();
-		
-		// EXEC for now, ET_CORE later
-		elf_header.type = ElfEHeader.PHEADER_ET_EXEC;
-		
-		// Version
-		elf_header.version = local_elf.getElfVersion();
-		
-		// String Index
-		elf_header.shstrndx = 1;
-		
-		// XXX: I hate this, there must be a better way to get architecture than this ugly, ugly hack
-		String arch_test = arch.toString();
-		String type = arch_test.substring(0, arch_test.lastIndexOf("@"));
-		
-		if (type.equals("frysk.proc.LinuxIa32")) {
-			elf_header.machine = ElfEMachine.EM_386;
-			elf_header.ident[4] = ElfEHeader.PHEADER_ELFCLASS32;
-		}
-		if (type.equals("frysk.proc.LinuxPPC64")) {
-			elf_header.machine = ElfEMachine.EM_PPC64;
-			elf_header.ident[4] = ElfEHeader.PHEADER_ELFCLASS64;
-		}
-		if (type.equals("frysk.proc.LinuxX8664")) {
-			elf_header.machine = ElfEMachine.EM_X86_64;
-			elf_header.ident[4] = ElfEHeader.PHEADER_ELFCLASS64;
-		}
-		
-		local_elf.updateEHeader(elf_header);
-
+		LinuxElfCoreFiller coreFiller = LinuxElfCoreFillerFactory.getElfCoreFiller(proc);
+		coreFiller.fillElfHeader(local_elf);
+        
 		// Count maps
 		final MapsCounter counter = new MapsCounter();
 		counter.construct(proc.getMainTask().getTid());
@@ -320,7 +282,7 @@
 		stringSection.update(stringSectionHeader);
 		
 		// Repoint shstrndx to string segment number
-		elf_header = local_elf.getEHeader();
+		ElfEHeader elf_header = local_elf.getEHeader();
 		elf_header.shstrndx = (int) stringSection.getIndex();
 		local_elf.updateEHeader(elf_header);
 
@@ -450,7 +412,6 @@
 				data.setType(0);
 				section.update(sectionHeader);
 				
-				
 				// inefficient to do this for each map, but alternative is to rerun another builder
 				// so for right now, less of two evil. Needs a rethinks.
 				final long i = local_elf.update(ElfCommand.ELF_C_NULL);
--- /dev/null	2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/util/core/LinuxElfCoreFillerFactory.java	2006-10-17 10:15:58.000000000 +0800
@@ -0,0 +1,38 @@
+package frysk.util.core;
+
+import java.util.logging.Level;
+
+import lib.elf.Elf;
+import lib.elf.ElfCommand;
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfException;
+import lib.elf.ElfFileException;
+import frysk.proc.Isa;
+import frysk.proc.LinuxIa32;
+import frysk.proc.LinuxPPC64;
+import frysk.proc.LinuxX8664;
+import frysk.proc.Proc;
+import frysk.proc.Task;
+import frysk.proc.TaskException;
+
+public class LinuxElfCoreFillerFactory
+{
+
+  public static LinuxElfCoreFiller getElfCoreFiller(Proc proc) 
+    throws TaskException
+  {
+    Isa procIsa = proc.getMainTask().getIsa();     
+    
+    //XXX if more ISA is available, add them here.
+    //XXX LinuxIa32On64 and LinuxPPC32On64 should be added.
+    if (procIsa instanceof LinuxIa32)
+      return new LinuxElfX86Core(proc);
+    else if (procIsa instanceof LinuxX8664)
+      return new LinuxElfX8664Core(proc);
+    else if (procIsa instanceof LinuxPPC64)
+      return new LinuxElfPPC64Core(proc);
+    else
+      return null;
+  }
+}
--- /dev/null	2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/util/core/LinuxElfCoreFiller.java	2006-10-17 10:16:03.000000000 +0800
@@ -0,0 +1,66 @@
+package frysk.util.core;
+
+import inua.eio.ByteOrder;
+import frysk.proc.Isa;
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+import lib.elf.Elf;
+import lib.elf.ElfEHeader;
+import lib.elf.ElfSection;
+
+public abstract class LinuxElfCoreFiller
+{
+  Proc proc = null;
+  
+  public LinuxElfCoreFiller(Proc proc)
+  {
+    this.proc = proc;
+  }
+  
+  public void fillEHArchInfo(ElfEHeader elfHeader)
+  throws TaskException
+  {
+    Isa arch = proc.getMainTask().getIsa();     
+    ByteOrder order = arch.getByteOrder();
+    
+    if (order == ByteOrder.BIG_ENDIAN)
+        elfHeader.ident[5] = ElfEHeader.PHEADER_ELFDATA2MSB;
+    else
+        elfHeader.ident[5] = ElfEHeader.PHEADER_ELFDATA2LSB;  
+  }
+  
+  public abstract void fillENoteSection(ElfSection noteSection);
+  
+  /**
+   * Fill the ELF header information for the ELF core file.
+   * 
+   * @param elfCore
+   * @param proc
+   * @return null if fail to construct ELF header.
+   */
+  public ElfEHeader fillElfHeader(Elf elfCore) throws TaskException
+  {
+    //XXX: construct ELF header for elf object. 
+    elfCore.createNewEHeader();
+    ElfEHeader elf_header = elfCore.getEHeader();
+    
+    fillEHArchInfo(elf_header);
+    // Version
+    elf_header.ident[6] = (byte) elfCore.getElfVersion();
+    
+    // EXEC for now, ET_CORE later
+    elf_header.type = ElfEHeader.PHEADER_ET_EXEC;
+    //elf_header.type = ElfEHeader.PHEADER_ET_CORE;
+    
+    // Version
+    elf_header.version = elfCore.getElfVersion();
+    
+    // String Index
+    elf_header.shstrndx = 1;
+        
+    elfCore.updateEHeader(elf_header);
+    
+    return elf_header;
+  }
+}
+
--- /dev/null	2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/util/core/LinuxElfPPC64Core.java	2006-10-17 10:16:08.000000000 +0800
@@ -0,0 +1,29 @@
+package frysk.util.core;
+
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+
+public class LinuxElfPPC64Core extends LinuxElfCoreFiller
+{
+  public LinuxElfPPC64Core(Proc proc)
+  {
+    super(proc);
+  }
+  
+  public void fillEHArchInfo(ElfEHeader elfHeader)
+  throws TaskException
+  {
+    super.fillEHArchInfo(elfHeader);
+    
+    elfHeader.machine = ElfEMachine.EM_PPC64;
+    elfHeader.ident[4] = ElfEHeader.PHEADER_ELFCLASS64;
+  }
+  
+  public void fillENoteSection(ElfSection noteSection)
+  {
+    //XXX: arch-dependent. 
+  }
+}
--- /dev/null	2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/util/core/LinuxElfX8664Core.java	2006-10-17 10:16:15.000000000 +0800
@@ -0,0 +1,30 @@
+package frysk.util.core;
+
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+
+public class LinuxElfX8664Core extends LinuxElfCoreFiller
+{
+
+  public LinuxElfX8664Core(Proc proc)
+  {
+    super(proc);
+  }
+  
+  public void fillEHArchInfo(ElfEHeader elfHeader)
+  throws TaskException
+  {
+    super.fillEHArchInfo(elfHeader);
+    
+    elfHeader.machine = ElfEMachine.EM_X86_64;
+    elfHeader.ident[4] = ElfEHeader.PHEADER_ELFCLASS64;
+  }
+  
+  public void fillENoteSection(ElfSection noteSection)
+  {
+    //XXX: arch-dependent. 
+  }
+}
--- /dev/null	2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/util/core/LinuxElfX86Core.java	2006-10-17 10:16:20.000000000 +0800
@@ -0,0 +1,29 @@
+package frysk.util.core;
+
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+
+public class LinuxElfX86Core extends LinuxElfCoreFiller
+{
+  public LinuxElfX86Core(Proc proc)
+  {
+    super(proc);
+  }
+  
+  public void fillEHArchInfo(ElfEHeader elfHeader) throws TaskException
+  {
+     
+    super.fillEHArchInfo(elfHeader);
+    
+    elfHeader.machine = ElfEMachine.EM_386;
+    elfHeader.ident[4] = ElfEHeader.PHEADER_ELFCLASS32;
+  }
+  
+  public void fillENoteSection(ElfSection noteSection)
+  {
+    //XXX: arch-dependent. 
+  }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]