From 4cd214dce4579f86a85a96c882e0fc8c4d94601c Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 10 Jun 2024 17:53:30 +0200 Subject: [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 : 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 Approved-By: Tom Tromey PR python/31845 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31845 [1] https://docs.python.org/3/c-api/arg.html --- gdb/python/py-disasm.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'gdb/python') 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 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) -- cgit v1.1