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


It seems this patch addresses two ideas:

- create prspinfo data structures in part;
- re-factor FCore into an arch-based factory solution.

First I would like to address the second part..

I do not think there is an answer just yet for the question: Is a separate factory instantiation needed for each architecture? Not until fcore has a core file written completely for one architecture. There is still the notes section left to do. Looking at other code that generates core files, they do not follow this approach of different factories (and therefore different method) of constructing core file data. As far as I can see, the only arch-dependent data that exists for the headers is:

LSB or MSB (one byte flag)
32 or 64 bit (one byte flag)
Machine name (one byte flag)

And General Register/fp register Info.

The register info is accessed already in a generic and independent way via an iterator pattern. I am wondering if "right now" the re-factor is a little heavyweight for a lightweight solution. And the other thing that concerns me is the construction of the core factories relies heavily on the generation of Isa factories. I get the idea that Isa will be re-factored soon, and that will cause ripple down implications. However I can see great use for it, if/when there is useful additional data beyond what are in corefiles right now, to extend notes for Frysk's own purposes. Then I think the factory solution would be ideal then.

The first part of the patch looks great (prspinfo specific solution: ElfNhdr.cxx, ElfNhdr.java,ElfNhdrType.java,ElfPrpsinfo.cxx,ElfPrpsinfo.java) and I would check it in. Good work, I really like the solution there.

I would like to propose keeping the FCore -> (Factory) re-factor out for now. Let's get the core file written in a generic and simple fashion like other generators do first. Then perhaps the question about needing the factories can be answered. As most of FCore is done, no code will be lost, and can always go back later and redo with your patch. I qualify later as being "days from now", pretty short term.

Regards


Phil Yong Zheng wrote:
I was hoping that the Isa factory based abstraction would already help here. OTOH, I like the idea you proposed here though I am wary of building factories (ours) on top of ISA's own. However it really cleanly cuts the code up into arch dependent parts within the FCore code. So I agree we should go ahead and implement it down the line.

What I am doing today/this week is exposing the notes section to the core file. First thing I'll have to do is expose the notes structures to the Java bindings of Libelf, then build on the population of those structures. So I'll think on this some more during that time ;)

Regards

Phil


Phil, when I try to construct prpsinfo, there's no any definition in
elfutils package. So I have to use <linux/elfcore.h> for java binding.
And at the sametime, I refactor the arch-dependent code on CORE dumping
again in order to dump out prpsinfo more easily. I just write some
source codes now and post them out for comments from anybody who is
interested in this.


Looking forward to your commends.

Best regards.
Yong Zheng
------------------------------------------------------------------------


