From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12812 invoked by alias); 6 Dec 2007 12:46:03 -0000 Received: (qmail 12753 invoked by uid 22791); 6 Dec 2007 12:46:02 -0000 X-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,FORGED_RCVD_HELO,SPF_HELO_PASS,SPF_PASS,TW_FH X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 06 Dec 2007 12:45:54 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.1) with ESMTP id lB6CjrAr024098 for ; Thu, 6 Dec 2007 07:45:53 -0500 Received: from pobox-2.corp.redhat.com (pobox-2.corp.redhat.com [10.11.255.15]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id lB6Cjqft014119 for ; Thu, 6 Dec 2007 07:45:52 -0500 Received: from localhost.localdomain (vpn-6-20.fab.redhat.com [10.33.6.20]) by pobox-2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id lB6Cjpde005784 for ; Thu, 6 Dec 2007 07:45:51 -0500 Message-ID: <4757EEFE.6040002@redhat.com> Date: Thu, 06 Dec 2007 12:46:00 -0000 From: Phil Muldoon User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: Frysk Hackers Subject: Auxv command in fhpd Content-Type: multipart/mixed; boundary="------------030501040706010609050605" X-Virus-Checked: Checked by ClamAV on sourceware.org X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q4/txt/msg00208.txt.bz2 This is a multi-part message in MIME format. --------------030501040706010609050605 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 357 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 --------------030501040706010609050605 Content-Type: text/x-patch; name="auxv.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="auxv.patch" Content-length: 8906 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 + + * TopLevelCommand.java(TopLevelCommand): add auxv command. + * TestAuxvCommand.java: New. + * AuxvCommand.java: New. + 2007-12-04 Andrew Cagney 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"); --------------030501040706010609050605--