public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Start of LinuxCoreFactory.
Date: Wed, 20 Feb 2008 19:37:00 -0000	[thread overview]
Message-ID: <20080220193728.32104.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  caffa28dbf44f934103b9f00eeea11e15ce97581 (commit)
      from  c090884f02c5f144dd60c09657f9890aa859fa7f (commit)

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

- Log -----------------------------------------------------------------
commit caffa28dbf44f934103b9f00eeea11e15ce97581
Author: Andrew Cagney <cagney@redhat.com>
Date:   Wed Feb 20 14:35:28 2008 -0500

    Start of LinuxCoreFactory.
    
    frysk-core/frysk/proc/dead/ChangeLog
    2008-02-20  Andrew Cagney  <cagney@redhat.com>
    
    	* LinuxCoreFactory.java: New file. Code from LinuxCoreHost,
    	LinuxCoreProc, and LinuxCoreTask.

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

Summary of changes:
 frysk-core/frysk/proc/dead/ChangeLog             |    5 +
 frysk-core/frysk/proc/dead/LinuxCoreFactory.java |  129 ++++++++++++++++++++++
 2 files changed, 134 insertions(+), 0 deletions(-)
 create mode 100644 frysk-core/frysk/proc/dead/LinuxCoreFactory.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/proc/dead/ChangeLog b/frysk-core/frysk/proc/dead/ChangeLog
index 687aaa3..e818f2b 100644
--- a/frysk-core/frysk/proc/dead/ChangeLog
+++ b/frysk-core/frysk/proc/dead/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-20  Andrew Cagney  <cagney@redhat.com>
+
+	* LinuxCoreFactory.java: New file. Code from LinuxCoreHost,
+	LinuxCoreProc, and LinuxCoreTask.
+	
 2008-02-19  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* CorefileByteBuffer.java (peek): Delete log calls.
diff --git a/frysk-core/frysk/proc/dead/LinuxCoreFactory.java b/frysk-core/frysk/proc/dead/LinuxCoreFactory.java
new file mode 100644
index 0000000..1cb6eca
--- /dev/null
+++ b/frysk-core/frysk/proc/dead/LinuxCoreFactory.java
@@ -0,0 +1,129 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 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
+// 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.proc.dead;
+
+import java.io.File;
+import lib.dwfl.Elf;
+import lib.dwfl.ElfCommand;
+import lib.dwfl.ElfData;
+import lib.dwfl.ElfEHeader;
+import lib.dwfl.ElfPHeader;
+import lib.dwfl.ElfPrpsinfo;
+import frysk.proc.Proc;
+import frysk.rsl.Log;
+
+/**
+ * Data needed to construct a core file; shared between the core Host,
+ * Proc And task.
+ */
+
+public class LinuxCoreFactory {
+    private static final Log fine = Log.fine(LinuxCoreFactory.class);
+
+    static Elf core;
+    static Elf exe;
+
+    /**
+     * Construct the core file; if the EXE is non-null use it for
+     * meta-data; otherwise use the executable extracted from the
+     * core.
+     *
+     * All File paths <b>must</b> be canonical.
+     */
+    public static Proc create(File coreFile, File exeFile,
+			      boolean includeMetaData) {
+	try {
+	    // Open the core file; validate it.
+	    core = new Elf(coreFile, ElfCommand.ELF_C_READ);
+	    ElfEHeader eHeader = core.getEHeader();
+	    if (eHeader.type != ElfEHeader.PHEADER_ET_CORE) {
+		throw new RuntimeException("'" + coreFile
+					   + "' is not a corefile.");
+	    }
+	
+	    // Find the note section; there is only ever one note
+	    // section and it must be present.
+	    ElfData noteData = null;
+	    for (int i = 0; i < eHeader.phnum; i++) {
+		// Test if pheader is of types notes..
+		ElfPHeader pHeader = core.getPHeader(i);
+		if (pHeader.type == ElfPHeader.PTYPE_NOTE) {
+		    // if so, copy, break an leave.
+		    noteData = core.getRawData(pHeader.offset,
+					       pHeader.filesz);
+		    break;
+		}
+	    }
+	    if (noteData == null)
+		throw new RuntimeException("'" + coreFile
+					   + "' is corrupt; no note section");
+	    
+	    // Extract the pr/ps information from the note.
+	    ElfPrpsinfo prpsInfo = ElfPrpsinfo.decode(noteData);
+	    String[] args = prpsInfo.getPrPsargs().split(" ");
+	    fine.log("args", args);
+
+	    if (exeFile == null) {
+		// Only place to find full path + exe is in the args
+		// list. Remove ./ if present.
+		if (args.length > 0) {
+		    if (args[0].startsWith("./"))
+			exeFile = new File(args[0].substring(2));
+		    else
+			exeFile = new File(args[0]);
+		} else {
+		    exeFile = new File(prpsInfo.getPrFname());
+		}
+		fine.log("exe from core", exeFile);
+	    } else {
+		fine.log("exe for core", exeFile);
+	    }
+	    if (includeMetaData)
+		exe = new Elf(exeFile, ElfCommand.ELF_C_READ);
+
+	    return null;
+	} finally { 
+	    if (core != null)
+		core.close();
+	    if (exe != null)
+		exe.close();
+	}
+    }
+}


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


                 reply	other threads:[~2008-02-20 19:37 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=20080220193728.32104.qmail@sourceware.org \
    --to=cagney@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).