public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: frysk@sourceware.org
Subject: DummyDisassembler for fstep
Date: Tue, 28 Aug 2007 11:01:00 -0000	[thread overview]
Message-ID: <1188298851.3817.7.camel@dijkstra.wildebeest.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 921 bytes --]

Hi,

In the last test reports I saw that FStep.testFirstStep was disabled
because we don't have a disassembler anymore. This made me a little
nervous since the test isn't actually testing the disassembler at all
and the test is a good indicator of subtle observer issues with stepping
and breakpoints. So I added a quick and dirty DummyDisassembler to fstep
that is used when no full blown Disassembler is available.

2007-08-28  Mark Wielaard  <mwielaard@redhat.com>

    * fstep.java (DummyDisassembler): New static helper class.
    (updateAttached): Create DummyDisassembler when needed.
    (updateHit): Add new observers first before removing Code observer.
    * TestFStep.java: Always supported.

With this the test passes again and now fstep even gives some useful
output even without the full disassembler. Maybe someone wants to make
this more generic for other consumers of the disassembler?

Cheers,

Mark



[-- Attachment #2: fstep-dummy-dis.patch --]
[-- Type: text/x-patch, Size: 2996 bytes --]

Index: frysk-core/frysk/bindir/TestFStep.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/bindir/TestFStep.java,v
retrieving revision 1.5
diff -u -r1.5 TestFStep.java
--- frysk-core/frysk/bindir/TestFStep.java	16 Aug 2007 20:15:11 -0000	1.5
+++ frysk-core/frysk/bindir/TestFStep.java	28 Aug 2007 10:58:46 -0000
@@ -54,8 +54,6 @@
   // stepped program.
   public void testFirstStep() throws Exception
   {
-      if (unsupported("disassembler", !lib.opcodes.Disassembler.available()))
-	  return;
     Elf e = new Elf("/bin/true", ElfCommand.ELF_C_READ);
     try
       {
Index: frysk-core/frysk/bindir/fstep.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/bindir/fstep.java,v
retrieving revision 1.10
diff -u -r1.10 fstep.java
--- frysk-core/frysk/bindir/fstep.java	9 Jul 2007 16:31:29 -0000	1.10
+++ frysk-core/frysk/bindir/fstep.java	28 Aug 2007 10:58:46 -0000
@@ -42,6 +42,7 @@
 import frysk.proc.*;
 import frysk.util.CommandlineParser;
 import lib.opcodes.*;
+import inua.eio.ByteBuffer;
 import gnu.classpath.tools.getopt.*;
 import java.util.*;
 
@@ -186,12 +187,49 @@
     Manager.eventLoop.run();
   }
 
+  /**
+   * Disassembler to use when real disassembler isn't available.
+   * Only implements <code>disassembleInstructions</code> and just
+   * returns address and four bytes in raw hex form.
+   */
+  static class DummyDisassembler extends Disassembler
+  {
+    private final ByteBuffer memory;
+    DummyDisassembler(ByteBuffer memory)
+    {
+      super(memory);
+      this.memory = memory;
+    }
+
+    public List disassembleInstructions(long address, long count)
+    {
+      ArrayList list = new ArrayList();
+      memory.position(address);
+      while (count > 0)
+	{
+	  list.add("0x" + Long.toHexString(address)
+		   + "\t0x" + Integer.toHexString(memory.getByte() & 0xff)
+		   + " 0x" + Integer.toHexString(memory.getByte() & 0xff)
+		   + " 0x" + Integer.toHexString(memory.getByte() & 0xff)
+		   + " 0x" + Integer.toHexString(memory.getByte() & 0xff));
+          address++;
+	  count--;
+	}
+      return list;
+    }
+  }
+
   // TaskObserver.Attached interface
   public Action updateAttached(Task task)
   {
     // We only need one disassembler since all Tasks share their memory.
     if (disassembler == null)
-      disassembler = new Disassembler(task.getMemory());
+      {
+	if (Disassembler.available())
+	  disassembler = new Disassembler(task.getMemory());
+	else
+	  disassembler = new DummyDisassembler(task.getMemory());
+      }
 
     tasks.put(task, Long.valueOf(0));
 
@@ -226,9 +264,9 @@
   // TaskObserver.Code interface
   public Action updateHit(Task task, long address)
   {
-    task.requestDeleteCodeObserver(this, address);
     task.requestAddInstructionObserver(this);
     task.requestAddTerminatedObserver(this);
+    task.requestDeleteCodeObserver(this, address);
     return Action.BLOCK;
   }
 

                 reply	other threads:[~2007-08-28 11:01 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=1188298851.3817.7.camel@dijkstra.wildebeest.org \
    --to=mark@klomp.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).