aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
AgeCommit message (Collapse)AuthorFilesLines
2019-09-20bfd macro conversion to inline functionsAlan Modra1-7/+7
This converts some of the macros that access struct bfd fields to inline functions. bfd/ * archive.c (bfd_generic_archive_p): Use bfd_set_thin_archive. * bfd-in.h (bfd_get_filename, bfd_get_cacheable, bfd_get_format), (bfd_get_target, bfd_get_flavour, bfd_family_coff, bfd_big_endian), (bfd_little_endian, bfd_header_big_endian, bfd_header_little_endian), (bfd_get_file_flags, bfd_applicable_file_flags), (bfd_applicable_section_flags, bfd_has_map, bfd_is_thin_archive), (bfd_valid_reloc_types, bfd_usrdata, bfd_get_start_address), (bfd_get_symcount, bfd_get_outsymbols, bfd_count_sections), (bfd_get_dynamic_symcount, bfd_get_symbol_leading_char): Delete. * bfd/bfd.c (bfd_get_filename, bfd_get_cacheable, bfd_get_format), (bfd_get_file_flags, bfd_get_start_address, bfd_get_symcount), (bfd_get_dynamic_symcount, bfd_get_outsymbols, bfd_count_sections), (bfd_has_map, bfd_is_thin_archive, bfd_set_thin_archive), (bfd_usrdata, bfd_set_usrdata): New inline functions. * targets.c (bfd_get_target, bfd_get_flavour), (bfd_applicable_file_flags, bfd_family_coff, bfd_big_endian), (bfd_little_endian, bfd_header_big_endian), (bfd_header_little_endian, bfd_applicable_section_flags), (bfd_get_symbol_leading_char): New inline functions. * bfd-in2.h: Regenerate. binutils/ * ar.c (write_archive): Use bfd_set_thin_archive. gdb/ * gdb_bfd.c (gdb_bfd_ref, gdb_bfd_unref): Use bfd_set_usrdata. * dwarf2read.c (dwarf2_read_gdb_index, dwarf2_read_debug_names), (read_indirect_string_from_dwz): Use bfd accessor. * dwarf2read.h (struct dwz_file <filename>): Likewise. * machoread.c (macho_symfile_read_all_oso): Likewise. * solib.c (solib_bfd_open): Likewise. ld/ * ldelf.c (ldelf_after_open, ldelf_place_orphan * ldlang.c (walk_wild_file, lang_process): Use bfd_usrdata. (load_symbols, ldlang_add_file): Use bfd_set_usrdata. * ldmain.c (add_archive_element): Use bfd_usrdata. * ldlang.h (bfd_input_just_syms): New inline function. * emultempl/aarch64elf.em (build_section_lists): Use it. * emultempl/mmo.em (mmo_place_orphan): Likewise. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise. * emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise. * emultempl/ppc64elf.em (build_section_lists): Likewise. sim/ * ppc/emul_generic.c (emul_add_tree_options): Delete old bfd code.
2019-09-19bfd_section_* macrosAlan Modra1-60/+60
This large patch removes the unnecessary bfd parameter from various bfd section macros and functions. The bfd is hardly ever used and if needed for the bfd_set_section_* or bfd_rename_section functions can be found via section->owner except for the com, und, abs, and ind std_section special sections. Those sections shouldn't be modified anyway. The patch also removes various bfd_get_section_<field> macros, replacing their use with bfd_section_<field>, and adds bfd_set_section_lma. I've also fixed a minor bug in gas where compressed section renaming was done directly rather than calling bfd_rename_section. This would have broken bfd_get_section_by_name and similar functions, but that hardly mattered at such a late stage in gas processing. bfd/ * bfd-in.h (bfd_get_section_name, bfd_get_section_vma), (bfd_get_section_lma, bfd_get_section_alignment), (bfd_get_section_size, bfd_get_section_flags), (bfd_get_section_userdata): Delete. (bfd_section_name, bfd_section_size, bfd_section_vma), (bfd_section_lma, bfd_section_alignment): Lose bfd parameter. (bfd_section_flags, bfd_section_userdata): New. (bfd_is_com_section): Rename parameter. * section.c (bfd_set_section_userdata, bfd_set_section_vma), (bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section), (bfd_set_section_size): Delete bfd parameter, rename section parameter. (bfd_set_section_lma): New. * bfd-in2.h: Regenerate. * mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param, update callers. * aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c, * coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c, * compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h, * elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c, * elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c, * elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c, * elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c, * elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c, * elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c, * elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c, * elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c, * elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c, * elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c, * elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c, * elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c, * elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c, * elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c, * elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c, * elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c, * elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c, * elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c, * elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c, * mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c, * peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c, * xcofflink.c: Update throughout for bfd section macro and function changes. binutils/ * addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c, * objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c, * od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c, * resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update throughout for bfd section macro and function changes. gas/ * as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c, * read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c, * config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c, * config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c, * config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c, * config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c, * config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c, * config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c, * config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c, * config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c, * config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c, * config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c, * config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c, * config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c, * config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c, * config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c, * config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c, * config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c, * config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c, * config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c, * config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c, * config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c, * config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for bfd section macro and function changes. * write.c (compress_debug): Use bfd_rename_section. gdb/ * aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c, * coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c, * dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c, * exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h, * hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c, * i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c, * maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c, * mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c, * objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c, * ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c, * rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c, * s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c, * solib-spu.c, * solib-svr4.c, * solib-target.c, * spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c, * symmisc.c, * symtab.c, * target.c, * windows-nat.c, * xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c, * mi/mi-interp.c: Update throughout for bfd section macro and function changes. * gcore (gcore_create_callback): Use bfd_set_section_lma. * spu-tdep.c (spu_overlay_new_objfile): Likewise. gprof/ * corefile.c, * symtab.c: Update throughout for bfd section macro and function changes. ld/ * ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c, * emultempl/aarch64elf.em, * emultempl/aix.em, * emultempl/armcoff.em, * emultempl/armelf.em, * emultempl/cr16elf.em, * emultempl/cskyelf.em, * emultempl/m68hc1xelf.em, * emultempl/m68kelf.em, * emultempl/mipself.em, * emultempl/mmix-elfnmmo.em, * emultempl/mmo.em, * emultempl/msp430.em, * emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em, * emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update throughout for bfd section macro and function changes. libctf/ * ctf-open-bfd.c: Update throughout for bfd section macro changes. opcodes/ * arc-ext.c: Update throughout for bfd section macro changes. sim/ * common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c, * erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c, * m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c, * rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c, * rx/trace.c: Update throughout for bfd section macro changes.
2019-09-18Change boolean options to bool instead of intChristian Biesinger1-5/+5
This is for add_setshow_boolean_cmd as well as the gdb::option interface. gdb/ChangeLog: 2019-09-17 Christian Biesinger <cbiesinger@google.com> * ada-lang.c (ada_ignore_descriptive_types_p): Change to bool. (print_signatures): Likewise. (trust_pad_over_xvs): Likewise. * arch/aarch64-insn.c (aarch64_debug): Likewise. * arch/aarch64-insn.h (aarch64_debug): Likewise. * arm-linux-nat.c (arm_apcs_32): Likewise. * arm-linux-tdep.c (arm_apcs_32): Likewise. * arm-nbsd-nat.c (arm_apcs_32): Likewise. * arm-tdep.c (arm_debug): Likewise. (arm_apcs_32): Likewise. * auto-load.c (debug_auto_load): Likewise. (auto_load_gdb_scripts): Likewise. (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * auto-load.h (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * breakpoint.c (disconnected_dprintf): Likewise. (breakpoint_proceeded): Likewise. (automatic_hardware_breakpoints): Likewise. (always_inserted_mode): Likewise. (target_exact_watchpoints): Likewise. (_initialize_breakpoint): Update. * breakpoint.h (target_exact_watchpoints): Change to bool. * btrace.c (maint_btrace_pt_skip_pad): Likewise. * cli/cli-cmds.c (trace_commands): Likewise. * cli/cli-cmds.h (trace_commands): Likewise. * cli/cli-decode.c (add_setshow_boolean_cmd): Change int* argument to bool*. * cli/cli-logging.c (logging_overwrite): Change to bool. (logging_redirect): Likewise. (debug_redirect): Likewise. * cli/cli-option.h (option_def) <boolean>: Change return type to bool*. (struct boolean_option_def) <get_var_address_cb_>: Change return type to bool. <boolean_option_def>: Update. (struct flag_option_def): Change default type of Context to bool from int. <flag_option_def>: Change return type of var_address_cb_ to bool*. * cli/cli-setshow.c (do_set_command): Cast to bool* instead of int*. (get_setshow_command_value_string): Likewise. * cli/cli-style.c (cli_styling): Change to bool. (source_styling): Likewise. * cli/cli-style.h (source_styling): Likewise. (cli_styling): Likewise. * cli/cli-utils.h (struct qcs_flags) <quiet, cont, silent>: Change to bool. * command.h (var_types): Update comment. (add_setshow_boolean_cmd): Change int* var argument to bool*. * compile/compile-cplus-types.c (debug_compile_cplus_types): Change to bool. (debug_compile_cplus_scopes): Likewise. * compile/compile-internal.h (compile_debug): Likewise. * compile/compile.c (compile_debug): Likewise. (struct compile_options) <raw>: Likewise. * cp-support.c (catch_demangler_crashes): Likewise. * cris-tdep.c (usr_cmd_cris_version_valid): Likewise. (usr_cmd_cris_dwarf2_cfi): Likewise. * csky-tdep.c (csky_debug): Likewise. * darwin-nat.c (enable_mach_exceptions): Likewise. * dcache.c (dcache_enabled_p): Likewise. * defs.h (info_verbose): Likewise. * demangle.c (demangle): Likewise. (asm_demangle): Likewise. * dwarf-index-cache.c (debug_index_cache): Likewise. * dwarf2-frame.c (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2read.c (check_physname): Likewise. (use_deprecated_index_sections): Likewise. (dwarf_always_disassemble): Likewise. * eval.c (overload_resolution): Likewise. * event-top.c (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * event-top.h (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * exec.c (write_files): Likewise. * fbsd-nat.c (debug_fbsd_lwp): Likewise (debug_fbsd_nat): Likewise. * frame.h (struct frame_print_options) <print_raw_frame_arguments>: Likewise. (struct set_backtrace_options) <backtrace_past_main>: Likewise. <backtrace_past_entry> Likewise. * gdb-demangle.h (demangle): Likewise. (asm_demangle): Likewise. * gdb_bfd.c (bfd_sharing): Likewise. * gdbcore.h (write_files): Likewise. * gdbsupport/common-debug.c (show_debug_regs): Likewise. * gdbsupport/common-debug.h (show_debug_regs): Likewise. * gdbthread.h (print_thread_events): Likewise. * gdbtypes.c (opaque_type_resolution): Likewise. (strict_type_checking): Likewise. * gnu-nat.c (gnu_debug_flag): Likewise. * guile/scm-auto-load.c (auto_load_guile_scripts): Likewise. * guile/scm-param.c (pascm_variable): Add boolval. (add_setshow_generic): Update. (pascm_param_value): Update. (pascm_set_param_value_x): Update. * hppa-tdep.c (hppa_debug): Change to bool.. * infcall.c (may_call_functions_p): Likewise. (coerce_float_to_double_p): Likewise. (unwind_on_signal_p): Likewise. (unwind_on_terminating_exception_p): Likewise. * infcmd.c (startup_with_shell): Likewise. * inferior.c (print_inferior_events): Likewise. * inferior.h (startup_with_shell): Likewise. (print_inferior_events): Likewise. * infrun.c (step_stop_if_no_debug): Likewise. (detach_fork): Likewise. (debug_displaced): Likewise. (disable_randomization): Likewise. (non_stop): Likewise. (non_stop_1): Likewise. (observer_mode): Likewise. (observer_mode_1): Likewise. (set_observer_mode): Update. (sched_multi): Change to bool. * infrun.h (debug_displaced): Likewise. (sched_multi): Likewise. (step_stop_if_no_debug): Likewise. (non_stop): Likewise. (disable_randomization): Likewise. * linux-tdep.c (use_coredump_filter): Likewise. (dump_excluded_mappings): Likewise. * linux-thread-db.c (auto_load_thread_db): Likewise. (check_thread_db_on_load): Likewise. * main.c (captured_main_1): Update. * maint-test-options.c (struct test_options_opts) <flag_opt, xx1_opt, xx2_opt, boolean_opt>: Change to bool. * maint-test-settings.c (maintenance_test_settings_boolean): Likewise. * maint.c (maintenance_profile_p): Likewise. (per_command_time): Likewise. (per_command_space): Likewise. (per_command_symtab): Likewise. * memattr.c (inaccessible_by_default): Likewise. * mi/mi-main.c (mi_async): Likewise. (mi_async_1): Likewise. * mips-tdep.c (mips64_transfers_32bit_regs_p): Likewise. * nat/fork-inferior.h (startup_with_shell): Likewise. * nat/linux-namespaces.c (debug_linux_namespaces): Likewise. * nat/linux-namespaces.h (debug_linux_namespaces): Likewise. * nios2-tdep.c (nios2_debug): Likewise. * or1k-tdep.c (or1k_debug): Likewise. * parse.c (parser_debug): Likewise. * parser-defs.h (parser_debug): Likewise. * printcmd.c (print_symbol_filename): Likewise. * proc-api.c (procfs_trace): Likewise. * python/py-auto-load.c (auto_load_python_scripts): Likewise. * python/py-param.c (union parmpy_variable): Add "bool boolval" field. (set_parameter_value): Update. (add_setshow_generic): Update. * python/py-value.c (copy_py_bool_obj): Change argument from int* to bool*. * python/python.c (gdbpy_parameter_value): Cast to bool* instead of int*. * ravenscar-thread.c (ravenscar_task_support): Change to bool. * record-btrace.c (record_btrace_target::store_registers): Update. * record-full.c (record_full_memory_query): Change to bool. (record_full_stop_at_limit): Likewise. * record-full.h (record_full_memory_query): Likewise. * remote-notif.c (notif_debug): Likewise. * remote-notif.h (notif_debug): Likewise. * remote.c (use_range_stepping): Likewise. (interrupt_on_connect): Likewise. (remote_break): Likewise. * ser-tcp.c (tcp_auto_retry): Likewise. * ser-unix.c (serial_hwflow): Likewise. * skip.c (debug_skip): Likewise. * solib-aix.c (solib_aix_debug): Likewise. * spu-tdep.c (spu_stop_on_load_p): Likewise. (spu_auto_flush_cache_p): Likewise. * stack.c (struct backtrace_cmd_options) <full, no_filters, hide>: Likewise. (struct info_print_options) <quiet>: Likewise. * symfile-debug.c (debug_symfile): Likewise. * symfile.c (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symfile.h (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symtab.c (basenames_may_differ): Likewise. (struct filename_partial_match_opts) <dirname, basename>: Likewise. (struct info_print_options) <quiet, exclude_minsyms>: Likewise. (struct info_types_options) <quiet>: Likewise. * symtab.h (demangle): Likewise. (basenames_may_differ): Likewise. * target-dcache.c (stack_cache_enabled_1): Likewise. (code_cache_enabled_1): Likewise. * target.c (trust_readonly): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. (auto_connect_native_target): Likewise. (target_stop_and_wait): Update. (target_async_permitted): Change to bool. (target_async_permitted_1): Likewise. (may_write_registers_1): Likewise. (may_write_memory_1): Likewise. (may_insert_breakpoints_1): Likewise. (may_insert_tracepoints_1): Likewise. (may_insert_fast_tracepoints_1): Likewise. (may_stop_1): Likewise. * target.h (target_async_permitted): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. * thread.c (struct info_threads_opts) <show_global_ids>: Likewise. (make_thread_apply_all_options_def_group): Change argument from int* to bool*. (thread_apply_all_command): Update. (print_thread_events): Change to bool. * top.c (confirm): Likewise. (command_editing_p): Likewise. (history_expansion_p): Likewise. (write_history_p): Likewise. (info_verbose): Likewise. * top.h (confirm): Likewise. (history_expansion_p): Likewise. * tracepoint.c (disconnected_tracing): Likewise. (circular_trace_buffer): Likewise. * typeprint.c (print_methods): Likewise. (print_typedefs): Likewise. * utils.c (debug_timestamp): Likewise. (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * utils.h (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * valops.c (overload_resolution): Likewise. * valprint.h (struct value_print_options) <prettyformat_arrays, prettyformat_structs, vtblprint, unionprint, addressprint, objectprint, stop_print_at_null, print_array_indexes, deref_ref, static_field_print, pascal_static_field_print, raw, summary, symbol_print, finish_print>: Likewise. * windows-nat.c (new_console): Likewise. (cygwin_exceptions): Likewise. (new_group): Likewise. (debug_exec): Likewise. (debug_events): Likewise. (debug_memory): Likewise. (debug_exceptions): Likewise. (useshell): Likewise. * windows-tdep.c (maint_display_all_tib): Likewise. * xml-support.c (debug_xml): Likewise.
2019-09-11Change the type of copy_names from int to boolChristian Biesinger1-2/+2
This parameter is really a boolean, so change the type accordingly and update the callers. This is for symbol_set_names, add_psymbol_to_bcache, and add_psymbol_to_list. minimal_symbol_reader::record_full was already passing a bool to symbol_set_names. gdb/ChangeLog: 2019-09-11 Christian Biesinger <cbiesinger@google.com> * dbxread.c (read_dbx_symtab): Update. * dwarf2read.c (load_partial_dies): Update. * mdebugread.c (parse_partial_symbols): Update. (handle_psymbol_enumerators): Update. * psympriv.h (add_psymbol_to_list): Change type of copy_names to bool. * psymtab.c (add_psymbol_to_bcache): Likewise. (add_psymbol_to_list): Likewise. * symtab.c (symbol_set_names): Likewise. * symtab.h (symbol_set_names): Likewise. * xcoffread.c (scan_xcoff_symtab): Update.
2019-09-10Add Ada support for .debug_namesTom Tromey1-125/+158
This patch adds support for Ada to .debug_names. I opted to leave .gdb_index alone, because in my view it is a defunct format. gdb/ChangeLog 2019-09-10 Tom Tromey <tromey@adacore.com> * dwarf-index-write.c (write_psymbols): Extend error message. (debug_names::insert): Add Ada code. (debug_names::write_psymbols): Remove Ada check. (debug_names) <m_string_obstack>: New member. * dwarf2read.c (gdb_index_symbol_name_matcher): Remove. (gdb_index_symbol_name_matcher::matches): Remove. (mapped_index_base::find_name_components_bounds): Add "lang" parameter. (mapped_index_base::build_name_components): Also split names according to Ada syntax. (dw2_expand_symtabs_matching_symbol): Loop over languages. Change type of "match_callback". (check_match, check_find_bounds_finds) (dw2_expand_symtabs_matching): Update. (dw2_debug_names_iterator): Add new constructor. (dw2_debug_names_map_matching_symbols): New function. (dw2_debug_names_expand_symtabs_matching): Update. (dwarf2_debug_names_functions): Use dw2_debug_names_map_matching_symbols.
2019-09-10Fix latent bug in .debug_names file-name handlingTom Tromey1-3/+9
An internal Ada test case showed that the .debug_names code does not compute the same list of file names as the partial symbol reader. In particular, the partial symbol reader uses the DW_AT_name of the CU: /* Allocate a new partial symbol table structure. */ filename = dwarf2_string_attr (comp_unit_die, DW_AT_name, cu); if (filename == NULL) filename = ""; pst = create_partial_symtab (per_cu, filename); This patch changes the .debug_names reader to follow. gdb/ChangeLog 2019-09-10 Tom Tromey <tromey@adacore.com> * dwarf2read.c (dw2_get_file_names_reader): Add the CU's file name to the results. gdb/testsuite/ChangeLog 2019-09-10 Tom Tromey <tromey@adacore.com> * gdb.ada/dgopt.exp: New file. * gdb.ada/dgopt/x.adb: New file.
2019-09-10Change map_matching_symbols to take a lookup_name_infoTom Tromey1-2/+1
This patch further simplifies the map_matching_symbols callback, by having it take a lookup_name_info rather than a plain string. gdb/ChangeLog 2019-09-10 Tom Tromey <tromey@adacore.com> * ada-lang.c (add_nonlocal_symbols): Combine calls to map_matching_symbols. Update. * dwarf2read.c (dw2_map_matching_symbols): Update. * psymtab.c (match_partial_symbol): Change type; update. (psym_map_matching_symbols): Likewise. * symfile-debug.c (debug_qf_map_matching_symbols): Change type; update. * symfile.h (struct quick_symbol_functions) <map_matching_symbols>: Change "name" to be a lookup_name_info. Remove "match".
2019-09-10Change map_matching_symbols to take a symbol_found_callback_ftypeTom Tromey1-7/+7
This changes map_matching_symbols to take a symbol_found_callback_ftype, rather than separate callback and data parameters. This enables a future patch to clean up some existing code so that it can more readily be shared. gdb/ChangeLog 2019-09-10 Tom Tromey <tromey@adacore.com> * ada-lang.c (aux_add_nonlocal_symbols): Change type. (add_nonlocal_symbols): Update. * dwarf2read.c (dw2_map_matching_symbols): Change type. * psymtab.c (map_block, psym_map_matching_symbols): Change type. * symfile-debug.c (debug_qf_map_matching_symbols): Change type. * symfile.h (struct quick_symbol_functions) <map_matching_symbols>: Change type of "callback". Remove "data".
2019-09-09DWARF 5 support: Handle dwo_idAli Tamur1-25/+94
* DW_UT_skeleton and DW_UT_split_compile compilation units have dwo ids to match the compilation unit in the skeleton and .dwo files. The dwo_id is in the header. Tested with CC=/usr/bin/gcc (version 8.3.0) against master branch (also with -gsplit-dwarf and -gdwarf-4 flags) and there was no increase in the set of tests that fails. This is part of an effort to support DWARF 5 in gdb. gdb/ChangeLog: * dwarf2read.c (comp_unit_head): Update comment. (dwarf2_dwo_name): New function declaration. (dwarf_unit_type_name): New function declaration. (read_comp_unit_head): Add support for new compilation units, DW_UT_partial, DW_UT_skeleton, DW_UT_split_compile, DW_UT_split_type. Particularly, DW_UT_skeleton and DW_UT_split_compile have dwo_id (currently named as "signature") in their header. Also clarify error messages. (lookup_dwo_id): New function. Returns the dwo id of the given compile unit. (lookup_dwo_unit): Use the new lookup_dwo_id function. (init_cutu_and_read_dies): Use the new dwarf2_dwo_name and lookup_dwo_id functions. (create_dwo_cu_reader): Use the added lookup_dwo_id function. (dwarf2_dwo_name): Get the dwo name if present. (dwarf_unit_type_name): Convert DW_UT_* types to string for diagnostic purposes.
2019-09-07Change lookup_symbol's block_index parameter type to block_enumSimon Marchi1-5/+4
The only two values valid to pass to the block_index parameter of quick_symbol_functions::lookup_symbol are GLOBAL_BLOCK and STATIC_BLOCK, part of enum block_enum. Change the type of that parameter to block_enum. Change also the block_index field of dw2_symtab_iterator in the same way.. This makes it consistent with dw2_debug_names_iterator, which already uses block_enum for its block_index field. This is a follow-up to this thread: https://sourceware.org/ml/gdb-patches/2019-08/msg00097.html gdb/ChangeLog: * dwarf2read.c (struct dw2_symtab_iterator) <block_index>: Change type to gdb::optional<block_enum>. (dw2_symtab_iter_init): Change block_index parameter type to gdb::optional<block_enum>. (dw2_lookup_symbol): Change block_index parameter type to block_enum.c (dw2_debug_names_lookup_symbol): Likewise. * psymtab.c (psym_lookup_symbol): Likewise. * symfile-debug.c (debug_qf_lookup_symbol): Likewise. * symfile.h (struct quick_symbol_functions) <lookup_symbol>: Likewise.
2019-09-03Handle biased typesTom Tromey1-1/+6
In Ada, the programmer can request that a range type with a non-zero base be stored in the minimal number of bits required for the range. This is done by biasing the values; so, for example, a range of -7..-4 may be stored as two bits with a bias of -7. This patch implements this for gdb. It is done by adding a bias to struct range_bounds and then adjusting a few spots to handle this. The test case is written to use -fgnat-encodings=minimal, but a future compiler patch will change the compiler to emit DW_AT_GNU_bias with -fgnat-encodings=gdb. It seemed good to get the gdb patch in first. Tested on x86-64 Fedora 29; plus a variety of targets using AdaCore's internal test suite. gdb/ChangeLog 2019-09-03 Tom Tromey <tromey@adacore.com> * ada-valprint.c (ada_val_print_num): Don't recurse for range types. (has_negatives): Unbias a range type bound. * dwarf2read.c (read_subrange_type): Handle DW_AT_GNU_bias. * gdbtypes.c (operator==): Handle new field. (create_range_type): Add "bias" parameter. (create_static_range_type, resolve_dynamic_range): Update. * gdbtypes.h (struct range_bounds) <bias>: New member. (create_range_type): Add bias parameter. * printcmd.c (print_scalar_formatted): Unbias range types. * value.c (unpack_long): Unbias range types. (pack_long): Bias range types. gdb/testsuite/ChangeLog 2019-09-03 Tom Tromey <tromey@adacore.com> * gdb.ada/bias.exp: New file. * gdb.ada/bias/bias.adb: New file. * gdb.ada/print_chars.exp: Add regression test. * gdb.ada/print_chars/foo.adb (My_Character): New type. (MC): New variable.
2019-08-25dwarf2read: fix compilation issue with gcc 4.8Simon Marchi1-5/+6
gcc 4.8 (and probably other versions too) doesn't like that the local variable symbol_linkage has the same name as the enum class defined in the same context: CXX dwarf2read.o /home/smarchi/src/binutils-gdb/gdb/dwarf2read.c: In member function ‘dwarf2_per_cu_data* dw2_debug_names_iterator::next()’: /home/smarchi/src/binutils-gdb/gdb/dwarf2read.c:5850:22: error: ‘symbol_linkage’ is not a class, namespace, or enumeration } symbol_linkage = symbol_linkage::unknown; ^ Rename the local variable to avoid this. This problem was originally reported with the Netbsd builder on the buildbot, which uses gcc 5.5, I believe. I am not able to test it on that builder right now, but chances are that the fix will work there too. gdb/ChangeLog: * dwarf2read.c (dw2_debug_names_iterator::next): Rename local variable symbol_linkage to symbol_linkage_.
2019-08-25dwarf2read: replace gdb::optional<bool> with enumSimon Marchi1-5/+10
gdb::optional<bool> is dangerous, because it's easy to do: if (opt_bool) when you actually meant if (*opt_bool) or vice-versa. The first checks if the optional is set, the second checks if the wrapped bool is true. Replace it with an enum that explicitly defines the three possible states. gdb/ChangeLog: * dwarf2read.c (dw2_debug_names_iterator::next): Use enum to represent whether the symbol is static, dynamic, or we don't know.
2019-08-09[gdb] Fix gdb.dwarf2/varval.exp with -fPIE/-pieTom de Vries1-2/+8
With target board unix/-fPIE/-pie, we get: ... FAIL: gdb.dwarf2/varval.exp: print varval2 ... This is due comparing a get_frame_pc result (which includes the for PIE non-zero relocation offset) with pc_high and pc_low obtained using get_scope_pc_bounds (which do not include the relocation offset). Fix this by adjusting pc_high and pc_low with the relocation offset. Tested on x86_64-linux with target board unix/-fPIE/-pie. gdb/ChangeLog: 2019-08-09 Tom de Vries <tdevries@suse.de> PR gdb/24591 * dwarf2read.c (dwarf2_fetch_die_loc_sect_off): Adjust pc_high and pc_low with relocation offset.
2019-08-06Introduce obstack_strndupTom Tromey1-4/+4
This introduces obstack_strndup and changes gdb to use it. Note that obstack_strndup works like savestring, and not exactly like xstrndup. The difference is that obstack_strndup uses the passed-in length, while xstrndup uses strnlen to choose the length. gdb/ChangeLog 2019-08-06 Tom Tromey <tom@tromey.com> * stabsread.c (patch_block_stabs, read_one_struct_field) (read_enum_type): Use obstack_strndup. * rust-exp.y (rust_parser::copy_name): Use obstack_strndup. * gdb_obstack.h (obstack_strndup): Use obstack_strndup. * dwarf2read.c (guess_full_die_structure_name) (anonymous_struct_prefix): Use obstack_strndup. * dbxread.c (cp_set_block_scope): Use obstack_strndup. * c-exp.y (yylex): Use obstack_strndup. * ada-exp.y (write_object_renaming, write_ambiguous_var) (write_var_or_type): Use obstack_strndup.
2019-08-06Add obstack_strdup overload taking a std::stringTom Tromey1-17/+8
This adds an obstack_strdup overload that takes a std::string, and changes a few spots in gdb to use it. gdb/ChangeLog 2019-08-06 Tom Tromey <tom@tromey.com> * symfile.c (reread_symbols): Use obstack_strdup. * stabsread.c (read_type): Use obstack_strdup. * gdb_obstack.h (obstack_strdup): New overload. * dwarf2read.c (dwarf2_compute_name, create_dwo_unit_in_dwp_v1) (create_dwo_unit_in_dwp_v2, build_error_marker_type) (dwarf2_canonicalize_name): Use obstack_strdup. * dbxread.c (read_dbx_symtab): Use obstack_strdup. * cp-support.c (inspect_type, replace_typedefs_qualified_name): Use obstack_strdup.
2019-08-06Use obstack_strdup moreTom Tromey1-17/+7
This changes gdb to use obstack_strdup when appropriate, rather than the wordier obstack_copy0. gdb/ChangeLog 2019-08-06 Tom Tromey <tom@tromey.com> * xcoffread.c (SYMNAME_ALLOC, process_xcoff_symbol): Use obstack_strdup. * typeprint.c (typedef_hash_table::find_global_typedef): Use obstack_strdup. * symfile.c (allocate_compunit_symtab): Use obstack_strdup. * stabsread.c (common_block_start): Use obstack_strdup. * objfiles.c (set_objfile_main_name, objfile): Use obstack_strdup. * namespace.c (add_using_directive): Use obstack_strdup. * mdebugread.c (parse_symbol, parse_type): Use obstack_strdup. * jit.c (finalize_symtab): Use obstack_strdup. * dwarf2read.c (fixup_go_packaging, dwarf2_physname) (guess_partial_die_structure_name, partial_die_info::fixup) (dwarf2_name): Use obstack_strdup. * coffread.c (coff_read_struct_type, coff_read_enum_type): Use obstack_strdup. * c-exp.y (scan_macro_expansion): Use obstack_strdup. * buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use obstack_strdup. * ada-lang.c (ada_decode_symbol): Use obstack_strdup.
2019-08-07Make first and last lines of 'command help documentation' consistent.Philippe Waroquiers1-3/+3
With this patch, the help docs now respect 2 invariants: * The first line of a command help is terminated by a '.' character. * The last character of a command help is not a newline character. Note that the changes for the last invariant were done by Tom, as part of : [PATCH] Remove trailing newlines from help text https://sourceware.org/ml/gdb-patches/2019-06/msg00050.html but some occurrences have been re-introduced since then. Some help docs had to be rephrased/restructured to respect the above invariants. Before this patch, print_doc_line was printing the first line of a command help documentation, but stopping at the first '.' or ',' character. This was giving inconsistent results : * The first line of command helps was sometimes '.' terminated, sometimes not. * The first line of command helps was not always designed to be readable/understandable/unambiguous when stopping at the first '.' or ',' character. This e.g. created the following inconsistencies/problems: < catch exception -- Catch Ada exceptions < catch handlers -- Catch Ada exceptions < catch syscall -- Catch system calls by their names < down-silently -- Same as the `down' command while the new help is: > catch exception -- Catch Ada exceptions, when raised. > catch handlers -- Catch Ada exceptions, when handled. > catch syscall -- Catch system calls by their names, groups and/or numbers. > down-silently -- Same as the `down' command, but does not print anything. Also, the command help doc should not be terminated by a newline character, but this was not respected by all commands. The cli-option -OPT framework re-introduced some occurences. So, the -OPT build help framework was changed to not output newlines at the end of %OPTIONS% replacement. This patch changes the help documentations to ensure the 2 invariants given above. It implied to slightly rephrase or restructure some help docs. Based on the above invariants, print_doc_line (called by 'apropos' and 'help' commands to print the first line of a command help) now outputs the full first line of a command help. This all results in a lot of small changes in the produced help docs. There are less code changes than changes in the help docs, as a lot of docs are produced by some code (e.g. the remote packet usage settings). gdb/ChangeLog 2019-08-07 Philippe Waroquiers <philippe.waroquiers@skynet.be> * cli/cli-decode.h (print_doc_line): Add for_value_prefix argument. * cli/cli-decode.c (print_doc_line): Likewise. It now prints the full first line, except when FOR_VALUE_PREFIX. In this case, the trailing '.' is not output, and the first character is uppercased. (print_help_for_command): Update call to print_doc_line. (print_doc_of_command): Likewise. * cli/cli-setshow.c (deprecated_show_value_hack): Likewise. * cli/cli-option.c (append_indented_doc): Do not append newline. (build_help_option): Append newline after first appended_indented_doc only if a second call is done. (build_help): Append 2 new lines before each option, except the first one. * compile/compile.c (_initialize_compile): Add new lines after %OPTIONS%, when not at the end of the help. Change help doc or code producing the help doc to respect the invariants. * maint-test-options.c (_initialize_maint_test_options): Likewise. Also removed the new line after 'Options:', as all other commands do not put an empty line between 'Options:' and the first option. * printcmd.c (_initialize_printcmd): Likewise. * stack.c (_initialize_stack): Likewise. * interps.c (interpreter_exec_cmd): Fix "Usage:" line that was incorrectly telling COMMAND is optional. * ada-lang.c (_initialize_ada_language): Change help doc or code producing the help doc to respect the invariants. * ada-tasks.c (_initialize_ada_tasks): Likewise. * breakpoint.c (_initialize_breakpoint): Likewise. * cli/cli-cmds.c (_initialize_cli_cmds): Likewise. * cli/cli-logging.c (_initialize_cli_logging): Likewise. * cli/cli-setshow.c (_initialize_cli_setshow): Likewise. * cli/cli-style.c (cli_style_option::add_setshow_commands, _initialize_cli_style): Likewise. * corelow.c (core_target_info): Likewise. * dwarf-index-cache.c (_initialize_index_cache): Likewise. * dwarf2read.c (_initialize_dwarf2_read): Likewise. * filesystem.c (_initialize_filesystem): Likewise. * frame.c (_initialize_frame): Likewise. * gnu-nat.c (add_task_commands): Likewise. * infcall.c (_initialize_infcall): Likewise. * infcmd.c (_initialize_infcmd): Likewise. * interps.c (_initialize_interpreter): Likewise. * language.c (_initialize_language): Likewise. * linux-fork.c (_initialize_linux_fork): Likewise. * maint-test-settings.c (_initialize_maint_test_settings): Likewise. * maint.c (_initialize_maint_cmds): Likewise. * memattr.c (_initialize_mem): Likewise. * printcmd.c (_initialize_printcmd): Likewise. * python/lib/gdb/function/strfns.py (_MemEq, _StrLen, _StrEq, _RegEx): Likewise. * ravenscar-thread.c (_initialize_ravenscar): Likewise. * record-btrace.c (_initialize_record_btrace): Likewise. * record-full.c (_initialize_record_full): Likewise. * record.c (_initialize_record): Likewise. * regcache-dump.c (_initialize_regcache_dump): Likewise. * regcache.c (_initialize_regcache): Likewise. * remote.c (add_packet_config_cmd, init_remote_threadtests, _initialize_remote): Likewise. * ser-tcp.c (_initialize_ser_tcp): Likewise. * serial.c (_initialize_serial): Likewise. * skip.c (_initialize_step_skip): Likewise. * source.c (_initialize_source): Likewise. * stack.c (_initialize_stack): Likewise. * symfile.c (_initialize_symfile): Likewise. * symtab.c (_initialize_symtab): Likewise. * target-descriptions.c (_initialize_target_descriptions): Likewise. * top.c (init_main): Likewise. * tracefile-tfile.c (tfile_target_info): Likewise. * tracepoint.c (_initialize_tracepoint): Likewise. * tui/tui-win.c (_initialize_tui_win): Likewise. * utils.c (add_internal_problem_command): Likewise. * valprint.c (value_print_option_defs): Likewise. gdb/testsuite/ChangeLog 2019-08-07 Philippe Waroquiers <philippe.waroquiers@skynet.be> * gdb.base/style.exp: Update tests for help doc new invariants. * gdb.base/help.exp: Likewise.
2019-08-04Remove some variables in favor of using gdb::optionalSimon Marchi1-47/+30
While reading that code, I noticed that some variables essentially meant whether to consider some other variable or not. I think using gdb::optional (which was not available when this code was written) is clearer, as it embeds the used/not used predicate directly in the type of the variable, making it harder to miss. gdb/ChangeLog: * dwarf2read.c (struct dw2_symtab_iterator): <want_specific_block>: Remove. <block_index>: Change type to gdb::optional. (dw2_symtab_iter_init): Remove WANT_SPECIFIC_BLOCK parameter, change type of BLOCK_INDEX parameter to gdb::optional. (dw2_symtab_iter_next): Re-write in function of gdb::optional. (dw2_lookup_symbol): Don't pass argument for WANT_SPECIFIC_BLOCK. (dw2_expand_symtabs_for_function): Don't pass argument for WANT_SPECIFIC_BLOCK, pass empty optional for BLOCK_INDEX. (class dw2_debug_names_iterator) <dw2_debug_names_iterator>: Remove WANT_SPECIFIC_BLOCK parameter, change BLOCK_INDEX type to gdb::optional. <m_want_specific_block>: Remove. <m_block_index>: Change type to gdb::optional. (dw2_debug_names_iterator::next): Change type of IS_STATIC to gdb::optional. Re-write in function of gdb::optional. (dw2_debug_names_lookup_symbol): Don't pass argument for WANT_SPECIFIC_BLOCK. (dw2_debug_names_expand_symtabs_for_function): Don't pass argument for WANT_SPECIFIC_BLOCK, pass empty optional for BLOCK_INDEX.
2019-07-12gdb: Carry default property type around with dynamic propertiesAndrew Burgess1-38/+82
This commit is preparation for the next one, with the aim of better supporting signed dynamic properties on targets where the address size specified in the DWARF headers is smaller than a CORE_ADDR, for example debugging an i386 application on x86-64. Consider this small Fortran program 'bounds.f90': program test integer, allocatable :: array (:) allocate (array (-5:5)) array(3) = 1 end program test Compiled with 'gfortran -m32 -g3 -O0 -o bounds bounds.f90'. The DWARF for 'array' looks like this: <2><97>: Abbrev Number: 10 (DW_TAG_variable) <98> DW_AT_name : (indirect string, offset: 0x0): array <9c> DW_AT_decl_file : 1 <9d> DW_AT_decl_line : 2 <9e> DW_AT_type : <0xaf> <a2> DW_AT_location : 2 byte block: 91 58 (DW_OP_fbreg: -40) <2><a5>: Abbrev Number: 11 (DW_TAG_lexical_block) <a6> DW_AT_low_pc : 0x80485c3 <aa> DW_AT_high_pc : 0x8b <2><ae>: Abbrev Number: 0 <1><af>: Abbrev Number: 12 (DW_TAG_array_type) <b0> DW_AT_data_location: 2 byte block: 97 6 (DW_OP_push_object_address; DW_OP_deref) <b3> DW_AT_allocated : 4 byte block: 97 6 30 2e (DW_OP_push_object_address; DW_OP_deref; DW_OP_lit0; DW_OP_ne) <b8> DW_AT_type : <0x2a> <2><bc>: Abbrev Number: 13 (DW_TAG_subrange_type) <bd> DW_AT_lower_bound : 4 byte block: 97 23 10 6 (DW_OP_push_object_address; DW_OP_plus_uconst: 16; DW_OP_deref) <c2> DW_AT_upper_bound : 4 byte block: 97 23 14 6 (DW_OP_push_object_address; DW_OP_plus_uconst: 20; DW_OP_deref) <c7> DW_AT_byte_stride : 6 byte block: 97 23 c 6 34 1e (DW_OP_push_object_address; DW_OP_plus_uconst: 12; DW_OP_deref; DW_OP_lit4; DW_OP_mul) <2><ce>: Abbrev Number: 0 If we look at the DW_AT_lower_bound attribute, which will become a dynamic property that GDB evaluates when needed by calling dwarf2_evaluate_property. The process of evaluating a dynamic property requires GDB to execute each DW_OP_* operation, the results of these operations is held on a stack of 'struct value *'s. When the entire expression is evaluated the result is on top of the stack. If we look at DW_AT_lower_bound then the last operation is DW_OP_deref, this loads a signed address the size of which matches the DWARF address size, and so in our i386 on x86-64 situation, the top of the stack will be a signed 4-byte value. The problem is how these values are fetched from the stack. Currently they are always fetched by a call to dwarf_expr_context::fetch_address, which converts the value to an unsigned value with a length matching the values current length, before converting to a CORE_ADDR. This means we loose the signed nature of the property. I wonder if the best solution for dealing with signed properties will be to move away from an over reliance on fetch_address, and instead come up with a new solution that considers the current type of the value on the stack, and the type that the value needs to become; basically a solution built around casting rather than assuming we always want an address. However, before we can start to even think about moving away from fetch_address, there is a more urgent issue to fix, which is we don't currently know what type each property should be. We just hold the value of the property in a CORE_ADDR as returned by fetch_address, and rely on higher level code (outside of the DWARF expression evaluation code) to fix things up for us. This is what this patch aims to address. When creating a dynamic property (see attr_to_dynamic_prop in dwarf2read.c) we can sometimes figure out the type of a property; if the property is a reference to another DIE then it will have a DW_AT_type attribute. However, the DW_AT_lower_bound case above isn't a reference to another DIE, it's just a DWARF expression. We don't have any indication for what type the property should have. Luckily, the DWARF spec helps us out, for the lower and upper bounds 5.13 of the DWARFv5 spec tells us that without any other type information the bounds are signed integers the same size as a DWARF address. It is my belief that we can find a suitable default type for every dynamic property, either specified explicitly in the DWARF spec, or we can infer an obvious choice if the spec doesn't help us. This commit extends the creation of all dynamic properties to include suggesting a suitable default type, all dynamic properties now always carry their type around with them. In later commits we can use this property type to ensure that the value we extract from the DWARF stack is handled in a suitable manor to correctly maintain its sign extension. There should be no user visible changes from this commit. The actual fix to correctly support negative array bounds will come later. gdb/ChangeLog: * dwarf2loc.c (dwarf2_evaluate_property): Update to take account of changes to field names, and use new is_reference field to decide if a property is a reference or not. * dwarf2loc.h (struct dwarf2_locexpr_baton): Add 'is_reference' field. (struct dwarf2_property_baton): Update header comment, rename 'referenced_type' to 'property_type' and update comments. * dwarf2read.c (attr_to_dynamic_prop): Add extra parameter to hold default property type, store in property baton, update to take accound of renamed field. (read_func_scope): Update call to attr_to_dynamic_prop. (read_array_type): Likewise. (dwarf2_per_cu_addr_sized_int_type): New function. (read_subrange_index_type): Move type finding code to dwarf2_per_cu_addr_sized_int_type. (read_subrange_type): Update calls to attr_to_dynamic_prop. (dwarf2_per_cu_addr_type): New function. (set_die_type): Update calls to attr_to_dynamic_prop.
2019-07-12gdb/dwarf: Ensure the target type of ranges is not voidAndrew Burgess1-40/+52
If a DW_TAG_subrange_type DWARF entry has no DW_AT_type then a default type based on the size of an address on the current target is assumed. We store this type as the target type for GDB's range types. Currently GDB can create ranges for which the target type is VOID, this is incorrect but seems to cause no problems. I believe the reason this doesn't cause any issues is because the languages (for example Ada) that actually make use of a ranges target type also have compilers that generate DWARF that includes a DW_AT_type attribute. However, gfortran does not include a DW_AT_type, its DWARF instead relies on the default target type. This isn't currently a problem for GDB as gfortran doesn't make use of the target type when printing subranges, but it shouldn't hurt to fix this issue now. I've added an assert into create_range_type that will catch this issue if it comes up again. This was tested on an x86-64/GNU-Linux machine with both the Ada and gfortran compilers available with both '--target_board=unix' and '--target_board=unix/-m32'. There are no user visible changes after this commit. gdb/ChangeLog: * dwarf2read.c (read_subrange_index_type): New function. (read_subrange_type): Move code into new function and call it. * gdbtypes.c (create_range_type): Add some asserts.
2019-07-09Rename common to gdbsupportTom Tromey1-10/+10
This is the next patch in the ongoing series to move gdbsever to the top level. This patch just renames the "common" directory. The idea is to do this move in two parts: first rename the directory (this patch), then move the directory to the top. This approach makes the patches a bit more tractable. I chose the name "gdbsupport" for the directory. However, as this patch was largely written by sed, we could pick a new name without too much difficulty. Tested by the buildbot. gdb/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * contrib/ari/gdb_ari.sh: Change common to gdbsupport. * configure: Rebuild. * configure.ac: Change common to gdbsupport. * gdbsupport: Rename from common. * acinclude.m4: Change common to gdbsupport. * Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES) (HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to gdbsupport. * aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c, amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c, amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c, amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c, amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c, arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c, arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c, arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c, arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c, auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h, btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c, charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c, cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c, coff-pe-read.c, command.h, compile/compile-c-support.c, compile/compile-c.h, compile/compile-cplus-symbols.c, compile/compile-cplus-types.c, compile/compile-cplus.h, compile/compile-loc2c.c, compile/compile.c, completer.c, completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c, cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c, darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c, disasm.h, dtrace-probe.c, dwarf-index-cache.c, dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c, dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c, event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c, features/aarch64-core.c, features/aarch64-fpu.c, features/aarch64-pauth.c, features/aarch64-sve.c, features/i386/32bit-avx.c, features/i386/32bit-avx512.c, features/i386/32bit-core.c, features/i386/32bit-linux.c, features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c, features/i386/32bit-segments.c, features/i386/32bit-sse.c, features/i386/64bit-avx.c, features/i386/64bit-avx512.c, features/i386/64bit-core.c, features/i386/64bit-linux.c, features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c, features/i386/64bit-segments.c, features/i386/64bit-sse.c, features/i386/x32-core.c, features/riscv/32bit-cpu.c, features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c, features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c, features/riscv/64bit-fpu.c, features/tic6x-c6xp.c, features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h, findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h, gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c, gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c, go32-nat.c, guile/guile.c, guile/scm-ports.c, guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c, i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c, i386-linux-tdep.c, i386-tdep.c, i387-tdep.c, ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c, inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h, inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h, inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c, linux-tdep.c, linux-thread-db.c, location.c, machoread.c, macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h, mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h, minsyms.c, mips-linux-tdep.c, namespace.h, nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h, nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c, nat/amd64-linux-siginfo.c, nat/fork-inferior.c, nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c, nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c, nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h, nat/linux-waitpid.c, nat/mips-linux-watch.c, nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c, nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c, nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h, obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c, parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c, procfs.c, producer.c, progspace.h, psymtab.h, python/py-framefilter.c, python/py-inferior.c, python/py-ref.h, python/py-type.c, python/python.c, record-btrace.c, record-full.c, record.c, record.h, regcache-dump.c, regcache.c, regcache.h, remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c, riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c, selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c, ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c, source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c, stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h, symtab.c, symtab.h, target-descriptions.c, target-descriptions.h, target-memory.c, target.c, target.h, target/waitstatus.c, target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c, top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c, tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h, unittests/array-view-selftests.c, unittests/child-path-selftests.c, unittests/cli-utils-selftests.c, unittests/common-utils-selftests.c, unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c, unittests/format_pieces-selftests.c, unittests/function-view-selftests.c, unittests/lookup_name_info-selftests.c, unittests/memory-map-selftests.c, unittests/memrange-selftests.c, unittests/mkdir-recursive-selftests.c, unittests/observable-selftests.c, unittests/offset-type-selftests.c, unittests/optional-selftests.c, unittests/parse-connection-spec-selftests.c, unittests/ptid-selftests.c, unittests/rsp-low-selftests.c, unittests/scoped_fd-selftests.c, unittests/scoped_mmap-selftests.c, unittests/scoped_restore-selftests.c, unittests/string_view-selftests.c, unittests/style-selftests.c, unittests/tracepoint-selftests.c, unittests/unpack-selftests.c, unittests/utils-selftests.c, unittests/xml-utils-selftests.c, utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c, value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c, xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c, xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport. gdb/gdbserver/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * configure: Rebuild. * configure.ac: Change common to gdbsupport. * acinclude.m4: Change common to gdbsupport. * Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS) (version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change common to gdbsupport. * ax.c, event-loop.c, fork-child.c, gdb_proc_service.h, gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c, inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c, linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c, linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c, linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h, nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c, server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h, thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change common to gdbsupport.
2019-07-01Avoid use-after-free in DWARF debug names codeTom Tromey1-6/+3
A static analyzer pointed out that find_vec_in_debug_names will use the contents of a unique_ptr after it has been destroyed. This patch fixes the bug by hoisting the declaration into the appropriate enclosing block. I'm checking this in as obvious. gdb/ChangeLog 2019-07-01 Tom Tromey <tromey@adacore.com> * dwarf2read.c (dw2_debug_names_iterator::find_vec_in_debug_names): Hoist declaration of without_params. Fix formatting.
2019-06-28Handle either order of name and linkage nameTom Tromey1-2/+8
We discovered that the Ada support in gdb depends on the order of the DW_AT_name and DW_AT_linkage_name attributes in the DWARF. In particular, if they are emitted in the "wrong" order for some system symbols, "catch exception" will not work. This patch fixes this problem by arranging to always prefer the linkage name if both exist. This seems to be what the full symbol reader already does -- that is, this is another bug arising from having two different DWARF readers. Another possible issue here is that gdb still doesn't really preserve mangled names properly. There's a PR open about this. However, this seems to be somewhat involved to fix, which is why this patch continues to work around the bigger issue. gdb/ChangeLog 2019-06-28 Tom Tromey <tromey@adacore.com> * dwarf2read.c (partial_die_info::read): Prefer the linkage name for Ada. gdb/testsuite/ChangeLog 2019-06-28 Tom Tromey <tromey@adacore.com> * gdb.dwarf2/ada-linkage-name.c: New file. * gdb.dwarf2/ada-linkage-name.exp: New file.
2019-06-22[gdb] Fix s390x -m31 buildTom de Vries1-18/+24
When building gdb on s390x with -m31, we run into this Wformat warning (which Werror turns into an error): ... gdb/dwarf2read.c: In function \ 'void create_addrmap_from_aranges(dwarf2_per_objfile*, \ dwarf2_section_info*)': gdb/dwarf2read.c:3277:22: error: format '%zu' expects argument of type \ 'size_t', but argument 3 has type 'int' [-Werror=format=] warning (_("Section .debug_aranges in %s entry at offset %zu " ... The Wformat warning is triggered in this statement: ... warning (_("Section .debug_aranges in %s entry at offset %zu " "length %s exceeds section length %s, " "ignoring .debug_aranges."), objfile_name (objfile), entry_addr - section->buffer, plongest (bytes_read + entry_length), pulongest (section->size)); ... where 'entry_addr - section->buffer' is of type ptrdiff_t and '%zu' prints an unsigned with the same size as size_t/ssize_t. On s390x with -m31, we have: - size_t : unsigned long int (32-bit) - ptrdiff_t: int (32-bit) Wformat warns against this because even though long int and int have the same size, the types are not compatible. [ The Wformat warning is to similar to what we would get for x86_64 -m32 (where long and int are also the same size) and: ... int i; printf ("%ld", i); ... ] Fix this by using '%s' and plongest instead of '%zu' to print ptrdiff_t. Build and reg-tested on x86_64. gdb/ChangeLog: 2019-06-22 Tom de Vries <tdevries@suse.de> * dwarf2read.c (create_addrmap_from_aranges) (read_debug_names_from_section): Print ptrdiff_t using '%s' and plongest instead of '%zu'.
2019-06-21dwarf2read: Get rid of VEC (dwarf2_section_info_def)Simon Marchi1-34/+12
This patch removes uses of VEC (dwarf2_section_info_def) in favor of std::vector<dwarf2_section_info>. The conversion is relatively straightforward, no function changes are intended. gdb/ChangeLog: * dwarf2read.h (dwarf2_section_info_def): Remove. (DEF_VEC_O (dwarf2_section_info_def)): Remove. * dwarf2read.c (struct dwo_sections) <types>: Change type to std::vector<dwarf2_section_info>. (struct dwo_file) <~dwo_file>: Remove. (dwarf2_per_objfile::~dwarf2_per_objfile): Don't manually free types field. (dwarf2_per_objfile::locate_sections): Adjust to std::vector. (dwarf2_read_debug_names): Likewise. (create_debug_types_hash_table): Change parameter type to array_view, adjust code accordingly. (dwarf2_locate_dwo_sections): Adjust to std::vector. (partial_die_info::fixup): Likewise. (determine_prefix): Likewise. * dwarf-index-write.c (write_psymtabs_to_index): Adjust.
2019-06-21dwarf2read: Make dwo_file::dbfd a gdb_bfd_ref_ptrSimon Marchi1-6/+4
This removes the manual call to gdb_bfd_ref in favor of gdb_bfd_ref_ptr. gdb/ChangeLog: * dwarf2read.c (struct dwo_file) <dbfd>: Change type to gdb_bfd_ref_ptr. <~dwo_file>: Remove call to gdb_bfd_unref. (open_and_init_dwo_file): Move gdb_bfd_ref_ptr into dbfd field. Call gdb_bfd_ref_ptr::get.
2019-06-21dwarf2read: C++ify dwo_fileSimon Marchi1-74/+38
This patch changes dwo_file to be allocated/deallocated with new/delete, so that we can start using C++ features in it, and in struct dwo_sections. The free_dwo_file function becomes the destructor of struct dwo_file (and will disappear in upcoming patches, which will use gdb_bfd_ref_ptr for dbfd and an std::vector for sections.types). gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <dwo_files>: Change type to htab_up. * dwarf2read.c (struct dwo_file): Initialize fields. <~dwo_file>: New. (free_dwo_file): Remove, move content to ~dwo_file. (struct dwo_file_deleter): Remove. (dwo_file_up>: Remove custom deleter. (free_dwo_files): Remove. (dwarf2_per_objfile::~dwarf2_per_objfile): Don't explicitly free dwo_files. (process_skeletonless_type_units): Call unique_ptr::get. (allocate_dwo_file_hash_table): Add deleter to created hash table. Change return type to htab_up. (lookup_dwo_file_slot): Don't memset dwo_file, call unique_ptr::get. (create_dwo_unit_in_dwp_v1): Allocate dwo_file with new. (create_dwo_unit_in_dwp_v2): Likewise. (open_and_init_dwo_file): Likewise. (free_dwo_file_from_slot): Remove.
2019-06-21dwarf2read: Use bool for dwarf2_section_info fieldsSimon Marchi1-2/+2
Use bool instead of char where applicable in dwarf2_section_info. No functional changes intended. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_section_info) <readin, is_virtual>: Change type to bool. * dwarf2read.c (dwarf2_read_section, create_dwp_v2_section): Use true instead of 1.
2019-06-18[gdb] Fix abstract_to_concrete typeTom de Vries1-4/+9
The test-case varval.exp fails here: ... FAIL: gdb.dwarf2/varval.exp: print varval2 ... with boards readnow/cc-with-gdb-index/cc-with-debug-names, as well as if gdb is build with -fsanitize=address -lasan. The problem is that the abstract_to_concrete map in which we track the association of abstract to concrete DIEs (for DW_OP_GNU_variable_value support) has type std::unordered_map<die_info_ptr, std::vector<die_info_ptr>>, and the die_info_ptrs that we register in the map may be invalid by the time that we start to lookup DIEs in the map. Fix this by using the sect_offset instead to identify the DIEs in the map. Build and tested on x86_64-linux. gdb/ChangeLog: 2019-06-18 Tom de Vries <tdevries@suse.de> PR gdb/24515 * dwarf2read.h (abstract_to_concrete): Change type from std::unordered_map<die_info_ptr, std::vector<die_info_ptr>> to std::unordered_map<sect_offset, std::vector<sect_offset>>. * dwarf2read.c (read_variable): Update. (dwarf2_fetch_die_loc_sect_off): Update.
2019-06-16Write index for dwz -m fileSimon Marchi1-30/+2
PR 24445 ("dwz multifile index not written to index cache") exposed the fact that we are not doing things right when we generate an index for an object file that has is linked to a dwz file. The same happens whether the index is generated with the intent of populating the index cache or using the save gdb-index command. The problem can be observed when running these tests with the cc-with-dwz-m board: FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats FAIL: gdb.dwarf2/gdb-index.exp: index used FAIL: gdb.dwarf2/gdb-index.exp: index used after symbol reloading When generating the index for such file and inspecting the CU list of the resulting index (with readelf --debug-dump=gdb_index), we can see something like: CU table: [ 0] 0x0 - 0xb9 [ 1] 0x0 - 0x44 This is supposed to be a sorted list of the ranges of all CUs in the file this index represents, so already having some overlap is a red flag. It turns out that we save the ranges of CUs coming from both the main file and the dwz file in the same index. After digging a little bit, it became quite obvious that the index in the main file should only list the CUs present in the main file, and a separate index should be generated for the dwz file, listing the CUs present in that file. First, that's what happens if you run dwz on a file that already has a GDB index embedded. Second, dwarf2read.c has code to read an index from a dwz file. The index in the dwz file is actually required to be present, if the main file has an index. So this patch changes write_psymtabs_to_index to generate an index for the dwz file, if present. That index only contains a CU list, just like what the dwz tool does when processing a file that already contains an index. Some notes about the implementation: - The file management (creating a temp file, make sure it's close/removed on error - in the right order) is a bit heavy in write_psymtabs_to_index, and I needed to add a third file. I factored this pattern in a separate class, index_wip_file. - It became a bit tedious to keep the call to assert_file_size in write_psymtabs_to_index, write_gdbindex would have had to return two sizes. Instead, I moved the calls to assert_file_size where the file is written. The downside is that we lose the filename at this point, but it was only used for the very improbable case of ftell failing, so I think it's not a problem. - The actual writing of the index file is factored out to write_gdbindex_1, so it can be re-used for both index files. - While the "save gdb-index" command will now write two .gdb-index files, this patch does not update the gdb-add-index.sh script, this will come in a later patch. gdb/ChangeLog: YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com> PR gdb/24445 * dwarf-index-write.h (write_psymtabs_to_index): Add dwz_basename parameter. * dwarf-index-write.c (write_gdbindex): Move file writing to write_gdbindex_1. Change return type void. (assert_file_size): Move up, remove filename parameter. (write_gdbindex_1): New function. (write_debug_names): Change return type to void, call assert_file_size. (struct index_wip_file): New struct. (write_psymtabs_to_index): Add dwz_basename parameter. Move file logic to index_wip_file. Write index for dwz file if needed. (save_gdb_index_command): Pass basename of dwz file, if present. * dwarf-index-cache.c (index_cache::store): Obtain and pass build-id of dwz file, if present. * dwarf2read.c (struct dwz_file): Move to dwarf2read.h. (dwarf2_get_dwz_file): Likewise. * dwarf2read.h (struct dwz_file): Move from dwarf2read.c. (dwarf2_get_dwz_file): Likewise. gdb/testsuite/ChangeLog: YYYY-MM-DD Tom de Vries <tdevries@suse.de> PR gdb/24445 * gdb.dwarf2/gdb-index.exp (add_gdb_index): Update dwz file with generated index.
2019-06-11Dwarf: Don't add nameless modules to partial symbol tableBernhard Heckel1-8/+9
A name for BLOCK DATA in Fortran is optional. If no name has been assigned, GDB crashes during read-in of DWARF when BLOCK DATA is represented via DW_TAG_module. BLOCK DATA is used for one-time initialization of non-pointer variables in named common blocks. As of now there is no issue when gfortran is used as DW_TAG_module is not emitted. However, with Intel ifort the nameless DW_TAG_module is present and has the following form: ... <1><dd>: Abbrev Number: 7 (DW_TAG_module) <de> DW_AT_decl_line : 46 <df> DW_AT_decl_file : 1 <e0> DW_AT_description : (indirect string, offset: 0x110): block data <e4> DW_AT_high_pc : 0x402bb7 <ec> DW_AT_low_pc : 0x402bb7 ... The missing name leads to a crash in add_partial_symbol, during length calculation. gdb/ChangeLog: 2019-06-11 Bernhard Heckel <bernhard.heckel@intel.com> * dwarf2read.c (add_partial_symbol): Skip nameless modules. gdb/testsuite/Changelog: 2019-06-11 Bernhard Heckel <bernhard.heckel@intel.com> * gdb.fortran/block-data.f: New. * gdb.fortran/block-data.exp: New.
2019-06-10[gdb] Fix heap-buffer-overflow in cp_find_first_component_auxTom de Vries1-1/+1
When compiling gdb with '-lasan -fsanitizer=address' and running tests with: - export ASAN_OPTIONS="detect_leaks=0:alloc_dealloc_mismatch=0", - target board cc-with-gdb-index, - the "[gdb/testsuite] Fix gdb.base/break-probes.exp with native-gdbserver" commit reverted to avoid running into PR24617, we get with gdb.arch/amd64-init-x87-values.exp: ... ==31229==ERROR: AddressSanitizer: heap-buffer-overflow on address \ 0x62500098c93c at pc 0x000000bcc748 bp 0x7ffe39487660 sp 0x7ffe39487658 READ of size 1 at 0x62500098c93c thread T0 #0 0xbcc747 in cp_find_first_component_aux src/gdb/cp-support.c:999 #1 0xbcc6e9 in cp_find_first_component(char const*) \ src/gdb/cp-support.c:977 #2 0xcc2cf3 in mapped_index_base::build_name_components() \ src/gdb/dwarf2read.c:4499 #3 0xcc3322 in dw2_expand_symtabs_matching_symbol src/gdb/dwarf2read.c:4552 #4 0xcc817f in dw2_expand_symtabs_matching src/gdb/dwarf2read.c:5228 #5 0xfe8f48 in iterate_over_all_matching_symtabs src/gdb/linespec.c:1147 #6 0x1003506 in add_matching_symbols_to_info src/gdb/linespec.c:4413 #7 0xffe21b in find_function_symbols src/gdb/linespec.c:3886 #8 0xffe4a2 in find_linespec_symbols src/gdb/linespec.c:3914 #9 0xfee3ad in linespec_parse_basic src/gdb/linespec.c:1865 #10 0xff5128 in parse_linespec src/gdb/linespec.c:2655 #11 0xff8872 in event_location_to_sals src/gdb/linespec.c:3150 #12 0xff90a8 in decode_line_full(event_location const*, int, \ program_space*, symtab*, int, linespec_result*, \ char const*, char const*) src/gdb/linespec.c:3230 #13 0x9ce449 in parse_breakpoint_sals src/gdb/breakpoint.c:9057 #14 0x9ea022 in create_sals_from_location_default src/gdb/breakpoint.c:13708 #15 0x9e2c1f in bkpt_create_sals_from_location src/gdb/breakpoint.c:12514 #16 0x9cff06 in create_breakpoint(gdbarch*, event_location const*, \ char const*, int, char const*, int, int, bptype, int, \ auto_boolean, breakpoint_ops const*, int, int, int, \ unsigned int) src/gdb/breakpoint.c:9238 #17 0x9d114a in break_command_1 src/gdb/breakpoint.c:9402 #18 0x9d1b60 in break_command(char const*, int) src/gdb/breakpoint.c:9473 #19 0xac96aa in do_const_cfunc src/gdb/cli/cli-decode.c:106 #20 0xad0e5a in cmd_func(cmd_list_element*, char const*, int) \ src/gdb/cli/cli-decode.c:1892 #21 0x15226f6 in execute_command(char const*, int) src/gdb/top.c:630 #22 0xddde37 in command_handler(char const*) src/gdb/event-top.c:586 #23 0xdde7c1 in command_line_handler(std::unique_ptr<char, \ gdb::xfree_deleter<char> >&&) src/gdb/event-top.c:773 #24 0xddc9e8 in gdb_rl_callback_handler src/gdb/event-top.c:217 #25 0x16f2198 in rl_callback_read_char src/readline/callback.c:220 #26 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \ src/gdb/event-top.c:175 #27 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192 #28 0xddd9f5 in stdin_event_handler(int, void*) src/gdb/event-top.c:514 #29 0xdd7d8f in handle_file_event src/gdb/event-loop.c:731 #30 0xdd8607 in gdb_wait_for_event src/gdb/event-loop.c:857 #31 0xdd629c in gdb_do_one_event() src/gdb/event-loop.c:321 #32 0xdd6344 in start_event_loop() src/gdb/event-loop.c:370 #33 0x10a7715 in captured_command_loop src/gdb/main.c:331 #34 0x10aa548 in captured_main src/gdb/main.c:1173 #35 0x10aa5d8 in gdb_main(captured_main_args*) src/gdb/main.c:1188 #36 0x87bd35 in main src/gdb/gdb.c:32 #37 0x7f16e1434f89 in __libc_start_main (/lib64/libc.so.6+0x20f89) #38 0x87bb49 in _start (build/gdb/gdb+0x87bb49) 0x62500098c93c is located 0 bytes to the right of 8252-byte region \ [0x62500098a900,0x62500098c93c) allocated by thread T0 here: #0 0x7f16e359a600 in malloc (/usr/lib64/libasan.so.5+0xeb600) #1 0x1742ddf in bfd_malloc src/bfd/libbfd.c:275 #2 0x1738824 in bfd_get_full_section_contents src/bfd/compress.c:253 #3 0xe30044 in gdb_bfd_map_section(bfd_section*, unsigned long*) \ src/gdb/gdb_bfd.c:704 #4 0xcb56bf in dwarf2_read_section(objfile*, dwarf2_section_info*) \ src/gdb/dwarf2read.c:2539 #5 0xd5bcd0 in get_gdb_index_contents_from_section<dwarf2_per_objfile> \ src/gdb/dwarf2read.c:6217 #6 0xd7fc7d in gdb::function_view<gdb::array_view<unsigned char const> \ (...) const src/gdb/common/function-view.h:284 #7 0xd7fddd in gdb::function_view<gdb::array_view<unsigned char const> \ (...) src/gdb/common/function-view.h:278 #8 0xd730cf in gdb::function_view<gdb::array_view<unsigned char const> \ (...) const src/gdb/common/function-view.h:247 #9 0xcbc7ee in dwarf2_read_gdb_index src/gdb/dwarf2read.c:3582 #10 0xcce731 in dwarf2_initialize_objfile(objfile*, dw_index_kind*) \ src/gdb/dwarf2read.c:6297 #11 0xdb88c4 in elf_symfile_read src/gdb/elfread.c:1256 #12 0x141262a in read_symbols src/gdb/symfile.c:798 #13 0x14140a7 in syms_from_objfile_1 src/gdb/symfile.c:1000 #14 0x1414393 in syms_from_objfile src/gdb/symfile.c:1017 #15 0x1414fb7 in symbol_file_add_with_addrs src/gdb/symfile.c:1124 #16 0x14159b7 in symbol_file_add_from_bfd(bfd*, char const*, \ enum_flags<symfile_add_flag>, std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>, objfile*) src/gdb/symfile.c:1203 #17 0x1415b6c in symbol_file_add(char const*, enum_flags<symfile_add_flag>, std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>) src/gdb/symfile.c:1216 #18 0x1415f2f in symbol_file_add_main_1 src/gdb/symfile.c:1240 #19 0x1418599 in symbol_file_command(char const*, int) \ src/gdb/symfile.c:1675 #20 0xde2fa6 in file_command src/gdb/exec.c:433 #21 0xac96aa in do_const_cfunc src/gdb/cli/cli-decode.c:106 #22 0xad0e5a in cmd_func(cmd_list_element*, char const*, int) \ src/gdb/cli/cli-decode.c:1892 #23 0x15226f6 in execute_command(char const*, int) src/gdb/top.c:630 #24 0xddde37 in command_handler(char const*) src/gdb/event-top.c:586 #25 0xdde7c1 in command_line_handler(std::unique_ptr<char, \ gdb::xfree_deleter<char> >&&) src/gdb/event-top.c:773 #26 0xddc9e8 in gdb_rl_callback_handler src/gdb/event-top.c:217 #27 0x16f2198 in rl_callback_read_char src/readline/callback.c:220 #28 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \ src/gdb/event-top.c:175 #29 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192 SUMMARY: AddressSanitizer: heap-buffer-overflow src/gdb/cp-support.c:999 in \ cp_find_first_component_aux Shadow bytes around the buggy address: 0x0c4a801298d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c4a801298e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c4a801298f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c4a80129900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c4a80129910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0c4a80129920: 00 00 00 00 00 00 00[04]fa fa fa fa fa fa fa fa 0x0c4a80129930: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c4a80129940: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c4a80129950: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c4a80129960: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c4a80129970: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==31229==ABORTING ... The problem happens as follows. The executable amd64-init-x87-values gets an index (due to target board cc-with-gdb-index), which looks as follows: ... Hex dump of section '.gdb_index': 0x00000000 08000000 18000000 28000000 28000000 ........(...(... 0x00000010 3c000000 3c200000 00000000 00000000 <...< .......... 0x00000020 2e000000 00000000 d4004000 00000000 ..........@..... 0x00000030 db004000 00000000 00000000 00000000 ..@............. 0x00000040 00000000 00000000 00000000 00000000 ................ 0x00000050 00000000 00000000 00000000 00000000 ................ ... more zeroes ... 0x00002010 00000000 00000000 00000000 00000000 ................ 0x00002020 00000000 00000000 00000000 00000000 ................ 0x00002030 00000000 00000000 00000000 ............ ... The structure of this index is: ... header : [0x0, 0x18) : size 0x18 culist : [0x18 ,0x28) : size 0x10 typesculist : [0x28, 0x28) : size 0x0 adress area : [0x28, 0x3c) : size 0x14 symbol table : [0x3c, 0x203c) : size 0x2000 constant pool: [0x203c, 0x203c): size 0x0 EOF : 0x203c ... Note that the symbol table consists entirely of empty slots (where an empty slot is a pair of 32-bit zeroes), and that the constant pool is empty. The problem happens here in mapped_index_base::build_name_components: ... auto count = this->symbol_name_count (); for (offset_type idx = 0; idx < count; idx++) { if (this->symbol_name_slot_invalid (idx)) continue; const char *name = this->symbol_name_at (idx); ... when accessing the slot at idx == 0 in the symbol table, symbol_name_slot_invalid returns false so we calculate name, which is calculated using 'constant_pool + symbol_table[idx].name', which means we get name == constant_pool. And given that the constant pool is empty, name now points past the memory allocated for the index, and when we access name[0] for the first time in cp_find_first_component_aux, we run into the heap-buffer-overflow. Fix this by fixing the definition of symbol_name_slot_invalid: ... - return bucket.name == 0 && bucket.vec; + return bucket.name == 0 && bucket.vec == 0; ... Tested on x86_64-linux. gdb/ChangeLog: 2019-06-10 Tom de Vries <tdevries@suse.de> PR gdb/24618 * dwarf2read.c (struct mapped_index::symbol_name_slot_invalid): Make sure an empty slot (defined by a 32-bit zero pair) is recognized as invalid.
2019-06-10[gdb/symtab] Support DW_AT_main_subprogram with -readnow.Tom de Vries1-0/+4
DW_AT_main_subprogram is supported in normal mode in read_partial_die, but not in -readnow mode. Fix this by adding support for DW_AT_main_subprogram in read_func_scope. Tested on x86_64-linux with native and RFC target board readnow ( https://sourceware.org/ml/gdb-patches/2019-05/msg00073.html ). gdb/ChangeLog: 2019-06-10 Tom de Vries <tdevries@suse.de> PR symtab/16264 PR symtab/24517 * dwarf2read.c (read_func_scope): Handle DW_AT_main_subprogram.
2019-05-29Don't crash is dwarf_decode_macro_bytes's 'body' is NULL, even when '!is_define'Sergio Durigan Junior1-17/+14
Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1715008 On commit 7bede82892a06e6c26989803e70f53697392dcf9 ("Don't crash if dwarf_decode_macro_bytes's 'body' is NULL"), I was too strict when checking if 'body' is NULL: the check only comprised the case when 'is_define' is true. However, the corruption of .debug_macro by rpmbuild's "debugedit" also affects the case when 'is_define' is false, i.e., when the macro is being undefined. This commit improves the check and covers both cases now. This has been tested on Fedora 30 with a problematic debuginfo, and I don't see a segfault anymore. OK to push? gdb/ChangeLog: 2019-05-29 Sergio Durigan Junior <sergiodj@redhat.com> Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1715008 * dwarf2read.c (dwarf_decode_macro_bytes): Move check to see if 'body' is NULL to the outter 'if', protecting the '!is_define' situation as well.
2019-05-29Make some DWARF complaints clearerTom Tromey1-6/+19
I noticed that the complaint in partial_die_parent_scope was not using dwarf_tag_name, so I changed that. Then I noticed that dwarf_tag_name does not show the numeric value for an unrecognized tag, so I changed that function and all the related functions to do so. gdb/ChangeLog 2019-05-29 Tom Tromey <tromey@adacore.com> * dwarf2read.c (partial_die_parent_scope): Call dwarf_tag_name. (dwarf_unknown): New function. (dwarf_tag_name, dwarf_attr_name, dwarf_form_name) (dwarf_type_encoding_name): Use dwarf_unknown.
2019-05-18gdb: Add constructor to struct cu_partial_die_infoAndrew Burgess1-11/+16
Adds a constructor to 'struct cu_partial_die_info' and disables the default constructor, preventing partially initialised instances from being created. Update 'find_partial_die' to return a const struct. Users of 'find_partial_die' are updated to take account of the above two changes. There should be no user visible changes after this commit. gdb/ChangeLog: * dwarf2read.c (struct cu_partial_die_info): Add constructor, delete default constructor. (find_partial_die): Update to return const struct. (partial_die_parent_scope): Move variable declaration into scope of its use and change its type to auto. (guess_partial_die_structure_name): Likewise. (partial_die_info::fixup): Likewise.
2019-05-17[gdb] Fix heap-use-after-free in typename_concatTom de Vries1-10/+32
When running gdb using AddressSanitizer, and loading a cc1plus binary built with profiledbootstrap and -flto, we run into a heap-use-after-free error: ... $ LD_PRELOAD=/usr/lib64/libasan.so.3 ./gdb -batch cc1plus ==26855==ERROR: AddressSanitizer: heap-use-after-free on address \ 0x62100ad8a8b0 at pc 0x7f13803cc9e3 bp 0x7ffe55b0d090 sp 0x7ffe55b0c840 READ of size 47 at 0x62100ad8a8b0 thread T0 #0 0x7f13803cc9e2 (/usr/lib64/libasan.so.3+0x3e9e2) #1 0x5e7a0d in typename_concat gdb/dwarf2read.c:22661 #2 0x5c6437 in partial_die_full_name gdb/dwarf2read.c:8876 #3 0x5c6555 in add_partial_symbol gdb/dwarf2read.c:8893 #4 0x5c6ecf in add_partial_subprogram gdb/dwarf2read.c:9156 #5 0x5c5e90 in scan_partial_symbols gdb/dwarf2read.c:8668 #6 0x5c6c0a in add_partial_namespace gdb/dwarf2read.c:9081 #7 0x5c5f99 in scan_partial_symbols gdb/dwarf2read.c:8702 #8 0x5c48b6 in process_psymtab_comp_unit_reader gdb/dwarf2read.c:8056 #9 0x5c3c1f in init_cutu_and_read_dies gdb/dwarf2read.c:7689 #10 0x5c4c03 in process_psymtab_comp_unit gdb/dwarf2read.c:8140 #11 0x5c58a2 in dwarf2_build_psymtabs_hard gdb/dwarf2read.c:8500 #12 0x5c0d03 in dwarf2_build_psymtabs(objfile*) gdb/dwarf2read.c:6337 #13 0x612359 in read_psyms gdb/elfread.c:1311 #14 0x798a64 in require_partial_symbols(objfile*, int) gdb/psymtab.c:115 #15 0x867d7b in read_symbols gdb/symfile.c:821 #16 0x8683d9 in syms_from_objfile_1 gdb/symfile.c:1000 #17 0x8684a1 in syms_from_objfile gdb/symfile.c:1017 #18 0x868873 in symbol_file_add_with_addrs gdb/symfile.c:1124 #19 0x868b0a in symbol_file_add_from_bfd(bfd*, char const*, \ enum_flags<symfile_add_flag>, std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>, objfile*) gdb/symfile.c:1204 #20 0x868b64 in symbol_file_add(char const*, \ enum_flags<symfile_add_flag>, \ std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>) gdb/symfile.c:1217 #21 0x868c39 in symbol_file_add_main_1 gdb/symfile.c:1240 #22 0x868bd0 in symbol_file_add_main(char const*, \ enum_flags<symfile_add_flag>) gdb/symfile.c:1231 #23 0x71f1b2 in symbol_file_add_main_adapter gdb/main.c:395 #24 0x71f10e in catch_command_errors gdb/main.c:372 #25 0x71ff5f in captured_main_1 gdb/main.c:1043 #26 0x72045d in captured_main gdb/main.c:1163 #27 0x7204c8 in gdb_main(captured_main_args*) gdb/main.c:1188 #28 0x40fd7d in main gdb/gdb.c:32 #29 0x7f137e300f49 in __libc_start_main (/lib64/libc.so.6+0x20f49) #30 0x40fc89 in _start (/data/gdb_versions/devel/build/gdb/gdb+0x40fc89) 0x62100ad8a8b0 is located 944 bytes inside of 4064-byte region \ [0x62100ad8a500,0x62100ad8b4e0) freed by thread T0 here: #0 0x7f13804523a0 in __interceptor_free (/usr/lib64/libasan.so.3+0xc43a0) #1 0x435e44 in xfree<void> gdb/common/common-utils.h:60 #2 0xa82c25 in call_freefun libiberty/obstack.c:103 #3 0xa83098 in _obstack_free libiberty/obstack.c:280 #4 0x4367da in auto_obstack::~auto_obstack() gdb/gdb_obstack.h:101 #5 0x5ed72c in dwarf2_cu::~dwarf2_cu() gdb/dwarf2read.c:25341 #6 0x5fb5bb in std::default_delete<dwarf2_cu>::operator()(dwarf2_cu*) const \ /usr/include/c++/7/bits/unique_ptr.h:78 #7 0x5f7334 in std::unique_ptr<dwarf2_cu, \ std::default_delete<dwarf2_cu> >::~unique_ptr() \ /usr/include/c++/7/bits/unique_ptr.h:268 #8 0x5c3ce5 in init_cutu_and_read_dies gdb/dwarf2read.c:7624 #9 0x5c4c03 in process_psymtab_comp_unit gdb/dwarf2read.c:8140 #10 0x5c58a2 in dwarf2_build_psymtabs_hard gdb/dwarf2read.c:8500 #11 0x5c0d03 in dwarf2_build_psymtabs(objfile*) gdb/dwarf2read.c:6337 #12 0x612359 in read_psyms gdb/elfread.c:1311 #13 0x798a64 in require_partial_symbols(objfile*, int) gdb/psymtab.c:115 #14 0x867d7b in read_symbols gdb/symfile.c:821 #15 0x8683d9 in syms_from_objfile_1 gdb/symfile.c:1000 #16 0x8684a1 in syms_from_objfile gdb/symfile.c:1017 #17 0x868873 in symbol_file_add_with_addrs gdb/symfile.c:1124 #18 0x868b0a in symbol_file_add_from_bfd(bfd*, char const*, \ enum_flags<symfile_add_flag>, std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>, objfile*) gdb/symfile.c:1204 #19 0x868b64 in symbol_file_add(char const*, \ enum_flags<symfile_add_flag>, std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>) gdb/symfile.c:1217 #20 0x868c39 in symbol_file_add_main_1 gdb/symfile.c:1240 #21 0x868bd0 in symbol_file_add_main(char const*, \ enum_flags<symfile_add_flag>) gdb/symfile.c:1231 #22 0x71f1b2 in symbol_file_add_main_adapter gdb/main.c:395 #23 0x71f10e in catch_command_errors gdb/main.c:372 #24 0x71ff5f in captured_main_1 gdb/main.c:1043 #25 0x72045d in captured_main gdb/main.c:1163 #26 0x7204c8 in gdb_main(captured_main_args*) gdb/main.c:1188 #27 0x40fd7d in main gdb/gdb.c:32 #28 0x7f137e300f49 in __libc_start_main (/lib64/libc.so.6+0x20f49) previously allocated by thread T0 here: #0 0x7f13804526b8 in __interceptor_malloc (/usr/lib64/libasan.so.3+0xc46b8) #1 0x5114b5 in xmalloc gdb/common/common-utils.c:44 #2 0xa82bd5 in call_chunkfun libiberty/obstack.c:94 #3 0xa82eda in _obstack_newchunk libiberty/obstack.c:206 #4 0x477310 in allocate_on_obstack::operator new(unsigned long, obstack*) \ gdb/gdb_obstack.h:117 #5 0x5dea8c in load_partial_dies gdb/dwarf2read.c:18571 #6 0x5c487f in process_psymtab_comp_unit_reader gdb/dwarf2read.c:8054 #7 0x5c3c1f in init_cutu_and_read_dies gdb/dwarf2read.c:7689 #8 0x5c4c03 in process_psymtab_comp_unit gdb/dwarf2read.c:8140 #9 0x5c58a2 in dwarf2_build_psymtabs_hard gdb/dwarf2read.c:8500 #10 0x5c0d03 in dwarf2_build_psymtabs(objfile*) gdb/dwarf2read.c:6337 #11 0x612359 in read_psyms gdb/elfread.c:1311 #12 0x798a64 in require_partial_symbols(objfile*, int) gdb/psymtab.c:115 #13 0x867d7b in read_symbols gdb/symfile.c:821 #14 0x8683d9 in syms_from_objfile_1 gdb/symfile.c:1000 #15 0x8684a1 in syms_from_objfile gdb/symfile.c:1017 #16 0x868873 in symbol_file_add_with_addrs gdb/symfile.c:1124 #17 0x868b0a in symbol_file_add_from_bfd(bfd*, char const*, \ enum_flags<symfile_add_flag>, \ std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>, objfile*) gdb/symfile.c:1204 #18 0x868b64 in symbol_file_add(char const*, enum_flags<symfile_add_flag>, \ std::vector<other_sections, \ std::allocator<other_sections> >*, \ enum_flags<objfile_flag>) gdb/symfile.c:1217 #19 0x868c39 in symbol_file_add_main_1 gdb/symfile.c:1240 #20 0x868bd0 in symbol_file_add_main(char const*, \ enum_flags<symfile_add_flag>) gdb/symfile.c:1231 #21 0x71f1b2 in symbol_file_add_main_adapter gdb/main.c:395 #22 0x71f10e in catch_command_errors gdb/main.c:372 #23 0x71ff5f in captured_main_1 gdb/main.c:1043 #24 0x72045d in captured_main gdb/main.c:1163 #25 0x7204c8 in gdb_main(captured_main_args*) gdb/main.c:1188 #26 0x40fd7d in main gdb/gdb.c:32 #27 0x7f137e300f49 in __libc_start_main (/lib64/libc.so.6+0x20f49) ... This error happens as follows. The function find_partial_die has a cu argument, but returns a pdi which may or may not be from that cu: ... /* Find a partial DIE at OFFSET, which may or may not be in CU, except in the case of .debug_types DIEs which do not reference outside their CU (they do however referencing other types via DW_FORM_ref_sig8). */ static struct partial_die_info * find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu) ... So the pdi returned by find_partial_die here in partial_die_parent_scope may be from another cu: ... partial_die_parent_scope (struct partial_die_info *pdi, struct dwarf2_cu *cu) { const char *grandparent_scope; struct partial_die_info *parent, *real_pdi; /* We need to look at our parent DIE; if we have a DW_AT_specification, then this means the parent of the specification DIE. */ real_pdi = pdi; while (real_pdi->has_specification) real_pdi = find_partial_die (real_pdi->spec_offset, real_pdi->spec_is_dwz, cu); parent = real_pdi->die_parent; ... in which case both real_pdi and parent will be not from cu, but from another one, say cu2. Subsequently, cu's comp_unit_obstack is used to set parent->scope: ... parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, parent->name, 0, cu); ... So, we use cu->comp_unit_obstack to assign a value to the scope field of a pdi belonging to cu2, and when cu is deleted, the scope field points to a freed value. Fix this by making find_partial_die return the cu corresponding to the returned pdi, and handling this at the call sites. Tested on x86_64-linux. gdb/ChangeLog: 2019-05-17 Tom de Vries <tdevries@suse.de> PR gdb/24094 * dwarf2read.c (struct cu_partial_die_info): New struct. (find_partial_die): Return cu_partial_die_info. (partial_die_parent_scope, guess_partial_die_structure_name) (partial_die_info::fixup): Handle new return type of find_partial_die.
2019-05-15Don't crash if dwarf_decode_macro_bytes's 'body' is NULLSergio Durigan Junior1-1/+18
Hi, Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 During the Fedora RPM build process, gdb-add-index is invoked to extract the DWARF index from the binary, and GDB will segfault because dwarf2read.c:parse_definition_macro's 'body' variable is NULL. The underlying problem is that Fedora's rpm-build's "debugedit" program will silently corrupt .debug_macro strings when a binary is compiled with -g3. This is being taken care of by Mark Wielaard, here: https://bugzilla.redhat.com/show_bug.cgi?id=1708786 However, I still feel it's important to make GDB more resilient against invalid DWARF input, so I'm proposing this rather simple patch to catch the situation when "body == NULL" (i.e., it's probably been corrupted) and issue a complaint. This is not a real fix to the problem, of course, but at least GDB is able to finish without segfaulting. OK for master? gdb/ChangeLog: 2019-05-15 Sergio Durigan Junior <sergiodj@redhat.com> Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 * dwarf2read.c (dwarf_decode_macro_bytes): Check whether 'body' is NULL, and complain if that's the case.
2019-05-08Convert dwarf2_per_objfile to type-safe registry APITom Tromey1-37/+6
This changes dwarf2_per_objfile to use the type-safe registry API. This also changes dwarf2_per_objfile not to be allocated on an obstack. It seemed clearer to me to simply allocate it on the heap; and I didn't see a drawback from doing so. gdb/ChangeLog 2019-05-08 Tom Tromey <tom@tromey.com> * dwarf2read.h (struct dwarf2_per_objfile): Don't inherit from allocate_on_obstack. * dwarf2read.c (dwarf2_objfile_data_key): Change type. (get_dwarf2_per_objfile): Update. (set_dwarf2_per_objfile): Remove. (dwarf2_has_info, dwarf2_get_section_info): Update. (dwarf2_free_objfile): Remove. (_initialize_dwarf2_read): Update.
2019-05-03Remove "struct" from foreach statementsTom Tromey1-1/+1
Some versions of gcc have a bug that causes for (struct mumble : something) ... to give a compiler error. We routinely work around this bug in gdb, but apparently had not done so in a while. This patch fixes the remaining known cases of this problem. gdb/ChangeLog 2019-05-03 Sandra Loosemore <sandra@codesourcery.com> Tom Tromey <tom@tromey.com> * dictionary.c (collate_pending_symbols_by_language): Remove "struct" from foreach. * symtab.c (lookup_global_symbol_from_objfile) (lookup_symbol_in_objfile_from_linkage_name): Remove "struct" from foreach. * ser-tcp.c (net_open): Remove "struct" from foreach. * objfiles.c (objfile_relocate, objfile_rebase) (objfile_has_symbols): Remove "struct" from foreach. * minsyms.c (lookup_minimal_symbol_by_pc_section): Remove "struct" from foreach. * dwarf2read.c (handle_struct_member_die): Remove "struct" from foreach. * darwin-nat.c (thread_info_from_private_thread_info): Remove "struct" from foreach. * ada-lang.c (create_excep_cond_exprs) (ada_exception_catchpoint_cond_string): Remove "struct" from foreach.
2019-04-30Support DW_FORM_strx1, _strx2, _strx3, _strx4 forms.Ali Tamur1-4/+46
Dwarf5 defines DW_FORM_strx1 and others, which are similar to DW_FORM_strx but uses 1-4 bytes unsigned integers. This is a small step towards supporting dwarf5 in gdb.
2019-04-30Fix crash in dwarf2read.c with template parametersTom Tromey1-7/+28
PR c++/24470 concerns a crash in dwarf2read.c that occurs with a particular test case. The issue turns out to be that process_structure_scope will pass NULL to symbol_symtab. This happens because new_symbol decided not to create a symbol for the particular DIE. This patch fixes the problem by finding another reasonably-appropriate symtab to use instead; issuing a complaint if one cannot be found for some reason. As mentioned in the bug, I think there are other bugs here. For example, when using "ptype" on the "l" object in the test case, I think I would expect to see the template parameter. I didn't research this too closely, since it seemed more important to fix the crash. Tested on x86-64 Fedora 29. I'd like to check this in to the 8.3 branch as well. 2019-04-30 Tom Tromey <tromey@adacore.com> PR c++/24470: * dwarf2read.c (process_structure_scope): Handle case where type has template parameters but no symbol was created. gdb/testsuite/ChangeLog 2019-04-30 Tom Tromey <tromey@adacore.com> PR c++/24470: * gdb.cp/temargs.cc: Add test code from PR.
2019-04-30gdb/fortran: better types for components of complex numbersAndrew Burgess1-9/+29
Currently when using $_creal and $_cimag to access the components of a complex number the types of these components will have C type names 'float', 'double', etc. This is because the components of a complex number are not given type names in DWARF, so GDB has to pick some suitable names, and currently we always use the C names. This commit changes the type names used based on the language, so for Fortran we will now use the Fortran float types, and so will get the Fortran float type names 'real', 'real*8', etc. gdb/ChangeLog: * dwarf2read.c (dwarf2_init_complex_target_type): Use different types for Fortran. gdb/testsuite/ChangeLog: * gdb.fortran/complex.exp: Expand. * gdb.fortran/complex.f: Renamed to... * gdb.fortran/complex.f90: ...this, and extended to add more complex values.
2019-04-25[PATCH] Support for DW_FORM_strx tagAli Tamur1-2/+9
DW_FORM_strx is the new name of DW_FORM_GNU_str_index in the Dwarf 5 standard. This is a small step towards supporting Dwarf 5 in gdb.
2019-04-23Remove unused overload of line_header::file_name_atTom Tromey1-8/+0
I noticed that one of the overloads of line_header::file_name_at is unused. This patch removes it. gdb/ChangeLog 2019-04-23 Tom Tromey <tromey@adacore.com> * dwarf2read.c (line_header::file_name_at): Remove unused overload.
2019-04-22Support for DW_OP_addrx and DW_FORM_addrx tagsAli Tamur1-5/+15
DW_OP_addrx is the new name of DW_OP_GNU_addr_index, and DW_FORM_addrx is the name of DW_FORM_addr_index in the Dwarf 5 standard. This is a small step towards supporting Dwarf 5 in gdb. Note: I could not find any tests specifically for *_GNU_addr_index, and I did not add any new tests, please advise.
2019-04-17Avoid crash in dwarf2_init_complex_target_typeTom Tromey1-1/+1
After commit 35add35 ("gdb: Fix failure in gdb.base/complex-parts.exp for x86-32"), dwarf2_init_complex_target_type can crash if "tt" is nullptr. This patch avoids the problem by checking for this case. No test case because I don't know a good way to write one; it was found by an internal AdaCore test case that apparently uses a 16 bit floating point type. gdb/ChangeLog: * dwarf2read.c (dwarf2_init_complex_target_type): Check "tt" against nullptr before use. gdb/ChangeLog 2019-04-17 Tom Tromey <tromey@adacore.com> * dwarf2read.c (dwarf2_init_complex_target_type): Check "tt" against nullptr before use.
2019-04-13gdb: Fix failure in gdb.base/complex-parts.exp for x86-32Andrew Burgess1-0/+10
The x86-32 ABI specifies 96-bit long double, this was causing a failure on the test gdb.base/complex-parts.exp. The problem is that GDB tries to find a builtin floating point type of the correct size in order to reuse the name of that type as the name for the components of the complex type being built. Previously GDB was only aware of floating point types sized 32, 64, or 128 bits. This patch teaches GDB how to handle 96 bit floating point type. gdb/ChangeLog: * dwarf2read.c (dwarf2_init_complex_target_type): Handle complex target types of size 96-bits, add some additional comments, and check that the builtin type we found was the correct size.
2019-04-08Rename gdb exception typesTom Tromey1-1/+1
This renames the gdb exception types. The old types were only needed due to the macros in common-exception.h that are now gone. The intermediate layer of gdb_exception_RETURN_MASK_ALL did not seem needed, so this patch removes it entirely. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * common/common-exceptions.h (gdb_exception_RETURN_MASK_ALL): Remove. (gdb_exception_error): Rename from gdb_exception_RETURN_MASK_ERROR. (gdb_exception_quit): Rename from gdb_exception_RETURN_MASK_QUIT. (gdb_quit_bad_alloc): Update. * aarch64-tdep.c: Update. * ada-lang.c: Update. * ada-typeprint.c: Update. * ada-valprint.c: Update. * amd64-tdep.c: Update. * arch-utils.c: Update. * break-catch-throw.c: Update. * breakpoint.c: Update. * btrace.c: Update. * c-varobj.c: Update. * cli/cli-cmds.c: Update. * cli/cli-interp.c: Update. * cli/cli-script.c: Update. * common/common-exceptions.c: Update. * common/new-op.c: Update. * common/selftest.c: Update. * compile/compile-c-symbols.c: Update. * compile/compile-cplus-symbols.c: Update. * compile/compile-object-load.c: Update. * compile/compile-object-run.c: Update. * completer.c: Update. * corelow.c: Update. * cp-abi.c: Update. * cp-support.c: Update. * cp-valprint.c: Update. * darwin-nat.c: Update. * disasm-selftests.c: Update. * dtrace-probe.c: Update. * dwarf-index-cache.c: Update. * dwarf-index-write.c: Update. * dwarf2-frame-tailcall.c: Update. * dwarf2-frame.c: Update. * dwarf2loc.c: Update. * dwarf2read.c: Update. * eval.c: Update. * event-loop.c: Update. * event-top.c: Update. * exec.c: Update. * f-valprint.c: Update. * fbsd-tdep.c: Update. * frame-unwind.c: Update. * frame.c: Update. * gdbtypes.c: Update. * gnu-v3-abi.c: Update. * guile/guile-internal.h: Update. * guile/scm-block.c: Update. * guile/scm-breakpoint.c: Update. * guile/scm-cmd.c: Update. * guile/scm-disasm.c: Update. * guile/scm-frame.c: Update. * guile/scm-lazy-string.c: Update. * guile/scm-math.c: Update. * guile/scm-param.c: Update. * guile/scm-ports.c: Update. * guile/scm-pretty-print.c: Update. * guile/scm-symbol.c: Update. * guile/scm-symtab.c: Update. * guile/scm-type.c: Update. * guile/scm-value.c: Update. * i386-linux-tdep.c: Update. * i386-tdep.c: Update. * inf-loop.c: Update. * infcall.c: Update. * infcmd.c: Update. * infrun.c: Update. * jit.c: Update. * language.c: Update. * linespec.c: Update. * linux-fork.c: Update. * linux-nat.c: Update. * linux-tdep.c: Update. * linux-thread-db.c: Update. * main.c: Update. * mi/mi-cmd-break.c: Update. * mi/mi-cmd-stack.c: Update. * mi/mi-interp.c: Update. * mi/mi-main.c: Update. * objc-lang.c: Update. * p-valprint.c: Update. * parse.c: Update. * ppc-linux-tdep.c: Update. * printcmd.c: Update. * python/py-arch.c: Update. * python/py-breakpoint.c: Update. * python/py-cmd.c: Update. * python/py-finishbreakpoint.c: Update. * python/py-frame.c: Update. * python/py-framefilter.c: Update. * python/py-gdb-readline.c: Update. * python/py-inferior.c: Update. * python/py-infthread.c: Update. * python/py-lazy-string.c: Update. * python/py-linetable.c: Update. * python/py-objfile.c: Update. * python/py-param.c: Update. * python/py-prettyprint.c: Update. * python/py-progspace.c: Update. * python/py-record-btrace.c: Update. * python/py-record.c: Update. * python/py-symbol.c: Update. * python/py-type.c: Update. * python/py-unwind.c: Update. * python/py-utils.c: Update. * python/py-value.c: Update. * python/python.c: Update. * record-btrace.c: Update. * record-full.c: Update. * remote-fileio.c: Update. * remote.c: Update. * riscv-tdep.c: Update. * rs6000-aix-tdep.c: Update. * rs6000-tdep.c: Update. * rust-exp.y: Update. * rust-lang.c: Update. * s390-tdep.c: Update. * selftest-arch.c: Update. * solib-dsbt.c: Update. * solib-frv.c: Update. * solib-spu.c: Update. * solib-svr4.c: Update. * solib.c: Update. * sparc64-linux-tdep.c: Update. * stack.c: Update. * symfile-mem.c: Update. * symmisc.c: Update. * target.c: Update. * thread.c: Update. * top.c: Update. * tracefile-tfile.c: Update. * tui/tui.c: Update. * typeprint.c: Update. * unittests/cli-utils-selftests.c: Update. * unittests/parse-connection-spec-selftests.c: Update. * valops.c: Update. * valprint.c: Update. * value.c: Update. * varobj.c: Update. * windows-nat.c: Update. * x86-linux-nat.c: Update. * xml-support.c: Update. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * gdbreplay.c: Update. * linux-low.c: Update. * server.c: Update.