--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-imports/lib/elf/ElfNhdr.java 2006-10-18 21:02:35.000000000 +0800
@@ -0,0 +1,136 @@
+package lib.elf;
+
+public class ElfNhdr
+{
+ private long namesz = 4;
+ private long descsz = 0;
+ private int type = ElfNhdrType.NT_INVALID.getValue();
+ + private String name = "CORE";
+ private ElfNoteSectionEntry desc = null;
+ + public static abstract class ElfNoteSectionEntry
+ {
+ public abstract long getEntrySize();
+ public abstract long fillMemRegion(byte[] buffer, long startAddress);
+ }
+ + //XXX: no ElfNhdr struct in elfutils package now(2006-10-18).
+ //private long pointer;
+ + public ElfNhdr()
+ {
+
+ }
+ + public String getName()
+ {
+ return this.name;
+ }
+ public long getNameSize()
+ {
+ return this.namesz;
+ }
+ public void setName(String nhdrName)
+ {
+ if (null == nhdrName)
+ return;
+ + this.name = nhdrName;
+ this.namesz = nhdrName.length();
+ }
+ + public ElfNhdrType getNhdrType()
+ {
+ return ElfNhdrType.intern(this.type);
+ }
+ public ElfNoteSectionEntry getNhdrDesc()
+ {
+ return this.desc;
+ }
+ public long getDescSize()
+ {
+ return this.descsz;
+ }
+ + public void setNhdrDesc(ElfNhdrType nhdrType, ElfNoteSectionEntry nhdrDesc)
+ {
+ this.type = nhdrType.getValue();
+ this.desc = nhdrDesc;
+ this.descsz = nhdrDesc.getEntrySize();
+ }
+ + /**
+ * Get the whole size of Nhdr (incluing the namesz and descsz).
+ * + * @return
+ */
+ public long getNhdrEntrySize()
+ {
+ long size = 0;
+ + int nhdrSize = 0;
+ + nhdrSize = getNhdrSize();
+ if ((nhdrSize <= 0) ||
+ (namesz <= 0) || (descsz <= 0))
+ {
+ //Invalid object.
+ return size;
+ }
+ + size = nhdrSize + namesz + descsz;
+ + return size;
+ }
+ + /**
+ * Just get the size of Nhdr struct.
+ * + * @return
+ */
+ public native int getNhdrSize();
+ + protected native long fillNhdr(byte[] buffer, long startAddress);
+ protected native long fillNhdrName(byte[] buffer, long startAddress);
+ + /**
+ * Fill the region starting from startAddress in buffer according to this ElfNhdr object.
+ * + * @param noteSecBuffer
+ * @param startAddress
+ * @return
+ */
+ public long fillMemRegion(byte[] buffer, long startAddress)
+ {
+ long nhdrEntrySize = 0;
+ + long fillSize = 0;
+ + fillSize = fillNhdr(buffer, startAddress);
+ if (fillSize != getNhdrSize())
+ {
+ //XXX: error occurred. throw excetpion?
+ }
+ + nhdrEntrySize += fillSize;
+ startAddress += fillSize;
+ fillSize = fillNhdrName(buffer, startAddress);
+ if (fillSize != this.namesz)
+ {
+ //XXX: error occurred. Throw exception?
+ }
+ + nhdrEntrySize += fillSize;
+ startAddress += fillSize;
+ fillSize = this.desc.fillMemRegion(buffer, startAddress);
+ if (fillSize != this.descsz)
+ {
+ //XXX: error occurred. Throw exception?
+ }
+ + nhdrEntrySize += fillSize;
+ return fillSize;
+ }
+ +}
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-imports/lib/elf/ElfNhdrType.java 2006-10-18 21:02:38.000000000 +0800
@@ -0,0 +1,70 @@
+package lib.elf;
+
+public class ElfNhdrType
+{
+ public static final ElfNhdrType NT_INVALID = new ElfNhdrType(0, "NT_INVALID");
+ public static final ElfNhdrType NT_PRSTATUS = new ElfNhdrType(1, "NT_PRSTATUS");
+ public static final ElfNhdrType NT_FPREGSET = new ElfNhdrType(2, "NT_FPREGSET");
+ public static final ElfNhdrType NT_PRPSINFO = new ElfNhdrType(3, "NT_PRPSINFO");
+ public static final ElfNhdrType NT_PRXREG = new ElfNhdrType(4, "NT_PRXREG");
+ + public static final ElfNhdrType NT_TASKSTRUCT = new ElfNhdrType(4, "NT_TASKSTRUCT");
+ public static final ElfNhdrType NT_PLATFORM = new ElfNhdrType(5, "NT_PLATFORM");
+ public static final ElfNhdrType NT_AUXV = new ElfNhdrType(6, "NT_AUXV");
+ public static final ElfNhdrType NT_GWINDOWS = new ElfNhdrType(7, "NT_GWINDOWS");
+ public static final ElfNhdrType NT_ASRS = new ElfNhdrType(8, "NT_ASRS");
+ + public static final ElfNhdrType NT_PSTATUS = new ElfNhdrType(10, "NT_PSTATUS");
+ public static final ElfNhdrType NT_PSINFO = new ElfNhdrType(13, "NT_PSINFO");
+ public static final ElfNhdrType NT_PRCRED = new ElfNhdrType(14, "NT_PRCRED");
+ + public static final ElfNhdrType NT_UTSNAME = new ElfNhdrType(15, "NT_UTSNAME");
+ public static final ElfNhdrType NT_LWPSTATUS = new ElfNhdrType(16, "NT_LWPSTATUS");
+ public static final ElfNhdrType NT_LWPSINFO = new ElfNhdrType(17, "NT_LWPSINFO");
+ public static final ElfNhdrType NT_PRFPXREG = new ElfNhdrType(20, "NT_PRFPXREG");
+ + private static ElfNhdrType[] types = {NT_INVALID, + NT_PRSTATUS, NT_FPREGSET, NT_PRPSINFO, NT_PRXREG, NT_PLATFORM,
+ NT_AUXV, NT_GWINDOWS, NT_ASRS, NT_INVALID, NT_PSTATUS,
+ NT_INVALID, NT_INVALID, NT_PSINFO, NT_PRCRED, NT_UTSNAME,
+ NT_LWPSTATUS, NT_LWPSINFO, NT_INVALID, NT_INVALID, NT_PRFPXREG
+ };
+ + private int value = 0;
+ private String name = null;
+ + private ElfNhdrType(int value, String name)
+ {
+ this.value = value;
+ this.name = name;
+ }
+ + /**
+ * @return true iff the object is an ElfType and equal to this object
+ */
+ public boolean equals(Object obj)
+ {
+ if(!(obj instanceof ElfNhdrType))
+ return false;
+ + return ((ElfNhdrType)obj).value == this.value;
+ }
+ + public int getValue()
+ {
+ return this.value;
+ }
+ + public static ElfNhdrType intern(int type)
+ {
+ if ((type <= 0) || (type > (types.length - 1)))
+ return NT_INVALID;
+ else
+ return types[type];
+ }
+ + public String toString()
+ {
+ return this.name + "(" + this.value + ")";
+ }
+}
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-imports/lib/elf/ElfPrpsinfo.java 2006-10-18 21:02:55.000000000 +0800
@@ -0,0 +1,242 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2005, IBM 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.elf;
+
+public class ElfPrpsinfo extends ElfNhdr.ElfNoteSectionEntry
+{
+ private char pr_state;
+ private char pr_sname;
+ private char pr_zomb;
+ private char pr_nice;
+ + private long pr_flag;
+ + // on most platform, pr_uid is unsigned int. + // In java, "int" it sigend, so we have to use long type.
+ private long pr_uid;
+ private long pr_gid;
+ + private int pr_pid;
+ private int pr_ppid;
+ private int pr_pgrp;
+ private int pr_sid;
+ + //XXX: the following two value must keep the same with the elfutils package.
+ public static int ELF_PRPSINFO_FNAME_MAXLEN = 16;
+ public static int ELF_PRPSINFO_ARGS_MAXLEN = 80;
+ + // filename of executable
+ private char[] pr_fname = new char[ELF_PRPSINFO_FNAME_MAXLEN];
+ + // initial part of arg list
+ private char[] pr_psargs = new char[ELF_PRPSINFO_ARGS_MAXLEN];
+ + private int pid;
+ + public ElfPrpsinfo(int pid)
+ {
+ this.pid = pid;
+ }
+ + public void setPrState(char state)
+ {
+ this.pr_state = state;
+ }
+ + public char getPrState()
+ {
+ return this.pr_state;
+ }
+ + public void setPrSname(char sname)
+ {
+ this.pr_sname = sname;
+ }
+ + public char getPrSname()
+ {
+ return this.pr_sname;
+ }
+ + public void setPrZomb(char zomb)
+ {
+ this.pr_zomb = zomb;
+ }
+ + public char getPrZomb()
+ {
+ return this.pr_zomb;
+ }
+ + public void setPrNice(char nice)
+ {
+ this.pr_nice = nice;
+ }
+ + public char getPrNice()
+ {
+ return this.pr_nice;
+ }
+ + public void setPrFlag(long flag)
+ {
+ this.pr_flag = flag;
+ }
+ + public long getPrFlag()
+ {
+ return this.pr_flag;
+ }
+ + public void setPrUid(long uid)
+ {
+ this.pr_uid = uid;
+ }
+ + public long getPrUid()
+ {
+ return this.pr_uid;
+ }
+ + public void setPrGid(long gid)
+ {
+ this.pr_gid = gid;
+ }
+ + public long getPrGid()
+ {
+ return this.pr_gid;
+ }
+ + public void setPrPid(int pid)
+ {
+ this.pr_pid = pid;
+ }
+ public int getPrPid()
+ {
+ return this.pr_pid;
+ }
+ + public void setPrPpid(int ppid)
+ {
+ this.pr_ppid = ppid;
+ }
+
+ public int getPrPpid()
+ {
+ return this.pr_ppid;
+ }
+ + public void setPrPgrp(int pgrp)
+ {
+ this.pr_pgrp = pgrp;
+ }
+ + public int setPrPgrp()
+ {
+ return this.pr_pgrp;
+ }
+ + public void setPrSid(int sid)
+ {
+ this.pr_sid = sid;
+ }
+
+ public int getPrSid()
+ {
+ return this.pr_sid;
+ }
+ + public void setPrFname(String fname)
+ {
+ if (null == fname)
+ return;
+ + int length = fname.length();
+ if (length < ELF_PRPSINFO_FNAME_MAXLEN)
+ {
+ this.pr_fname = fname.toCharArray();
+ this.pr_fname[length] = '0';
+ }
+ else
+ {
+ String name = fname.substring(0, ELF_PRPSINFO_FNAME_MAXLEN);
+ + this.pr_fname = name.toCharArray();
+ this.pr_fname[ELF_PRPSINFO_FNAME_MAXLEN] = '0'; + }
+ }
+ public char[] getPrFname()
+ {
+ return this.pr_fname;
+ }
+
+ public void getPrPsargs(String args)
+ {
+ if (null == args)
+ return;
+ + int length = args.length();
+ if (length < ELF_PRPSINFO_ARGS_MAXLEN)
+ {
+ this.pr_psargs = args.toCharArray();
+ this.pr_psargs[length] = '0';
+ }
+ else
+ {
+ String name = args.substring(0, ELF_PRPSINFO_ARGS_MAXLEN);
+ + this.pr_psargs = name.toCharArray();
+ this.pr_psargs[ELF_PRPSINFO_ARGS_MAXLEN] = '0'; + }
+ }
+ public char[] getPrPsargs()
+ {
+ return this.pr_psargs;
+ }
+ + public int getPid()
+ {
+ return this.pid;
+ }
+ + public native long getEntrySize();
+ public native long fillMemRegion(byte[] buffer, long startAddress);
+}
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-imports/lib/elf/cni/ElfNhdr.cxx 2006-10-18 21:03:09.000000000 +0800
@@ -0,0 +1,102 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2005, IBM 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.
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <gelf.h>
+#include <gcj/cni.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <gelf.h>
+
+#include "lib/elf/ElfNhdr.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+jint
+lib::elf::ElfNhdr::getNhdrSize()
+{
+ return sizeof(GElf_Nhdr);
+}
+
+jlong +lib::elf::ElfNhdr::fillNhdr(jbyteArray buffer, jlong startAddress)
+{
+ jbyte *bs = elements(buffer) + startAddress;
+
+ errno = 0;
+ GElf_Nhdr *nhdr = (GElf_Nhdr *)malloc(sizeof(GElf_Nhdr));
+
+ memset(nhdr, 0, sizeof(GElf_Nhdr));
+
+ // copy the GElf_Nhdr struct into buffer.
+ //
+ nhdr->n_namesz = this->namesz;
+ nhdr->n_descsz = this->descsz;
+
+ nhdr->n_type = this->type;
+
+ memcpy(bs, nhdr, sizeof(GElf_Nhdr));
+
+ return sizeof(GElf_Nhdr);
+}
+
+jlong +lib::elf::ElfNhdr::fillNhdrName(jbyteArray buffer, jlong startAddress)
+{
+ jlong size = 0; + jbyte *bs = elements(buffer) + startAddress;
+
+ //Copy the name infor into buffer.
+ size = (jlong)JvGetStringUTFRegion(this->name, 0, this->namesz, (char *)bs);
+ return size;
+}
+ + +#ifdef __cplusplus
+}
+#endif
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-imports/lib/elf/cni/ElfPrpsinfo.cxx 2006-10-18 21:03:15.000000000 +0800
@@ -0,0 +1,108 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2005, IBM 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.
+
+#include <linux/elfcore.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <gcj/cni.h>
+//#include <string.h>
+//#include <sys/types.h>
+//#include <sys/stat.h>
+//#include <fcntl.h>
+//#include <stdio.h>
+//#include <errno.h>
+
+
+#include "lib/elf/ElfPrpsinfo.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+jlong
+lib::elf::ElfPrpsinfo::getEntrySize()
+{
+ int entrySize = sizeof(elf_prpsinfo);
+
+ return (jlong)entrySize;
+}
+
+jlong +lib::elf::ElfPrpsinfo::fillMemRegion(jbyteArray buffer, jlong startAddress)
+{
+ jbyte *bs = elements(buffer);
+ struct elf_prpsinfo *prpsinfo = NULL;
+
+ prpsinfo = (struct elf_prpsinfo *)malloc(sizeof(struct elf_prpsinfo));
+
+ memset(prpsinfo, 0, sizeof(struct elf_prpsinfo));
+
+ prpsinfo->pr_state = this->pr_state;
+ prpsinfo->pr_sname = this->pr_sname;
+ prpsinfo->pr_zomb = this->pr_zomb;
+ prpsinfo->pr_nice = this->pr_nice;
+ prpsinfo->pr_flag = this->pr_flag;
+
+ prpsinfo->pr_uid = this->pr_uid;
+ prpsinfo->pr_gid = this->pr_gid;
+
+ prpsinfo->pr_pid = this->pr_pid;
+ prpsinfo->pr_ppid = this->pr_ppid;
+ prpsinfo->pr_pgrp = this->pr_pgrp;
+
+ prpsinfo->pr_sid = this->pr_sid;
+
+ jchar *fname = elements(this->pr_fname);
+ jchar *args = elements(this->pr_psargs);
+
+ memcpy(prpsinfo->pr_fname, fname, sizeof(fname));
+ prpsinfo->pr_fname[sizeof(fname)] = '\0';
+
+ memcpy(prpsinfo->pr_psargs, args, sizeof(args));
+ prpsinfo->pr_psargs[sizeof(args)] = '\0';
+
+ memcpy(bs + startAddress, prpsinfo, sizeof(prpsinfo));
+
+ return sizeof(prpsinfo);
+}
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/proc/LinuxElfCoreFactory.java 2006-10-18 21:03:41.000000000 +0800
@@ -0,0 +1,38 @@
+package frysk.proc;
+
+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 LinuxElfCoreFactory
+{
+
+ public static LinuxElfCore getElfCore(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 LinuxElfCoreIa32(proc);
+ else if (procIsa instanceof LinuxX8664)
+ return new LinuxElfCoreX8664(proc);
+ else if (procIsa instanceof LinuxPPC64)
+ return new LinuxElfCorePPC64(proc);
+ else
+ return null;
+ }
+}
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/proc/LinuxElfCoreIa32On64.java 2006-10-18 21:03:49.000000000 +0800
@@ -0,0 +1,27 @@
+package frysk.proc;
+
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+
+public class LinuxElfCoreIa32On64 extends LinuxElfCore
+{
+ public LinuxElfCoreIa32On64(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. + }
+}
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/proc/LinuxElfCorePPC32On64.java 2006-10-18 21:03:56.000000000 +0800
@@ -0,0 +1,27 @@
+package frysk.proc;
+
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+
+public class LinuxElfCorePPC32On64 extends LinuxElfCore
+{
+ public LinuxElfCorePPC32On64(Proc proc)
+ {
+ super(proc);
+ }
+ + public void fillEHArchInfo(ElfEHeader elfHeader)
+ throws TaskException
+ {
+ super.fillEHArchInfo(elfHeader);
+ + elfHeader.machine = ElfEMachine.EM_PPC;
+ elfHeader.ident[4] = ElfEHeader.PHEADER_ELFCLASS32;
+ }
+ + public void fillENoteSection(ElfSection noteSection)
+ {
+ //XXX: arch-dependent. + }
+}
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/proc/LinuxElfCoreX8664.java 2006-10-18 21:04:01.000000000 +0800
@@ -0,0 +1,30 @@
+package frysk.proc;
+
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+
+public class LinuxElfCoreX8664 extends LinuxElfCore
+{
+
+ public LinuxElfCoreX8664(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/proc/LinuxElfCoreIa32.java 2006-10-18 21:04:06.000000000 +0800
@@ -0,0 +1,29 @@
+package frysk.proc;
+
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+
+public class LinuxElfCoreIa32 extends LinuxElfCore
+{
+ public LinuxElfCoreIa32(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. + }
+}
--- /dev/null 2006-10-16 17:26:51.467209250 +0800
+++ frysk-core/frysk/proc/LinuxElfCore.java 2006-10-18 21:04:10.000000000 +0800
@@ -0,0 +1,164 @@
+package frysk.util.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import inua.eio.ByteOrder;
+import frysk.proc.Isa;
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+import lib.elf.Elf;
+import lib.elf.ElfData;
+import lib.elf.ElfEHeader;
+import lib.elf.ElfNhdr;
+import lib.elf.ElfNoteSectionEntry;
+import lib.elf.ElfSection;
+
+public abstract class LinuxElfCore
+{
+ Proc proc = null;
+ + public LinuxElfCore(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; + }
+ + /**
+ * Fill the ElfNhdr object according to Proc object.
+ * + * @param nhdrEntry
+ * @param proc
+ * @return less than zero when error occurs, or return one value + * that is equal to zero or more than zero.
+ */
+ protected int fillENotePrpsinfo(ElfNhdr nhdrEntry, Proc proc)
+ {
+ //XXX: fill the elf_prpsinfo here.
+ }
+ + /**
+ * Transform all information carried by list into ElfData object.
+ * + * @param noteSectionData
+ * @param list ElfNhdr list.
+ * @return the number of invalid ElfNhdr objects.
+ */
+ protected int constructSectionData(ElfData noteSectionData, List nhdrList)
+ {
+ int size = 0;
+ + long secSize = 0;
+ long entrySize = 0;
+ + size = nhdrList.size();
+ if (size <= 0)
+ return 0;
+ + // Count the size of the whole PT_NOTE section.
+ for (int index = 0; index < size; index++)
+ {
+ ElfNhdr entry = (ElfNhdr)nhdrList.get(index);
+ + entrySize = entry.getNhdrEntrySize();
+ if (entrySize <= 0)
+ {
+ //One invalid entry, ignore it.
+ nhdrList.remove(index);
+ size--;
+ index--;
+ continue;
+ }
+ + secSize += entrySize;
+ }
+ //XXX: in the operation "new byte[count]", count must be "int". + // If secSize is bigger than the max of "int' type, how can we do?
+ byte[] noteSecBuffer = new byte[(int)secSize];
+ long startAddress = 0;
+ + // Begin to fill the noteSection memory region.
+ size = nhdrList.size();
+ for (int index = 0; index < size; index++)
+ {
+ ElfNhdr entry = (ElfNhdr)nhdrList.get(index);
+ + entry.fillMemRegion(noteSecBuffer, startAddress);
+ + startAddress += entry.getNhdrEntrySize();
+ }
+ + return size;
+ }
+ + public void fillENoteSection(ElfSection noteSection)
+ {
+ int ret = -1;
+ int entryCount = 0;
+ + ArrayList list = new ArrayList();
+ + ElfNhdr prpsinfoNhdr = new ElfNhdr();
+ noteSection.getPointer()
+ ret = this.fillENotePrpsinfo(prpsinfoNhdr, this.proc);
+ if (ret >= 0)
+ {
+ // Fill PRPSINFO correctly.
+ list.add(entryCount, prpsinfoNhdr);
+ entryCount++;
+ }
+ + //XXX: Continue to fill other ElfNhdr object, such as NT_PRSTATUS info.
+ // ElfNhdr psstatusNhdr = new ...
+ + if (list.size() <= 0)
+ return;
+ + ElfData sectionDate = noteSection.createNewElfData();
+ constructSectionData(sectionDate, list);
+ }
+ + /**
+ * 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/proc/LinuxElfCorePPC64.java 2006-10-18 21:04:17.000000000 +0800
@@ -0,0 +1,29 @@
+package frysk.proc;
+
+import lib.elf.ElfEHeader;
+import lib.elf.ElfEMachine;
+import lib.elf.ElfSection;
+import frysk.proc.Proc;
+import frysk.proc.TaskException;
+
+public class LinuxElfCorePPC64 extends LinuxElfCore
+{
+ public LinuxElfCorePPC64(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. + }
+}


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