aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2017-01-26Fix crash when loading a core with unexpected register section sizeAntoine Tremblay2-1/+8
When loading a core without an executable like so: $ gdb --core core for example often the gdbarch won't contain the iterate_over_regset_sections method. For example on ARM. This will generate a call to get_core_register_section with a NULL regset like at corelow.c:628 get_core_register_section (regcache, NULL, ".reg", 0, 0, "general-purpose", 1); However a check for REGSET_VARIABLE_SIZE in get_core_register_section assumes that regset is != NULL thus leading to a crash with this backtrace: (gdb) bt #0 0x000000000065907b in get_core_register_section (regcache=regcache@entry=0x2c26260, regset=regset@entry=0x0, name=name@entry=0xdbf7b2 ".reg", min_size=min_size@entry=0, which=which@entry=0, human_name=human_name@entry=0xdbac28 "general-purpose", required=1) at ../../gdb/corelow.c:542 #1 0x0000000000659b70 in get_core_registers (ops=<optimized out>, regcache=0x2c26260, regno=<optimized out>) at ../../gdb/corelow.c:628 #2 0x000000000076e5fb in target_fetch_registers (regcache=regcache@entry=0x2c26260, regno=regno@entry=15) at ../../gdb/target.c:3590 Note that commit: f962539ad23759 ("Warn if core file register section is larger than expected") introduced this issue. Thus releases > 7.8.2 are affected. Also, this would have been caught by gdb.base/corefile.exp but the problem is that this triggers only if the core dump is missing some data so that it's not recognized as a linux core dump, or it's not a linux core dump and the core file register section is larger than expected. So if you just create a core and read it on linux with ARM the osabi is detected properly and iterate_over_regset_sections is present and so the problem is not triggered. Thus creating a linux test for this with a crafted core that meets the problem requirements is non-trivial. This patch fixes this crash by adding a check for regset existence before running the condition. gdb/ChangeLog: * corelow.c (get_core_register_section): Check for regset existence before checking for REGSET_VARIABLE_SIZE.
2017-01-26Don't throw exception in dis_asm_memory_errorYao Qi5-2/+32
Hi, GDB calls some APIs from opcodes to do disassembly and provide some call backs. This model makes troubles on C++ exception unwinding, because GDB is a C++ program, and opcodes is still compiled as C. As we can see, frame #10 and #12 are C++, while #frame 11 is C, #10 0x0000000000544228 in memory_error (err=TARGET_XFER_E_IO, memaddr=<optimized out>) at ../../binutils-gdb/gdb/corefile.c:237 #11 0x00000000006b0a54 in print_insn_aarch64 (pc=0, info=0xffffffffeeb0) at ../../binutils-gdb/opcodes/aarch64-dis.c:3185 #12 0x0000000000553590 in gdb_pretty_print_insn (gdbarch=gdbarch@entry=0xbbceb0, uiout=uiout@entry=0xbc73d0, di=di@entry=0xffffffffeeb0, insn=0xffffffffed40, insn@entry=0xffffffffed90, flags=flags@entry=0, C++ exception unwinder can't go across frame #11 unless it has unwind table. However, C program on many architectures doesn't have it in default. As a result, GDB aborts, which is described in PR 20939. This is not the first time we see this kind of problem. We've had a commit 89525768cd086a0798a504c81fdf7ebcd4c904e1 "Propagate GDB/C++ exceptions across readline using sj/lj-based TRY/CATCH". We can fix the disassembly bug in a similar way, this is the option one. Since opcodes is built with gdb, we fix this problem in a different way as we did for the same issue with readline. Instead of throwing exception in dis_asm_memory_error, we record the failed memory address, and throw exception when GDB returns from opcodes disassemblers. gdb: 2017-01-26 Yao Qi <yao.qi@linaro.org> Pedro Alves <palves@redhat.com> PR gdb/20939 * disasm.c (gdb_disassembler::dis_asm_memory_error): Don't call memory_error, save memaddr instead. (gdb_disassembler::print_insn): If gdbarch_print_insn returns negative, cal memory_error. * disasm.h (gdb_disassembler) <m_err_memaddr>: New field. gdb/testsuite: 2017-01-26 Yao Qi <yao.qi@linaro.org> * gdb.base/all-architectures.exp.in (do_arch_tests): Test disassemble on address 0.
2017-01-26Disassembly unit test: memory errorYao Qi2-0/+47
This patch adds a unit test about memory error occurs on reading memory, and check MEMORY_ERROR exception is always thrown. gdb: 2017-01-26 Yao Qi <yao.qi@linaro.org> * disasm-selftests.c (memory_error_test): New function. (_initialize_disasm_selftests): Register memory_error_test.
2017-01-26Disassembly unit test: disassemble one instructionYao Qi5-0/+322
This patch adds one unit test, which disassemble one instruction for every gdbarch if available. The test needs one valid instruction of each gdbarch, and most of them are got from breakpoint instruction. For the rest gdbarch whose breakpoint instruction isn't a valid instruction, I copy one instruction from the gas/testsuite/gas/ directory. I get the valid instruction of most gdbarch except ia64, mep, mips, tic6x, and xtensa. People familiar with these arch should be easy to extend the test. In order to achieve "do the unit test for every gdbarch", I add selftest-arch.[c,h], so that we can register a function pointer, which has one argument gdbarch. selftest.c will iterate over all gdbarches to call the registered function pointer. gdb: 2017-01-26 Yao Qi <yao.qi@linaro.org> * Makefile.in (SFILES): Add disasm-selftests.c and selftest-arch.c. (COMMON_OBS): Add disasm-selftests.o and selftest-arch.o. * disasm-selftests.c: New file. * selftest-arch.c: New file. * selftest-arch.h: New file.
2017-01-26Call print_insn_mep in mep_gdb_print_insnYao Qi2-7/+9
opcodes/mep-dis.c:mep_print_insn has already had the code to handle the case when info->section is NULL, /* Picking the right ISA bitmask for the current context is tricky. */ if (info->section) { } else /* sid or gdb */ { } so that we can still cal print_insn_mep even section can't be found. On the other hand, user can disassemble an arbitrary address which doesn't map to any section at all. gdb: 2017-01-26 Yao Qi <yao.qi@linaro.org> * mep-tdep.c (mep_gdb_print_insn): Set info->arch to bfd_arch_mep. Don't return 0 if section is not found. Call print_insn_mep.
2017-01-26Refactor disassembly codeYao Qi8-157/+207
This patch addes class gdb_disassembler, and refactor code to use it. The gdb_disassembler object is saved in disassember_info.application_data. However, disassember_info.application_data is already used by gdb for arm, mips spu, and scm-disasm. In arm and mips, .application_data is gdbarch, but we can still get gdbarch from gdb_disassember. The use of application_data in spu is a little bit complicated. It creates its own disassemble_info, and save spu_dis_asm_data in .application_data. This will overwrite the pointer to gdb_disassembler, so we need to find another place to save spu_dis_asm_data. I extend disassemble_info, and put "id" there. gdb: 2017-01-26 Pedro Alves <palves@redhat.com> Yao Qi <yao.qi@linaro.org> * arm-tdep.c: Include "disasm.h". (gdb_print_insn_arm): Update code to get gdbarch. * disasm.c (dis_asm_read_memory): Change it to gdb_disassembler::dis_asm_read_memory. (dis_asm_memory_error): Likewise. (dis_asm_print_address): Likewise. (gdb_pretty_print_insn): Change it to gdb_disassembler::pretty_print_insn. (dump_insns): Add one argument gdb_disassemlber. All callers updated. (do_mixed_source_and_assembly_deprecated): Likewise. (do_mixed_source_and_assembly): Likewise. (do_assembly_only): Likewise. (gdb_disassembler::gdb_disassembler): New. (gdb_disassembler::print_insn): New. * disasm.h (class gdb_disassembler): New. (gdb_pretty_print_insn): Remove declaration. (gdb_disassemble_info): Likewise. * guile/scm-disasm.c (class gdbscm_disassembler): New. (gdbscm_disasm_read_memory_worker): Update. (gdbscm_disasm_read_memory): Update. (gdbscm_disasm_memory_error): Remove. (gdbscm_disasm_print_address): Remove. (gdbscm_disassembler::gdbscm_disassembler): New. (gdbscm_print_insn_from_port): Update. * mips-tdep.c: Include disasm.h. (gdb_print_insn_mips): Update code to get gdbarch. * record-btrace.c (btrace_insn_history): Update. * spu-tdep.c: Include disasm.h. (struct spu_dis_asm_data): Remove. (struct spu_dis_asm_info): New. (spu_dis_asm_print_address): Use spu_dis_asm_info to get SPU id. (gdb_print_insn_spu): Cast disassemble_info to spu_dis_asm_info.
2017-01-26New function null_streamYao Qi4-16/+26
This patch adds a new function null_stream, which returns a null stream. The null stream can be used in multiple places. It is used in gdb_insn_length, and the following patches will use it too. gdb: 2017-01-26 Yao Qi <yao.qi@linaro.org> * disasm.c (do_ui_file_delete): Delete. (gdb_insn_length): Move code creating stream to ... * utils.c (null_stream): ... here. New function. * utils.h (null_stream): Declare.
2017-01-25Use dwarf assembler in gdb.dwarf2/implptr-64bit.expYao Qi4-236/+154
This patch adds a DW_OP_implicit_value in dwarf assembler, and uses dwarf assembler in implptr-64bit.exp. Using dwarf assembler in implptr-64bit.exp exposes some limitations in dwarf assembler, - some variables are not evaluated in the caller's context, so we can not pass variable to assembler, like this Dwarf::assemble $asm_file { cu { version $dwarf_version addr_size $addr_size is_64 $is_64 } { } and {DW_AT_type :$struct_label "DW_FORM_ref$ref_addr_size"} this limitation is fixed by adding "uplevel" and "subst". - dwarf assembler doesn't emit DW_FORM_ref_addr for label referencing. this limitation is fixed by adding a new character "%", { type %$int_label } this means we want to emit DW_FORM_ref_addr for label referencing. - we can't set the form of label referencing offset in dwarf assembler. Nowadays, dwarf assembler guesses the form of labels, which is DW_FORM_ref4. However, in implptr-64bit.exp, both DW_FORM_ref4 and DW_FORM_ref8 is used (see REF_ADDR in implptr-64bit.S). This patch adds the flexibility of setting the form of label reference. Both of them below are valid, {DW_AT_type :$struct_label} {DW_AT_type :$struct_label DW_FORM_ref8} the former form is the default DW_FORM_ref4. I compared the .debug_info of objects without and with this patch applied. There is no changes except abbrev numbers. gdb/testsuite: 2017-01-25 Andreas Arnez <arnez@linux.vnet.ibm.com> Yao Qi <yao.qi@linaro.org> * gdb.dwarf2/implptr-64bit.exp: Use dwarf assembler. * gdb.dwarf2/implptr-64bit.S: Remove. * lib/dwarf.exp (Dwarf): Handle character "%". Evaluate some variables in caller's context. Add DW_OP_implicit_value.
2017-01-25Handle DW_OP_GNU_implicit_pointer in dwarf assemblerYao Qi2-1/+11
DW_OP_GNU_implicit_pointer refers to a DIE with an offset of different sizes in different dwarf versions. In v2, the size is the pointer size, while in v3 and above, it is the ref_addr size. This patch fixes dwarf assembler to emit the correct size of offset. We've already fixed this size issue in gdb, https://sourceware.org/ml/gdb-patches/2011-09/msg00451.html gdb/testsuite: 2017-01-25 Yao Qi <yao.qi@linaro.org> * lib/dwarf.exp (Dwarf::_location): Handle DW_OP_GNU_implicit_pointer with proper size.
2017-01-24Fix typo in ExitedEvent docSimon Marchi2-1/+5
The field "inferior" of the ExitedEvent object is not displayed properly. gdb/doc/ChangeLog: * python.texi (Events In Python): Fix typo.
2017-01-23Minor simplification of (Python) find_thread_objectSimon Marchi2-8/+6
Since the reference to the Inferior Python object is managed by gdbpy_ref (RAII), we can return directly from the loop. It's just a leftover from the cleanups era. gdb/ChangeLog: * python/py-inferior.c (find_thread_object): Return directly from the loop. Remove "found" variable.
2017-01-21Document the GDB 7.12.1 release in gdb/ChangeLogJoel Brobecker1-0/+4
gdb/ChangeLog: GDB 7.12.1 released.
2017-01-20Fix Py_DECREF being executed without holding the GILSimon Marchi3-8/+14
When the gdbpy_ref objects get destroyed, they call Py_DECREF to decrement the reference counter of the python object they hold a reference to. Any time we call into the Python API, we should be holding the GIL. The gdbpy_enter object does that for us in an RAII-fashion. However, if gdbpy_enter is declared after a gdbpy_ref object in a function, gdbpy_enter's destructor will be called (and the GIL will be released) before gdbpy_ref's destructor is called. Therefore, we will end up calling Py_DECREF without holding the GIL. This became obvious with Python 3.6, where memory management functions have asserts to make sure that the GIL is held. This was exposed by tests py-as-string.exp, py-function.exp and py-xmethods. For example: (gdb) p $_as_string(enum_valid) Fatal Python error: Python memory allocator called without holding the GIL Current thread 0x00007f7f7b21c780 (most recent call first): [1] 18678 abort (core dumped) ./gdb -nx testsuite/outputs/gdb.python/py-as-string/py-as-string #0 0x00007ffff618bc37 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff618f028 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff6b104d6 in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1457 #3 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #4 0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e65290 <_PyMem_Debug+48>, ptr=0x24f8830) at Objects/obmalloc.c:1994 #5 0x00007ffff6a38e1d in PyMem_Free (ptr=<optimized out>) at Objects/obmalloc.c:442 #6 0x00007ffff6b866c6 in _PyFaulthandler_Fini () at ./Modules/faulthandler.c:1369 #7 0x00007ffff6b104bd in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1431 #8 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #9 0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e652c0 <_PyMem_Debug+96>, ptr=0x7ffff46b6040) at Objects/obmalloc.c:1994 #10 0x00007ffff6a38f55 in PyObject_Free (ptr=<optimized out>) at Objects/obmalloc.c:503 #11 0x00007ffff6a5f27e in unicode_dealloc (unicode=unicode@entry=0x7ffff46b6040) at Objects/unicodeobject.c:1794 #12 0x00007ffff6a352a9 in _Py_Dealloc (op=0x7ffff46b6040) at Objects/object.c:1786 #13 0x000000000063f28b in gdb_Py_DECREF (op=0x7ffff46b6040) at /home/emaisin/src/binutils-gdb/gdb/python/python-internal.h:192 #14 0x000000000063fa33 in gdbpy_ref_policy::decref (ptr=0x7ffff46b6040) at /home/emaisin/src/binutils-gdb/gdb/python/py-ref.h:35 #15 0x000000000063fa77 in gdb::ref_ptr<_object, gdbpy_ref_policy>::~ref_ptr (this=0x7fffffffcdf0, __in_chrg=<optimized out>) at /home/emaisin/src/binutils-gdb/gdb/common/gdb_ref_ptr.h:91 #16 0x000000000064d8b8 in fnpy_call (gdbarch=0x2b50010, language=0x115d2c0 <c_language_defn>, cookie=0x7ffff46b7468, argc=1, argv=0x7fffffffcf48) at /home/emaisin/src/binutils-gdb/gdb/python/py-function.c:145 The fix is to place the gdbpy_enter first in the function. I also cleaned up the comments a bit and removed the unnecessary initialization of the value variable. gdb/ChangeLog: * python/py-function.c (fnpy_call): Reorder declarations to have the gdbpy_enter object declared first. * python/py-xmethods.c (gdbpy_get_xmethod_arg_types): Likewise.
2017-01-20Add missing PR reference in ChangeLogSimon Marchi1-0/+1
2017-01-20Fix python-interactive with Python 3.6Simon Marchi3-2/+17
New in v2: - Define PyMem_RawMalloc as PyMem_Malloc for Python < 3.4 and use PyMem_RawMalloc in the code. Since Python 3.4, the callback installed in PyOS_ReadlineFunctionPointer should return a value allocated with PyMem_RawMalloc instead of PyMem_Malloc. The reason is that PyMem_Malloc must be called with the Python Global Interpreter Lock (GIL) held, which is not the case in the context where this function is called. PyMem_RawMalloc was introduced for cases like this. In Python 3.6, it looks like they added an assert to verify that PyMem_Malloc was not called without the GIL. The consequence is that typing anything in the python-interactive mode of gdb crashes the process. The same behavior was observed with the official package on Arch Linux as well as with a manual Python build on Ubuntu 14.04. This is what is shown with a debug build of Python 3.6 (the error with a non-debug build is far less clear): (gdb) pi >>> print(1) Fatal Python error: Python memory allocator called without holding the GIL Current thread 0x00007f1459af8780 (most recent call first): [1] 21326 abort ./gdb and the backtrace: #0 0x00007ffff618bc37 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff618f028 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff6b104d6 in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1457 #3 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #4 0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e65290 <_PyMem_Debug+48>, ptr=0x24f8830) at Objects/obmalloc.c:1994 #5 0x00007ffff6a38e1d in PyMem_Free (ptr=<optimized out>) at Objects/obmalloc.c:442 #6 0x00007ffff6b866c6 in _PyFaulthandler_Fini () at ./Modules/faulthandler.c:1369 #7 0x00007ffff6b104bd in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1431 #8 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #9 0x00007ffff6a37aa3 in _PyMem_DebugMalloc (ctx=0x7ffff6e65290 <_PyMem_Debug+48>, nbytes=5) at Objects/obmalloc.c:1980 #10 0x00007ffff6a38d91 in PyMem_Malloc (size=<optimized out>) at Objects/obmalloc.c:418 #11 0x000000000064dbe2 in gdbpy_readline_wrapper (sys_stdin=0x7ffff6514640 <_IO_2_1_stdin_>, sys_stdout=0x7ffff6514400 <_IO_2_1_stdout_>, prompt=0x7ffff4d4f7d0 ">>> ") at /home/emaisin/src/binutils-gdb/gdb/python/py-gdb-readline.c:75 The documentation is very clear about it [1] and it was also mentioned in the "What's New In Python 3.4" page [2]. [1] https://docs.python.org/3/c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer [2] https://docs.python.org/3/whatsnew/3.4.html#changes-in-the-c-api gdb/ChangeLog: * python/python-internal.h (PyMem_RawMalloc): Define for Python < 3.4. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Use PyMem_RawMalloc instead of PyMem_Malloc.
2017-01-20Fix uppercase test names in gdb.python/py-xmethods.expLuis Machado2-20/+31
Some leftover uppercase test names in py-xmethods.exp. The patch also replaces two "continue" calls with untested calls to make things a bit more clear. gdb/testsuite/ChangeLog: 2017-01-20 Luis Machado <lgustavo@codesourcery.com> * gdb.python/py-xmethods.exp: Fix test names starting with lowercase and add untested calls.
2017-01-20Make gdb.python/python.exp more robustLuis Machado2-1/+20
I noticed gdb.python/python.exp failing on aarch64-elf like so: FAIL: gdb.python/python.exp: Test decode_line func1 line number This particular test expects the line number for func1 to be 19, hardcoded. In my aarch64-elf tests gdb thinks func1 is at line 20, making the test fail. The following patch addresses this by reading the line number information from GDB and comparing it against the python decoded symtab information. gdb/testsuite/ChangeLog: 2017-01-20 Luis Machado <lgustavo@codesourcery.com> * gdb.python/python.exp: Check line number against what GDB thinks the line number is for func1.
2017-01-20Add command to erase all flash memory regionsLuis Machado9-0/+122
Changes in v4: - Replaced phex call with hex_string. Changes in v3: - Addressed comments by Pedro. - Output of memory region size now in hex format. - Misc formatting fixups. - Addressed Simon's comments on formatting. - Adjusted command text in the manual entry. - Fixed up ChangeLog. - Renamed flash_erase_all_command to flash_erase_command. Changes in v2: - Added NEWS entry. - Fixed long lines. - Address printing with paddress. Years ago we contributed flash programming patches upstream. The following patch is a leftover one that complements that functionality by adding a new command to erase all reported flash memory blocks. The command is most useful when we're dealing with flash-enabled targets (mostly bare-metal) and we need to reset the board for some reason. The wiping out of flash memory regions should help the target come up with a known clean state from which the user can load a new image and resume debugging. It is convenient enough to do this from the debugger, and there is also an MI command to expose this functionality to the IDE's. gdb/doc/ChangeLog: 2017-01-20 Mike Wrighton <mike_wrighton@codesourcery.com> Luis Machado <lgustavo@codesourcery.com> * gdb.texinfo (-target-flash-erase): New MI command description. (flash-erase): New CLI command description. gdb/ChangeLog: 2017-01-20 Mike Wrighton <mike_wrighton@codesourcery.com> Luis Machado <lgustavo@codesourcery.com> * NEWS (New commands): Mention flash-erase. (New MI commands): Mention target-flash-erase. * mi/mi-cmds.c (mi_cmd_target_flash_erase): Add target-flash-erase MI command. * mi/mi-cmds.h (mi_cmd_target_flash_erase): New declaration. * mi/mi-main.c (mi_cmd_target_flash_erase): New function. * target.c (flash_erase_command): New function. (initialize_targets): Add new flash-erase command. * target.h (flash_erase_command): New declaration.
2017-01-20fix gdbserver build in nat/linux-ptrace.c on arm-androidJoel Brobecker2-0/+7
The following change replaced an include of gregset.h by an include of <sys/procfs.h>: commit 39b22471578843019026c50fcdbe0483a6045970 Date: Thu Aug 11 12:01:22 2016 +0100 Subject: Fix fallout from gdb/20413's fix (x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER) Unfortunately, this broke gdbserver on Android, because that file does not exist on this platform. This patch fixes the issue by conditionalizing its include with HAVE_SYS_PROCFS_H (which we check both in gdb/configure and gdbserver/configure). gdb/ChangeLog: * nat/linux-ptrace.c: Only include <sys/procfs.h> if HAVE_SYS_PROCFS_H is defined. Tested by rebuilding gdbserver on arm-android and GNU/Linux.
2017-01-18Allocate data in cached_reg_tAlan Hayward2-6/+25
2017-01-18 Alan Hayward <alan.hayward@arm.com> * remote.c (struct cached_reg): Change data into a pointer. * (stop_reply_dtr): Free data pointers before deleting vector. (process_stop_reply): Likewise. (remote_parse_stop_reply): Allocate space for data
2017-01-18Use register_size () instead of MAX_REGISTER_SIZEAlan Hayward4-5/+16
2017-01-18 Alan Hayward <alan.hayward@arm.com> * amd64-tdep.c (amd64_pseudo_register_read_value): remove MAX_REGISTER_SIZE. (amd64_pseudo_register_read_value): Likewise. * remote.c (fetch_register_using_p): Remove MAX_REGISTER_SIZE. (store_register_using_P): Likewise. * regcache.c (regcache_xfer_part): Likewise.
2017-01-16gdb: sparc: split real and pseudo registers.Ivo Raisr5-87/+190
gdb/ChangeLog: 2017-01-16 Ivo Raisr <ivo.raisr@oracle.com> Split real and pseudo registers. * sparc-tdep.h (SPARC_CORE_REGISTERS): New macro. (sparc32_pseudo_regnum): New enum. * sparc64-tdep.h (sparc64_pseudo_regnum): New enum. * sparc-tdep.c (SPARC32_FPU_REGISTERS): New macro. (SPARC32_CP0_REGISTERS): New macro. (sparc32_pseudo_register_name): New function. (sparc32_register_name): Use sparc32_pseudo_register_name. (sparc32_pseudo_register_type): New function. (sparc32_register_type): Use sparc32_pseudo_register_type. (sparc32_pseudo_register_read, sparc32_pseudo_register_write): Handle pseudo register numbers. * sparc64-tdep.c SPARC64_FPU_REGISTERS): New macro. (SPARC64_CP0_REGISTERS): New macro. (sparc64_pseudo_register_name): New function. (sparc64_register_name): Use sparc64_pseudo_register_name. (sparc64_pseudo_register_type): New function. (sparc64_register_type): Use sparc64_pseudo_register_type. (sparc64_pseudo_register_read, sparc64_pseudo_register_write): Handle pseudo register numbers. (sparc64_store_floating_fields, sparc64_extract_floating_fields, sparc64_store_arguments): Handle pseudo register numbers.
2017-01-13Don't print too much if remote_debug is onYao Qi2-4/+39
If we turn "remote debug" on and GDB does some vFile operations, a lot of things will be printed in the screen, which makes "remote debug" useless. This patch changes the code that we only print 512 chars in max in debugging messages, like this, Sending packet: $qXfer:features:read:target.xml:0,fff#7d...Packet received: l<?xml version="1.0"?>\n<!-- Copyright (C) 2010-2016 Free Software Foundation, Inc.\n\n Copying and distribution of this file, with or without modification,\n are permitted in any medium without royalty provided the copyright\n notice and this notice are preserved. -->\n\n<!-- AMD64 with AVX - Includes Linux-only special "register". -->\n\n<!DOCTYPE target SYSTEM "gdb-target.dtd">\n<target>\n <architecture>i386:x86-64</architecture>\n <osabi>GNU/Linux</osabi>\n <xi:include href="64bit-core.xml"/>\n <xi:[14 bytes omitted] Sending packet: $qXfer:auxv:read::0,1000#6b...Packet received: l!\000\000\000\000\000\000\000\000d\000\000\000\000\000\000\000\003\000\000\000\000\000\000\000@\000@\000\000\000\000\000\004\000\000\000\000\000\000\0008\000\000\000\000\000\000\000\005\000\000\000\000\000\000\000\t\000\000\000\000\000\000\000\a\000\000\000\000\000\000\000\177\000\000\b\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\t\000\000\000\000\000\000\000\000\004@\000\000\000\000\000\013\000\000\000\000\000\000\003\000\000\000\000\000\000\f\000\000\000\000\000\000\003\000\000\000\000\000\000\r\000\000\000\000\000\000\003\000\000\000\000\000\000\016\000\000\000\000\000\000\003\000\000\000\000\000\000\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\031\000\000\000\000\000\000\177\000\000\037\000\000\000\000\000\000\000\000\017\000\000\000\000\000\000\00\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000[582 bytes omitted] gdb: 2017-01-13 Yao Qi <yao.qi@linaro.org> * remote.c (REMOTE_DEBUG_MAX_CHAR): New macro. (putpkt_binary): Print only REMOTE_DEBUG_MAX_CHAR chars in debug output. (getpkt_or_notif_sane_1): Likewise.
2017-01-13'make check-headers' for c++ headerYao Qi2-2/+7
If I run 'make check-headers', I get these errors, .... In file included from ../../binutils-gdb/gdb/common/common-defs.h:78:0, from ../../binutils-gdb/gdb/defs.h:28, from <command-line>:0: ../../binutils-gdb/gdb/common/common-utils.h:23:18: fatal error: string: No such file or directory #include <string> ^ because we still parse headers as c file with a c compiler, which is no longer true after we moved to C++. This patch changes it to use C++ compiler and parse headers as c++ headers. gdb: 2017-01-13 Yao Qi <yao.qi@linaro.org> * Makefile.in (checker-headers): Use CXX and CXX_DIALET instead of CC. Pass "-x c++-header" instead of "-x c".
2017-01-12Update comment in remote_can_async_pSimon Marchi2-1/+6
I find this comment counter intuitive, and it probably predates the always-target-async change. AFAIK, remote will always be async, unless the user explicitly prevents it with "maint set target-async off". gdb/ChangeLog: * remote.c (remote_can_async_p): Update comment.
2017-01-12Update comment in linux_nat_can_async_pSimon Marchi2-3/+6
I think this comment is outdated. Nowadays, linux-nat is always async, unless the user has explictly turned it off with "maint set target-async off". gdb/ChangeLog: * linux-nat.c (linux_nat_can_async_p): Update comment.
2017-01-12Remove dead serial_interface_lookup callsSimon Marchi2-5/+5
By inspecting the serial_add_interface calls, I found that the serial interface names that we have today are: - hardwire - terminal - pipe - tcp - event The calls to serial_interface_lookup with any other names are most likely leftovers which can be removed since these serial interfaces don't exist anymore. The commits that removed the "pc" and "parallel" interfaces are respectively: cb2a4ac5dae478fcd9d6e772530c3aba0576fc7a and e386d4d2fb55042f77d0557a0849ed2464aee7b3 gdb/ChangeLog: * serial.c (serial_open): Forget about "pc" and "lpt" serial interface.
2017-01-11Fix typo in lookup_cmd_1 commentSimon Marchi2-1/+5
gdb/ChangeLog: * cli/cli-decode.c (lookup_cmd_1): Fix typo in comment.
2017-01-10Add constructor and destructor to demangle_parse_infoTom Tromey5-79/+52
This adds a constructor and destructor to demangle_parse_info, and then changes all the users to use them. This removes make_cleanup_cp_demangled_name_parse_free and its single use. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-type.c (typy_legacy_template_argument): Update. * cp-support.h (struct demangle_parse_info) (demangle_parse_info, ~demangle_parse_info): Declare new members. (cp_demangled_name_to_comp): Return unique_ptr. (cp_demangled_name_parse_free) (make_cleanup_cp_demangled_name_parse_free) (cp_new_demangle_parse_info): Remove. * cp-support.c (do_demangled_name_parse_free_cleanup) (make_cleanup_cp_demangled_name_parse_free): Remove. (inspect_type, cp_canonicalize_string_full) (cp_canonicalize_string): Update. (mangled_name_to_comp): Change return type. (cp_class_name_from_physname, method_name_from_physname) (cp_func_name, cp_remove_params): Update. * cp-name-parser.y (demangle_parse_info): New constructor, from cp_new_demangle_parse_info. (~demangle_parse_info): New destructor, from cp_demangled_name_parse_free. (cp_merge_demangle_parse_infos): Update. (cp_demangled_name_to_comp): Change return type.
2017-01-10Remove cleanups from execute_gdb_commandTom Tromey6-14/+18
This replaces a cleanup in execute_gdb_command with an instance of std::string. Testing showed that this originally missed a cleanup that was returned by prevent_dont_repeat. This version of the patch changes prevent_dont_repeat to return a scoped_restore rather than a cleanup. 2017-01-10 Tom Tromey <tom@tromey.com> * top.c (prevent_dont_repeat): Change return type. * python/python.c (execute_gdb_command): Use std::string. Update. * guile/guile.c (gdbscm_execute_gdb_command): Update. * command.h (prevent_dont_repeat): Change return type. * breakpoint.c (bpstat_do_actions_1): Update.
2017-01-10Use scoped_value_mark in dwarf2_evaluate_loc_desc_fullTom Tromey3-15/+32
This changes dwarf2_evaluate_loc_desc_full to use scoped_value_mark. Note that this function previously called do_cleanup using the same cleanup multiple times. I had thought this was buggy, but re-reading make_my_cleanup2 indicates that it is not. Nevertheless it is surprising, and at least one of the calls (the one that is completely removed in this patch) seems to have been done under the assumption that it would still have some effect. 2017-01-10 Tom Tromey <tom@tromey.com> * value.h (scoped_value_mark::~scoped_value_mark): Call free_to_mark. (scoped_value_mark::free_to_mark): New method. * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Use scoped_value_mark.
2017-01-10Add scoped_value_markTom Tromey5-54/+55
This adds a scoped_value_mark class, that records the value mark in the constructor and then calls value_free_to_mark in the destructor. It then updates various spots in gdb to use this class, rather than a cleanup. It would be better overall to replace "struct value *" with a shared_ptr, maybe eliminating the need for this class (watchpoints would perhaps need some new mechanism as well). However, that's difficult to do. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-value.c (valpy_dereference, valpy_referenced_value) (valpy_reference_value, valpy_const_value, valpy_get_address) (valpy_get_dynamic_type, valpy_lazy_string, valpy_do_cast) (valpy_getitem, valpy_call, valpy_binop_throw, valpy_negative) (valpy_absolute, valpy_richcompare_throw): Use scoped_value_mark. * dwarf2loc.c (dwarf2_loc_desc_get_symbol_read_needs): Use scoped_value_mark. * dwarf2-frame.c (execute_stack_op): Use scoped_value_mark. * value.h (scoped_value_mark): New class.
2017-01-10Remove make_cleanup_discard_psymtabsTom Tromey4-42/+45
This removes make_cleanup_discard_psymtabs in favor of a new class. 2017-01-10 Tom Tromey <tom@tromey.com> * dwarf2read.c (dwarf2_build_psymtabs): Use psymtab_discarder. * psympriv.h (make_cleanup_discard_psymtabs): Don't declare. * psymtab.c (discard_psymtabs_upto): Remove. (make_cleanup_discard_psymtabs): Remove. (struct psymtab_state): Remove.
2017-01-10Introduce and use gdb::unlinkerTom Tromey5-74/+110
This introduces a new class, gdb::unlinker, that unlinks a file in the destructor. The user of this class has the option to preserve the file instead, by calling the "keep" method. This patch then changes the spots in gdb that use unlink in a cleanup to use this class instead. In one spot I went ahead and removed all the cleanups from the function. This fixes one latent bug -- do_bfd_delete_cleanup could refer to freed memory, by decref'ing the BFD before using its filename. 2017-01-10 Tom Tromey <tom@tromey.com> * record-full.c (record_full_save_cleanups): Remove. (record_full_save): Use gdb::unlinker. * gcore.c (do_bfd_delete_cleanup): Remove. (gcore_command): Use gdb::unlinker, unique_xmalloc_ptr. Remove cleanups. * dwarf2read.c (unlink_if_set): Remove. (write_psymtabs_to_index): Use gdb::unlinker. * common/gdb_unlinker.h: New file.
2017-01-10Use class to manage BFD reference countsTom Tromey37-547/+491
This introduces a new specialization of gdb::ref_ptr that can be used to manage BFD reference counts. Then it changes most places in gdb to use this new class, rather than explicit reference-counting or cleanups. This patch removes make_cleanup_bfd_unref. If you look you will see a couple of spots using "release" where a use of gdb_bfd_ref_ptr would be cleaner. These will be fixed in the next patch. I think this patch fixes some latent bugs. For example, it seems to me that previously objfpy_add_separate_debug_file leaked a BFD. I'm not 100% certain that the macho_symfile_read_all_oso change is correct. The existing code here is hard for me to follow. One goal of this sort of automated reference counting, though, is to make it more difficult to make logic errors; so hopefully the code is clear now. 2017-01-10 Tom Tromey <tom@tromey.com> * windows-tdep.c (windows_xfer_shared_library): Update. * windows-nat.c (windows_make_so): Update. * utils.h (make_cleanup_bfd_unref): Remove. * utils.c (do_bfd_close_cleanup, make_cleanup_bfd_unref): Remove. * symfile.h (symfile_bfd_open) (find_separate_debug_file_in_section): Return gdb_bfd_ref_ptr. * symfile.c (read_symbols, symbol_file_add) (separate_debug_file_exists): Update. (symfile_bfd_open): Return gdb_bfd_ref_ptr. (generic_load, reread_symbols): Update. * symfile-mem.c (symbol_file_add_from_memory): Update. * spu-linux-nat.c (spu_bfd_open): Return gdb_bfd_ref_ptr. (spu_symbol_file_add_from_memory): Update. * solist.h (struct target_so_ops) <bfd_open>: Return gdb_bfd_ref_ptr. (solib_bfd_fopen, solib_bfd_open): Return gdb_bfd_ref_ptr. * solib.c (solib_bfd_fopen, solib_bfd_open): Return gdb_bfd_ref_ptr. (solib_map_sections, reload_shared_libraries_1): Update. * solib-svr4.c (enable_break): Update. * solib-spu.c (spu_bfd_fopen): Return gdb_bfd_ref_ptr. * solib-frv.c (enable_break2): Update. * solib-dsbt.c (enable_break): Update. * solib-darwin.c (gdb_bfd_mach_o_fat_extract): Return gdb_bfd_ref_ptr. (darwin_solib_get_all_image_info_addr_at_init): Update. (darwin_bfd_open): Return gdb_bfd_ref_ptr. * solib-aix.c (solib_aix_bfd_open): Return gdb_bfd_ref_ptr. * record-full.c (record_full_save): Update. * python/py-objfile.c (objfpy_add_separate_debug_file): Update. * procfs.c (insert_dbx_link_bpt_in_file): Update. * minidebug.c (find_separate_debug_file_in_section): Return gdb_bfd_ref_ptr. * machoread.c (macho_add_oso_symfile): Change abfd to gdb_bfd_ref_ptr. (macho_symfile_read_all_oso): Update. (macho_check_dsym): Return gdb_bfd_ref_ptr. (macho_symfile_read): Update. * jit.c (bfd_open_from_target_memory): Return gdb_bfd_ref_ptr. (jit_bfd_try_read_symtab): Update. * gdb_bfd.h (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr) (gdb_bfd_openw, gdb_bfd_openr_iovec) (gdb_bfd_openr_next_archived_file, gdb_bfd_fdopenr): Return gdb_bfd_ref_ptr. (gdb_bfd_ref_policy): New struct. (gdb_bfd_ref_ptr): New typedef. * gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr) (gdb_bfd_openw, gdb_bfd_openr_iovec) (gdb_bfd_openr_next_archived_file, gdb_bfd_fdopenr): Return gdb_bfd_ref_ptr. * gcore.h (create_gcore_bfd): Return gdb_bfd_ref_ptr. * gcore.c (create_gcore_bfd): Return gdb_bfd_ref_ptr. (gcore_command): Update. * exec.c (exec_file_attach): Update. * elfread.c (elf_symfile_read): Update. * dwarf2read.c (dwarf2_get_dwz_file): Update. (try_open_dwop_file, open_dwo_file): Return gdb_bfd_ref_ptr. (open_and_init_dwo_file): Update. (open_dwp_file): Return gdb_bfd_ref_ptr. (open_and_init_dwp_file): Update. * corelow.c (core_open): Update. * compile/compile-object-load.c (compile_object_load): Update. * common/gdb_ref_ptr.h (ref_ptr::operator->): New operator. * coffread.c (coff_symfile_read): Update. * cli/cli-dump.c (bfd_openr_or_error, bfd_openw_or_error): Return gdb_bfd_ref_ptr. Rename. (dump_bfd_file, restore_command): Update. * build-id.h (build_id_to_debug_bfd): Return gdb_bfd_ref_ptr. * build-id.c (build_id_to_debug_bfd): Return gdb_bfd_ref_ptr. (find_separate_debug_file_by_buildid): Update.
2017-01-10Add gdb_ref_ptr.hTom Tromey3-126/+230
This adds a new gdb_ref_ptr.h, that implements a reference-counting smart pointer class, where the user of the class supplies a reference-counting policy object. This class will be used in the next patch, which changes most explicit BFD reference counts to use this new type. Meanwhile, this patch changes gdbpy_ref to be a specialization of this new class. This change required adding new nullptr_t overloads some operators in gdb_ref_ptr.h. I suspect this was needed because some Python header redefines NULL, but I'm not certain. 2017-01-10 Tom Tromey <tom@tromey.com> * common/gdb_ref_ptr.h: New file. * python/py-ref.h (struct gdbpy_ref_policy): New. (gdbpy_ref): Now a typedef.
2017-01-10Remove make_cleanup_htab_deleteTom Tromey9-190/+148
This removes make_cleanup_htab_delete in favor of destructors, building on an earlier patch that added the htab_up typedef. Testing revealed that more cleanup-removal work was needed in dwarf2loc.c, so this version of the patch changes code there to use unordered_set and vector, removing some more cleanups. 2017-01-10 Tom Tromey <tom@tromey.com> * utils.h (make_cleanup_htab_delete): Don't declare. * utils.c (do_htab_delete_cleanup, make_cleanup_htab_delete): Remove. * linespec.c (decode_compound_collector): Add constructor, destructor. (lookup_prefix_sym): Remove cleanup. (symtab_collector): Add constructor, destructor. (collect_symtabs_from_filename): Remove cleanup. * disasm.c (do_mixed_source_and_assembly): Use htab_up. * compile/compile-c-symbols.c (generate_c_for_variable_locations): Use htab_up. * gnu-v3-abi.c (gnuv3_print_vtable): Use htab_up. * dwarf2read.c (dw2_expand_symtabs_matching) (dw2_map_symbol_filenames, dwarf_decode_macros) (write_psymtabs_to_index): Use htab_up. * dwarf2loc.c (func_verify_no_selftailcall) (call_site_find_chain_1, func_verify_no_selftailcall) (chain_candidate, call_site_find_chain_1): Use std::unordered_set, std::vector, gdb::unique_xmalloc_ptr. (call_sitep): Remove typedef. (dwarf2_locexpr_baton_eval): Remove unused variable.
2017-01-10Remove make_cleanup_py_decref and make_cleanup_py_xdecrefTom Tromey3-45/+7
make_cleanup_py_decref and make_cleanup_py_xdecref are now unused, so this patch removes themm. Future Python changes should use gdbpy_ref instead. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python-internal.h (make_cleanup_py_decref) (make_cleanup_py_xdecref): Don't declare. * python/py-utils.c (py_decref, make_cleanup_py_decref) (py_xdecref, make_cleanup_py_xdecref): Remove.
2017-01-10Use gdbpy_ref rather than make_cleanup_py_decrefTom Tromey2-31/+33
This changes some spots in py-framefilter.c to use gdbpy_ref rather than make_cleanup_py_decref or make_cleanup_py_xdecref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (py_mi_print_variables): Use gdbpy_ref. (py_print_locals, enumerate_locals, py_print_args): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in enumerate_argsTom Tromey2-35/+25
This changes enumerate_args to use gdbpy_ref, and gets rid of many gotos. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (enumerate_args): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-utils.cTom Tromey2-34/+23
This changes more places in py-utils.c to use gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-utils.c (unicode_to_encoded_string) (python_string_to_target_string) (python_string_to_target_python_string) (python_string_to_host_string, gdbpy_obj_to_string) (get_addr_from_python): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in pyuw_object_attribute_to_pointerTom Tromey2-3/+7
This changes pyuw_object_attribute_to_pointer to use gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-unwind.c (pyuw_object_attribute_to_pointer): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in python.cTom Tromey2-67/+59
This changes more places in python.c to use gdbpy_ref. Additionally, previously gdbpy_apply_type_printers would return EXT_LANG_RC_ERROR if a type printer returned None. However, that doesn't seem correct to me; this patch changes it to return EXT_LANG_RC_NOP in this case. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python.c (eval_python_command, gdbpy_decode_line) (gdbpy_run_events, gdbpy_start_type_printers) (gdbpy_apply_type_printers): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-param.cTom Tromey2-10/+13
This changes py-param.c to use gdbpy_ref in a couple more spots. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-param.c (get_doc_string, compute_enum_values): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-inferior.cTom Tromey2-17/+11
This changes py-inferior.c to use gdbpy_ref in more places. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-inferior.c (find_thread_object, build_inferior_list): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py_print_frameTom Tromey2-10/+8
This changes py_print_frame to use gdbpy_ref in more places. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (py_print_frame): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in bpfinishpy_out_of_scopeTom Tromey2-4/+8
This changes bpfinishpy_out_of_scope to use gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-finishbreakpoint.c (bpfinishpy_out_of_scope): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-cmd.cTom Tromey2-51/+37
This changes py-cmd.c to use gdbpy_ref in more places. This also fixes a latent memory leak in cmdpy_completer_helper, which unnecessarily increfs the result of PyObject_CallMethodObjArgs. This is not needed because that function returns a new reference. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-cmd.c (cmdpy_completer_helper): Use gdbpy_ref. Remove extra incref. (cmdpy_completer_handle_brkchars, cmdpy_completer, cmdpy_init): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in gdbpy_breakpoint_cond_says_stopTom Tromey2-5/+8
This changes gdbpy_breakpoint_cond_says_stop to use gdbpy_ref rather than explicit reference management. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in archpy_disassembleTom Tromey2-20/+14
This changes archpy_disassemble to use gdbpy_ref. It also fixes a latent bug where archpy_disassemble was decref'ing the results of a all to PyArg_ParseTupleAndKeywords. This is incorrect because PyArg_ParseTupleAndKeywords returns borrowed references. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-arch.c (archpy_disassemble): Use gdbpy_ref. Don't decref results of PyArg_ParseTupleAndKeywords.