poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Poke utility pk-elfextractor


From: Jose E. Marchesi
Subject: Re: Poke utility pk-elfextractor
Date: Sun, 21 Feb 2021 09:05:42 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Indu!

>> Are you able to reproduce it interactively:
>> (poke) file foo.o
>> (poke) load elf
>> (poke) var elf = Elf64_File @ 0#B
>> (poke) var ctfsec = elf.get_section_by_name (".ctf")
>> (poke) save :file "foo.out" :from ctfsec.sh_offset :size ctfsec.sh_size
>> 
>
> Yes. This problem is reproducible interactively.
>
> You were right. The problem was in pk-save.pk. We need to use the
> output_offset as the offset to copy to. So, the following fixes the
> problem:
>
> diff --git a/poke/pk-save.pk b/poke/pk-save.pk
> index ec2a23cb..6d5eae88 100644
> --- a/poke/pk-save.pk
> +++ b/poke/pk-save.pk
> @@ -86,7 +86,7 @@ fun save = (int ios = get_ios,
>     output_offset = iosize (file_ios);
>
>   /* Copy the stuff.  */
> - copy :from_ios ios :to_ios file_ios :from from :size size;
> + copy :from_ios ios :to_ios file_ios :from from :to output_offset
> :size size;
>
>   /* Cleanup.  */
>   close (file_ios);

Ah yes, in `copy' :to defaults to :from...

Very nice.  Applied your fix in the commit below, along with a new test.
Thank you! :)

commit f4a3987fbdff2aec89313b196eb450fe53c7b073 (HEAD -> master, origin/master, 
origin/HEAD)
Author: Jose E. Marchesi <jose.marchesi@oracle.com>
Date:   Sun Feb 21 09:05:07 2021 +0100

    poke: fix output offset in the `save' command
    
    2021-02-21  Indu Bhagat  <indu.bhagat@oracle.com>
                Jose E. Marchesi  <jemarch@gnu.org>
    
            * poke/pk-save.pk (save): Fix invocation to copy.
            * testsuite/poke.cmd/save-2.pk: New test.
            * testsuite/Makefile.am (EXTRA_DIST): Update.

diff --git a/ChangeLog b/ChangeLog
index 12cd8dab..8c9d3d73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-02-21  Indu Bhagat  <indu.bhagat@oracle.com>
+           Jose E. Marchesi  <jemarch@gnu.org>
+
+       * poke/pk-save.pk (save): Fix invocation to copy.
+       * testsuite/poke.cmd/save-2.pk: New test.
+       * testsuite/Makefile.am (EXTRA_DIST): Update.
+
 2021-02-21  Jose E. Marchesi  <jemarch@gnu.org>
 
        * Makefile.am (update-hacking): New maintenance rule to regenerate
diff --git a/poke/pk-save.pk b/poke/pk-save.pk
index ec2a23cb..8ea9628f 100644
--- a/poke/pk-save.pk
+++ b/poke/pk-save.pk
@@ -86,7 +86,8 @@ fun save = (int ios = get_ios,
    output_offset = iosize (file_ios);
 
  /* Copy the stuff.  */
- copy :from_ios ios :to_ios file_ios :from from :size size;
+ copy :from_ios ios :to_ios file_ios :from from :to output_offset
+      :size size;
 
  /* Cleanup.  */
  close (file_ios);
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 4e9afb36..6920ab69 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -84,6 +84,7 @@ EXTRA_DIST = \
   poke.cmd/maps-alien-1.pk \
   poke.cmd/nbd-1.pk \
   poke.cmd/save-1.pk \
+  poke.cmd/save-2.pk \
   poke.cmd/scrabble-1.pk \
   poke.cmd/scrabble-2.pk \
   poke.cmd/scrabble-3.pk \
diff --git a/testsuite/poke.cmd/save-2.pk b/testsuite/poke.cmd/save-2.pk
new file mode 100644
index 00000000..ae04a5f7
--- /dev/null
+++ b/testsuite/poke.cmd/save-2.pk
@@ -0,0 +1,12 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80} foo.data } */
+/* { dg-data {c*} {} bar.data } */
+
+/* { dg-command { .set obase 16 } } */
+/* { dg-command { .file foo.data } } */
+/* { dg-command { save :from 2#B :size 4#B :file "bar.data" } } */
+/* { dg-command { .file bar.data } } */
+/* { dg-command { byte[4] @ 0#B } } */
+/* { dg-output "\\\[0x30UB,0x40UB,0x50UB,0x60UB\\\]" } */
+/* { dg-command { iosize (get_ios) } } */
+/* { dg-output "\n0x4#B"} */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]