diff options
author | Tom de Vries <tdevries@suse.de> | 2024-06-10 17:53:30 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-06-10 17:53:30 +0200 |
commit | 4cd214dce4579f86a85a96c882e0fc8c4d94601c (patch) | |
tree | 6bf2d63bf3024ddc28c61a94fa91164373900656 | |
parent | 25d826c6bfddd8a660d2a0627d8896f73a7abadb (diff) | |
download | gdb-4cd214dce4579f86a85a96c882e0fc8c4d94601c.zip gdb-4cd214dce4579f86a85a96c882e0fc8c4d94601c.tar.gz gdb-4cd214dce4579f86a85a96c882e0fc8c4d94601c.tar.bz2 |
[gdb/python] Fix gdb.python/py-disasm.exp on arm-linux
After fixing test-case gdb.python/py-disasm.exp to recognize the arm nop:
...
nop {0}
...
we run into:
...
disassemble test^M
Dump of assembler code for function test:^M
0x004004d8 <+0>: push {r11} @ (str r11, [sp, #-4]!)^M
0x004004dc <+4>: add r11, sp, #0^M
0x004004e0 <+8>: nop {0}^M
=> 0x004004e4 <+12>: Python Exception <class 'ValueError'>: Buffer \
returned from read_memory is sized 0 instead of the expected 4^M
^M
unknown disassembler error (error = -1)^M
(gdb) FAIL: $exp: global_disassembler=ShowInfoRepr: disassemble test
...
This is caused by this code in gdbpy_disassembler::read_memory_func:
...
gdbpy_ref<> result_obj (PyObject_CallMethod ((PyObject *) obj,
"read_memory",
"KL", len, offset));
...
where len has type "unsigned int", while "K" means "unsigned long long" [1].
Fix this by using "I" instead, meaning "unsigned int".
Also, offset has type LONGEST, which is typedef'ed to int64_t, while "L" means
"long long".
Fix this by using type gdb_py_longest for offset, in combination with format
character "GDB_PY_LL_ARG". Likewise in disasmpy_info_read_memory.
Tested on arm-linux.
Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
PR python/31845
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31845
[1] https://docs.python.org/3/c-api/arg.html
-rw-r--r-- | gdb/python/py-disasm.c | 12 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-disasm.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-disasm.py | 2 |
3 files changed, 9 insertions, 7 deletions
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c index 2d8ce44..9337514 100644 --- a/gdb/python/py-disasm.c +++ b/gdb/python/py-disasm.c @@ -667,12 +667,13 @@ disasmpy_info_read_memory (PyObject *self, PyObject *args, PyObject *kw) disasm_info_object *obj = (disasm_info_object *) self; DISASMPY_DISASM_INFO_REQUIRE_VALID (obj); - LONGEST length, offset = 0; + gdb_py_longest length, offset = 0; gdb::unique_xmalloc_ptr<gdb_byte> buffer; static const char *keywords[] = { "length", "offset", nullptr }; - if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "L|L", keywords, - &length, &offset)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, + GDB_PY_LL_ARG "|" GDB_PY_LL_ARG, + keywords, &length, &offset)) return nullptr; /* The apparent address from which we are reading memory. Note that in @@ -849,13 +850,14 @@ gdbpy_disassembler::read_memory_func (bfd_vma memaddr, gdb_byte *buff, /* The DisassembleInfo.read_memory method expects an offset from the address stored within the DisassembleInfo object; calculate that offset here. */ - LONGEST offset = (LONGEST) memaddr - (LONGEST) obj->address; + gdb_py_longest offset + = (gdb_py_longest) memaddr - (gdb_py_longest) obj->address; /* Now call the DisassembleInfo.read_memory method. This might have been overridden by the user. */ gdbpy_ref<> result_obj (PyObject_CallMethod ((PyObject *) obj, "read_memory", - "KL", len, offset)); + "I" GDB_PY_LL_ARG, len, offset)); /* Handle any exceptions. */ if (result_obj == nullptr) diff --git a/gdb/testsuite/gdb.python/py-disasm.exp b/gdb/testsuite/gdb.python/py-disasm.exp index 7c6f972..5d7d922 100644 --- a/gdb/testsuite/gdb.python/py-disasm.exp +++ b/gdb/testsuite/gdb.python/py-disasm.exp @@ -65,7 +65,7 @@ proc py_remove_all_disassemblers {} { # # Each different disassembler tests some different feature of the # Python disassembler API. -set nop "(nop|nop\t0)" +set nop "(nop|nop\t0|[string_to_regexp nop\t{0}])" set unknown_error_pattern "unknown disassembler error \\(error = -1\\)" set addr_pattern "\r\n=> ${curr_pc_pattern} <\[^>\]+>:\\s+" set base_pattern "${addr_pattern}${nop}" diff --git a/gdb/testsuite/gdb.python/py-disasm.py b/gdb/testsuite/gdb.python/py-disasm.py index c09eae8..2741fdb 100644 --- a/gdb/testsuite/gdb.python/py-disasm.py +++ b/gdb/testsuite/gdb.python/py-disasm.py @@ -46,7 +46,7 @@ def check_building_disassemble_result(): def is_nop(s): - return s == "nop" or s == "nop\t0" + return s == "nop" or s == "nop\t0" or s == "nop\t{0}" # Remove all currently registered disassemblers. |