* Auxv command in fhpd
@ 2007-12-06 12:46 Phil Muldoon
0 siblings, 0 replies; only message in thread
From: Phil Muldoon @ 2007-12-06 12:46 UTC (permalink / raw)
To: Frysk Hackers
[-- Attachment #1: Type: text/plain, Size: 357 bytes --]
On the way to building a map command for fhpd, I also built an auxv
command. As they are pretty similar in nature, and are fairly simple to
implement, I've included a patch here perhaps to illustrate how to add
commands to fhpd. It comprises of three parts: The command class
itself, the TopLevelCommand modifications, and expect tests.
Regards
Phil
[-- Attachment #2: auxv.patch --]
[-- Type: text/x-patch, Size: 8906 bytes --]
diff --git a/frysk-core/frysk/hpd/AuxvCommand.java b/frysk-core/frysk/hpd/AuxvCommand.java
new file mode 100644
index 0000000..79f52fd
--- /dev/null
+++ b/frysk-core/frysk/hpd/AuxvCommand.java
@@ -0,0 +1,119 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2007, 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.hpd;
+
+import inua.elf.AT;
+import java.util.Iterator;
+import java.util.List;
+import frysk.proc.Auxv;
+import frysk.proc.Proc;
+
+public class AuxvCommand extends ParameterizedCommand {
+
+ boolean verbose = false;
+
+ public AuxvCommand() {
+ super("Print process auxiliary", "auxv [-verbose]",
+ "Print out the process auxiliary data for this "
+ + "process.");
+
+ add(new CommandOption("verbose", "Print out known auxv descriptions ") {
+ void parse(String argument, Object options) {
+ verbose = true;
+ }
+ });
+
+ }
+
+ void interpret(CLI cli, Input cmd, Object options) {
+ PTSet ptset = cli.getCommandPTSet(cmd);
+ Iterator taskDataIterator = ptset.getTaskData();
+ if (taskDataIterator.hasNext() == false)
+ cli.addMessage("Cannot find main task. Cannot print out auxv", Message.TYPE_ERROR);
+ Proc mainProc = ((TaskData) taskDataIterator.next()).getTask().getProc();
+ Auxv[] liveAux = mainProc.getAuxv();
+
+ class BuildAuxv extends AuxvStringBuilder {
+
+ public StringBuffer auxvData = new StringBuffer();
+ public void buildLine(String type, String desc, String value) {
+ if (verbose)
+ auxvData.append(type+" (" + desc+") : " + value+"\n");
+ else
+ auxvData.append(type+" : " + value+"\n");
+ }
+ }
+
+ BuildAuxv buildAuxv = new BuildAuxv();
+ buildAuxv.construct(liveAux);
+
+ cli.outWriter.println(buildAuxv.auxvData.toString());
+ }
+
+ int completer(CLI cli, Input input, int cursor, List completions) {
+ return -1;
+ }
+
+ abstract class AuxvStringBuilder
+ {
+ protected AuxvStringBuilder() {
+ }
+
+ public final void construct (Auxv[] rawAuxv) {
+ String value;
+ for (int i=0; i < rawAuxv.length; i++) {
+ switch (rawAuxv[i].type) {
+ case 33:
+ case 16:
+ case 3:
+ case 9:
+ case 15:
+ value = "0x"+Long.toHexString(rawAuxv[i].val);
+ break;
+ default:
+ value = ""+rawAuxv[i].val;
+ }
+ buildLine(AT.toString(rawAuxv[i].type), AT.toPrintString(rawAuxv[i].type), value);
+ }
+ }
+
+ abstract public void buildLine(String type, String desc, String value);
+ }
+}
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 2f4412a..7e612de 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-06 Phil Muldoon <pmuldoon@redhat.com>
+
+ * TopLevelCommand.java(TopLevelCommand): add auxv command.
+ * TestAuxvCommand.java: New.
+ * AuxvCommand.java: New.
+
2007-12-04 Andrew Cagney <cagney@redhat.com>
Merge frysk.sys.Sig into frysk.sys.Signal.
diff --git a/frysk-core/frysk/hpd/TestAuxvCommand.java b/frysk-core/frysk/hpd/TestAuxvCommand.java
new file mode 100644
index 0000000..35fad72
--- /dev/null
+++ b/frysk-core/frysk/hpd/TestAuxvCommand.java
@@ -0,0 +1,72 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2007 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.hpd;
+
+import frysk.Config;
+
+public class TestAuxvCommand extends TestLib {
+
+ public void testAuxVCoreCommand() {
+ e = new HpdTestbed();
+ e.send("core " + Config.getPkgDataFile("test-core-x86").getPath()
+ + " -noexe\n");
+ e.expect(5, "Attached to core file.*");
+ e.send("auxv\n");
+ e.expect("AT_SYSINFO : 6464512");
+ e.expect("AT_SYSINFO_EHDR : 0x62a000");
+ e.expect("AT_HWCAP : 0xafe9f1bf");
+ e.expect("AT_PAGESZ : 4096");
+ e.expect("AT_CLKTCK : 100");
+ e.expect("AT_PHDR : 0x8048034");
+ e.expect("AT_PHENT : 32");
+ e.expect("AT_PHNUM : 8");
+ e.expect("AT_BASE : 0");
+ e.expect("AT_FLAGS : 0");
+ e.expect("AT_ENTRY : 0x80483e0");
+ e.expect("AT_UID : 500");
+ e.expect("AT_EUID : 500");
+ e.expect("AT_GID : 500");
+ e.expect("AT_EGID : 500");
+ e.expect("AT_0x17 : 0");
+ e.expect("AT_PLATFORM : 0xbfcfee4b");
+ e.expect("AT_NULL : 0");
+ e.close();
+ }
+}
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index 4289903..875836a 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -80,6 +80,7 @@ public class TopLevelCommand extends MultiLevelCommand {
add(new AliasCommands.Alias(), "alias");
add(new AliasCommands.Unalias(), "unalias");
add(new AttachCommand(), "attach");
+ add(new AuxvCommand(), "auxv");
add(new BreakpointCommand(), "b|reak");
add(new CoreCommand(), "core");
add(new DbgVariableCommands.Set(), "set");
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-12-06 12:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-06 12:46 Auxv command in fhpd Phil Muldoon
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).