public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* [patch] core file inserted breakpoints
@ 2007-07-16 15:27 Mark Wielaard
  2007-07-16 15:45 ` Phil Muldoon
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2007-07-16 15:27 UTC (permalink / raw)
  To: frysk; +Cc: pmuldoon

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

Hi,

For scenario 2 from bug # 4761 I created the following testcase that
checks whether breakpoint instructions inserted by frysk-core show up in
the fcore generated image.

2007-07-16  Mark Wielaard  <mwielaard@redhat.com>

        * TestLinuxCore.java (testInsertedBreakpoint): New method.
        (getFunctionEntryAddress): New private method.
        (CodeObserver): New static helper class.
        (AttachedObserver): Likewise.

As it happens they don't and the test PASSes (x86_64/FC6). This is
because fcore currently writes out the elf sections as it can find them
on disk. Phil and me decided it wouldn't hurt to add the testcase anyway
in case the sendrecMaps() code in core gets rewritten. Then this can be
a valuable testcase to show no regressions slip in.

Cheers,

Mark

[-- Attachment #2: breakpoint-core-test.patch --]
[-- Type: text/x-patch, Size: 5370 bytes --]

? frysk-core/frysk/proc/dead/.ChangeLog.swp
Index: frysk-core/frysk/proc/dead/TestLinuxCore.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/dead/TestLinuxCore.java,v
retrieving revision 1.4
diff -u -r1.4 TestLinuxCore.java
--- frysk-core/frysk/proc/dead/TestLinuxCore.java	13 Jul 2007 17:40:42 -0000	1.4
+++ frysk-core/frysk/proc/dead/TestLinuxCore.java	16 Jul 2007 15:26:38 -0000
@@ -43,7 +43,9 @@
 import inua.eio.ByteBuffer;
 
 import java.io.File;
+import java.util.ArrayList;
 
+import frysk.proc.Action;
 import frysk.proc.Isa;
 import frysk.proc.Task;
 import frysk.proc.Proc;
@@ -53,12 +55,17 @@
 import frysk.proc.ProcId;
 import frysk.proc.Manager;
 import frysk.proc.MemoryMap;
+import frysk.proc.TaskObserver;
 import frysk.util.CoredumpAction;
 import frysk.util.StacktraceAction;
 import frysk.event.Event;
 import frysk.event.RequestStopEvent;
 import frysk.proc.ProcBlockAction;
 import frysk.proc.ProcCoreAction;
+
+import lib.dw.*;
+import lib.elf.*;
+
 public class TestLinuxCore
     extends TestLib
 	    
@@ -338,6 +345,63 @@
       }
   }
 
+  /**
+   * Tests that inserted breakpoints aren't visible in the fcore file.
+   */
+  public void testInsertedBreakpoint() throws Exception
+  {
+    Proc ackProc = giveMeAProc();
+    Task procTask = ackProc.getMainTask();
+
+    // Make sure we are attached.
+    AttachedObserver attachedObserver = new AttachedObserver();
+    procTask.requestAddAttachedObserver(attachedObserver);
+    assertRunUntilStop("adding AttachedObserver");
+
+    // Get the memory at a breakpoint before insertion.
+    ByteBuffer memory = procTask.getMemory();
+    long proc_address = getFunctionEntryAddress(ackProc, "bp1_func");
+    memory.position(proc_address);
+    byte origb = memory.getByte();
+
+    // Insert the breakpoint (which will change the raw text/code segment).
+    CodeObserver code = new CodeObserver(procTask, proc_address);
+    procTask.requestAddCodeObserver(code, proc_address);
+    assertRunUntilStop("add breakpoint observer");
+
+    // Create a core file from the process and load it back in.
+    String coreFileName = constructCore(ackProc);
+    File xtestCore = new File(coreFileName);
+    Host lcoreHost = new LinuxHost(Manager.eventLoop,
+				   xtestCore);
+    Proc coreProc = lcoreHost.getProc(new ProcId(ackProc.getPid()));
+    Task coreTask = coreProc.getMainTask();
+
+    // Check that the breakpoint isn't visible.
+    long core_address = getFunctionEntryAddress(coreProc, "bp1_func");
+    memory = coreTask.getMemory();
+    memory.position(core_address);
+    byte coreb = memory.getByte();
+    assertEquals(origb, coreb);
+  }
+
+  /**
+   * Returns the address of the requested function through query the
+   * Proc Elf and DwarfDie. Asserts that the function has only 1
+   * entry point.
+   */
+  private static long getFunctionEntryAddress(Proc proc, String func)
+    throws ElfException
+  {
+    Elf elf = new Elf(proc.getExe(), ElfCommand.ELF_C_READ);
+    Dwarf dwarf = new Dwarf(elf, DwarfCommand.READ, null);
+    DwarfDie die = DwarfDie.getDecl(dwarf, func);
+    ArrayList entryAddrs = die.getEntryBreakpoints();
+    
+    // We really expect just one entry point.
+    assertEquals(entryAddrs.size(), 1);
+    return ((Long) entryAddrs.get(0)).longValue();
+  }
 
   /**
    * Generate a process suitable for attaching to (ie detached when returned).
@@ -379,4 +443,79 @@
     assertRunUntilStop("Running event loop for core file");
     return coreDump.getConstructedFileName();
   }
+
+  // Helper class for inserting a Code breakpoint observer.
+  static class CodeObserver
+    implements TaskObserver.Code
+  {
+    private final Task task;
+    private final long address;
+
+    boolean hit;
+
+    public CodeObserver(Task task, long address)
+    {
+      this.task = task;
+      this.address = address;
+    }
+
+    public Action updateHit (Task task, long address)
+    {
+      if (! task.equals(this.task))
+        throw new IllegalStateException("Wrong Task, given " + task
+                                        + " not equals expected "
+                                        + this.task);
+      if (address != this.address)
+        throw new IllegalStateException("Wrong address, given " + address
+                                        + " not equals expected "
+                                        + this.address);
+
+      hit = true;
+
+      Manager.eventLoop.requestStop();
+      return Action.BLOCK;
+    }
+
+    public void addedTo(Object o)
+    {
+      Manager.eventLoop.requestStop();
+    }
+
+    public void deletedFrom(Object o)
+    {
+      Manager.eventLoop.requestStop();
+    }
+
+    public void addFailed (Object o, Throwable w)
+    {
+      fail("add to " + o + " failed, because " + w);
+    }
+  }
+
+  // Helper class for attaching to a task.
+  static class AttachedObserver
+    implements TaskObserver.Attached
+  {
+    public Action updateAttached(Task task)
+    {
+      Manager.eventLoop.requestStop();
+      return Action.BLOCK;
+    }
+
+    public void addFailed(Object observable, Throwable w)
+    {
+      fail(w.toString());
+    }
+
+    public void addedTo(Object observable)
+    {
+      // Ignored
+    }
+
+    public void deletedFrom(Object observable)
+    {
+      // Ignored
+    }
+  }
+
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] core file inserted breakpoints
  2007-07-16 15:27 [patch] core file inserted breakpoints Mark Wielaard
@ 2007-07-16 15:45 ` Phil Muldoon
  2007-07-16 15:59   ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Muldoon @ 2007-07-16 15:45 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: frysk

