aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
AgeCommit message (Collapse)AuthorFilesLines
2021-01-01Update copyright year range in all GDB filesJoel Brobecker79-79/+79
This commits the result of running gdb/copyright.py as per our Start of New Year procedure... gdb/ChangeLog Update copyright year range in copyright header of all GDB files.
2020-12-23gdb: remove some uses of LA_PRINT_STRINGAndrew Burgess1-2/+2
This commit removes some, but not all, uses of LA_PRINT_STRING. In this commit I've removed those uses where there is an obvious language object on which I can instead call the printstr method. In the remaining 3 uses it is harder to know if the correct thing is to call printstr on the current language, or on a specific language. Currently obviously, we always call on the current language (as that's what LA_PRINT_STRING does), and clearly this behaviour is good enough right now, but is it "right"? I've left them for now and will give them more thought in the future. gdb/ChangeLog: * expprint.c (print_subexp_standard): Replace uses of LA_PRINT_STRING. * f-valprint.c (f_language::value_print_inner): Likewise. * guile/scm-pretty-print.c (ppscm_print_string_repr): Likewise. * p-valprint.c (pascal_language::value_print_inner): Likewise. * python/py-prettyprint.c (print_string_repr): Likewise.
2020-12-18Add address keyword to Value.format_stringHannes Domani1-1/+6
This makes it possible to disable the address in the result string: const char *str = "alpha"; (gdb) py print(gdb.parse_and_eval("str").format_string()) 0x404000 "alpha" (gdb) py print(gdb.parse_and_eval("str").format_string(address=False)) "alpha" gdb/ChangeLog: 2020-12-18 Hannes Domani <ssbssa@yahoo.de> * python/py-value.c (valpy_format_string): Implement address keyword. gdb/doc/ChangeLog: 2020-12-18 Hannes Domani <ssbssa@yahoo.de> * python.texi (Values From Inferior): Document the address keyword. gdb/testsuite/ChangeLog: 2020-12-18 Hannes Domani <ssbssa@yahoo.de> * gdb.python/py-format-string.exp: Add tests for address keyword.
2020-12-18Fix accessing a method's fields from PythonHannes Domani1-0/+1
Considering this example: struct C { int func() { return 1; } } c; int main() { return c.func(); } Accessing the fields of C::func, when requesting the function by its type, works: (gdb) py print(gdb.parse_and_eval('C::func').type.fields()[0].type) C * const But when trying to do the same via a class instance, it fails: (gdb) py print(gdb.parse_and_eval('c')['func'].type.fields()[0].type) Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: Type is not a structure, union, enum, or function type. Error while executing Python code. The difference is that in the former the function type is TYPE_CODE_FUNC: (gdb) py print(gdb.parse_and_eval('C::func').type.code == gdb.TYPE_CODE_FUNC) True And in the latter the function type is TYPE_CODE_METHOD: (gdb) py print(gdb.parse_and_eval('c')['func'].type.code == gdb.TYPE_CODE_METHOD) True So this adds the functionality for TYPE_CODE_METHOD as well. gdb/ChangeLog: 2020-12-18 Hannes Domani <ssbssa@yahoo.de> * python/py-type.c (typy_get_composite): Add TYPE_CODE_METHOD. gdb/testsuite/ChangeLog: 2020-12-18 Hannes Domani <ssbssa@yahoo.de> * gdb.python/py-type.exp: Add tests for TYPE_CODE_METHOD.
2020-12-11Change varobj_item::value to a value_ref_ptrTom Tromey1-1/+1
This changes varobj_item::value to be a value_ref_ptr, removing some manual management. gdb/ChangeLog 2020-12-11 Tom Tromey <tom@tromey.com> * varobj.c (install_dynamic_child, varobj_clear_saved_item) (update_dynamic_varobj_children, create_child) (create_child_with_value): Update. * varobj-iter.h (struct varobj_item) <value>: Now a value_ref_ptr. * python/py-varobj.c (py_varobj_iter::next): Call release_value.
2020-12-11Change varobj_dynamic::child_iter to unique_ptrTom Tromey2-4/+5
This changes varobj_dynamic::child_iter to be a unique_ptr, removing some manual management. gdb/ChangeLog 2020-12-11 Tom Tromey <tom@tromey.com> * varobj.c (struct varobj_dynamic) <child_iter>: Now unique_ptr. (varobj_get_iterator): Return unique_ptr. (update_dynamic_varobj_children, install_visualizer) (varobj::~varobj): Update. * python/python-internal.h (py_varobj_get_iterator): Return unique_ptr. * python/py-varobj.c (py_varobj_get_iterator): Return unique_ptr.
2020-12-11Change varobj_iter::next to return unique_ptrTom Tromey1-3/+3
This changes varobj_iter::next to return a unique_ptr. This fits in with the ongoing theme of trying to express these ownership transfers via the type system. gdb/ChangeLog 2020-12-11 Tom Tromey <tom@tromey.com> * varobj.c (update_dynamic_varobj_children): Update. * varobj-iter.h (struct varobj_iter) <next>: Change return type. * python/py-varobj.c (struct py_varobj_iter) <next>: Change return type. (py_varobj_iter::next): Likewise.
2020-12-11C++-ify varobj iterationTom Tromey1-51/+29
This changes the varobj iteration code to use a C++ class rather than a C struct with a separate "ops" structure. The only implementation is updated to use inheritance. This simplifies the code quite nicely. gdb/ChangeLog 2020-12-11 Tom Tromey <tom@tromey.com> * varobj.c (update_dynamic_varobj_children, install_visualizer) (varobj::~varobj): Update. * varobj-iter.h (struct varobj_iter): Change to interface class. (struct varobj_iter_ops): Remove. (varobj_iter_next, varobj_iter_delete): Remove. * python/py-varobj.c (struct py_varobj_iter): Derive from varobj_iter. Add constructor, destructor. Rename members. (py_varobj_iter::~py_varobj_iter): Rename from py_varobj_iter_dtor. (py_varobj_iter::next): Rename from py_varobj_iter_next. (py_varobj_iter_ops): Remove. (py_varobj_iter): Rename from py_varobj_iter_ctor. (py_varobj_iter_new): Remove. (py_varobj_get_iterator): Update.
2020-12-04Remove redundant typedefsTom Tromey23-92/+88
I was inspired by this patch of Simon's: https://sourceware.org/pipermail/gdb-patches/2020-November/173522.html ... to remove other typedefs that are no longer necessary now that gdb uses C++. I didn't remove absolutely every one -- I didn't touch the tdep files. However, I removed many of them. In some cases, I removed an existing different struct tag. 2020-12-04 Tom Tromey <tromey@adacore.com> * linespec.c (struct linespec_token): Rename; remove typedef. * guile/scm-block.c (struct block_smob): Remove typedef. (struct block_syms_progress_smob): Likewise. * guile/scm-symbol.c (struct symbol_smob): Remove typedef. * guile/scm-symtab.c (symtab_smob): Remove typedef. (struct sal_smob): Remove typedef. * guile/scm-param.c (struct param_smob): Remove typedef. * guile/scm-progspace.c (struct pspace_smob): Rename. * guile/scm-objfile.c (struct objfile_smob): Rename. * guile/scm-iterator.c (struct iterator_smob): Rename. * guile/scm-frame.c (struct frame_smob): Rename. * guile/scm-arch.c (struct arch_smob): Rename. * guile/scm-type.c (struct field_smob): Remove typedef. (struct type_smob): Rename. * guile/scm-cmd.c (struct command_smob): Remove typedef. * guile/scm-ports.c (struct ioscm_memory_port): Remove typedef. * guile/scm-value.c (struct value_smob): Remove typedef. * guile/scm-lazy-string.c (lazy_string_smob): Remove typedef. * guile/guile-internal.h (struct scheme_variable) (struct scheme_function, struct scheme_integer_constant) (struct gdb_smob, struct chained_gdb_smob) (struct eqable_gdb_smob, arch_smob, frame_smob, iterator_smob) (objfile_smob, pspace_smob, type_smob): Remove typedef. * guile/scm-pretty-print.c (pretty_printer_smob): Remove typedef. (struct pretty_printer_worker_smob): Remove typedef. * guile/scm-exception.c (struct exception_smob): Remove typedef. * python/py-block.c (struct block_object): Remove typedef. (block_syms_iterator_object): Update. (set_block): Update. (block_syms_iterator_object): Remove typedef. * python/py-inferior.c (struct membuf_object): Remove typedef. * python/py-symtab.c (struct symtab_object): Remove typedef. (set_symtab): Update. (sal_object): Remove typedef. (set_sal): Update. * python/py-frame.c (frame_object): Remove typedef. * python/py-record-btrace.c (struct btpy_list_object): Remove typedef. * python/py-arch.c (struct arch_object): Remove typedef. * python/py-linetable.c (struct linetable_entry_object) (linetable_object, struct ltpy_iterator_object): Remove typedef. * python/py-events.h (eventregistry_object): Remove typedef. (struct events_object): Remove typedef. * python/python-internal.h (gdbpy_breakpoint_object): Remove typedef. (thread_object): Remove typedef. * python/py-progspace.c (pspace_object): Remove typedef. * python/py-value.c (struct value_object): Remove typedef. * python/py-record.h (recpy_record_object): Remove typedef. (struct recpy_element_object): Remove typedef. * python/py-lazy-string.c (lazy_string_object): Remove typedef. * python/py-objfile.c (objfile_object): Remove typedef. * python/py-cmd.c (struct cmdpy_object): Remove typedef. * python/py-type.c (type_object): Remove typedef. (typy_iterator_object): Update. (set_type): Update. (field_object): Remove typedef. (typy_iterator_object): Remove typedef. * python/py-registers.c (register_descriptor_iterator_object): Remove typedef. (struct register_descriptor_object) (struct reggroup_iterator_object, struct reggroup_object): Remove typedef. * python/py-record.c (recpy_gap_object): Remove typedef. * python/py-symbol.c (symbol_object): Remove typedef. (set_symbol): Update. * python/py-event.h (event_object): Remove typedef. * python/py-param.c (parmpy_object): Remove typedef. * python/py-instruction.c (struct py_insn_obj): Remove typedef. * python/py-unwind.c (struct pending_frame_object): Remove typedef. (unwind_info_object, struct cached_frame_info): Likewise.
2020-11-02Minor Python simplificationsTom Tromey1-39/+24
I noticed that a few "#if"s could be removed from the Python code. This patch is the result. gdb/ChangeLog 2020-11-02 Tom Tromey <tromey@adacore.com> * python/python.c: Consolidate two HAVE_PYTHON blocks. (python_GdbModuleDef): Move earlier. Now static. (do_start_initialization): Consolidate some IS_PY3K blocks.
2020-11-02gdb, gdbserver, gdbsupport: fix leading space vs tabs issuesSimon Marchi22-255/+255
Many spots incorrectly use only spaces for indentation (for example, there are a lot of spots in ada-lang.c). I've always found it awkward when I needed to edit one of these spots: do I keep the original wrong indentation, or do I fix it? What if the lines around it are also wrong, do I fix them too? I probably don't want to fix them in the same patch, to avoid adding noise to my patch. So I propose to fix as much as possible once and for all (hopefully). One typical counter argument for this is that it makes code archeology more difficult, because git-blame will show this commit as the last change for these lines. My counter counter argument is: when git-blaming, you often need to do "blame the file at the parent commit" anyway, to go past some other refactor that touched the line you are interested in, but is not the change you are looking for. So you already need a somewhat efficient way to do this. Using some interactive tool, rather than plain git-blame, makes this trivial. For example, I use "tig blame <file>", where going back past the commit that changed the currently selected line is one keystroke. It looks like Magit in Emacs does it too (though I've never used it). Web viewers of Github and Gitlab do it too. My point is that it won't really make archeology more difficult. The other typical counter argument is that it will cause conflicts with existing patches. That's true... but it's a one time cost, and those are not conflicts that are difficult to resolve. I have also tried "git rebase --ignore-whitespace", it seems to work well. Although that will re-introduce the faulty indentation, so one needs to take care of fixing the indentation in the patch after that (which is easy). gdb/ChangeLog: * aarch64-linux-tdep.c: Fix indentation. * aarch64-ravenscar-thread.c: Fix indentation. * aarch64-tdep.c: Fix indentation. * aarch64-tdep.h: Fix indentation. * ada-lang.c: Fix indentation. * ada-lang.h: Fix indentation. * ada-tasks.c: Fix indentation. * ada-typeprint.c: Fix indentation. * ada-valprint.c: Fix indentation. * ada-varobj.c: Fix indentation. * addrmap.c: Fix indentation. * addrmap.h: Fix indentation. * agent.c: Fix indentation. * aix-thread.c: Fix indentation. * alpha-bsd-nat.c: Fix indentation. * alpha-linux-tdep.c: Fix indentation. * alpha-mdebug-tdep.c: Fix indentation. * alpha-nbsd-tdep.c: Fix indentation. * alpha-obsd-tdep.c: Fix indentation. * alpha-tdep.c: Fix indentation. * amd64-bsd-nat.c: Fix indentation. * amd64-darwin-tdep.c: Fix indentation. * amd64-linux-nat.c: Fix indentation. * amd64-linux-tdep.c: Fix indentation. * amd64-nat.c: Fix indentation. * amd64-obsd-tdep.c: Fix indentation. * amd64-tdep.c: Fix indentation. * amd64-windows-tdep.c: Fix indentation. * annotate.c: Fix indentation. * arc-tdep.c: Fix indentation. * arch-utils.c: Fix indentation. * arch/arm-get-next-pcs.c: Fix indentation. * arch/arm.c: Fix indentation. * arm-linux-nat.c: Fix indentation. * arm-linux-tdep.c: Fix indentation. * arm-nbsd-tdep.c: Fix indentation. * arm-pikeos-tdep.c: Fix indentation. * arm-tdep.c: Fix indentation. * arm-tdep.h: Fix indentation. * arm-wince-tdep.c: Fix indentation. * auto-load.c: Fix indentation. * auxv.c: Fix indentation. * avr-tdep.c: Fix indentation. * ax-gdb.c: Fix indentation. * ax-general.c: Fix indentation. * bfin-linux-tdep.c: Fix indentation. * block.c: Fix indentation. * block.h: Fix indentation. * blockframe.c: Fix indentation. * bpf-tdep.c: Fix indentation. * break-catch-sig.c: Fix indentation. * break-catch-syscall.c: Fix indentation. * break-catch-throw.c: Fix indentation. * breakpoint.c: Fix indentation. * breakpoint.h: Fix indentation. * bsd-uthread.c: Fix indentation. * btrace.c: Fix indentation. * build-id.c: Fix indentation. * buildsym-legacy.h: Fix indentation. * buildsym.c: Fix indentation. * c-typeprint.c: Fix indentation. * c-valprint.c: Fix indentation. * c-varobj.c: Fix indentation. * charset.c: Fix indentation. * cli/cli-cmds.c: Fix indentation. * cli/cli-decode.c: Fix indentation. * cli/cli-decode.h: Fix indentation. * cli/cli-script.c: Fix indentation. * cli/cli-setshow.c: Fix indentation. * coff-pe-read.c: Fix indentation. * coffread.c: Fix indentation. * compile/compile-cplus-types.c: Fix indentation. * compile/compile-object-load.c: Fix indentation. * compile/compile-object-run.c: Fix indentation. * completer.c: Fix indentation. * corefile.c: Fix indentation. * corelow.c: Fix indentation. * cp-abi.h: Fix indentation. * cp-namespace.c: Fix indentation. * cp-support.c: Fix indentation. * cp-valprint.c: Fix indentation. * cris-linux-tdep.c: Fix indentation. * cris-tdep.c: Fix indentation. * darwin-nat-info.c: Fix indentation. * darwin-nat.c: Fix indentation. * darwin-nat.h: Fix indentation. * dbxread.c: Fix indentation. * dcache.c: Fix indentation. * disasm.c: Fix indentation. * dtrace-probe.c: Fix indentation. * dwarf2/abbrev.c: Fix indentation. * dwarf2/attribute.c: Fix indentation. * dwarf2/expr.c: Fix indentation. * dwarf2/frame.c: Fix indentation. * dwarf2/index-cache.c: Fix indentation. * dwarf2/index-write.c: Fix indentation. * dwarf2/line-header.c: Fix indentation. * dwarf2/loc.c: Fix indentation. * dwarf2/macro.c: Fix indentation. * dwarf2/read.c: Fix indentation. * dwarf2/read.h: Fix indentation. * elfread.c: Fix indentation. * eval.c: Fix indentation. * event-top.c: Fix indentation. * exec.c: Fix indentation. * exec.h: Fix indentation. * expprint.c: Fix indentation. * f-lang.c: Fix indentation. * f-typeprint.c: Fix indentation. * f-valprint.c: Fix indentation. * fbsd-nat.c: Fix indentation. * fbsd-tdep.c: Fix indentation. * findvar.c: Fix indentation. * fork-child.c: Fix indentation. * frame-unwind.c: Fix indentation. * frame-unwind.h: Fix indentation. * frame.c: Fix indentation. * frv-linux-tdep.c: Fix indentation. * frv-tdep.c: Fix indentation. * frv-tdep.h: Fix indentation. * ft32-tdep.c: Fix indentation. * gcore.c: Fix indentation. * gdb_bfd.c: Fix indentation. * gdbarch.sh: Fix indentation. * gdbarch.c: Re-generate * gdbarch.h: Re-generate. * gdbcore.h: Fix indentation. * gdbthread.h: Fix indentation. * gdbtypes.c: Fix indentation. * gdbtypes.h: Fix indentation. * glibc-tdep.c: Fix indentation. * gnu-nat.c: Fix indentation. * gnu-nat.h: Fix indentation. * gnu-v2-abi.c: Fix indentation. * gnu-v3-abi.c: Fix indentation. * go32-nat.c: Fix indentation. * guile/guile-internal.h: Fix indentation. * guile/scm-cmd.c: Fix indentation. * guile/scm-frame.c: Fix indentation. * guile/scm-iterator.c: Fix indentation. * guile/scm-math.c: Fix indentation. * guile/scm-ports.c: Fix indentation. * guile/scm-pretty-print.c: Fix indentation. * guile/scm-value.c: Fix indentation. * h8300-tdep.c: Fix indentation. * hppa-linux-nat.c: Fix indentation. * hppa-linux-tdep.c: Fix indentation. * hppa-nbsd-nat.c: Fix indentation. * hppa-nbsd-tdep.c: Fix indentation. * hppa-obsd-nat.c: Fix indentation. * hppa-tdep.c: Fix indentation. * hppa-tdep.h: Fix indentation. * i386-bsd-nat.c: Fix indentation. * i386-darwin-nat.c: Fix indentation. * i386-darwin-tdep.c: Fix indentation. * i386-dicos-tdep.c: Fix indentation. * i386-gnu-nat.c: Fix indentation. * i386-linux-nat.c: Fix indentation. * i386-linux-tdep.c: Fix indentation. * i386-nto-tdep.c: Fix indentation. * i386-obsd-tdep.c: Fix indentation. * i386-sol2-nat.c: Fix indentation. * i386-tdep.c: Fix indentation. * i386-tdep.h: Fix indentation. * i386-windows-tdep.c: Fix indentation. * i387-tdep.c: Fix indentation. * i387-tdep.h: Fix indentation. * ia64-libunwind-tdep.c: Fix indentation. * ia64-libunwind-tdep.h: Fix indentation. * ia64-linux-nat.c: Fix indentation. * ia64-linux-tdep.c: Fix indentation. * ia64-tdep.c: Fix indentation. * ia64-tdep.h: Fix indentation. * ia64-vms-tdep.c: Fix indentation. * infcall.c: Fix indentation. * infcmd.c: Fix indentation. * inferior.c: Fix indentation. * infrun.c: Fix indentation. * iq2000-tdep.c: Fix indentation. * language.c: Fix indentation. * linespec.c: Fix indentation. * linux-fork.c: Fix indentation. * linux-nat.c: Fix indentation. * linux-tdep.c: Fix indentation. * linux-thread-db.c: Fix indentation. * lm32-tdep.c: Fix indentation. * m2-lang.c: Fix indentation. * m2-typeprint.c: Fix indentation. * m2-valprint.c: Fix indentation. * m32c-tdep.c: Fix indentation. * m32r-linux-tdep.c: Fix indentation. * m32r-tdep.c: Fix indentation. * m68hc11-tdep.c: Fix indentation. * m68k-bsd-nat.c: Fix indentation. * m68k-linux-nat.c: Fix indentation. * m68k-linux-tdep.c: Fix indentation. * m68k-tdep.c: Fix indentation. * machoread.c: Fix indentation. * macrocmd.c: Fix indentation. * macroexp.c: Fix indentation. * macroscope.c: Fix indentation. * macrotab.c: Fix indentation. * macrotab.h: Fix indentation. * main.c: Fix indentation. * mdebugread.c: Fix indentation. * mep-tdep.c: Fix indentation. * mi/mi-cmd-catch.c: Fix indentation. * mi/mi-cmd-disas.c: Fix indentation. * mi/mi-cmd-env.c: Fix indentation. * mi/mi-cmd-stack.c: Fix indentation. * mi/mi-cmd-var.c: Fix indentation. * mi/mi-cmds.c: Fix indentation. * mi/mi-main.c: Fix indentation. * mi/mi-parse.c: Fix indentation. * microblaze-tdep.c: Fix indentation. * minidebug.c: Fix indentation. * minsyms.c: Fix indentation. * mips-linux-nat.c: Fix indentation. * mips-linux-tdep.c: Fix indentation. * mips-nbsd-tdep.c: Fix indentation. * mips-tdep.c: Fix indentation. * mn10300-linux-tdep.c: Fix indentation. * mn10300-tdep.c: Fix indentation. * moxie-tdep.c: Fix indentation. * msp430-tdep.c: Fix indentation. * namespace.h: Fix indentation. * nat/fork-inferior.c: Fix indentation. * nat/gdb_ptrace.h: Fix indentation. * nat/linux-namespaces.c: Fix indentation. * nat/linux-osdata.c: Fix indentation. * nat/netbsd-nat.c: Fix indentation. * nat/x86-dregs.c: Fix indentation. * nbsd-nat.c: Fix indentation. * nbsd-tdep.c: Fix indentation. * nios2-linux-tdep.c: Fix indentation. * nios2-tdep.c: Fix indentation. * nto-procfs.c: Fix indentation. * nto-tdep.c: Fix indentation. * objfiles.c: Fix indentation. * objfiles.h: Fix indentation. * opencl-lang.c: Fix indentation. * or1k-tdep.c: Fix indentation. * osabi.c: Fix indentation. * osabi.h: Fix indentation. * osdata.c: Fix indentation. * p-lang.c: Fix indentation. * p-typeprint.c: Fix indentation. * p-valprint.c: Fix indentation. * parse.c: Fix indentation. * ppc-linux-nat.c: Fix indentation. * ppc-linux-tdep.c: Fix indentation. * ppc-nbsd-nat.c: Fix indentation. * ppc-nbsd-tdep.c: Fix indentation. * ppc-obsd-nat.c: Fix indentation. * ppc-ravenscar-thread.c: Fix indentation. * ppc-sysv-tdep.c: Fix indentation. * ppc64-tdep.c: Fix indentation. * printcmd.c: Fix indentation. * proc-api.c: Fix indentation. * producer.c: Fix indentation. * producer.h: Fix indentation. * prologue-value.c: Fix indentation. * prologue-value.h: Fix indentation. * psymtab.c: Fix indentation. * python/py-arch.c: Fix indentation. * python/py-bpevent.c: Fix indentation. * python/py-event.c: Fix indentation. * python/py-event.h: Fix indentation. * python/py-finishbreakpoint.c: Fix indentation. * python/py-frame.c: Fix indentation. * python/py-framefilter.c: Fix indentation. * python/py-inferior.c: Fix indentation. * python/py-infthread.c: Fix indentation. * python/py-objfile.c: Fix indentation. * python/py-prettyprint.c: Fix indentation. * python/py-registers.c: Fix indentation. * python/py-signalevent.c: Fix indentation. * python/py-stopevent.c: Fix indentation. * python/py-stopevent.h: Fix indentation. * python/py-threadevent.c: Fix indentation. * python/py-tui.c: Fix indentation. * python/py-unwind.c: Fix indentation. * python/py-value.c: Fix indentation. * python/py-xmethods.c: Fix indentation. * python/python-internal.h: Fix indentation. * python/python.c: Fix indentation. * ravenscar-thread.c: Fix indentation. * record-btrace.c: Fix indentation. * record-full.c: Fix indentation. * record.c: Fix indentation. * reggroups.c: Fix indentation. * regset.h: Fix indentation. * remote-fileio.c: Fix indentation. * remote.c: Fix indentation. * reverse.c: Fix indentation. * riscv-linux-tdep.c: Fix indentation. * riscv-ravenscar-thread.c: Fix indentation. * riscv-tdep.c: Fix indentation. * rl78-tdep.c: Fix indentation. * rs6000-aix-tdep.c: Fix indentation. * rs6000-lynx178-tdep.c: Fix indentation. * rs6000-nat.c: Fix indentation. * rs6000-tdep.c: Fix indentation. * rust-lang.c: Fix indentation. * rx-tdep.c: Fix indentation. * s12z-tdep.c: Fix indentation. * s390-linux-tdep.c: Fix indentation. * score-tdep.c: Fix indentation. * ser-base.c: Fix indentation. * ser-mingw.c: Fix indentation. * ser-uds.c: Fix indentation. * ser-unix.c: Fix indentation. * serial.c: Fix indentation. * sh-linux-tdep.c: Fix indentation. * sh-nbsd-tdep.c: Fix indentation. * sh-tdep.c: Fix indentation. * skip.c: Fix indentation. * sol-thread.c: Fix indentation. * solib-aix.c: Fix indentation. * solib-darwin.c: Fix indentation. * solib-frv.c: Fix indentation. * solib-svr4.c: Fix indentation. * solib.c: Fix indentation. * source.c: Fix indentation. * sparc-linux-tdep.c: Fix indentation. * sparc-nbsd-tdep.c: Fix indentation. * sparc-obsd-tdep.c: Fix indentation. * sparc-ravenscar-thread.c: Fix indentation. * sparc-tdep.c: Fix indentation. * sparc64-linux-tdep.c: Fix indentation. * sparc64-nbsd-tdep.c: Fix indentation. * sparc64-obsd-tdep.c: Fix indentation. * sparc64-tdep.c: Fix indentation. * stabsread.c: Fix indentation. * stack.c: Fix indentation. * stap-probe.c: Fix indentation. * stubs/ia64vms-stub.c: Fix indentation. * stubs/m32r-stub.c: Fix indentation. * stubs/m68k-stub.c: Fix indentation. * stubs/sh-stub.c: Fix indentation. * stubs/sparc-stub.c: Fix indentation. * symfile-mem.c: Fix indentation. * symfile.c: Fix indentation. * symfile.h: Fix indentation. * symmisc.c: Fix indentation. * symtab.c: Fix indentation. * symtab.h: Fix indentation. * target-float.c: Fix indentation. * target.c: Fix indentation. * target.h: Fix indentation. * tic6x-tdep.c: Fix indentation. * tilegx-linux-tdep.c: Fix indentation. * tilegx-tdep.c: Fix indentation. * top.c: Fix indentation. * tracefile-tfile.c: Fix indentation. * tracepoint.c: Fix indentation. * tui/tui-disasm.c: Fix indentation. * tui/tui-io.c: Fix indentation. * tui/tui-regs.c: Fix indentation. * tui/tui-stack.c: Fix indentation. * tui/tui-win.c: Fix indentation. * tui/tui-winsource.c: Fix indentation. * tui/tui.c: Fix indentation. * typeprint.c: Fix indentation. * ui-out.h: Fix indentation. * unittests/copy_bitwise-selftests.c: Fix indentation. * unittests/memory-map-selftests.c: Fix indentation. * utils.c: Fix indentation. * v850-tdep.c: Fix indentation. * valarith.c: Fix indentation. * valops.c: Fix indentation. * valprint.c: Fix indentation. * valprint.h: Fix indentation. * value.c: Fix indentation. * value.h: Fix indentation. * varobj.c: Fix indentation. * vax-tdep.c: Fix indentation. * windows-nat.c: Fix indentation. * windows-tdep.c: Fix indentation. * xcoffread.c: Fix indentation. * xml-syscall.c: Fix indentation. * xml-tdesc.c: Fix indentation. * xstormy16-tdep.c: Fix indentation. * xtensa-config.c: Fix indentation. * xtensa-linux-nat.c: Fix indentation. * xtensa-linux-tdep.c: Fix indentation. * xtensa-tdep.c: Fix indentation. gdbserver/ChangeLog: * ax.cc: Fix indentation. * dll.cc: Fix indentation. * inferiors.h: Fix indentation. * linux-low.cc: Fix indentation. * linux-nios2-low.cc: Fix indentation. * linux-ppc-ipa.cc: Fix indentation. * linux-ppc-low.cc: Fix indentation. * linux-x86-low.cc: Fix indentation. * linux-xtensa-low.cc: Fix indentation. * regcache.cc: Fix indentation. * server.cc: Fix indentation. * tracepoint.cc: Fix indentation. gdbsupport/ChangeLog: * common-exceptions.h: Fix indentation. * event-loop.cc: Fix indentation. * fileio.cc: Fix indentation. * filestuff.cc: Fix indentation. * gdb-dlfcn.cc: Fix indentation. * gdb_string_view.h: Fix indentation. * job-control.cc: Fix indentation. * signals.cc: Fix indentation. Change-Id: I4bad7ae6be0fbe14168b8ebafb98ffe14964a695
2020-10-27gdb/breakpoint: add flags to 'condition' and 'break' commands to force conditionTankut Baris Aktemur1-1/+1
The previous patch made it possible to define a condition if it's valid at some locations. If the condition is invalid at all of the locations, it's rejected. However, there may be cases where the user knows the condition *will* be valid at a location in the future, e.g. due to a shared library load. To make it possible that such condition can be defined, this patch adds an optional '-force' flag to the 'condition' command, and, respectively, a '-force-condition' flag to the 'break'command. When the force flag is passed, the condition is not rejected even when it is invalid for all the current locations (note that all the locations would be internally disabled in this case). For instance: (gdb) break test.c:5 Breakpoint 1 at 0x1155: file test.c, line 5. (gdb) cond 1 foo == 42 No symbol "foo" in current context. Defining the condition was not possible because 'foo' is not available. The user can override this behavior with the '-force' flag: (gdb) cond -force 1 foo == 42 warning: failed to validate condition at location 1.1, disabling: No symbol "foo" in current context. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> stop only if foo == 42 1.1 N 0x0000000000001155 in main at test.c:5 Now the condition is accepted, but the location is automatically disabled. If a future location has a context in which 'foo' is available, that location would be enabled. For the 'break' command, -force-condition has the same result: (gdb) break test.c:5 -force-condition if foo == 42 warning: failed to validate condition at location 0x1169, disabling: No symbol "foo" in current context. Breakpoint 1 at 0x1169: file test.c, line 5. gdb/ChangeLog: 2020-10-27 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * breakpoint.h (set_breakpoint_condition): Add a new bool parameter. * breakpoint.c: Update the help text of the 'condition' and 'break' commands. (set_breakpoint_condition): Take a new bool parameter to control whether condition definition should be forced even when the condition expression is invalid in all of the current locations. (condition_command): Update the call to 'set_breakpoint_condition'. (find_condition_and_thread): Take the "-force-condition" flag into account. * linespec.c (linespec_keywords): Add "-force-condition" as an element. (FORCE_KEYWORD_INDEX): New #define. (linespec_lexer_lex_keyword): Update to consider "-force-condition" as a keyword. * ada-lang.c (create_ada_exception_catchpoint): Ditto. * guile/scm-breakpoint.c (gdbscm_set_breakpoint_condition_x): Ditto. * python/py-breakpoint.c (bppy_set_condition): Ditto. * NEWS: Mention the changes to the 'break' and 'condition' commands. gdb/testsuite/ChangeLog: 2020-10-27 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.base/condbreak-multi-context.exp: Expand to test forcing the condition. * gdb.linespec/cpcompletion.exp: Update to consider the '-force-condition' keyword. * gdb.linespec/explicit.exp: Ditto. * lib/completion-support.exp: Ditto. gdb/doc/ChangeLog: 2020-10-27 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.texinfo (Set Breaks): Document the '-force-condition' flag of the 'break'command. * gdb.texinfo (Conditions): Document the '-force' flag of the 'condition' command.
2020-09-28Remove target_has_registers macroTom Tromey1-1/+1
This removes the target_has_registers object-like macro, replacing it with the underlying function. gdb/ChangeLog 2020-09-28 Tom Tromey <tom@tromey.com> * tui/tui-regs.c (tui_get_register) (tui_data_window::show_registers): Update. * thread.c (scoped_restore_current_thread::restore) (scoped_restore_current_thread::scoped_restore_current_thread): Update. * regcache-dump.c (regcache_print): Update. * python/py-finishbreakpoint.c (bpfinishpy_detect_out_scope_cb): Update. * mi/mi-main.c (mi_cmd_data_write_register_values): Update. * mep-tdep.c (current_me_module, current_options): Update. * linux-thread-db.c (thread_db_load): Update. * infcmd.c (registers_info, info_vector_command) (info_float_command): Update. * ia64-tdep.c (ia64_frame_prev_register) (ia64_sigtramp_frame_prev_register): Update. * ia64-libunwind-tdep.c (libunwind_frame_prev_register): Update. * gcore.c (derive_stack_segment): Update. * frame.c (get_current_frame, has_stack_frames): Update. * findvar.c (language_defn::read_var_value): Update. * arm-tdep.c (arm_pc_is_thumb): Update. * target.c (target_has_registers): Rename from target_has_registers_1. * target.h (target_has_registers): Remove macro. (target_has_registers): Rename from target_has_registers_1.
2020-09-27Use an inner window in tui_py_windowTom Tromey1-27/+32
This changes tui_py_window to create an inner curses window. This greatly simplifies tui_py_window::output, beacuse it no longer needs to be careful to avoid overwriting the window's border. This patch also makes it a bit easier for a later patch to rewrite tui_copy_source_line. gdb/ChangeLog 2020-09-27 Tom Tromey <tom@tromey.com> * python/py-tui.c (class tui_py_window) <refresh_window>: New method. <erase>: Update. <cursor_x, cursor_y>: Remove. <m_inner_window>: New member. (tui_py_window::rerender): Create inner window. (tui_py_window::output): Write to inner window.
2020-09-17Use htab_up in type copyingTom Tromey1-6/+4
This changes create_copied_types_hash to return an htab_up, then modifies the callers to avoid explicit use of htab_delete. gdb/ChangeLog 2020-09-17 Tom Tromey <tom@tromey.com> * value.c (preserve_values): Update. * python/py-type.c (save_objfile_types): Update. * guile/scm-type.c (save_objfile_types): Update. * gdbtypes.h (create_copied_types_hash): Return htab_up. * gdbtypes.c (create_copied_types_hash): Return htab_up. * compile/compile-object-run.c (compile_object_run): Update.
2020-09-15Don't use PyInt_FromLongTom Tromey11-24/+36
Avoid the use of PyInt_FromLong, preferring gdb_py_object_from_longest instead. I found found another spot that was incorrectly handling errors (see gdbpy_create_ptid_object) while writing this patch; it is fixed here. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/python-internal.h (PyInt_FromLong): Remove define. * python/py-value.c (convert_value_from_python): Use gdb_py_object_from_longest. * python/py-type.c (typy_get_code): Use gdb_py_object_from_longest. * python/py-symtab.c (salpy_get_line): Use gdb_py_object_from_longest. * python/py-symbol.c (sympy_get_addr_class, sympy_line): Use gdb_py_object_from_longest. * python/py-record.c (recpy_gap_reason_code): Use gdb_py_object_from_longest. * python/py-record-btrace.c (recpy_bt_insn_size) (recpy_bt_func_level, btpy_list_count): Use gdb_py_object_from_longest. * python/py-infthread.c (gdbpy_create_ptid_object): Use gdb_py_object_from_longest. Fix error handling. * python/py-framefilter.c (bootstrap_python_frame_filters): Use gdb_py_object_from_longest. * python/py-frame.c (frapy_type, frapy_unwind_stop_reason): Use gdb_py_object_from_longest. * python/py-breakpoint.c (bppy_get_type, bppy_get_number) (bppy_get_thread, bppy_get_task, bppy_get_hit_count) (bppy_get_ignore_count): Use gdb_py_object_from_longest.
2020-09-15Don't use PyLong_FromUnsignedLongTom Tromey1-2/+2
This changes gdb to avoid PyLong_FromUnsignedLong, preferring gdb_py_object_from_ulongest instead. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/python.c (gdbpy_parameter_value): Use gdb_py_object_from_ulongest.
2020-09-15Don't use PyLong_FromLongLongTom Tromey2-2/+2
This changes gdb to avoid PyLong_FromLongLong, preferring to use gdb_py_object_from_longest instead. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/py-infevents.c (create_register_changed_event_object): Use gdb_py_object_from_longest. * python/py-exitedevent.c (create_exited_event_object): Use gdb_py_object_from_longest.
2020-09-15Don't use PyLong_FromLongTom Tromey7-12/+20
This changes gdb to avoid PyLong_FromLong, preferring to gdb_py_object_from_longest instead. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/python.c (gdbpy_parameter_value): Use gdb_py_object_from_longest. * python/py-type.c (convert_field, typy_range): Use gdb_py_object_from_longest. * python/py-tui.c (gdbpy_tui_width, gdbpy_tui_height): Use gdb_py_object_from_longest. * python/py-lazy-string.c (stpy_get_length): Use gdb_py_object_from_longest. * python/py-infthread.c (thpy_get_num, thpy_get_global_num): Use gdb_py_object_from_longest. * python/py-infevents.c (create_memory_changed_event_object): Use gdb_py_object_from_longest. * python/py-inferior.c (infpy_get_num): Use gdb_py_object_from_longest. (infpy_get_pid): Likewise.
2020-09-15Don't use gdb_py_long_from_ulongestTom Tromey7-16/+23
Remove the gdb_py_long_from_ulongest defines and change the Python layer to prefer gdb_py_object_from_ulongest. While writing this I noticed that the error handling in archpy_disassemble was incorrect -- it could call PyDict_SetItemString with a NULL value. This patch also fixes this bug. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/python-internal.h (gdb_py_long_from_ulongest): Remove defines. * python/py-value.c (valpy_long): Use gdb_py_object_from_ulongest. * python/py-symtab.c (salpy_get_pc): Use gdb_py_object_from_ulongest. (salpy_get_last): Likewise. * python/py-record-btrace.c (recpy_bt_insn_pc): Use gdb_py_object_from_ulongest. * python/py-lazy-string.c (stpy_get_address): Use gdb_py_object_from_ulongest. * python/py-frame.c (frapy_pc): Use gdb_py_object_from_ulongest. * python/py-arch.c (archpy_disassemble): Use gdb_py_object_from_ulongest and gdb_py_object_from_longest. Fix error handling.
2020-09-15Don't use gdb_py_long_from_longestTom Tromey4-9/+5
Change the Python layer to avoid gdb_py_long_from_longest, and remove the defines. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/python-internal.h (gdb_py_long_from_longest): Remove defines. * python/py-value.c (valpy_long): Use gdb_py_object_from_longest. * python/py-type.c (convert_field, typy_get_sizeof): Use gdb_py_object_from_longest. * python/py-record-btrace.c (btpy_list_index): Use gdb_py_object_from_longest.
2020-09-15Don't use PyInt_FromSsize_tTom Tromey2-3/+2
Change the Python layer to avoid PyInt_FromSsize_t, and remove the compatibility define. gdb/ChangeLog 2020-09-15 Tom Tromey <tromey@adacore.com> * python/python-internal.h (PyInt_FromSsize_t): Remove define. * python/py-record.c (recpy_element_number): Use gdb_py_object_from_longest. (recpy_gap_number): Likewise.
2020-09-14gdb: remove TYPE_STUBSimon Marchi1-1/+1
gdb/ChangeLog: * gdbtypes.h (TYPE_STUB): Remove, replace all uses with type::is_stub. Change-Id: Iec25b50449a0d10a38f815209e478c343e98632c
2020-09-14gdb: remove TYPE_UNSIGNEDSimon Marchi1-2/+2
gdb/ChangeLog: * gdbtypes.h (TYPE_UNSIGNED): Remove, replace all uses with type::is_unsigned. Change-Id: I84f76f5cd44ff7294e421d317376a9e476bc8666
2020-08-17Convert CORE_ADDR to Python using gdb_py_object_from_ulongestTom Tromey3-4/+4
An internal test failed on a riscv64-elf cross build because Inferior.search_memory returned a negative value. I tracked this down to to use of PyLong_FromLong in infpy_search_memory. Then, I looked at other conversions of CORE_ADDR to Python and fixed these as well. I don't think there is a good way to write a test for this. gdb/ChangeLog 2020-08-17 Tom Tromey <tromey@adacore.com> * python/py-inferior.c (infpy_search_memory): Use gdb_py_object_from_ulongest. * python/py-infevents.c (create_inferior_call_event_object) (create_memory_changed_event_object): Use gdb_py_object_from_ulongest. * python/py-linetable.c (ltpy_entry_get_pc): Use gdb_py_object_from_ulongest.
2020-07-28gdb/python: make more use of RegisterDescriptorsAndrew Burgess4-44/+86
This commit unifies all of the Python register lookup code (used by Frame.read_register, PendingFrame.read_register, and gdb.UnwindInfo.add_saved_register), and adds support for using a gdb.RegisterDescriptor for register lookup. Currently the register unwind code (PendingFrame and UnwindInfo) allow registers to be looked up either by name, or by GDB's internal number. I suspect the number was added for performance reasons, when unwinding we don't want to repeatedly map from name to number for every unwind. However, this kind-of sucks, it means Python scripts could include GDB's internal register numbers, and if we ever change this numbering in the future users scripts will break in unexpected ways. Meanwhile, the Frame.read_register method only supports accessing registers using a string, the register name. This commit unifies all of the register to register-number lookup code in our Python bindings, and adds a third choice into the mix, the use of gdb.RegisterDescriptor. The register descriptors can be looked up by name, but once looked up, they contain GDB's register number, and so provide all of the performance benefits of using a register number directly. However, as they are looked up by name we are no longer tightly binding the Python API to GDB's internal numbering scheme. As we may already have scripts in the wild that are using the register numbers directly I have kept support for this in the API, but I have listed this method last in the manual, and I have tried to stress that this is NOT a good method to use and that users should use either a string or register descriptor approach. After this commit all existing Python code should function as before, but users now have new options for how to identify registers. gdb/ChangeLog: * python/py-frame.c: Remove 'user-regs.h' include. (frapy_read_register): Rewrite to make use of gdbpy_parse_register_id. * python/py-registers.c (gdbpy_parse_register_id): New function, moved here from python/py-unwind.c. Updated the return type, and also accepts register descriptor objects. * python/py-unwind.c: Remove 'user-regs.h' include. (pyuw_parse_register_id): Moved to python/py-registers.c. (unwind_infopy_add_saved_register): Update to use gdbpy_parse_register_id. (pending_framepy_read_register): Likewise. * python/python-internal.h (gdbpy_parse_register_id): Declare. gdb/testsuite/ChangeLog: * gdb.python/py-unwind.py: Update to make use of a register descriptor. gdb/doc/ChangeLog: * python.texi (Unwinding Frames in Python): Update descriptions for PendingFrame.read_register and gdb.UnwindInfo.add_saved_register. (Frames In Python): Update description of Frame.read_register.
2020-07-28gdb: Add a find method for RegisterDescriptorIteratorAndrew Burgess1-1/+43
Adds a new method 'find' to the gdb.RegisterDescriptorIterator class, this allows gdb.RegisterDescriptor objects to be looked up directly by register name rather than having to iterate over all registers. This will be of use for a later commit. I've documented the new function in the manual, but I don't think a NEWS entry is required here, as, since the last release, the whole register descriptor mechanism is new, and is already mentioned in the NEWS file. gdb/ChangeLog: * python/py-registers.c: Add 'user-regs.h' include. (register_descriptor_iter_find): New function. (register_descriptor_iterator_object_methods): New static global methods array. (register_descriptor_iterator_object_type): Add pointer to methods array. gdb/testsuite/ChangeLog: * gdb.python/py-arch-reg-names.exp: Add additional tests. gdb/doc/ChangeLog: * python.texi (Registers In Python): Document new find function.
2020-07-22gdb/python: Use reference not pointer in py-registers.cAndrew Burgess1-9/+9
Pedro's review comments arrived after I'd already committed this change: commit f7306dac19c502232f766c3881313857915f330d Date: Tue Jul 7 15:00:30 2020 +0100 gdb/python: Reuse gdb.RegisterDescriptor objects where possible See: https://sourceware.org/pipermail/gdb-patches/2020-July/170726.html There should be no user visible changes after this commit. gdb/ChangeLog: * python/py-registers.c (gdbpy_register_object_data_init): Remove redundant local variable. (gdbpy_get_register_descriptor): Extract descriptor vector as a reference, not pointer, update code accordingly.
2020-07-21gdb/python: Reuse gdb.RegisterGroup objects where possibleAndrew Burgess1-11/+30
Only create one gdb.RegisterGroup Python object for each of GDB's reggroup objects. I could have added a field into the reggroup object to hold the Python object pointer for each reggroup, however, as reggroups are never deleted within GDB, and are global (not per-architecture) a simpler solution seemed to be just to hold a single global map from reggroup pointer to a Python object representing the reggroup. Then we can reuse the objects out of this map. After this commit it is possible for a user to tell that two gdb.RegisterGroup objects are now identical when previously they were unique, however, as both these objects are read-only I don't think this should be a problem. There should be no other user visible changes after this commit. gdb/ChangeLog: * python/py-registers.c : Add 'unordered_map' include. (gdbpy_new_reggroup): Renamed to... (gdbpy_get_reggroup): ...this. Update to only create register group descriptors when needed. (gdbpy_reggroup_iter_next): Update. gdb/testsuite/ChangeLog: * gdb.python/py-arch-reg-groups.exp: Additional tests.
2020-07-21gdb/python: Reuse gdb.RegisterDescriptor objects where possibleAndrew Burgess1-13/+48
Instead of having the gdb.RegisterDescriptorIterator creating new gdb.RegisterDescriptor objects for each regnum, instead cache gdb.RegisterDescriptor objects on the gdbarch object and reuse these. This means that for every gdbarch/regnum pair there is a single unique gdb.RegisterDescriptor, this feels like a neater implementation than the existing one. It is possible for a user to see (in Python code) that the descriptors are now identical, but as the descriptors are read-only this should make no real difference. There should be no other user visible changes. gdb/ChangeLog: * python/py-registers.c (gdbpy_register_object_data): New static global. (gdbpy_register_object_data_init): New function. (gdbpy_new_register_descriptor): Renamed to... (gdbpy_get_register_descriptor): ...this, and update to reuse existing register descriptors where possible. (gdbpy_register_descriptor_iter_next): Update. (gdbpy_initialize_registers): Register new gdbarch data. gdb/testsuite/ChangeLog: * gdb.python/py-arch-reg-names.exp: Additional tests.
2020-07-12gdb: make type::bounds work for array and string typesSimon Marchi1-3/+0
Getting the bounds of an array (or string) type is a common operation, and is currently done through its index type: my_array_type->index_type ()->bounds () I think it would make sense to let the `type::bounds` methods work for arrays and strings, as a shorthand for this. It's natural that when asking for the bounds of an array, we get the bounds of the range type used as its index type. In a way, it's equivalent as the now-removed TYPE_ARRAY_{LOWER,UPPER}_BOUND_IS_UNDEFINED and TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE, except it returns the `range_bounds` object. The caller is then responsible for getting the property it needs in it. I updated all the spots I could find that could take advantage of this. Note that this also makes `type::bit_stride` work on array types, since `type::bit_stride` uses `type::bounds`. `my_array_type->bit_stride ()` now returns the bit stride of the array's index type. So some spots are also changed to take advantage of this. gdb/ChangeLog: * gdbtypes.h (struct type) <bounds>: Handle array and string types. * ada-lang.c (assign_aggregate): Use type::bounds on array/string type. * c-typeprint.c (c_type_print_varspec_suffix): Likewise. * c-varobj.c (c_number_of_children): Likewise. (c_describe_child): Likewise. * eval.c (evaluate_subexp_for_sizeof): Likewise. * f-typeprint.c (f_type_print_varspec_suffix): Likewise. (f_type_print_base): Likewise. * f-valprint.c (f77_array_offset_tbl): Likewise. (f77_get_upperbound): Likewise. (f77_print_array_1): Likewise. * guile/scm-type.c (gdbscm_type_range): Likewise. * m2-typeprint.c (m2_array): Likewise. (m2_is_long_set_of_type): Likewise. * m2-valprint.c (get_long_set_bounds): Likewise. * p-typeprint.c (pascal_type_print_varspec_prefix): Likewise. * python/py-type.c (typy_range): Likewise. * rust-lang.c (rust_internal_print_type): Likewise. * type-stack.c (type_stack::follow_types): Likewise. * valarith.c (value_subscripted_rvalue): Likewise. * valops.c (value_cast): Likewise. Change-Id: I5c0c08930bffe42fd69cb4bfcece28944dd88d1f
2020-07-12gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUNDSimon Marchi1-4/+4
Remove the macros, use the getters of `struct dynamic_prop` instead. gdb/ChangeLog: * gdbtypes.h (TYPE_LOW_BOUND, TYPE_HIGH_BOUND): Remove. Update all callers to use type::range_bounds followed by dynamic_prop::{low,high}. Change-Id: I31beeed65d94d81ac4f999244a8b859e2ee961d1
2020-07-06gdb/python: New method to access list of register groupsAndrew Burgess3-0/+214
Add a new method gdb.Architecture.register_groups which returns a new object of type gdb.RegisterGroupsIterator. This new iterator then returns objects of type gdb.RegisterGroup. Each gdb.RegisterGroup object just wraps a single reggroup pointer, and (currently) has just one read-only property 'name' that is a string, the name of the register group. As with the previous commit (adding gdb.RegisterDescriptor) I made gdb.RegisterGroup an object rather than just a string in case we want to add additional properties in the future. gdb/ChangeLog: * NEWS: Mention additions to Python API. * python/py-arch.c (archpy_register_groups): New function. (arch_object_methods): Add 'register_groups' method. * python/py-registers.c (reggroup_iterator_object): New struct. (reggroup_object): New struct. (gdbpy_new_reggroup): New function. (gdbpy_reggroup_to_string): New function. (gdbpy_reggroup_name): New function. (gdbpy_reggroup_iter): New function. (gdbpy_reggroup_iter_next): New function. (gdbpy_new_reggroup_iterator): New function (gdbpy_initialize_registers): Register new types. (reggroup_iterator_object_type): Define new Python type. (gdbpy_reggroup_getset): New static global. (reggroup_object_type): Define new Python type. * python/python-internal.h gdb/testsuite/ChangeLog: * gdb.python/py-arch-reg-groups.exp: New file. gdb/doc/ChangeLog: * gdb.texi (Registers): Add @anchor for 'info registers <reggroup>' command. * python.texi (Architectures In Python): Document new register_groups method. (Registers In Python): Document two new object types related to register groups.
2020-07-06gdb/python: Add gdb.Architecture.registers methodAndrew Burgess4-0/+302
This commit adds a new method gdb.Architecture.registers that returns an object of the new type gdb.RegisterDescriptorIterator. This iterator returns objects of the new type gdb.RegisterDescriptor. A RegisterDescriptor is not a way to read the value of a register, this is already covered by Frame.read_register, a RegisterDescriptor is simply a way to discover from Python, which registers are available for a given architecture. I did consider just returning a string, the name of each register, instead of a RegisterDescriptor, however, I'm aware that it we don't want to break the existing Python API in any way, so if I return just a string now, but in the future we want more information about a register then we would have to add a second API to get that information. By going straight to a descriptor object now, it is easy to add additional properties in the future should we wish to. Right now the only property of a register that a user can access is the name of the register. In future we might want to be able to ask the register about is register groups, or its type. gdb/ChangeLog: * Makefile.in (SUBDIR_PYTHON_SRCS): Add py-registers.c * python/py-arch.c (archpy_registers): New function. (arch_object_methods): Add 'registers' method. * python/py-registers.c: New file. * python/python-internal.h (gdbpy_new_register_descriptor_iterator): Declare. (gdbpy_initialize_registers): Declare. * python/python.c (do_start_initialization): Call gdbpy_initialize_registers. * NEWS: Mention additions to the Python API. gdb/testsuite/ChangeLog: * gdb.python/py-arch-reg-names.exp: New file. gdb/doc/ChangeLog: * python.texi (Python API): Add new section the menu. (Frames In Python): Add new @anchor. (Architectures In Python): Document new registers method. (Registers In Python): New section.
2020-07-06gdb/python: Add architecture method to gdb.PendingFrameAndrew Burgess1-0/+20
It could be useful to determine the architecture of a frame being unwound during the frame unwind process, that is, before we have a gdb.Frame, but when we only have a gdb.PendingFrame. The PendingFrame already has a pointer to the gdbarch internally, this commit just exposes an 'architecture' method to Python, and has this return a gdb.Architecture object (list gdb.Frame.architecture does). gdb/ChangeLog: * NEWS: Mention new Python API method. * python/py-unwind.c (pending_framepy_architecture): New function. (pending_frame_object_methods): Add architecture method. gdb/testsuite/ChangeLog: * gdb.python/py-unwind.py (TestUnwinder::__call__): Add test for gdb.PendingFrame.architecture method. gdb/doc/ChangeLog: * python.texi (Unwinding Frames in Python): Document PendingFrame.architecture method.
2020-06-22default-args: allow to define default arguments for aliasesPhilippe Waroquiers3-5/+5
Currently, a user can define an alias, but cannot have default arguments for this alias. This patch modifies the 'alias' command so that default args can be provided. (gdb) h alias Define a new command that is an alias of an existing command. Usage: alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...] ALIAS is the name of the alias command to create. COMMAND is the command being aliased to. Options: -a Specify that ALIAS is an abbreviation of COMMAND. Abbreviations are not used in command completion.. GDB will automatically prepend the provided DEFAULT-ARGS to the list of arguments explicitly provided when using ALIAS. Use "help aliases" to list all user defined aliases and their default args. Examples: Make "spe" an alias of "set print elements": alias spe set print elements Make "elms" an alias of "elements" in the "set print" command: alias -a set print elms set print elements Make "btf" an alias of "backtrace -full -past-entry -past-main" : alias btf = backtrace -full -past-entry -past-main Make "wLapPeu" an alias of 2 nested "with": alias wLapPeu = with language pascal -- with print elements unlimited -- (gdb) The way 'default-args' is implemented makes it trivial to set default args also for GDB commands (such as "backtrace") and for GDB pre-defined aliases (such as "bt"). It was however deemed better to not allow to define default arguments for pre-defined commands and aliases, to avoid users believing that e.g. default args for "backtrace" would apply to "bt". If needed, default-args could be allowed for GDB predefined commands and aliases by adding a command 'set default-args GDB_COMMAND_OR_PREDEFINED_ALIAS [DEFAULT-ARGS...]'. * 'alias' command now has a completer that helps to complete: - ALIAS (if the user defines an alias after a prefix), - the aliased COMMAND - the possible options for the aliased COMMAND. * Help and apropos commands show the definitions of the aliases that have default arguments, e.g. (gdb) help backtrace backtrace, btf, where, bt alias btf = backtrace -full -past-entry -past-main Print backtrace of all stack frames, or innermost COUNT frames. Usage: backtrace [OPTION]... [QUALIFIER]... [COUNT | -COUNT] Options: -entry-values no|only|preferred|if-needed|both|compact|default Set printing of function arguments at function entry. ... gdb/ChangeLog 2020-06-22 Philippe Waroquiers <philippe.waroquiers@skynet.be> * cli/cli-cmds.c (lookup_cmd_for_default_args) (alias_command_completer) (make_alias_options_def_group): New functions. (alias_opts, alias_option_defs): New struct and array. (alias_usage_error): Update usage. (alias_command): Handles optional DEFAULT-ARGS... arguments. Use option framework. (_initialize_cli_cmds): Update alias command help. Update aliases command help. (show_user): Add NULL for new default_args lookup_cmd argument. (valid_command_p): Rename to validate_aliased_command. Add NULL for new default_args lookup_cmd argument. Verify that the aliased_command has no default args. * cli/cli-decode.c (help_cmd): Show aliases definitions. (lookup_cmd_1, lookup_cmd): New argument default_args. (add_alias_cmd): Add NULL for new default_args lookup_cmd argument. (print_help_for_command): Show default args under the layout alias some_alias = some_aliased_cmd some_alias_default_arg. * cli/cli-decode.h (struct cmd_list_element): New member default_args. xfree default_args in destructor. * cli/cli-script.c (process_next_line, do_define_command): Add NULL for new default_args lookup_cmd argument. * command.h: Declare new default_args argument in lookup_cmd and lookup_cmd_1. * completer.c (complete_line_internal_1): Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. * guile/scm-param.c (add_setshow_generic, pascm_parameter_defined_p): Likewise. * infcmd.c (_initialize_infcmd): Likewise. * python/py-auto-load.c (gdbpy_initialize_auto_load): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. * python/py-param.c (add_setshow_generic): Likewise. * remote.c (_initialize_remote): Likewise. * top.c (execute_command): Prepend default_args if command has some. (set_verbose): Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument. * tracepoint.c (validate_actionline, encode_actions_1): Add NULL for new default_args lookup_cmd or lookup_cmd_1 argument.
2020-06-16Fix crash when TUI window creation failsTom Tromey1-1/+4
If a TUI window is written in Python, and if the window construction function fails, then gdb will crash. This patch fixes the crash. gdb/ChangeLog 2020-06-16 Tom Tromey <tom@tromey.com> * python/py-tui.c (tui_py_window::~tui_py_window): Handle case where m_window==nullptr. gdb/testsuite/ChangeLog 2020-06-16 Tom Tromey <tom@tromey.com> * gdb.python/tui-window.py (failwin): New function. Register it as a TUI window type. * gdb.python/tui-window.exp: Create new "fail" layout. Test it.
2020-06-08gdb: remove TYPE_FIELD_TYPE macroSimon Marchi1-2/+2
Remove the `TYPE_FIELD_TYPE` macro, changing all the call sites to use `type::field` and `field::type` directly. gdb/ChangeLog: * gdbtypes.h (TYPE_FIELD_TYPE): Remove. Change all call sites to use type::field and field::type instead. Change-Id: Ifda6226a25c811cfd334a756a9fbc5c0afdddff3
2020-06-08gdb: remove TYPE_INDEX_TYPE macroSimon Marchi1-2/+2
Remove `TYPE_INDEX_TYPE` macro, changing all the call sites to use `type::index_type` directly. gdb/ChangeLog: * gdbtypes.h (TYPE_INDEX_TYPE): Remove. Change all call sites to use type::index_type instead. Change-Id: I56715df0bdec89463cda6bd341dac0e01b2faf84
2020-06-05Revert "gdb/python: Avoid use after free in py-tui.c"Andrew Burgess1-1/+1
This reverts commit 982a38f60b0ece9385556cff45567e06710478cb. I missed that the title being assigned too was a std::string, and so there is no leak.
2020-06-05gdb/python: Avoid use after free in py-tui.cAndrew Burgess1-1/+1
When setting the window title of a tui frame we do this: gdb::unique_xmalloc_ptr<char> value = python_string_to_host_string (<python-object>); ... win->window->title = value.get (); The problem here is that 'get ()' only borrows the pointer from value, when value goes out of scope the pointer will be freed. As a result, the tui frame will be left with a pointer to undefined memory contents. Instead we should be using 'value.release ()' to take ownership of the pointer from value. gdb/ChangeLog: * python/py-tui.c (gdbpy_tui_set_title): Use release, not get, to avoid use after free.
2020-05-28Fix Python3.9 related runtime problemsKevin Buettner1-26/+30
Python3.9b1 is now available on Rawhide. GDB w/ Python 3.9 support can be built using the configure switch -with-python=/usr/bin/python3.9. Attempting to run gdb/Python3.9 segfaults on startup: #0 0x00007ffff7b0582c in PyEval_ReleaseLock () from /lib64/libpython3.9.so.1.0 #1 0x000000000069ccbf in do_start_initialization () at worktree-test1/gdb/python/python.c:1789 #2 _initialize_python () at worktree-test1/gdb/python/python.c:1877 #3 0x00000000007afb0a in initialize_all_files () at init.c:237 ... Consulting the the documentation... https://docs.python.org/3/c-api/init.html ...we find that PyEval_ReleaseLock() has been deprecated since version 3.2. It recommends using PyEval_SaveThread or PyEval_ReleaseThread() instead. In do_start_initialization, in gdb/python/python.c, we can replace the calls to PyThreadState_Swap() and PyEval_ReleaseLock() with a single call to PyEval_SaveThread. (Thanks to Keith Seitz for working this out.) With that in place, GDB gets a little bit further. It still dies on startup, but the backtrace is different: #0 0x00007ffff7b04306 in PyOS_InterruptOccurred () from /lib64/libpython3.9.so.1.0 #1 0x0000000000576e86 in check_quit_flag () at worktree-test1/gdb/extension.c:776 #2 0x0000000000576f8a in set_active_ext_lang (now_active=now_active@entry=0x983c00 <extension_language_python>) at worktree-test1/gdb/extension.c:705 #3 0x000000000069d399 in gdbpy_enter::gdbpy_enter (this=0x7fffffffd2d0, gdbarch=0x0, language=0x0) at worktree-test1/gdb/python/python.c:211 #4 0x0000000000686e00 in python_new_inferior (inf=0xddeb10) at worktree-test1/gdb/python/py-inferior.c:251 #5 0x00000000005d9fb9 in std::function<void (inferior*)>::operator()(inferior*) const (__args#0=<optimized out>, this=0xccad20) at /usr/include/c++/10/bits/std_function.h:617 #6 gdb::observers::observable<inferior*>::notify (args#0=0xddeb10, this=<optimized out>) at worktree-test1/gdb/../gdbsupport/observable.h:106 #7 add_inferior_silent (pid=0) at worktree-test1/gdb/inferior.c:113 #8 0x00000000005dbcb8 in initialize_inferiors () at worktree-test1/gdb/inferior.c:947 ... We checked with some Python Developers and were told that we should acquire the GIL prior to calling any Python C API function. We definitely don't have the GIL for calls of PyOS_InterruptOccurred(). I moved class_gdbpy_gil earlier in the file and use it in gdbpy_check_quit_flag() to acquire (and automatically release) the GIL. With those changes in place, I was able to run to a GDB prompt. But, when trying to quit, it segfaulted again due to due to some other problems with gdbpy_check_quit_flag(): Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. 0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0 (top-gdb) bt 8 #0 0x00007ffff7bbab0c in new_threadstate () from /lib64/libpython3.9.so.1.0 #1 0x00007ffff7afa5ea in PyGILState_Ensure.cold () from /lib64/libpython3.9.so.1.0 #2 0x000000000069b58c in gdbpy_gil::gdbpy_gil (this=<synthetic pointer>) at worktree-test1/gdb/python/python.c:278 #3 gdbpy_check_quit_flag (extlang=<optimized out>) at worktree-test1/gdb/python/python.c:278 #4 0x0000000000576e96 in check_quit_flag () at worktree-test1/gdb/extension.c:776 #5 0x000000000057700c in restore_active_ext_lang (previous=0xe9c050) at worktree-test1/gdb/extension.c:729 #6 0x000000000088913a in do_my_cleanups ( pmy_chain=0xc31870 <final_cleanup_chain>, old_chain=0xae5720 <sentinel_cleanup>) at worktree-test1/gdbsupport/cleanups.cc:131 #7 do_final_cleanups () at worktree-test1/gdbsupport/cleanups.cc:143 In this case, we're trying to call a Python C API function after Py_Finalize() has been called from finalize_python(). I made finalize_python set gdb_python_initialized to false and then cause check_quit_flag() to return early when it's false. With these changes in place, GDB seems to be working again with Python3.9b1. I think it likely that there are other problems lurking. I wouldn't be surprised to find that there are other calls into Python where we don't first make sure that we have the GIL. Further changes may well be needed. I see no regressions testing on Rawhide using a GDB built with the default Python version (3.8.3) versus one built using Python 3.9b1. I've also tested on Fedora 28, 29, 30, 31, and 32 (all x86_64) using the default (though updated) system installed versions of Python on those OSes. This means that I've tested against Python versions 2.7.15, 2.7.17, 2.7.18, 3.7.7, 3.8.2, and 3.8.3. In each case GDB still builds without problem and shows no regressions after applying this patch. gdb/ChangeLog: 2020-MM-DD Kevin Buettner <kevinb@redhat.com> Keith Seitz <keiths@redhat.com> * python/python.c (do_start_initialization): For Python 3.9 and later, call PyEval_SaveThread instead of PyEval_ReleaseLock. (class gdbpy_gil): Move to earlier in file. (finalize_python): Set gdb_python_initialized. (gdbpy_check_quit_flag): Acquire GIL via gdbpy_gil. Return early when not initialized.
2020-05-23gdb: remove TYPE_FIELD macroSimon Marchi1-1/+1
Replace all uses of it by type::field. Note that since type::field returns a reference to the field, some spots are used to assign the whole field structure. See ctfread.c, function attach_fields_to_type, for example. This is the same as was happening with the macro, so I don't think it's a problem, but if anybody sees a really nicer way to do this, now could be a good time to implement it. gdb/ChangeLog: * gdbtypes.h (TYPE_FIELD): Remove. Replace all uses with type::field.
2020-05-22gdb: remove TYPE_NFIELDS macroSimon Marchi1-4/+4
Remove `TYPE_NFIELDS`, changing all the call sites to use `type::num_fields` directly. This is quite a big diff, but this was mostly done using sed and coccinelle. A few call sites were done by hand. gdb/ChangeLog: * gdbtypes.h (TYPE_NFIELDS): Remove. Change all cal sites to use type::num_fields instead. Change-Id: Ib73be4c36f9e770e0f729bac3b5257d7cb2f9591
2020-05-16gdb: remove TYPE_NAME macroSimon Marchi1-5/+5
Remove `TYPE_NAME`, changing all the call sites to use `type::name` directly. This is quite a big diff, but this was mostly done using sed and coccinelle. A few call sites were done by hand. gdb/ChangeLog: * gdbtypes.h (TYPE_NAME): Remove. Change all cal sites to use type::name instead.
2020-05-14gdb: remove TYPE_CODE macroSimon Marchi6-52/+52
Remove TYPE_CODE, changing all the call sites to use type::code directly. This is quite a big diff, but this was mostly done using sed and coccinelle. A few call sites were done by hand. gdb/ChangeLog: * gdbtypes.h (TYPE_CODE): Remove. Change all call sites to use type::code instead.
2020-05-08Remove ALL_PSPACESTom Tromey1-8/+6
This removes the ALL_PSPACES macro. In this case it seemed cleanest to change how program spaces are stored -- instead of using a linked list, they are now stored in a std::vector. gdb/ChangeLog 2020-05-08 Tom Tromey <tom@tromey.com> * symtab.c (set_symbol_cache_size) (maintenance_print_symbol_cache, maintenance_flush_symbol_cache) (maintenance_print_symbol_cache_statistics): Update. * symmisc.c (print_symbol_bcache_statistics) (print_objfile_statistics, maintenance_print_objfiles) (maintenance_info_symtabs, maintenance_check_symtabs) (maintenance_expand_symtabs, maintenance_info_line_tables): Update. * symfile-debug.c (set_debug_symfile): Update. * source.c (forget_cached_source_info): Update. * python/python.c (gdbpy_progspaces): Update. * psymtab.c (maintenance_info_psymtabs): Update. * probe.c (parse_probes): Update. * linespec.c (iterate_over_all_matching_symtabs) (collect_symtabs_from_filename, search_minsyms_for_name): Update. * guile/scm-progspace.c (gdbscm_progspaces): Update. * exec.c (exec_target::close): Update. * ada-tasks.c (ada_tasks_new_objfile_observer): Update. * breakpoint.c (print_one_breakpoint_location) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint): Update. * progspace.c (program_spaces): Now a std::vector. (maybe_new_address_space): Update. (add_program_space): Remove. (program_space::program_space): Update. (remove_program_space): Update. (number_of_program_spaces): Remove. (print_program_space, update_address_spaces): Update. * progspace.h (program_spaces): Change type. (ALL_PSPACES): Remove. (number_of_program_spaces): Don't declare. (struct program_space) <next>: Remove.
2020-04-28Allow Python commands to be in class_tuiTom Tromey1-4/+5
Now that Python code can create TUI windows, it seemed appropriate to allow Python commands to appear in the "TUI" help class. This patch adds this capability. gdb/ChangeLog 2020-04-28 Tom Tromey <tom@tromey.com> * NEWS: Update. * python/py-cmd.c (gdbpy_initialize_commands): Add COMMAND_TUI. (cmdpy_init): Allow class_tui. gdb/doc/ChangeLog 2020-04-28 Tom Tromey <tom@tromey.com> * python.texi (Commands In Python): Document gdb.COMMAND_TUI.
2020-04-24Add Python support for dynamic typesTom Tromey1-2/+33
This changes the gdb Python API to add support for dynamic types. In particular, this adds an attribute to gdb.Type, and updates some attributes to reflect dynamic sizes and field offsets. There's still no way to get the dynamic type from one of its concrete instances. This could perhaps be added if needed. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> PR python/23662: * python/py-type.c (convert_field): Handle FIELD_LOC_KIND_DWARF_BLOCK. (typy_get_sizeof): Handle TYPE_HAS_DYNAMIC_LENGTH. (typy_get_dynamic): Nw function. (type_object_getset): Add "dynamic". * NEWS: Add entry. gdb/doc/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> PR python/23662: * python.texi (Types In Python): Document new features. gdb/testsuite/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> PR python/23662: * gdb.ada/variant.exp: Add Python checks. * gdb.rust/simple.exp: Add dynamic type checks.
2020-04-20Mark move constructors as "noexcept"Tom Tromey2-2/+2
I recently learned that move constructors generally should be marked "noexcept". This ensures that standard containers will move objects when possible, rather than copy them. This patch fixes the cases I could find. Note that implicitly-defined or defaulted move constructors will automatically do what you'd expect; that is, they are noexcept if all the members have noexcept move constructors. While doing this, I noticed a couple of odd cases where the move constructor seemed to assume that the object being constructed could have state requiring destruction. I've fixed these as well. See completion_result and scoped_mmap. gdb/ChangeLog 2020-04-20 Tom Tromey <tromey@adacore.com> * python/python.c (struct gdbpy_event): Mark move constructor as noexcept. * python/py-tui.c (class gdbpy_tui_window_maker): Mark move constructor as noexcept. * completer.h (struct completion_result): Mark move constructor as noexcept. * completer.c (completion_result::completion_result): Use initialization style. Don't call reset_match_list. gdbsupport/ChangeLog 2020-04-20 Tom Tromey <tromey@adacore.com> * scoped_mmap.h (scoped_mmap): Mark move constructor as noexcept. Use initialization style. Don't call destroy. * scoped_fd.h (class scoped_fd): Mark move constructor as noexcept. * gdb_ref_ptr.h (class ref_ptr): Mark move constructor as noexcept.