diff mbox

scripts/dump-guest-memory.py: fix int128_get64 on recent gcc

Message ID 20170310085331.17916-1-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau March 10, 2017, 8:53 a.m. UTC
The Int128 is no longer a struct, reaching a python exception:
Python Exception <class 'gdb.error'> Attempt to extract a component of a value that is not a (null).:

Replace struct access with a cast to uint64 instead.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1427466

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/dump-guest-memory.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini March 10, 2017, 9:59 a.m. UTC | #1
On 10/03/2017 09:53, Marc-André Lureau wrote:
> The Int128 is no longer a struct, reaching a python exception:
> Python Exception <class 'gdb.error'> Attempt to extract a component of a value that is not a (null).:
> 
> Replace struct access with a cast to uint64 instead.
> 
> Fixes:
> https://bugzilla.redhat.com/show_bug.cgi?id=1427466
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  scripts/dump-guest-memory.py | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
> index 9956fc036c..bbe1c14ba2 100644
> --- a/scripts/dump-guest-memory.py
> +++ b/scripts/dump-guest-memory.py
> @@ -314,8 +314,10 @@ def get_arch_phdr(endianness, elfclass):
>  def int128_get64(val):
>      """Returns low 64bit part of Int128 struct."""
>  
> -    assert val["hi"] == 0
> -    return val["lo"]
> +    u64t = gdb.lookup_type('uint64_t').array(2)
> +    u64 = val.cast(u64t)
> +    assert u64[1] == 0
> +    return u64[0]
>  
>  
>  def qlist_foreach(head, field_str):
> 

I'm afraid this is not big-endian-friendly (Python lets you check that
with "sys.byteorder == 'little'").

Also when building on a 32-bit machine the old code should be used; I
think you need to use try/except to choose between the two.

Paolo
diff mbox

Patch

diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
index 9956fc036c..bbe1c14ba2 100644
--- a/scripts/dump-guest-memory.py
+++ b/scripts/dump-guest-memory.py
@@ -314,8 +314,10 @@  def get_arch_phdr(endianness, elfclass):
 def int128_get64(val):
     """Returns low 64bit part of Int128 struct."""
 
-    assert val["hi"] == 0
-    return val["lo"]
+    u64t = gdb.lookup_type('uint64_t').array(2)
+    u64 = val.cast(u64t)
+    assert u64[1] == 0
+    return u64[0]
 
 
 def qlist_foreach(head, field_str):