Mark Wielaard wrote:
> As it happens they don't and the test PASSes (x86_64/FC6). This is
> because fcore currently writes out the elf sections as it can find them
> on disk. Phil and me decided it wouldn't hurt to add the testcase anyway
> in case the sendrecMaps() code in core gets rewritten. Then this can be
> a valuable testcase to show no regressions slip in.
>
>   
Mark,

Quick question: Does this pass on x86?

Regards

Phil

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] core file inserted breakpoints
  2007-07-16 15:45 ` Phil Muldoon
@ 2007-07-16 15:59   ` Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2007-07-16 15:59 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: frysk

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

Hi Phil,

On Mon, 2007-07-16 at 10:45 -0500, Phil Muldoon wrote:
> Mark Wielaard wrote:
> > As it happens they don't and the test PASSes (x86_64/FC6). This is
> > because fcore currently writes out the elf sections as it can find them
> > on disk. Phil and me decided it wouldn't hurt to add the testcase anyway
> > in case the sendrecMaps() code in core gets rewritten. Then this can be
> > a valuable testcase to show no regressions slip in.
>
> Quick question: Does this pass on x86?

Yes!

$ uname -a
Linux hermans.wildebeest.org 2.6.21-1.3228.fc7 #1 SMP Tue Jun 12 15:37:31 EDT 2007 i686 i686 i386 GNU/Linux
$ ./TestRunner frysk.proc.dead.TestLinuxCore
Running testLinuxCoreFileMaps(frysk.proc.dead.TestLinuxCore) ...PASS
Running testLinuxCoreFileStackTrace(frysk.proc.dead.TestLinuxCore) ...PASS
Running testLinuxHostPopulation(frysk.proc.dead.TestLinuxCore) ...PASS
Running testLinuxProcPopulation(frysk.proc.dead.TestLinuxCore) ...PASS
Running testLinuxProcAuxV(frysk.proc.dead.TestLinuxCore) ...PASS
Running testLinuxTaskMemory(frysk.proc.dead.TestLinuxCore) ...PASS
Running testLinuxTaskPopulation(frysk.proc.dead.TestLinuxCore) ...PASS
Running testInsertedBreakpoint(frysk.proc.dead.TestLinuxCore) ...PASS

Time: 0.468

OK (8 tests)

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-07-16 15:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-16 15:27 [patch] core file inserted breakpoints Mark Wielaard
2007-07-16 15:45 ` Phil Muldoon
2007-07-16 15:59   ` Mark Wielaard

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).