Change perror_string to return a std::string, removing a cleanup in
the process.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* utils.c (perror_string): Return a std::string.
(throw_perror_with_name, perror_warning_with_name): Update.
Change demangle_command to use std::string and unique_xmalloc_ptr,
removing some cleanups.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* demangle.c (demangle_command): Use std::string,
unique_xmalloc_ptr.
Change do_set_command to use std::string, removing a cleanup and some
manual resizing code.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* cli/cli-setshow.c (do_set_command): Use std::string.
Change cd_command to use unique_xmalloc_ptr, removing a cleanup.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr.
Change mi_cmd_interpreter_exec to use std::string, removing a cleanup.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* mi/mi-interp.c (mi_cmd_interpreter_exec): Use std::string.
Change env_execute_cli_command to use unique_xmalloc_ptr, removing a
cleanup.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* mi/mi-cmd-env.c (env_execute_cli_command): Use
gdb::unique_xmalloc_ptr.
This changes a few spots in thread.c to use std::string, removing some
cleanups.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* thread.c (print_thread_info_1): Use string_printf.
(thread_apply_command, thread_apply_all_command): Use
std::string.
This changes memory_error_message to return a std::string and fixes up
the callers. This removes some cleanups.
ChangeLog
2017-09-03 Tom Tromey <tom@tromey.com>
* valprint.c (val_print_string): Update.
* gdbcore.h (memory_error_message): Return std::string.
* corefile.c (memory_error_message): Return std::string.
(memory_error): Update.
* breakpoint.c (insert_bp_location): Update.
A quite straightforward change. It does "fix" leaks in record-btrace.c,
although since this is only used in debug printing code, it has no real
world impact.
gdb/ChangeLog:
* target/waitstatus.h (target_waitstatus_to_string): Change
return type to std::string.
* target/waitstatus.c (target_waitstatus_to_string): Return
std::string.
* target.h (target_waitstatus_to_string): Remove declaration.
* infrun.c (resume, clear_proceed_status_thread,
print_target_wait_results, do_target_wait, save_waitstatus,
stop_all_threads): Adjust.
* record-btrace.c (record_btrace_wait): Adjust.
* target-debug.h
(target_debug_print_struct_target_waitstatus_p): Adjust.
gdb/gdbserver/ChangeLog:
* linux-low.c (linux_wait_1): Adjust.
* server.c (queue_stop_reply_callback): Adjust.
On <=RHEL6 hosts Fedora/RHEL GDB started to 'kill -STOP' all processes it
detached. Even those not originally T-stopped. This is a Fedora-specific
patch which is based on upstream GDB's PROC_STATE_STOPPED state.
I believe (I did not verify) this patch did regress it:
commit d617208bb0
Author: Pedro Alves <palves@redhat.com>
Date: Mon Jul 25 12:42:17 2016 +0100
linux-procfs: Introduce enum proc_state
As originally there was strstr() but now there is strcmp() and so the missing
trailing '\n' no longer matches.
The Bug was found by Michal Kolar.
Reproducibility:
$ gdb -p $PID
(gdb) quit
$ ...
Actual results:
===
RHEL6.9 x86_64 # scl enable devtoolset-7 bash
RHEL6.9 x86_64 # which gdb
/opt/rh/devtoolset-7/root/usr/bin/gdb
RHEL6.9 x86_64 # ./testcase.sh
24737 pts/0 S+ 0:00 /bin/sleep 4
24737 pts/0 T+ 0:00 /bin/sleep 4
RHEL6.9 x86_64 #
===
Expected results:
===
RHEL6.9 x86_64 # which gdb
/usr/bin/gdb
RHEL6.9 x86_64 # ./testcase.sh
24708 pts/0 S+ 0:00 /bin/sleep 4
24708 pts/0 S+ 0:00 /bin/sleep 4
./testcase.sh: line 20: kill: (24708) - No such process
RHEL6.9 x86_64 #
===
gdb/ChangeLog
2017-09-01 Jan Kratochvil <jan.kratochvil@redhat.com>
PR gdb/22046
* nat/linux-procfs.c (parse_proc_status_state): Fix PROC_STATE_STOPPED
detection.
This patch implements the ability to set/unset environment variables
on the remote target, mimicking what GDB already offers to the user.
There are two features present here: user-set and user-unset
environment variables.
User-set environment variables are only the variables that are
explicitly set by the user, using the 'set environment' command. This
means that variables that were already present in the environment when
starting GDB/GDBserver are not transmitted/considered by this feature.
User-unset environment variables are variables that are explicitly
unset by the user, using the 'unset environment' command.
The idea behind this patch is to store user-set and user-unset
environment variables in two separate sets, both part of gdb_environ.
Then, when extended_remote_create_inferior is preparing to start the
inferior, it will iterate over the two sets and set/unset variables
accordingly. Three new packets are introduced:
- QEnvironmentHexEncoded, which is used to set environment variables,
and contains an hex-encoded string in the format "VAR=VALUE" (VALUE
can be empty if the user set a variable with a null value, by doing
'set environment VAR=').
- QEnvironmentUnset, which is used to unset environment variables, and
contains an hex-encoded string in the format "VAR".
- QEnvironmentReset, which is always the first packet to be
transmitted, and is used to reset the environment, i.e., discard any
changes made by the user on previous runs.
The QEnvironmentHexEncoded packet is inspired on LLDB's extensions to
the RSP. Details about it can be seen here:
<https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt>
I decided not to implement the QEnvironment packet because it is
considered deprecated by LLDB. This packet, on LLDB, serves the same
purpose of QEnvironmentHexEncoded, but sends the information using a
plain text, non-hex-encoded string.
The other two packets are new.
This patch also includes updates to the documentation, testsuite, and
unit tests, without introducing regressions.
gdb/ChangeLog:
2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com>
* NEWS (Changes since GDB 8.0): Add entry mentioning new support
for setting/unsetting environment variables on the remote target.
(New remote packets): Add entries for QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset.
* common/environ.c (gdb_environ::operator=): Extend method to
handle m_user_set_env_list and m_user_unset_env_list.
(gdb_environ::clear): Likewise.
(match_var_in_string): Change type of first parameter from 'char
*' to 'const char *'.
(gdb_environ::set): Extend method to handle
m_user_set_env_list and m_user_unset_env_list.
(gdb_environ::unset): Likewise.
(gdb_environ::clear_user_set_env): New method.
(gdb_environ::user_set_envp): Likewise.
(gdb_environ::user_unset_envp): Likewise.
* common/environ.h (gdb_environ): Handle m_user_set_env_list and
m_user_unset_env_list on move constructor/assignment.
(unset): Add new default parameter 'update_unset_list = true'.
(clear_user_set_env): New method.
(user_set_envp): Likewise.
(user_unset_envp): Likewise.
(m_user_set_env_list): New std::set.
(m_user_unset_env_list): Likewise.
* common/rsp-low.c (hex2str): New function.
(bin2hex): New overload for bin2hex function.
* common/rsp-low.c (hex2str): New prototype.
(str2hex): New overload prototype.
* remote.c: Include "environ.h". Add QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset.
(remote_protocol_features): Add QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset packets.
(send_environment_packet): New function.
(extended_remote_environment_support): Likewise.
(extended_remote_create_inferior): Call
extended_remote_environment_support.
(_initialize_remote): Add QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset packet configs.
* unittests/environ-selftests.c (gdb_selftest_env_var):
New variable.
(test_vector_initialization): New function.
(test_init_from_host_environ): Likewise.
(test_reinit_from_host_environ): Likewise.
(test_set_A_unset_B_unset_A_cannot_find_A_can_find_B):
Likewise.
(test_unset_set_empty_vector): Likewise.
(test_vector_clear): Likewise.
(test_std_move): Likewise.
(test_move_constructor):
(test_self_move): Likewise.
(test_set_unset_reset): Likewise.
(run_tests): Rewrite in terms of the functions above.
gdb/gdbserver/ChangeLog:
2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com>
* server.c (handle_general_set): Handle QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset packets.
(handle_query): Inform remote that QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset are supported.
gdb/doc/ChangeLog:
2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.texinfo (set environment): Add @anchor. Explain that
environment variables set by the user are sent to GDBserver.
(unset environment): Likewise, but for unsetting variables.
(Connecting) <Remote Packet>: Add "environment-hex-encoded",
"QEnvironmentHexEncoded", "environment-unset", "QEnvironmentUnset",
"environment-reset" and "QEnvironmentReset" to the table.
(Remote Protocol) <QEnvironmentHexEncoded, QEnvironmentUnset,
QEnvironmentReset>: New item, explaining the packet.
gdb/testsuite/ChangeLog:
2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/share-env-with-gdbserver.c: New file.
* gdb.base/share-env-with-gdbserver.exp: Likewise.
The problem of failing to build with arm-linux-gnueabihf-g++-4.8 was
that type CORE_ADDR is of "unsigned long" on a 64-bit machine so it's
OK to use %lx but is of type "unsigned long long" on a 32 bit system.
Fixed the problem in three places - (1) use a temp variable of type
CORE_ADDR as argument 3 when calling target_auxv_search() then assign
its value to "blksize" and "nbits" in 2 calls; (2) redo
adi_normalize_address() using masks and xor operators to calculate
normalized address; (3) call paddress() to print CORE_ADDR in either
printf_filtered() or error(). Thank you, Pedro, for all your
suggestions.
gdb/ChangeLog:
2017-08-31 Weimin Pan <weimin.pan@oracle.com>
* sparc64-tdep.c (adi_stat_t): Fix comment formatting.
(adi_available): Use a temp variable of type CORE_ADDR as argument
3 when calling target_auxv_search.
(adi_normalize_address): Use masks and xor operators to calculate
normalized address.
(adi_read_versions, adi_write_versions, adi_print_versions)
(do_examine, do_assign): Use paddress.
FreeBSD/mips kernels were recently changed to include the floating
point implementation revision register in the floating point register
set exported in process cores and via ptrace() (r318067). This change
will first ship in FreeBSD 12.0 when it is eventually released. The
space used to hold FIR was previously reserved in 'struct fpreg' as a
zero-filled dummy for padding, so 'struct fpreg' has not changed in
size. Since FIR should be non-zero on all MIPS processors supported
by FreeBSD, ignore a value of 0 from 'struct fpreg' and only report
non-zero values as a valid FIR register.
gdb/ChangeLog:
* mips-fbsd-nat.c (getfpregs_supplies): Return true for FIR.
* mips-fbsd-tdep.c (mips_fbsd_supply_fpregs): Split supply of FSR
out of loop and add supply of FIR.
(mips_fbsd_collect_fpregs): Split collect of FSR out of loop and
add collect of FIR.
Commit
Command names: make them case sensitive
3d7b173c29
made command name lookup case sensitive. However, define_command, used
when creating a user-defined command, converts the command name to
lowercase, assuming that the command name lookup works in a case
insensitive way. This causes user-defined commands with capital letters
in their name to only be callable with a lowercase version:
(gdb) define Foo
Type commands for definition of "Foo".
End with a line saying just "end".
>print 1
>end
(gdb) Foo
Undefined command: "Foo". Try "help".
(gdb) foo
$1 = 1
This patch removes that conversion to lowercase, so that the user can
call the command with the same name they provided.
gdb/ChangeLog:
* cli/cli-script.c (define_command): Don't convert command name
to lower case.
gdb/testsuite/ChangeLog:
* gdb.base/commands.exp (user_defined_command_case_sensitivity):
New proc, call it from toplevel.
The function is always called with DISPP set to NULL, so there is
no need for this parameter anymore. This patch removes it, and
eliminates some dead code associated to that.
gdb/ChangeLog:
* ada-lang.c (ada_lookup_struct_elt_type): Remove parameter "dispp".
Update all callers accordingly. Remove all code blocks handling
the case where DISPP is not NULL.
Tested on x86_64-linux, no regression.
These functions apply to thread, and not inferiors (in the gdbserver
sense, the abstraction for threads and processes, as in
inferior_list). Therefore, it would make more sense if these functions
were named with "thread" rather than "inferior".
gdb/gdbserver/ChangeLog:
* inferiors.h (inferior_target_data): Rename to ...
(thread_target_data): ... this.
(inferior_regcache_data): Rename to ...
(thread_regcache_data): ... this.
(set_inferior_regcache_data): Rename to ...
(set_thread_regcache_data): ... this.
* inferiors.c (inferior_target_data): Rename to ...
(thread_target_data): ... this.
(inferior_regcache_data): Rename to ...
(thread_regcache_data): ... this.
(set_inferior_regcache_data): Rename to ...
(set_thread_regcache_data): ... this.
(free_one_thread): Update.
* linux-low.h (get_thread_lwp): Update.
* regcache.c (get_thread_regcache): Update.
(regcache_invalidate_thread): Update.
(free_register_cache_thread): Update.
* win32-i386-low.c (update_debug_registers_callback): Update.
(win32_get_current_dr): Update.
* win32-low.c (thread_rec): Update.
(delete_thread_info): Update.
(continue_one_thread): Update.
(suspend_one_thread): Update.
The inferior (thread) target data is always set through add_thread.
gdb/gdbserver/ChangeLog:
* inferiors.c (set_inferior_target_data): Remove.
* inferiors.h (set_inferior_target_data): Remove.
GDB was now accessing as signatured_type memory allocated only by size of
dwarf2_per_cu_data.
gdb/ChangeLog
2017-08-24 Jan Kratochvil <jan.kratochvil@redhat.com>
* dwarf2read.c (build_type_psymtabs_reader): New prototype.
(process_psymtab_comp_unit): Accept IS_DEBUG_TYPES.
(read_comp_units_from_section): New parameter abbrev_section, use
read_and_check_comp_unit_head, allocate signatured_type if needed.
(create_all_comp_units): Update read_comp_units_from_section caller.
There is an assertion that is triggering when we start GDB and
instruct it to debug a remote inferior, but don't provide a local
binary, like:
./gdb -nx -q --data-directory=data-directory -ex "tar ext :1234" \
-ex "set remote exec-file /bin/ls" -ex r
In this case, when calling exec_file_locate_attach to locate the
inferior, GDB is incorrectly resetting the breakpoints without a
thread/inferior even running, which causes an assertion to be
triggered:
binutils-gdb/gdb/thread.c:1609: internal-error: scoped_restore_current_thread::scoped_restore_current_thread(): Assertion `tp != NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
This happens because add_current_inferior_and_thread (on remote.c) is
breaking an invariant: making inferior_ptid point to a non-existing
thread and then calling common code, which in this case is
breakpoint_re_set. The fix is to make sure that inferior_ptid points
to null_ptid if there is no thread present.
A testcase is provided. Regtested on buildbot.
gdb/ChangeLog:
2017-08-23 Pedro Alves <palves@redhat.com>
PR remote/21852
* remote.c (add_current_inferior_and_thread): Set inferior_ptid
to null_ptid and switch to thread without reading the registers
after adding the inferior.
gdb/testsuite/ChangeLog:
2017-08-23 Sergio Durigan Junior <sergiodj@redhat.com>
PR remote/21852
* gdb.server/normal.c: New file, copied from gdb.base.
* gdb.server/run-without-local-binary.exp: New file.
As discussed in
How to use compile & execute function in GDB
https://sourceware.org/ml/gdb/2015-04/msg00026.html
GDB currently searches for compilers on /usr/bin/ARCH-OS-gcc and
chooses a match from there. However, it is not currently possible for
the user to override which compiler to use. This is what this patch
implements.
It is also a sync between GCC's and GDB's interfaces.
gdb/ChangeLog
2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* NEWS (Changes since GDB 7.9): Add set compile-gcc and show
compile-gcc.
* compile/compile.c (compile_gcc, show_compile_gcc): New.
(compile_to_object): Implement compile_gcc.
(_initialize_compile): Install "set compile-gcc". Initialize
compile_gcc.
gdb/doc/ChangeLog
2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (Compiling and Injecting Code): Add to subsection
"Compiler search for the compile command" descriptions of set
compile-gcc and show compile-gcc.
include/ChangeLog
2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* gcc-interface.h (enum gcc_base_api_version): Update comment for
GCC_FE_VERSION_1.
(struct gcc_base_vtable): Rename set_arguments to set_arguments_v0.
Add set_arguments, set_triplet_regexp and set_driver_filename.
As discussed in
How to use compile & execute function in GDB
https://sourceware.org/ml/gdb/2015-04/msg00026.html
GDB currently searches for compilers on /usr/bin/ARCH-OS-gcc and
chooses a match from there. However, it is not currently possible for
the user to display which compiler was selected. Up until now, GDB's
compiler interface was not up-to-date with GCC's one, which means that
it wasn't possible to obtain this information. This patch implements
the mechanisms necessary for that.
gdb/ChangeLog
2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* compile/compile.c (compile_to_object): Conditionally call
set_verbose. Conditionally call compile or compile_v0.
include/ChangeLog
2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* gcc-interface.h (enum gcc_base_api_version): Add
GCC_FE_VERSION_1.
(struct gcc_base_vtable): Rename compile to compile_v0. Update
comment for compile. New methods set_verbose and compile.
The M7 processor supports an Application Data Integrity (ADI) feature
that detects invalid data accesses. When software allocates data, it
chooses a 4-bit version number, sets the version in the upper 4 bits
of the 64-bit pointer to that data, and stores the 4-bit version in
every cacheline of the object. Hardware saves the latter in spare
bits in the cache and memory hierarchy. On each load and store, the
processor compares the upper 4 VA (virtual address) bits to the
cacheline's version. If there is a mismatch, the processor generates a
version mismatch trap which can be either precise or disrupting. The
trap is an error condition which the kernel delivers to the process as
a SIGSEGV signal.
The upper 4 bits of the VA represent a version and are not part of the
true address. The processor clears these bits and sign extends bit 59
to generate the true address.
Note that 32-bit applications cannot use ADI.
This patch adds ADI support in gdb which allows the user to examine
current version tags and assign new version tags in the program. It
also catches and reports precise or disrupting memory corruption
traps.
gdb/ChangeLog:
2017-08-07 Weimin Pan <weimin.pan@oracle.com>
* sparc64-tdep.h: (adi_normalize_address): New export.
* sparc-nat.h: (open_adi_tag_fd): New export.
* sparc64-linux-nat.c: (open_adi_tag_fd): New function.
* sparc64-linux-tdep.c:
(SEGV_ACCADI, SEGV_ADIDERR, SEGV_ADIPERR) New defines.
(sparc64_linux_handle_segmentation_fault): New function.
(sparc64_linux_init_abi): Register
sparc64_linux_handle_segmentation_fault
* sparc64-tdep.c: Include cli-utils.h,gdbcmd.h,auxv.h.
(sparc64_addr_bits_remove): New function.
(sparc64_init_abi): Register sparc64_addr_bits_remove.
(MAX_PROC_NAME_SIZE): New macro.
(AT_ADI_BLKSZ, AT_ADI_NBITS, AT_ADI_UEONADI) New defines.
(sparc64adilist): New variable.
(adi_proc_list): New variable.
(find_adi_info): New function.
(add_adi_info): New function.
(get_adi_info_proc): New function.
(get_adi_info): New function.
(info_adi_command): New function.
(read_maps_entry): New function.
(adi_available): New function.
(adi_normalize_address): New function.
(adi_align_address): New function.
(adi_convert_byte_count): New function.
(adi_tag_fd): New function.
(adi_is_addr_mapped): New function.
(adi_read_versions): New function.
(adi_write_versions): New function.
(adi_print_versions): New function.
(do_examine): New function.
(do_assign): New function.
(adi_examine_command): New function.
(adi_assign_command): New function.
(_initialize_sparc64_adi_tdep): New function.
gdb/doc/ChangeLog:
2017-08-07 Weimin Pan <weimin.pan@oracle.com>
* gdb.texinfo (Architectures): Add new Sparc64 section to document
ADI support.
* NEWS: Add "adi examine" and "adi assign" commands.
gdb/testsuite/ChangeLog:
2017-08-07 Weimin Pan <weimin.pan@oracle.com>
* gdb.arch/sparc64-adi.exp: New file.
* gdb.arch/sparc64-adi.c: New file.
This adds a test for the "list" command change done in 0d999a6ef0
("List actual code around more than one location").
gdb/ChangeLog:
2017-08-22 Pedro Alves <palves@redhat.com>
* gdb.cp/overload.exp (line_range_pattern): New procedure.
(top level): Add "list all overloads" tests.
This changes install_breakpoint to take a std::unique_ptr rvalue-ref
argument. This makes it clear that install_breakpoint takes ownership
of the pointer, and prevents bugs like the one fixed by the previous
patch.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* breakpoint.h (install_breakpoint): Update.
* breakpoint.c (add_solib_catchpoint): Update.
(install_breakpoint): Change argument to a std::unique_ptr.
(create_fork_vfork_event_catchpoint): Use std::unique_ptr.
(create_breakpoint_sal, create_breakpoint): Update.
(watch_command_1, catch_exec_command_1)
(strace_marker_create_breakpoints_sal): Use std::unique_ptr.
(add_to_breakpoint_chain): Change argument to a std::unique_ptr.
Return the breakpoint.
(set_raw_breakpoint_without_location, set_raw_breakpoint)
(new_single_step_breakpoint): Update.
* break-catch-throw.c (handle_gnu_v3_exceptions): Use
std::unique_ptr.
* break-catch-syscall.c (create_syscall_event_catchpoint): Use
std::unique_ptr.
* break-catch-sig.c (create_signal_catchpoint): Use
std::unique_ptr.
* ada-lang.c (create_ada_exception_catchpoint): Use
std::unique_ptr.
I happened to notice that add_solib_catchpoint allocated the new
catchpoint with "new" but installed a cleanup using "xfree". This
patch fixes the bug by changing the function to use std::unique_ptr
instead.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* breakpoint.c (add_solib_catchpoint): Use std::unique_ptr.
This changes psymtab_search_name to return a unique_xmalloc_ptr and
fixes up its one caller. This allows the removal of some cleanups.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* psymtab.c (psymtab_search_name): Return a unique_xmalloc_ptr.
(lookup_partial_symbol): Update.
This changes rewrite_source_path to return a unique_xmalloc_ptr and
fixes up the callers. This allows removing some cleanups.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* source.h (rewrite_source_path): Return a unique_xmalloc_ptr.
* source.c (rewrite_source_path): Return a unique_xmalloc_ptr.
(find_and_open_source, symtab_to_fullname): Update.
* psymtab.c (psymtab_to_fullname): Update.
This changes gdb_realpath to return a unique_xmalloc_ptr and fixes up
the callers. This allows removing some cleanups. This change by
itself caused xfullpath.exp to fail; and attempting to fix that ran
into various problems (like .get() being optimized out); so this patch
also rewrites xfullpath.exp to be a C++ selftest instead.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* exec.c (exec_file_attach): Update.
* linux-thread-db.c (try_thread_db_load): Update.
* guile/scm-safe-call.c (gdbscm_safe_source_script): Update.
* utils.c (gdb_realpath): Change return type.
(gdb_realpath_keepfile): Update.
(gdb_realpath_check_trailer, gdb_realpath_tests): New functions.
(_initialize_utils): Register the new self test.
* source.c (openp): Update.
(find_and_open_source): Update.
* nto-tdep.c (nto_find_and_open_solib): Update.
* main.c (set_gdb_data_directory): Update.
(captured_main_1): Update.
* dwarf2read.c (dwarf2_get_dwz_file): Update
(dw2_map_symbol_filenames): Update.
* auto-load.c (auto_load_safe_path_vec_update): Update.
(filename_is_in_auto_load_safe_path_vec): Change type of
"filename_realp".
(auto_load_objfile_script): Update.
(file_is_auto_load_safe): Update. Use std::string.
* utils.h (gdb_realpath): Return a gdb::unique_xmalloc_ptr.
testsuite/ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* gdb.gdb/xfullpath.exp: Remove.
This changes gdb_realpath_keepfile to return a unique_xmalloc_ptr, and
fixes up the callers.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* utils.c (gdb_realpath_keepfile): Return a
gdb::unique_xmalloc_ptr.
* exec.c (exec_file_attach): Update.
* utils.h (gdb_realpath_keepfile): Return a
gdb::unique_xmalloc_ptr.
This changes gdb_abspath to return a unique_xmalloc_ptr, and fixes up
the callers. This allows the removal of a cleanup, and also puts
ownership rules into the API, where they belong.
ChangeLog
2017-08-22 Tom Tromey <tom@tromey.com>
* compile/compile.c (compile_file_command): Use
gdb::unique_xmalloc_ptr, std::string.
* utils.c (gdb_abspath): Change return type.
* source.c (openp): Update.
* objfiles.c (allocate_objfile): Update.
* main.c (set_gdb_data_directory): Update.
* utils.h (gdb_abspath): Return a gdb::unique_xmalloc_ptr.
With the following C++ code:
int bar() { return 0;}
int bar(int) { return 0; }
GDB behaves as:
(gdb) list bar
file: "overload.cc", line number: 1
file: "overload.cc", line number: 2
It would be better for GDB to list the actual code around those two
locations, not just print the location. Like:
(gdb) list bar
file: "overload.cc", line number: 1
1 int bar() { return 0;}
2 int bar(int) { return 0; }
file: "overload.cc", line number: 2
1 int bar() { return 0;}
2 int bar(int) { return 0; }
That's what this this commit implements.
Tested on x86-64 GNU/Linux.
gdb/ChangeLog:
2017-08-22 Zhouyi Zhou <zhouzhouyi@gmail.com>
* cli-cmds.c (list_commands): List actual code around more than
one location.
(Ref: https://sourceware.org/ml/gdb/2017-06/msg00048.html)
This patch improves GDB support for function aliases defined with
__attribute__ alias. For example, in the test added by this commit,
there is no reference to "func_alias" in the debug info at all, only
to "func"'s definition:
$ nm ./testsuite/outputs/gdb.base/symbol-alias/symbol-alias | grep " func"
00000000004005ae t func
00000000004005ae T func_alias
$ readelf -w ./testsuite/outputs/gdb.base/symbol-alias/symbol-alias | grep func -B 1 -A 8
<1><db>: Abbrev Number: 5 (DW_TAG_subprogram)
<dc> DW_AT_name : (indirect string, offset: 0x111): func
<e0> DW_AT_decl_file : 1
<e1> DW_AT_decl_line : 27
<e2> DW_AT_prototyped : 1
<e2> DW_AT_type : <0xf8>
<e6> DW_AT_low_pc : 0x4005ae
<ee> DW_AT_high_pc : 0xb
<f6> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<f8> DW_AT_GNU_all_call_sites: 1
So all GDB knows about "func_alias" is from the minsym (elf symbol):
(gdb) p func_alias
$1 = {<text variable, no debug info>} 0x4005ae <func>
(gdb) ptype func_alias
type = int ()
(gdb) p func
$2 = {struct S *(void)} 0x4005ae <func>
(gdb) ptype func
type = struct S {
int field1;
int field2;
} *(void)
The result is that calling func_alias from the command line produces
incorrect results.
This is similar (though not exactly the same) to the glibc
errno/__errno_location/__GI___errno_location situation. On glibc,
errno is defined like this:
extern int *__errno_location (void);
#define errno (*__errno_location ())
with __GI___errno_location being an internal alias for
__errno_location. On my system's libc (F23), I do see debug info for
__errno_location, in the form of name vs linkage name:
<1><95a5>: Abbrev Number: 18 (DW_TAG_subprogram)
<95a6> DW_AT_external : 1
<95a6> DW_AT_name : (indirect string, offset: 0x2c26): __errno_location
<95aa> DW_AT_decl_file : 1
<95ab> DW_AT_decl_line : 24
<95ac> DW_AT_linkage_name: (indirect string, offset: 0x2c21): __GI___errno_location
<95b0> DW_AT_prototyped : 1
<95b0> DW_AT_type : <0x9206>
<95b4> DW_AT_low_pc : 0x20f40
<95bc> DW_AT_high_pc : 0x11
<95c4> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<95c6> DW_AT_GNU_all_call_sites: 1
however that doesn't matter in practice, because GDB doesn't record
demangled names anyway, and so we end up with the exact same situation
covered by the testcase.
So the fix is to make the expression parser find a debug symbol for
the same address as the just-found minsym, when a lookup by name
didn't find a debug symbol by name. We now get:
(gdb) p func_alias
$1 = {struct S *(void)} 0x4005ae <func>
(gdb) p __errno_location
$2 = {int *(void)} 0x7ffff6e92830 <__errno_location>
I've made the test exercise variable aliases too, for completeness.
Those already work correctly, because unlike for function aliases, GCC
emits debug information for variable aliases.
Tested on GNU/Linux.
gdb/ChangeLog:
2017-08-21 Pedro Alves <palves@redhat.com>
PR gdb/19487
* c-exp.y (variable production): Handle function aliases.
* minsyms.c (msymbol_is_text): New function.
* minsyms.h (msymbol_is_text): Declare.
* symtab.c (find_function_alias_target): New function.
* symtab.h (find_function_alias_target): Declare.
gdb/testsuite/ChangeLog:
2017-08-21 Pedro Alves <palves@redhat.com>
PR gdb/19487
* gdb.base/symbol-alias.c: New.
* gdb.base/symbol-alias2.c: New.
* gdb.base/symbol-alias.exp: New.
(Ref: https://sourceware.org/ml/gdb/2017-06/msg00020.html)
Assuming int_t is a typedef to int:
typedef int int_t;
gdb currently loses this expression's typedef:
(gdb) p (int_t) 0
$1 = 0
(gdb) whatis $1
type = int
or:
(gdb) whatis (int_t) 0
type = int
or, to get "whatis" out of the way:
(gdb) maint print type (int_t) 0
...
name 'int'
code 0x8 (TYPE_CODE_INT)
...
This prevents a type printer for "int_t" kicking in, with e.g.:
(gdb) p (int_t) 0
From the manual, we can see that that "whatis (int_t) 0" command
invocation should have printed "type = int_t":
If @var{arg} is a variable or an expression, @code{whatis} prints its
literal type as it is used in the source code. If the type was
defined using a @code{typedef}, @code{whatis} will @emph{not} print
the data type underlying the @code{typedef}.
(...)
If @var{arg} is a type name that was defined using @code{typedef},
@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
That one-level stripping is currently done here, in
gdb/eval.c:evaluate_subexp_standard, handling OP_TYPE:
...
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *type = exp->elts[pc + 1].type;
/* If this is a typedef, then find its immediate target. We
use check_typedef to resolve stubs, but we ignore its
result because we do not want to dig past all
typedefs. */
check_typedef (type);
if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
type = TYPE_TARGET_TYPE (type);
return allocate_value (type);
}
However, this stripping is reachable in both:
#1 - (gdb) whatis (int_t)0 # ARG is an expression with a cast to
# typedef type.
#2 - (gdb) whatis int_t # ARG is a type name.
while only case #2 should strip the typedef. Removing that code from
evaluate_subexp_standard is part of the fix. Instead, we make the
"whatis" command implementation itself strip one level of typedefs
when the command argument is a type name.
We then run into another problem, also fixed by this commit:
value_cast always drops any typedefs of the destination type.
With all that fixed, "whatis (int_t) 0" now works as expected:
(gdb) whatis int_t
type = int
(gdb) whatis (int_t)0
type = int_t
value_cast has many different exit/convertion paths, for handling many
different kinds of casts/conversions, and most of them had to be
tweaked to construct the value of the right "to" type. The new tests
try to exercise most of it, by trying castin of many different
combinations of types. With:
$ make check TESTS="*/whatis-ptype*.exp */gnu_vector.exp */dfp-test.exp"
... due to combinatorial explosion, the testsuite results for the
tests above alone grow like:
- # of expected passes 246
+ # of expected passes 3811
You'll note that the tests exposed one GCC buglet, filed here:
Missing DW_AT_type in DW_TAG_typedef of "typedef of typedef of void"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81267
gdb/ChangeLog:
2017-08-21 Pedro Alves <palves@redhat.com>
* eval.c (evaluate_subexp_standard) <OP_TYPE>: Don't dig past
typedefs.
* typeprint.c (whatis_exp): If handling "whatis", and expression
is OP_TYPE, strip one typedef level. Otherwise don't strip
typedefs here.
* valops.c (value_cast): Save "to" type before resolving
stubs/typedefs. Use that type as resulting value's type.
gdb/testsuite/ChangeLog:
2017-08-21 Pedro Alves <palves@redhat.com>
* gdb.base/dfp-test.c
(d32_t, d64_t, d128_t, d32_t2, d64_t2, d128_t2, v_d32_t, v_d64_t)
(v_d128_t, v_d32_t2, v_d64_t2, v_d128_t2): New.
* gdb.base/dfp-test.exp: Add whatis/ptype/cast tests.
* gdb.base/gnu_vector.exp: Add whatis/ptype/cast tests.
* gdb.base/whatis-ptype-typedefs.c: New.
* gdb.base/whatis-ptype-typedefs.exp: New.
* gdb.python/py-prettyprint.c (int_type, int_type2): New typedefs.
(an_int, an_int_type, an_int_type2): New globals.
* gdb.python/py-prettyprint.exp (run_lang_tests): Add tests
involving typedefs and cast expressions.
* gdb.python/py-prettyprint.py (class pp_int_typedef): New.
(lookup_typedefs_function): New.
(typedefs_pretty_printers_dict): New.
(top level): Register lookup_typedefs_function in
gdb.pretty_printers.
This removes save_inferior_ptid, a cleanup function, in favor of
scoped_restore.
This also fixes a possible (it seems unlikely that it could happen in
practice) memory leak -- save_inferior_ptid should have used
make_cleanup_dtor, because it allocated memory.
I tested this on the buildbot. However, there are two caveats to
this. First, sometimes it seems I misread the results. Second, I
think this patch touches some platforms that can't be tested by the
buildbot. So, extra care seems warranted.
ChangeLog
2017-08-18 Tom Tromey <tom@tromey.com>
Pedro Alves <palves@redhat.com>
* spu-multiarch.c (parse_spufs_run): Use scoped_restore.
* sol-thread.c (sol_thread_resume, sol_thread_wait)
(sol_thread_xfer_partial, rw_common): Use scoped_restore.
* procfs.c (procfs_do_thread_registers): Use scoped_restore.
* proc-service.c (ps_xfer_memory): Use scoped_restore.
* linux-tdep.c (linux_corefile_thread): Remove a cleanup.
(linux_get_siginfo_data): Add "thread" argument. Use
scoped_restore.
* linux-nat.c (linux_child_follow_fork)
(check_stopped_by_watchpoint): Use scoped_restore.
* infrun.c (displaced_step_prepare_throw, write_memory_ptid)
(THREAD_STOPPED_BY, handle_signal_stop): Use scoped_restore.
(restore_inferior_ptid, save_inferior_ptid): Remove.
* btrace.c (btrace_fetch): Use scoped_restore.
* bsd-uthread.c (bsd_uthread_fetch_registers)
(bsd_uthread_store_registers): Use scoped_restore.
* breakpoint.c (reattach_breakpoints, detach_breakpoints): Use
scoped_restore.
* aix-thread.c (aix_thread_resume, aix_thread_wait)
(aix_thread_xfer_partial): Use scoped_restore.
* inferior.h (save_inferior_ptid): Remove.
opcodes/arm-dis.c:print_insn may update disassemble_info.mach to
bfd_mach_arm_unknown unless USER_SPECIFIED_MACHINE_TYPE is marked.
When default_print_insn is called for the first time,
disassemble_info.mach is correctly set in GDB, but arm-dis.c:print_insn
sets it to bfd_mach_arm_unknown. Then, when default_print_insn is
called again (in a loop), it triggers the assert.
The patch fixes the assert by marking USER_SPECIFIED_MACHINE_TYPE so that
opcodes won't reset disassemble_info.mach.
gdb:
2017-08-18 Yao Qi <yao.qi@linaro.org>
PR tdep/21818
* arm-tdep.c (gdb_print_insn_arm): Mark
USER_SPECIFIED_MACHINE_TYPE if exec_bfd isn't NULL.
This patch uses GDB self test in GDBserver. The self tests are run if
GDBserver is started with option --selftest.
gdb:
2017-08-18 Yao Qi <yao.qi@linaro.org>
* NEWS: Mention GDBserver's new option "--selftest".
* Makefile.in (SFILES): Remove selftest.c, add common/selftest.c.
* selftest.c: Move it to common/selftest.c.
* selftest.h: Move it to common/selftest.h.
* selftest-arch.c (reset): New function.
(tests_with_arch): Call reset.
gdb/gdbserver:
2017-08-18 Yao Qi <yao.qi@linaro.org>
* Makefile.in (OBS): Add selftest.o.
* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
* configure, config.in: Re-generated.
* server.c: Include common/sefltest.h.
(captured_main): Handle option --selftest.
gdb/testsuite:
2017-08-18 Yao Qi <yao.qi@linaro.org>
* gdb.server/unittest.exp: New.
gdb/doc:
2017-08-18 Yao Qi <yao.qi@linaro.org>
* gdb.texinfo (Server): Document "--selftest".
The next patch moves selftest.c to common/selftest.c, so that GDBserver
can use it as well. However selftest.c uses something isn't "portable" on
GDB and GDBserver.
First, this patch removes QUIT. I don't expect that we type ctrl-c during
self/unit tests, and each test shouldn't take long time. Secondly, I
replace exception_fprintf and printf_filtered with debug_printf. Verified
that unit tests still catch fails.
gdb:
2017-08-18 Yao Qi <yao.qi@linaro.org>
* selftest.c (run_tests): Don't call QUIT. Call debug_printf
instead of exception_fprintf and printf_filtered.
The heap-allocated 'old_source_verbose' local was accidentally left
behind by commit 2ec845e758 ("More uses of scoped_restore").
Valgrind caught it, like:
==20123== 8 bytes in 1 blocks are definitely lost in loss record 4,609 of 13,785
==20123== at 0x4C2A988: calloc (vg_replace_malloc.c:711)
==20123== by 0x60A2F8: xcalloc (common-utils.c:84)
==20123== by 0x4CDBE5: build_command_line(command_control_type, char const*) (cli-script.c:159)
==20123== by 0x4CDC32: get_command_line(command_control_type, char const*) (cli-script.c:172)
==20123== by 0x5230F1: python_command(char*, int) (python.c:421)
==20123== by 0x4C61AD: do_cfunc(cmd_list_element*, char*, int) (cli-decode.c:106)
==20123== by 0x4C911F: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1902)
==20123== by 0x7CA79E: execute_command(char*, int) (top.c:650)
==20123== by 0x695A0C: command_handler(char*) (event-top.c:590)
==20123== by 0x7CA33F: read_command_file(_IO_FILE*) (top.c:461)
==20123== by 0x4D0C3A: script_from_file(_IO_FILE*, char const*) (cli-script.c:1584)
==20123== by 0x4C2727: source_script_from_stream(_IO_FILE*, char const*, char const*) (cli-cmds.c:589)
gdb/ChangeLog:
2017-08-17 Pedro Alves <palves@redhat.com>
* cli/cli-cmds.c (source_command): Delete 'old_source_verbose'
local.
This plugs a couple leaks introduced by commit fff8551cf5
("dwarf2read.c: Some C++fycation, use std::vector, std::unique_ptr").
The first problem is that nothing owns the temporary line_header that
handle_DW_AT_stmt_list creates in some cases. Before the commit
mentioned above, the temporary line_header case used to have:
make_cleanup (free_cu_line_header, cu);
and that cleanup was assumed to be run by process_die, after
handle_DW_AT_stmt_list returns and before child DIEs were processed.
The second problem is found in setup_type_unit_groups: that also used
to have a similar make_cleanup call, and ended up with a similar leak
after the commit mentioned above.
Fix both cases by recording in dwarf2_cu whether a line header is
owned by the cu/die, and have process_die explicitly free the
line_header if so, making use of a new RAII object that also replaces
the reset_die_in_process cleanup, while at it.
Thanks to Philippe Waroquiers for noticing the leak and pointing in
the right direction.
gdb/ChangeLog:
2017-08-17 Pedro Alves <palves@redhat.com>
* dwarf2read.c (struct dwarf2_cu) <line_header_die_owner>: New
field.
(reset_die_in_process): Delete, replaced by ...
(process_die_scope): ... this new class. Make it responsible for
freeing cu->line_header too.
(process_die): Use process_die_scope.
(handle_DW_AT_stmt_list): Record the line header's owner CU/DIE in
cu->line_header_die_owner. Don't release the line header if it's
owned by the CU.
(setup_type_unit_groups): Make the CU/DIE own the line header.
Don't release the line header here.
Detected this leak with valgrind memcheck:
==30840== 194 bytes in 1 blocks are definitely lost in loss record 9,138 of 10,922
==30840== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30840== by 0x80DF82: bfd_malloc (libbfd.c:193)
==30840== by 0x80E12D: bfd_zmalloc (libbfd.c:278)
==30840== by 0x819E80: elf_x86_64_get_synthetic_symtab (elf64-x86-64.c:6835)
==30840== by 0x4F7B01: elf_read_minimal_symbols(objfile*, int, elfinfo const*) (elfread.c:1124)
==30840== by 0x4F7CE7: elf_symfile_read(objfile*, enum_flags<symfile_add_flag>) (elfread.c:1182)
==30840== by 0x7557FC: read_symbols(objfile*, enum_flags<symfile_add_flag>) (symfile.c:861)
==30840== by 0x755EE1: syms_from_objfile_1(objfile*, section_addr_info*, enum_flags<symfile_add_flag>) (symfile.c:1062)
We perform a dynamic allocation in
elf64-x86-64.c:elf_x86_64_get_synthetic_symtab
s = *ret = (asymbol *) bfd_zmalloc (size);
that appear to never get freed.
gdb:
2017-08-17 Alex Lindsay <alexlindsay239@gmail.com>
* elfread.c (elf_read_minimal_symbols): xfree synthsyms.
Currently, "layout asm" is not so useful as "layout src" with Single-Key mode:
you have to use multi-key commands like "ni" and "si" to do single-stepping.
This patch adds, in addition to "next" and "step" commands, corresponding
assembly-level ones - "nexti" and "stepi" - to Single-Key mode, with the
shortcuts of "o" (from "step Over") and "i" (from "Step Into") respectively.
gdb/ChangeLog:
* tui/tui.c (tui_commands): Add "nexti" and "stepi" to the Single-Key
mode command list.
gdb/doc/ChangeLog:
* gdb.texinfo (TUI Single Key Mode): Document the new shortcuts in
Single-Key mode.