diff options
| author | Dom Cote <buzdelabuz2+git@gmail.com> | 2016-05-23 19:25:16 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-23 20:04:14 -0400 |
| commit | 321958d9710c33e74ec98c0f3c96aa2a5dbe3008 (patch) | |
| tree | 42b41280311a6afb47f0a9a5a3b9cb1e28f60c95 /scripts/gdb/linux | |
| parent | 9f66dee720984edcbc6ea07ad70fe5b8f0421c04 (diff) | |
scripts/gdb: improve types abstraction for gdb python scripts
Change the read_u16 function so it accepts both 'str' and 'byte' as type
for the arguments.
When calling read_memory() from gdb API, depending on if it was built
with 2.7 or 3.X, the format used to return the data will differ ( 'str'
for 2.7, and 'byte' for 3.X ).
Add a function read_memoryview() to be able to get a 'memoryview' object
back from read_memory() both with python 2.7 and 3.X .
Tested with python 3.4 and 2.7
Tested with gdb 7.7
Link: http://lkml.kernel.org/r/73621f564503137a002a639d174e4fb35f73f462.1462865983.git.jan.kiszka@siemens.com
Signed-off-by: Dom Cote <buzdelabuz2+git@gmail.com>
Tested-by: Kieran Bingham <kieran@bingham.xyz> (Py2.7,Py3.4,GDB10)
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/gdb/linux')
| -rw-r--r-- | scripts/gdb/linux/utils.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py index de03a6b505bb..50805874cfc3 100644 --- a/scripts/gdb/linux/utils.py +++ b/scripts/gdb/linux/utils.py | |||
| @@ -87,11 +87,24 @@ def get_target_endianness(): | |||
| 87 | return target_endianness | 87 | return target_endianness |
| 88 | 88 | ||
| 89 | 89 | ||
| 90 | def read_memoryview(inf, start, length): | ||
| 91 | return memoryview(inf.read_memory(start, length)) | ||
| 92 | |||
| 93 | |||
| 90 | def read_u16(buffer): | 94 | def read_u16(buffer): |
| 95 | value = [0, 0] | ||
| 96 | |||
| 97 | if type(buffer[0]) is str: | ||
| 98 | value[0] = ord(buffer[0]) | ||
| 99 | value[1] = ord(buffer[1]) | ||
| 100 | else: | ||
| 101 | value[0] = buffer[0] | ||
| 102 | value[1] = buffer[1] | ||
| 103 | |||
| 91 | if get_target_endianness() == LITTLE_ENDIAN: | 104 | if get_target_endianness() == LITTLE_ENDIAN: |
| 92 | return ord(buffer[0]) + (ord(buffer[1]) << 8) | 105 | return value[0] + (value[1] << 8) |
| 93 | else: | 106 | else: |
| 94 | return ord(buffer[1]) + (ord(buffer[0]) << 8) | 107 | return value[1] + (value[0] << 8) |
| 95 | 108 | ||
| 96 | 109 | ||
| 97 | def read_u32(buffer): | 110 | def read_u32(buffer): |
