Commit Graph

41761 Commits

Author SHA1 Message Date
Tom Tromey 3fba72f761 Avoid shadowing in linux-tdep.c
This is one of the uglier changes to avoid local shadowing.  Because
obstack.h uses statement expressions, in some cases a nested obstack
call will result in shadowing.  Rather than try to fix obstack.h, this
patch simply works around the one instance of this problem.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* linux-tdep.c (linux_make_mappings_corefile_notes): Introduce new
	variable "size".
2018-10-04 22:51:47 -06:00
Tom Tromey 795afcbbb4 Use std::string in mdebugread.c
This changes a couple of spots in mdebugread to use std::string rather
than manual management.  This is simpler, and also avoids shadowing by
renaming the variable in question.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* mdebugread.c (parse_partial_symbols): Use std::string.
2018-10-04 22:51:46 -06:00
Tom Tromey da4ae14a4d Avoid shadowing in gdbserver
This fixes a few instances of shadowing in gdbserver.  These are all
simple fixes.

gdb/gdbserver/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* server.c (handle_status): Rename inner "thread".
	(process_serial_event): Declare "res" in 'm' case.
	* linux-low.c (last_thread_of_process_p, find_lwp_pid)
	(iterate_over_lwps): Rename inner "thread".
	(linux_qxfer_libraries_svr4): Rename inner "len".
	* gdbthread.h (find_thread_in_random): Rename inner "thread".
2018-10-04 22:51:46 -06:00
Tom Tromey b926417afa Simple -Wshadow=local fixes
This fixes all the straightforward -Wshadow=local warnings in gdb.  A
few standard approaches are used here:

* Renaming an inner (or outer, but more commonly inner) variable;
* Lowering a declaration to avoid a clash;
* Moving a declaration into a more inner scope to avoid a clash,
  including the special case of moving a declaration into a loop header.

I did not consider any of the changes in this patch to be particularly
noteworthy, though of course they should all still be examined.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* ctf.c (SET_ARRAY_FIELD): Rename "u32".
	* p-valprint.c (pascal_val_print): Split inner "i" variable.
	* xtensa-tdep.c (xtensa_push_dummy_call): Declare "i" in loop
	header.
	* xstormy16-tdep.c (xstormy16_push_dummy_call): Declare "val" in
	more inner scope.
	* xcoffread.c (read_xcoff_symtab): Rename inner "symbol".
	* varobj.c (varobj_update): Rename inner "newobj",
	"type_changed".
	* valprint.c (generic_emit_char): Rename inner "buf".
	* valops.c (find_overload_match): Rename inner "temp".
	(value_struct_elt_for_reference): Declare "v" in more inner
	scope.
	* v850-tdep.c (v850_push_dummy_call): Rename "len".
	* unittests/array-view-selftests.c (run_tests): Rename inner
	"vec".
	* tui/tui-stack.c (tui_show_frame_info): Declare "i" in loop
	header.
	* tracepoint.c (merge_uploaded_trace_state_variables): Declare
	"tsv" in more inner scope.
	(print_one_static_tracepoint_marker): Rename inner
	"tuple_emitter".
	* tic6x-tdep.c (tic6x_analyze_prologue): Declare "inst" lower.
	(tic6x_push_dummy_call): Don't redeclare "addr".
	* target-float.c: Declare "dto" lower.
	* symtab.c (lookup_local_symbol): Rename inner "sym".
	(find_pc_sect_line): Rename inner "pc".
	* stack.c (print_frame): Don't redeclare "gdbarch".
	(return_command): Rename inner "gdbarch".
	* s390-tdep.c (s390_prologue_frame_unwind_cache): Renam inner
	"sp".
	* rust-lang.c (rust_internal_print_type): Declare "i" in loop
	header.
	* rs6000-tdep.c (ppc_process_record): Rename inner "addr".
	* riscv-tdep.c (riscv_push_dummy_call): Declare "info" in inner
	scope.
	* remote.c (remote_target::update_thread_list): Don't redeclare
	"tp".
	(remote_target::process_initial_stop_replies): Rename inner
	"thread".
	(remote_target::remote_parse_stop_reply): Don't redeclare "p".
	(remote_target::wait_as): Don't redeclare "stop_reply".
	(remote_target::get_thread_local_address): Rename inner
	"result".
	(remote_target::get_tib_address): Likewise.
2018-10-04 22:51:45 -06:00
Simon Marchi 1f88d0c87c Fix undefined behavior, don't pass NULL to fwrite
If a vector that we try to write using file_write is empty, we may end
up passing NULL to fwrite, which triggers UBSan:

  .../gdb/dwarf-index-write.c:73:14: runtime error: null pointer passed as argument 1, which is declared to never be null

Avoid it by skipping the write if the vector is empty.

gdb/ChangeLog:

	* dwarf-index-write.c (file_write): Don't write if the vector is
	empty.
2018-10-04 22:59:44 -04:00
Tom de Vries 5c4481cc9b [gdb/python] Fix cpychecker error in pspy_solib_name
When using cpychecker, we run into:
...
gdb/python/py-progspace.c: \
  In function ‘PyObject* pspy_solib_name(PyObject*, PyObject*)’:
gdb/python/py-progspace.c:370:25: error: Mismatching type in call to \
  PyArg_ParseTuple with format code "K" [-Werror]
   if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc))
  argument 3 ("&pc") had type
    "gdb_py_longest *" (pointing to 64 bits)
  but was expecting
    "long long unsigned int *" (pointing to 64 bits)
  for format code "K"
...

Fix this fixing the type of the variable.

Build and reg-tested on x86_64-linux.

2018-10-05  Tom de Vries  <tdevries@suse.de>

	* python/py-progspace.c (pspy_solib_name): Fix type mismatch in
	PyArg_ParseTuple call.
2018-10-05 00:20:08 +02:00
Tom de Vries 96b1ad866b [gdb/python] Fix cpychecker error in recpy_bt_goto
When using cpychecker, we run into this error:
...
gdb/python/py-record-btrace.c: \
  In function ‘PyObject* recpy_bt_goto(PyObject*, PyObject*)’:
gdb/python/py-record-btrace.c:783:25: error: Mismatching type in call to \
  PyArg_ParseTuple with format code "O" [-Werror]
   if (!PyArg_ParseTuple (args, "O", &obj))
  argument 3 ("&obj") had type
    "const struct recpy_element_object * *"
  but was expecting
    "struct PyObject * *"
  for format code "O"
...

Fix this by using a new variable of the expected type instead.

Build and reg-tested on x86_64-linux.

2018-10-05  Tom de Vries  <tdevries@suse.de>

	* python/py-record-btrace.c (recpy_bt_goto): Fix type mismatch in
	PyArg_ParseTuple call.
2018-10-05 00:20:07 +02:00
Joel Brobecker d2f7dcb218 reformat parameters of gdb/psymtab.c::recursively_search_psymtabs
This is just to make sure one of the parameters doesn't end past
the 80 characters limit. And while at it, since all parameters were
on their own line except the first two that were listed on the same
line, it felf more consistent to just split them to have each and
every parameter on their own line.

gdb/ChangeLog:

        * psymtab.c (recursively_search_psymtabs): Reformat parameters
        to avoid exceeding 80 characters per line limit.

Tested by rebuilding GDB on x86_64-linux.
2018-10-04 18:04:13 -04:00
Tom Tromey 5ca8c39f05 Simplify complaints even more
This removes the SHORT_FIRST_MESSAGE case from complaints, leaving
only a single case.  This allows for the removal of the last argument
to clear_complaints, and also simplifies complaint_internal, removing
an extra allocation in the process.

After this, the "./gdb -iex 'set complaint 1' -nx ./gdb" example will
show:

    Reading symbols from ./gdb...
    During symbol reading: .debug_ranges entry has start address of zero [in module /home/tromey/gdb/build/gdb/gdb]
    During symbol reading: DW_AT_low_pc 0x0 is zero for DIE at 0x17116c1 [in module /home/tromey/gdb/build/gdb/gdb]
    During symbol reading: .debug_line address at offset 0xa22f5 is 0 [in module /home/tromey/gdb/build/gdb/gdb]
    During symbol reading: unsupported tag: 'DW_TAG_unspecified_type'
    During symbol reading: const value length mismatch for 'std::ratio<1, 1000000000>::num', got 8, expected 0

This is a bit wordier but, I think, a bit more clear, as the form of
the message no longer depends on precisely when it was emitted.  In
particular if you compare to the output from the 'Clean up "Reading
symbols" output' patch, you can see that earlier gdb would switch from
the prefix-less form to the "During symbol reading" form at a point
that is meaningless to the user (specifically, after psymtab reading
is done and gdb tries to expand a CU).

2018-10-04  Tom Tromey  <tom@tromey.com>

	* symfile.c (syms_from_objfile_1, finish_new_objfile)
	(reread_symbols): Update.
	* complaints.h (clear_complaints): Remove argument.
	* complaints.c (enum complaint_series): Remove.
	(series): Remove global.
	(complaint_internal): Update.
	(clear_complaints): Remove argument.

gdb/testsuite/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* gdb.cp/maint.exp (test_invalid_name): Update expected output.
	* gdb.gdb/complaints.exp (test_short_complaints): Remove.
	(test_initial_complaints, test_empty_complaints): Update.
	* gdb.dwarf2/dw2-stack-boundary.exp: Update.
2018-10-04 13:40:10 -06:00
Tom Tromey e79497a160 Only print "no debugging symbols" message once
The "no debugging symbols" message can be confusing in some cases, for
example when gdb finds separate debug info for an objfile, but the
separate debug info does not contain symbols.

For example:

    (gdb) file /bin/ls
    Reading symbols from /bin/ls...
    Reading symbols from .gnu_debugdata for /usr/bin/ls...
    (No debugging symbols found in .gnu_debugdata for /usr/bin/ls)
    (No debugging symbols found in /bin/ls)

Here, I think the second "no debugging symbols" message is redundant
and confusing.

This patch changes gdb to only emit this message when the objfile in
question does not have a separate debug file.  So, in the example
above, the output would now read:

    (gdb) file /bin/ls
    Reading symbols from /bin/ls...
    Reading symbols from .gnu_debugdata for /usr/bin/ls...
    (No debugging symbols found in .gnu_debugdata for /usr/bin/ls)

2018-10-04  Tom Tromey  <tom@tromey.com>

	* symfile.c (symbol_file_add_with_addrs): Do not print "no
	debugging symbols" message if there is a separate debug objfile.
2018-10-04 13:40:10 -06:00
Tom Tromey 3453e7e409 Clean up "Reading symbols" output
This patch is another attempt to fix PR cli/19551.  Unlike my previous
attempt, it doesn't print progress.  Instead, it just changes some
messages and adds newlines to make the output a bit nicer.

It also removes the "done." text that was previously emitted.  The
idea here is that it is obvious when gdb is done reading debug info,
as it starts then doing something else; and that while this message
did not provide much benefit to users, it did make it harder to make
the output clean.

After this change the output from "./gdb -iex 'set complaint 1' -nx ./gdb"
reads:

    Reading symbols from ./gdb...
    .debug_ranges entry has start address of zero [in module /home/tromey/gdb/build/gdb/gdb]
    DW_AT_low_pc 0x0 is zero for DIE at 0x17116c1 [in module /home/tromey/gdb/build/gdb/gdb]
    .debug_line address at offset 0xa22f5 is 0 [in module /home/tromey/gdb/build/gdb/gdb]
    During symbol reading, unsupported tag: 'DW_TAG_unspecified_type'.
    During symbol reading, const value length mismatch for 'std::ratio<1, 1000000000>::num', got 8, expected 0.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	PR cli/19551:
	* symfile.c (symbol_file_add_with_addrs): Update output.
	* psymtab.c (require_partial_symbols): Update output.

gdb/testsuite/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	PR cli/19551:
	* lib/mi-support.exp (mi_gdb_file_cmd): Update.
	* lib/gdb.exp (gdb_file_cmd): Update.
	* gdb.stabs/weird.exp (print_weird_var): Update.
	* gdb.server/solib-list.exp: Update.
	* gdb.multi/remove-inferiors.exp (test_remove_inferiors): Update.
	* gdb.mi/mi-cli.exp: Update.
	* gdb.linespec/linespec.exp: Update.
	* gdb.dwarf2/dw2-stack-boundary.exp: Update.
	* gdb.dwarf2/dw2-objfile-overlap.exp: Update.
	* gdb.cp/cp-relocate.exp: Update.
	* gdb.base/sym-file.exp: Update.
	* gdb.base/relocate.exp: Update.
	* gdb.base/readnever.exp: Update.
	* gdb.base/print-symbol-loading.exp (test_load_core): Update.
	* gdb.base/kill-detach-inferiors-cmd.exp: Update.
	* gdb.base/dbx.exp (gdb_file_cmd): Update.
	* gdb.base/code_elim.exp: Update.
	* gdb.base/break-unload-file.exp (test_break): Update.
	* gdb.base/break-interp.exp (test_attach_gdb): Update.
	* gdb.base/break-idempotent.exp (force_breakpoint_re_set):
	Update.
	* gdb.base/attach.exp (do_attach_tests): Update.
	* gdb.base/sepdebug.exp: Update.
	* gdb.python/py-section-script.exp: Update.
2018-10-04 13:40:10 -06:00
Tom Tromey 6afcf761c2 Make complaint output prettier
Currently complaints are not always printed with a newline.  For
example, when I run gdb on itself, I see output like:

    (gdb) set complaints 5
    (gdb) file ./gdb/gdb
    Reading symbols from ./gdb/gdb...DW_AT_low_pc 0x0 is zero for DIE at 0x437dd4 [in module /home/tromey/gdb/build/gdb/gdb]....debug_line address at offset 0x21bf9 is 0 [in module /home/tromey/gdb/build/gdb/gdb]...DW_AT_low_pc 0x0 is zero for DIE at 0x5a85dd [in module /home/tromey/gdb/build/gdb/gdb]....debug_line address at offset 0x2dc2d is 0 [in module /home/tromey/gdb/build/gdb/gdb]...DW_AT_low_pc 0x0 is zero for DIE at 0xab6033 [in module /home/tromey/gdb/build/gdb/gdb]....debug_line address at offset 0x4f683 is 0 [in module /home/tromey/gdb/build/gdb/gdb]...DW_AT_low_pc 0x0 is zero for DIE at 0x10028f0 [in module /home/tromey/gdb/build/gdb/gdb]....debug_line address at offset 0x75edf is 0 [in module /home/tromey/gdb/build/gdb/gdb]...DW_AT_low_pc 0x0 is zero for DIE at 0x1021364 [in module /home/tromey/gdb/build/gdb/gdb]....debug_line address at offset 0x76f62 is 0 [in module /home/tromey/gdb/build/gdb/gdb]...done.

That's one very long line.  I find it quite difficult to read that,
and I thought it would be better with some newlines, which is what
this patch does.  Now the output looks like:

    (gdb) file ./gdb
    Reading symbols from ./gdb...
    DW_AT_low_pc 0x0 is zero for DIE at 0x437dd4 [in module /home/tromey/gdb/build/gdb/gdb]
    .debug_line address at offset 0x21bf9 is 0 [in module /home/tromey/gdb/build/gdb/gdb]
    DW_AT_low_pc 0x0 is zero for DIE at 0x5a85dd [in module /home/tromey/gdb/build/gdb/gdb]
    .debug_line address at offset 0x2dc2d is 0 [in module /home/tromey/gdb/build/gdb/gdb]
    done.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	PR cli/22234:
	* complaints.c: Emit \n.

gdb/testsuite/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	PR cli/22234:
	* gdb.dwarf2/dw2-stack-boundary.exp: Update expected output.
	* gdb.gdb/complaints.exp (test_short_complaints): Update expected
	output.
2018-10-04 13:40:10 -06:00
Tom Tromey 22068491ad Use filtered printing when reading symbols
While working on this series, I found some unfiltered prints that
didn't make sense -- many things, like complaints, are filtered, while
their context (in this case the "Reading symbols ..."  messages) may
not be.

This patch changes some spots in symbol reading to use filtered
prints.  I think this is preferable overall; in fact I'd go farther
and say that unfiltered printing should just be removed.

One of these spots was not strictly related (the change to
dump_psymtab), but I left it in partly because it makes psymtab.c
"unfiltered-clean", and partly because it is an example of filtered
and unfiltered printing being mixed in the same function.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* symfile.c (symbol_file_add_with_addrs, symbol_file_clear)
	(separate_debug_file_exists, find_separate_debug_file)
	(add_symbol_file_command, reread_symbols, allocate_symtab)
	(allocate_compunit_symtab): Use filtered printing, not
	unfiltered.
	* psymtab.c (require_partial_symbols, dump_psymtab)
	(allocate_psymtab): Use filtered printing, not unfiltered.
2018-10-04 13:40:10 -06:00
Tom Tromey 9fdd7193e7 Fix off-by-one error in complaint_internal
complaint_internal had an off-by-one error, where it would allow one
extra complaint to be issued.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* complaints.c (complaint_internal): Correctly check complaint
	count.
2018-10-04 13:40:10 -06:00
Tom Tromey 3f2cf4dcd5 Remove some leftovers from complaints
There were a couple of leftovers from earlier patches in
complaints.[ch].  This removes them.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* complaints.h (struct complaints): Remove declaration.
	* complaints.c (clear_complaints): Remove an unused variable.
2018-10-04 13:40:10 -06:00
Tom Tromey fef1b2933d Avoid pagination in attach.exp
While re-testing the complaint series, I saw some unresolved tests in
attach.exp.  In particular, the tests were failing because the pager
was active.

This is partly a new problem, introduced because that series changes
some prints from unfiltered to filtered.  However, it is also a latent
bug, which you can see by shrinking your window very small and then
running the test.

This patch avoids the problem by passing -quiet to gdb and arranging
to set the window height and width in one other test.

Arguably instead of -quiet we should disable the pager during gdb's
welcome message.  I can do that if it seems desirable; but meanwhile
this patch is safe.

gdb/testsuite/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* gdb.base/attach.exp (test_command_line_attach_run): Use -quiet;
	set width and height to 0.
	(test_command_line_attach_run): Use -quiet.
2018-10-04 11:01:53 -06:00
Rainer Orth 4f9bdf7fa5 Add self to gdb/MAINTAINERS
Joel asked me to add myself to gdb/MAINTAINERS.  Done as follows, fixing two
incorrectly indented lines on the way.  Installed on master.

	* MAINTAINERS (Write After Approval): Add self.
2018-10-04 14:10:16 +02:00
Tom Tromey 875e539851 Avoid two uninitialized warnings from gcc
This avoids a couple of uninitialized warnings from gcc by
initializing the object in question.  The one in coffread.c seems like
it could be a latent bug.  The one in scm-value.c is harmless, but GCC
can't see that.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* guile/scm-value.c (gdbscm_value_to_string): Initialize
	"buffer_contents".
	* coffread.c (coff_symtab_read): Initialize "newobj".
2018-10-03 20:55:52 -06:00
Simon Marchi 8634679f82 Remove struct keyword in range-based for
I get the following error with gcc 6.3.0:

/home/simark/src/binutils-gdb/gdb/dwarf2read.c: In function 'void read_func_scope(die_info*, dwarf2_cu*)':
/home/simark/src/binutils-gdb/gdb/dwarf2read.c:13838:12: error: types may not be defined in a for-range-declaration [-Werror]
       for (struct symbol *sym : template_args)
            ^~~~~~

Removing the struct keyword fixes it.

gdb/ChangeLog:

	* dwarf2read.c (read_func_scope): Remove struct keyword in
	range-based for.
2018-10-03 17:51:35 -04:00
Tom Tromey f35d5adea1 Add --enable-ubsan
This adds --enable-ubsan to gdb's configure.  By default it is enabled
in development mode, and disabled otherwise.  This passes both
-fsanitize=undefined and -fno-sanitize-recover=undefined to
compilations, so that undefined behavior violations will be sure to
cause test failures.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* README: Mention --enable-ubsan.
	* NEWS: Mention --enable-ubsan.
	* acinclude.m4: Include sanitize.m4.
	* configure: Rebuild.
	* configure.ac: Call AM_GDB_UBSAN.
	* sanitize.m4: New file.

gdb/doc/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Configure Options): Document --enable-ubsan.
2018-10-03 15:19:06 -06:00
Tom Tromey 1dffa580e7 Avoid undefined behavior in expression dumping
-fsanitize=undefined pointed out undefined behavior in
dump_raw_expression like:

    runtime error: load of value 2887952, which is not a valid value for type 'exp_opcode'

dump_raw_expression will try to print the opcode for each element of
the expression, even when it is not valid.  To allow this, but have it
avoid undefined behavior, this patch sets the underlying type of enum
exp_opcode, and arranges for op_name to handle invalid opcodes more
nicely.

Before this patch, debug-expr.exp shows:

Dump of expression @ 0x60f000007750, before conversion to prefix form:
	Language c, 8 elements, 16 bytes each.
	Index                Opcode         Hex Value  String Value
	    0               OP_TYPE  89  Y...............
   <unknown 3851920>  107820862850704  ..:..b..........
	    2               OP_TYPE  89  Y...............
	    3          OP_VAR_VALUE  40  (...............
	    4     <unknown 2807568>  107820861806352  ..*..b..........
	    5     <unknown 2806368>  107820861805152  `.*..b..........
	    6          OP_VAR_VALUE  40  (...............
	    7      UNOP_MEMVAL_TYPE  57  9...............

Afterward, the output is:

Dump of expression @ 0x4820f90, before conversion to prefix form:
	Language c, 8 elements, 16 bytes each.
	Index                Opcode         Hex Value  String Value
	    0               OP_TYPE  89  Y...............
	    1   unknown opcode: 176  75444400  .0..............
	    2               OP_TYPE  89  Y...............
	    3          OP_VAR_VALUE  40  (...............
	    4               OP_BOOL  74616912  P.r.............
	    5   unknown opcode: 128  74615680  ..r.............
	    6          OP_VAR_VALUE  40  (...............
	    7      UNOP_MEMVAL_TYPE  57  9...............

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* expression.h (enum exp_opcode): Use uint8_t as base type.
	* expprint.c (op_name): Handle invalid opcodes.
2018-10-03 15:19:06 -06:00
Tom Tromey 5e70ee0905 Avoid undefined behavior in ada_operator_length
-fsanitize=undefined pointed out this error:

    runtime error: load of value 2887952, which is not a valid value for type 'exp_opcode'

This happens in gdb.ada/complete.exp when processing "complete p
my_glob".  This does not parse, so the Ada parser throws an exception;
but then the code in parse_exp_in_context_1 accepts the expression
anyway.  However, as no elements have been written to the expression,
undefined behavior results.

The fix is to notice this case in parse_exp_in_context_1.  This patch
also adds an assertion to prefixify_expression to enforce this
pre-existing constraint.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* parse.c (prefixify_expression): Add assert.
	(parse_exp_in_context_1): Throw exception if the expression is
	empty.
2018-10-03 15:19:06 -06:00
Tom Tromey 4dd1b46077 Avoid undefined behavior in read_signed_leb128
-fsanitize=undefined pointed out that read_signed_leb128 had an
undefined left-shift when processing the final byte of a 64-bit leb:

    runtime error: left shift of 127 by 63 places cannot be represented in type 'long int'

and an undefined negation:

    runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself

Both of these problems are readily avoided by havinng
read_signed_leb128 work in an unsigned type, and then casting to the
signed type at the return.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (read_signed_leb128): Work in ULONGEST.
2018-10-03 15:19:06 -06:00
Tom Tromey 20562150d8 Avoid undefined behavior in parse_number
-fsanitize=undefined pointed out that c-exp.y relied on undefined
behavior here:

      if (c != 'l' && c != 'u')
	n *= base;

...when a large hex constant "just fit" into a LONGEST, causing the
high bit to be set.

This fixes the problem by having the function work in an unsigned
type.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* c-exp.y (parse_number): Work in unsigned.  Remove casts.
2018-10-03 15:19:06 -06:00
Tom Tromey d359392f97 Avoid undefined behavior in read_subrange_type
-fsanitize=undefined pointed out an undefined shift of a negative
value in read_subrange_type.  The fix is to do the work in an unsigned
type, where this is defined.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (read_subrange_type): Make "negative_mask"
	unsigned.
2018-10-03 15:19:06 -06:00
Tom Tromey 0101665f86 Avoid undefined behavior in extract_integer
-fsanitize=undefined showed that extract_integer could left-shift a
negative value, which is undefined.  This patch fixes the problem by
doing all the work in an unsigned type.  This relies on
implementation-defined behavior, but I tend to think we are on safe
ground there.  (Also, if need be, violations of this could probably be
detected, either by configure or by a static_assert.)

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* findvar.c (extract_integer): Do work in an unsigned type.
2018-10-03 15:19:06 -06:00
Tom Tromey ad69edbb4b Use unsigned as base type for some enums
-fsanitize=undefined complains about using operator~ on various enum
types that are used with DEF_ENUM_FLAGS_TYPE.  This patch fixes these
problems by explicitly setting the base type for these enums to
unsigned.  It also adds a static assert to enum_flags to ensure that
future enums used this way have an unsigned underlying type.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* common/enum-flags.h (enum_flags::operator~): Add static assert.
	* symfile-add-flags.h (enum symfile_add_flag): Use unsigned as
	base type.
	* objfile-flags.h (enum objfile_flag): Use unsigned as base type.
	* gdbtypes.h (enum type_instance_flag_value): Use unsigned as base
	type.
	* c-lang.h (enum c_string_type_values): Use unsigned as base
	type.
	* btrace.h (enum btrace_thread_flag): Use unsigned as base type.
2018-10-03 15:19:06 -06:00
Tom Tromey 780942fc24 Change dwarf2_frame_state_reg_info::reg to be std::vector
This changes dwarf2_frame_state_reg_info::reg to be a std::vector.
This avoids passing NULL to memcpy in the copy constructor when the
original object does not have any registers.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* dwarf2-frame.h (dwarf2_frame_state_reg_info)
	<~dwarf2_frame_state_reg_info>: Update.
	<dwarf2_frame_state_reg_info>: Update.
	<alloc_regs>: Add assertion.  Update.
	<reg>: Now a std::vector.
	<num_regs>: Remove.
	<swap>: Update.
	* dwarf2-frame.c (dwarf2_restore_rule, execute_cfa_program)
	(execute_cfa_program_test, dwarf2_frame_cache): Update.
2018-10-03 15:19:06 -06:00
Tom Tromey 10657c047e Do not pass NULL to memcpy
-fsanitize=undefined pointed out a spot that passes NULL to memcpy,
which is undefined behavior according to the C standard.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

	* namespace.c (add_using_directive): Don't pass NULL to memcpy.
2018-10-03 15:19:06 -06:00
Philippe Waroquiers 34c0fc000f tid-parse.c tid_is_in_list correct 'See' comment.
Refer to tid-parse.h and tid_is_in_list is explained there.
2018-10-03 22:34:33 +02:00
Sandra Loosemore ca98345e0b Skip gdb ifunc tests on targets that don't support this feature.
2018-10-03  Sandra Loosemore  <sandra@codesourcery.com>

	* lib/gdb.exp (skip_ifunc_tests): New.
	* gdb.base/gnu-ifunc.exp: Skip if no ifunc support.  Handle
	other compile failures.
	* gdb.compile/compile-ifunc.exp: Skip if no ifunc support.
2018-10-03 09:16:53 -07:00
Tom Tromey 2398abf8bc Use pulongest in aarch64-linux-tdep.c
I tried a build on macOS today and it failed due to a mismatch between
the printf format and the type in aarch64-linux-tdep.c.  This patch
fixes the problem by using pulongest and %s rather than %ld.

gdb/ChangeLog
2018-10-02  Tom Tromey  <tom@tromey.com>

	* aarch64-linux-tdep.c (aarch64_linux_sigframe_init): Use pulongest.
2018-10-02 19:30:19 -06:00
John Darrington c1168a2f66 Allow remote debugging over a Unix local domain socket.
Extend the "target remote" and "target extended-remote" commands
such that if the filename provided is a Unix local domain (AF_UNIX)
socket, then it'll be treated as such, instead of trying to open
it as if it were a character device.

gdb/ChangeLog:
	* NEWS: Mention changed commands.
	* ser-uds.c: New file.
	* configure.ac (SER_HARDWIRE): Add ser-uds.o.
	* configure: Regenerate.
	* Makefile.in: Add new file.
	* serial.c (serial_open): Check if filename is a socket
	  and lookup the appropriate interface accordingly.

gdb/doc/ChangeLog:
	* gdb.texinfo (Remote Connection Commands): Describe
	  the changes to target remote and target extended-remote
	  relating to Unix domain sockets.
2018-10-02 16:10:57 +02:00
Simon Marchi ff34e6ae38 Fix is_amd64_regs_target check in i386-avx512.exp
As reported by Jan here:

  https://sourceware.org/ml/gdb-patches/2018-09/msg00831.html

the check that sets the number of available registers is backwards.

gdb/testsuite/ChangeLog:

	* gdb.arch/i386-avx512.exp: Fix setting of nr_regs based on
	is_amd64_regs_target.
2018-10-01 12:02:57 -04:00
Alan Hayward 6bb8890e2c Add aarch64-sighandler-regs.exp test
Add Aarch64 test to check register values of a previous frame
can be shown correctly across a signal.

gdb/testsuite/ChangeLog:

	* gdb.arch/aarch64-sighandler-regs.c: New test.
	* gdb.arch/aarch64-sighandler-regs.exp: New file.
	* lib/gdb.exp (skip_aarch64_sve_tests): New proc.
2018-10-01 14:51:09 +01:00
Alan Hayward 05c71722fc Aarch64: Detect FP regs in signal frame
Both the VFP and SVE registers may be contained within the reserved space of
the sigcontext and can be found by seraching for MAGIC values. Detect these
and add the registers (including pseudos) to the trad frame cache.

gdb/
	* aarch64-linux-tdep.c (AARCH64_SIGCONTEXT_RESERVED_OFFSET): Add
	define.
	(AARCH64_EXTRA_MAGIC): Likewise.
	(AARCH64_FPSIMD_MAGIC): Likewise.
	(AARCH64_SVE_MAGIC): Likewise.
	(AARCH64_EXTRA_DATAP_OFFSET): Likewise.
	(AARCH64_FPSIMD_FPSR_OFFSET): Likewise.
	(AARCH64_FPSIMD_FPCR_OFFSET): Likewise.
	(AARCH64_FPSIMD_V0_OFFSET): Likewise.
	(AARCH64_FPSIMD_VREG_SIZE): Likewise.
	(AARCH64_SVE_CONTEXT_VL_OFFSET): Likewise.
	(AARCH64_SVE_CONTEXT_REGS_OFFSET): Likewise.
	(AARCH64_SVE_CONTEXT_P_REGS_OFFSET): Likewise.
	(AARCH64_SVE_CONTEXT_FFR_OFFSET): Likewise.
	(AARCH64_SVE_CONTEXT_SIZE): Likewise.
	(read_aarch64_ctx): Add function.
	(aarch64_linux_sigframe_init): Detect FP registers.
2018-10-01 14:21:38 +01:00
Alan Hayward c74e7cb96f Aarch64: Move pseudo defines to header
gdb/
	* aarch64-tdep.c (AARCH64_Q0_REGNUM): Move to here.
	(AARCH64_D0_REGNUM): Likewise.
	(AARCH64_S0_REGNUM): Likewise.
	(AARCH64_H0_REGNUM): Likewise.
	(AARCH64_B0_REGNUM): Likewise.
	(AARCH64_SVE_V0_REGNUM): Likewise.
	* arch/aarch64.h (AARCH64_Q0_REGNUM): Move from here.
	(AARCH64_D0_REGNUM): Likewise.
	(AARCH64_S0_REGNUM): Likewise.
	(AARCH64_H0_REGNUM): Likewise.
	(AARCH64_B0_REGNUM): Likewise.
	(AARCH64_SVE_V0_REGNUM): Likewise.
2018-10-01 14:00:14 +01:00
Gary Benson 12b164e9a9 Remove ancient workaround
This commit removes a workaround for a bug in glibc 2.1.3, which
was released 2000-02-24 and superseded 2000-11-09.

gdb/ChangeLog:

	* gdb_proc_service.h (gdb_prfpregset_t): Remove typedef.
	* proc-service.c (ps_lgetfpregs, ps_lsetfpregs): Use
	prfpregset_t instead of gdb_prfpregset_t.
	* configure.ac (PRFPREGSET_T_BROKEN): Remove check.
	* configure, config.in: Rebuild.
2018-10-01 10:37:39 +01:00
Gary Benson 7c619dbdae Move duplicated code to common/gdb_proc_service.h
This commit moves now-identical code from gdb/gdb_proc_service.h
and gdb/gdbserver/gdb_proc_service.h into the new shared file
gdb/common/gdb_proc_service.h.

gdb/ChangeLog:

	* common/gdb_proc_service.h: New file, factored out from...
	* gdb_proc_service.h: Moved common code to the above file.
	* Makefile.in (HFILES_NO_SRCDIR): Add the above new file.

gdb/gdbserver/ChangeLog:

	* gdb_proc_service.h: Moved common code to
	common/gdb_proc_service.h.
2018-10-01 10:37:39 +01:00
Gary Benson 358ffcf28c Update GDB gdb_proc_service.h workaround to match gdbserver
This commit updates GDB's gdb_proc_service.h to use elf_{g,fp}regset_t
instead of gdb_{g,fp}regset_t if pr{g,fp}regset_t are undefined.
The types have been equivalent on GNU/Linux since at least 2005.

gdb/ChangeLog:

	* gdb_proc_service.h: Use elf_gregset_t if prgregset_t is
	undefined.  Use elf_fpregset_t if prfpregset_t is undefined.
2018-10-01 10:37:39 +01:00
Gary Benson 43b7e92b0c Add workaround from gdbserver's gdb_proc_service.h to GDB
This commit adds a workaround from gdbserver's gdb_proc_service.h
to GDB's.  It doesn't seem to have been needed on any glibc as far
back as 2001, but it's possibly required for other C libraries so
I've retained it.

gdb/ChangeLog:

	* configure.ac: Check if sys/procfs.h defines elf_fpregset_t.
	(AC_CHECK_HEADERS): Check for linux/elf.h.
	* configure, config.in: Rebuild.
	* gdb_proc_service.h: Include linux/elf.h if sys/procfs.h
	doesn't define elf_fpregset_t.
2018-10-01 10:37:39 +01:00
Gary Benson 3795e81442 gdb_proc_service.h comment and whitespace synchronization
This commit updates comments and whitespace in GDB's and gdbserver's
gdb_proc_service.h.

gdb/ChangeLog:

	* gdb_proc_service.h: Whitespace change.

gdb/gdbserver/ChangeLog:

	* gdb_proc_service.h: Synchronize comments and whitespace with
	GDB's version of this file.
2018-10-01 10:37:39 +01:00
Tom Tromey 4176f14d9c Don't check HAVE_UNISTD_H
I noticed some spots that were checking HAVE_UNISTD_H.  There is no
need to do this, as <unistd.h> is unconditionally included in many
places in gdb.  This sort of cleanup was done once before, in 2013:

    2013-07-01  Pedro Alves  <palves@redhat.com>

	    * defs.h: Don't check HAVE_UNISTD_H before including <unistd.h>.
	    (STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO): Delete.
	    * tracepoint.c: Don't check HAVE_UNISTD_H before including
	    <unistd.h>.

HAVE_UNISTD_H seems to come from gnulib, so there are still mentions
of it in the source.

gdb/ChangeLog
2018-10-01  Tom Tromey  <tom@tromey.com>

	* unittests/scoped_mmap-selftests.c: Don't check HAVE_UNISTD_H.
	* unittests/scoped_fd-selftests.c: Don't check HAVE_UNISTD_H.
	* common/scoped_fd.h: Don't check HAVE_UNISTD_H.
2018-10-01 02:58:23 -06:00
Tom Tromey a95746f917 Copy configure option documentation to gdb.texinfo
I realized that while I'd updated the README, I didn't update
gdb.texinfo to document the options to configure.

This patch copies the text from README into gdb.texinfo, adding
Texinfo markup.

gdb/ChangeLog
2018-10-01  Tom Tromey  <tom@tromey.com>

	* README: Minor change.

gdb/doc/ChangeLog
2018-10-01  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Configure Options): Document configure options.
2018-10-01 02:55:26 -06:00
Markus Metzger 224d30d393 testsuite: fix is_amd64_regs_target
Commit

    c221b2f Testsuite: Add gdb_can_simple_compile

changed the source file name extension of the test program from .s to .c
resulting in compile fails.  This, in turn, causes is_amd64_regs_target
checks to fail.  In gdb.btrace/tailcall.exp and others, this causes the
wrong source file to be picked and the test to fail on 64-bit targets.

Change the test source from an assembly program to a C program using
inline assembly.

testsuite/
	* lib/gdb.exp (is_amd64_regs_target): Change assembly to C inline
	assembly.
2018-10-01 10:06:56 +02:00
Pedro Alves dd20378271 Darwin: Remove unused variables [-Werror=unused-variable]
Building GDB with --host=x86_64-apple-darwin15 using G++ 5.3.0 runs
into a number of -Werror=unused-variable warnings/errors:

  ../../src/gdb/i386-darwin-nat.c: In function 'void i386_darwin_dr_set(int, CORE_ADDR)':
  ../../src/gdb/i386-darwin-nat.c:283:7: error: unused variable 'current_pid' [-Werror=unused-variable]
     int current_pid;
	 ^
  [etc, etc.]

This commit fixes all such warnings.

gdb/ChangeLog:
2018-09-30  Pedro Alves  <palves@redhat.com>

	* darwin-nat-info.c (darwin_debug_regions_recurse)
	(info_mach_exceptions_command): Remove unused local variables.
	* darwin-nat.c (darwin_decode_notify_message)
	(darwin_nat_target::resume, darwin_nat_target::mourn_inferior)
	(darwin_stop_inferior, darwin_setup_exceptions)
	(darwin_nat_target::kill, darwin_attach_pid, darwin_ptrace_him)
	(darwin_nat_target::attach, darwin_nat_target::detach)
	(darwin_read_write_inferior, darwin_read_dyld_info): Remove unused
	local variables.
	* i386-darwin-nat.c (i386_darwin_dr_set): Remove unused local
	variables.
2018-09-30 17:17:52 +01:00
Tom Tromey c82a2e6ff6 Remove some leftover text in gdb/README
I accidentally left some stray text in gdb/README.
This removes it.  I'm checking this in as obvious.

gdb/ChangeLog
2018-09-29  Tom Tromey  <tom@tromey.com>

	* README: Remove some leftover text.
2018-09-29 07:32:10 -06:00
Tom Tromey 7f0bd4202c Update gdb's configure instructions
gdb's README and configure instructions in the manual are quite out of
date.  They mention options that haven't existed for many years, among
other things.

This patch attempts to modernize the instructions somewhat.  It is not
exhaustive, just an improvement -- more could be done.  Perhaps even a
couple of the nodes should simply be removed and replaced by
references to the Autoconf manual.

The README file seems to have been generated from the Texinfo at some
point in the past.  I did not continue this, but instead edited it
separately.

gdb/ChangeLog
2018-09-29  Tom Tromey  <tom@tromey.com>

	* PROBLEMS: Rewrite.
	* README: Update.

gdb/doc/ChangeLog
2018-09-29  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Requirements): Mention C++, GNU make.
	(Requirements): Sort the table.  Add more libraries.
	(Running Configure): Remove obsolete text.
	(Separate Objdir): Likewise.
	(Configure Options): Likewise.
2018-09-29 07:07:33 -06:00
John Baldwin f37bc8b13c Use the existing instruction to determine the RISC-V breakpoint kind.
RISC-V supports instructions of varying lengths.  Standard existing
instructions in the base ISA are 4 bytes in length, but the 'C'
extension adds support for compressed, 2 byte instructions.  RISC-V
supports two different breakpoint instructions: EBREAK is a 4 byte
instruction in the base ISA, and C.EBREAK is a 2 byte instruction only
available on processors implementing the 'C' extension.  Using EBREAK
to set breakpoints on compressed instructions causes problems as the
second half of EBREAK will overwrite the first 2 bytes of the
following instruction breaking other threads in the process if their
PC is the following instruction.  Thus, breakpoints on compressed
instructions need to use C.EBREAK instead of EBREAK.

Previously, the riscv architecture checked the MISA register to
determine if the 'C' extension was available.  If so, it used C.EBREAK
for all breakpoints.  However, the MISA register is not necessarily
available to supervisor mode operating systems.  While native targets
could provide a fake MISA register value, this patch instead examines
the existing instruction at a breakpoint target to determine which
breakpoint instruction to use.  If the existing instruction is a
compressed instruction, C.EBREAK is used, otherwise EBREAK is used.

gdb/ChangeLog:

	* disasm-selftests.c (print_one_insn_test): Add bfd_arch_riscv to
	case with explicit breakpoint kind.
	* riscv-tdep.c (show_use_compressed_breakpoints): Remove
	'additional_info' and related logic.
	(riscv_debug_breakpoints): New variable.
	(riscv_breakpoint_kind_from_pc): Use the length of the existing
	instruction to determine the breakpoint kind.
	(_initialize_riscv_tdep): Add 'set/show debug riscv breakpoints'
	flag.  Update description of 'set/show riscv
	use-compressed-breakpoints' flag.
2018-09-28 14:15:54 -07:00
Andrew Burgess f67ffa6a78 gdb: Change how frames are selected for 'frame' and 'info frame'.
The 'frame' command, and thanks to code reuse the 'info frame' and
'select-frame' commands, currently have an overloaded mechanism for
selecting a frame.

These commands take one or two parameters, if it's one parameter then
we first try to use the parameter as an integer to select a frame by
level (or depth in the stack).  If that fails then we treat the
parameter as an address and try to select a stack frame by
stack-address.  If we still have not selected a stack frame, or we
initially had two parameters, then GDB allows the user to view a stack
frame that is not part of the current backtrace.  Internally, a new
frame is created with the given stack and pc addresses, and this is
shown to the user.

The result of this is that a typo by the user, entering the wrong stack
frame level for example, can result in a brand new frame being viewed
rather than an error.

The purpose of this commit is to remove this overloading, while still
offering the same functionality through some new sub-commands.  By
making the default behaviour of 'frame' (and friends) be to select a
stack frame by level index, it is hoped that enough
backwards-compatibility is maintained that users will not be overly
inconvenienced.

The 'frame', 'select-frame', and 'info frame' commands now all take a
frame specification string as an argument, this string can be any of the
following:

  (1) An integer.  This is treated as a frame level.  If a frame for
  that level does not exist then the user gets an error.

  (2) A string like 'level <LEVEL>', where <LEVEL> is a frame level
  as in option (1) above.

  (3) A string like 'address <STACK-ADDRESS>', where <STACK-ADDRESS>
  is a stack-frame address.  If there is no frame for this address
  then the user gets an error.

  (4) A string like 'function <NAME>', where <NAME> is a function name,
  the inner most frame for function <NAME> is selected.  If there is no
  frame for function <NAME> then the user gets an error.

  (5) A string like 'view <STACK-ADDRESS>', this views a new frame
  with stack address <STACK-ADDRESS>.

  (6) A string like 'view <STACK-ADDRESS> <PC-ADDRESS>', this views
  a new frame with stack address <STACK-ADDRESS> and the pc <PC-ADDRESS>.

This change assumes that the most common use of the commands like
'frame' is to select a frame by frame level, it is for this reason
that this is the behaviour that is kept for backwards compatibility.
Any of the alternative behaviours, which are assumed to be less used,
now require a change in user behaviour.

The MI command '-stack-select-frame' has not been changed.  This
ensures that we maintain backwards compatibility for existing
frontends.

gdb/ChangeLog:

	(NEWS): Mention changes to frame related commands.
	* cli/cli-decode.c (add_cmd_suppress_notification): New function.
	(add_prefix_cmd_suppress_notification): New function.
	(add_com_suppress_notification): Call
	add_cmd_suppress_notification.
	* command.h (add_cmd_suppress_notification): Declare.
	(add_prefix_cmd_suppress_notification): Declare.
	* mi/mi-cmd-stack.c: Add 'safe-ctype.h' include.
	(parse_frame_specification): Moved from stack.c, with
	simplification to handle a single argument.
	(mi_cmd_stack_select_frame): Use parse_frame_specification, the
	switch to the selected frame.  Add a header comment.
	* stack.c: Remove 'safe-ctype.h' include.
	(find_frame_for_function): Add declaration.
	(find_frame_for_address): New function.
	(parse_frame_specification): Moved into mi/mi-cmd-stack.c.
	(frame_selection_by_function_completer): New function.
	(info_frame_command): Rename to...
	(info_frame_command_core): ...this, and update parameter types.
	(select_frame_command): Rename to...
	(select_frame_command_core): ...this, and update parameter types.
	(frame_command): Rename to...
	(frame_command_core): ...this, and update parameter types.
	(class frame_command_helper): New class to wrap implementations of
	frame related sub-commands.
	(frame_apply_cmd_list): New static global.
	(frame_cmd_list): Make static.
	(select_frame_cmd_list): New global for sub-commands.
	(info_frame_cmd_list): New global for sub-commands.
	(_initialize_stack): Register sub-commands for 'frame',
	'select-frame', and 'info frame'.  Update 'frame apply' commands
	to use frame_apply_cmd_list.  Move function local static
	frame_apply_list to file static frame_apply_cmd_list for
	consistency.
	* stack.h (select_frame_command): Delete declarationn.
	(select_frame_for_mi): Declare new function.

gdb/doc/ChangeLog:

	* gdb.texinfo (Frames): Rewrite the description of 'frame number'
	to highlight that the number is also the frame's level.
	(Selection): Rewrite documentation for 'frame' and 'select-frame'
	commands.
	(Frame Info): Rewrite documentation for 'info frame' command.

gdb/testsuite/ChangeLog:

	* gdb.base/frame-selection.exp: New file.
	* gdb.base/frame-selection.c: New file.
2018-09-28 11:59:34 +01:00
Alan Hayward 9fc3183f0f testsuite: Fix race condition in check-libthread-db
It is possible for the created thread to reach the breakpoint before
the main thread has set errno to 23.

Prevent this using a pthread barrier.

	* gdb.threads/check-libthread-db.c (thread_routine): Use a
	pthread barrier.
	(main): Likewise.
2018-09-27 10:48:20 +01:00
Andrew Burgess d354055e6e gdb/riscv: Improve non-dwarf stack unwinding
This commit improves the prologue scanning stack unwinder, to better
support AUIPC, LUI, and more variants of ADD and ADDI.

This allows unwinding over frames containing large local variables,
where the frame size does not fit into a single instruction immediate,
and is first loaded into a temporary register, before being added to
the stack pointer.

A new test is added that tests this behaviour.  As there's nothing
truely RiscV specific about this test I've added it into gdb.base, but
as this depends on target specific code to perform the unwind it is
possible that some targets might fail this new test.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_insn::decode): Decode c.lui.
	(riscv_scan_prologue): Split handling of AUIPC, LUI, ADD, ADDI,
	and NOP.

gdb/testsuite/ChangeLog:

	* gdb.base/large-frame-1.c: New file.
	* gdb.base/large-frame-2.c: New file.
	* gdb.base/large-frame.exp: New file.
	* gdb.base/large-frame.h: New file.
2018-09-26 14:08:39 +01:00
Simon Marchi 853924149d elf32-nds32: Remove elf32_nds32_allocate_dynrelocs
It is unused, removing it fixes this error when building with clang:

    /home/emaisin/src/binutils-gdb/bfd/elf32-nds32.c:3172:1: error: unused function 'elf32_nds32_allocate_dynrelocs' [-Werror,-Wunused-function]
    elf32_nds32_allocate_dynrelocs (struct bfd_link_info *info, asection *sreloc,
    ^
    1 error generated.

gcc only reports the error if you remove "inline".  I don't know if this
is actually a mistake and it should actually be used though.

gdb/ChangeLog:

	* elf32-nds32.c (elf32_nds32_allocate_dynrelocs): Remove.
2018-09-26 08:27:23 -04:00
Tom Tromey 896ee09882 Remove dead definition from valops.c
This removes a variable definition in valops.c that has been
surrounded by "#if 0" since gdb moved to sourceware.

gdb/ChangeLog
2018-09-26  Tom Tromey  <tom@tromey.com>

	* valops.c (auto_abandon): Remove dead code.
2018-09-26 05:34:25 -06:00
Tom Tromey 57dbb3afed Small fix for "winheight" usage
I noticed that the usage string for "winheight" has a couple of
extraneous ">"s in it.  I must have forgotten to remove these back
when I changed the text to use the GNU style for metasyntactic
variables.

gdb/ChangeLog
2018-09-26  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (WIN_HEIGHT_USAGE): Remove extra ">"s.
2018-09-26 05:15:31 -06:00
Tom Tromey 49b036f1e0 Remove dead code from gdbserver's configure
gdbserver's configure removes -Wmissing-prototypes from the warning
flags.  However, this flag is only useful for C, so this deletion is
no longer needed.

gdb/gdbserver/ChangeLog
2018-09-25  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac (WARN_CFLAGS): Don't remove -Wmissing-prototypes.
2018-09-25 07:54:59 -06:00
Jozef Lawrynowicz db72737006 Fix PR gdb/20948: --write option to GDB causes segmentation fault
When opening a BFD for update, as gdb --write does, modifications to
anything but the contents of sections is restricted.

Do not try to write back any ELF headers in this case.

bfd/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	PR gdb/20948
	* elf.c (_bfd_elf_write_object_contents): Return from function
	early if abfd->direction == both_direction.

gdb/testsuite/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	PR gdb/20948
	* gdb.base/write_mem.exp: New test.
	* gdb.base/write_mem.c: Likewise.
2018-09-24 06:20:17 -06:00
Tom Tromey b5a9bfbebe Add "const" to a few locals in gdb
I noticed that some code in gdb was doing:

    char *mumble = getenv (...)

However, using "const char *" here would be clearer.
This patch fixes the instances I could readily build.

Tested by rebuilding.

gdb/ChangeLog
2018-09-24  Tom Tromey  <tom@tromey.com>

	* common/pathstuff.c (get_standard_cache_dir): Make
	"xdg_cache_home" and "home" const.
	* top.c (init_history): Make "tmpenv" const.
	* main.c (get_init_files): Make "homedir" const.
2018-09-24 06:17:13 -06:00
Tom Tromey ae778caf09 Allow setting a parameter to raise gdb.GdbError
A convention in the Python layer is that raising a gdb.GdbError will
not print the Python stack -- instead the exception is treated as any
other gdb exception.

PR python/18852 asks that this treatment be extended the the
get_set_value method of gdb.Parameter.  This makes sense, because it
lets Python-created parameters act like gdb parameters.

2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/18852:
	* python/py-param.c (get_set_value): Use gdbpy_handle_exception.

gdb/doc/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/18852:
	* python.texi (Parameters In Python): Document exception behavior
	of get_set_string.

gdb/testsuite/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/18852:
	* gdb.python/py-parameter.exp: Add test for parameter that throws
	on "set".
2018-09-23 23:15:12 -06:00
Tom Tromey 2b4ad2fe43 Consolidate gdb.GdbError handling
I noticed two nearly identical copies of the same code for handling
gdb.GdbError.  The only differences were in some error messages.
These differences didn't seem very important, so this patch pulls the
code out into a new function.

2018-09-23  Tom Tromey  <tom@tromey.com>

	* python/py-function.c (fnpy_call): Use gdbpy_handle_exception.
	* python/py-cmd.c (cmdpy_function): Use gdbpy_handle_exception.
	* python/python-internal.h (gdbpy_handle_exception): Declare.
	* python/py-utils.c (gdbpy_handle_exception): New function.
2018-09-23 23:15:12 -06:00
Tom Tromey fd3ba736db Check for negative argument in Type.template_argument
typy_template_argument did not check if the template argument was
non-negative.  A negative value could cause a gdb crash.

2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/17284:
	* python/py-type.c (typy_template_argument): Check for negative
	argument number.

gdb/testsuite/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/17284:
	* gdb.python/py-template.exp (test_template_arg): Add test for
	negative template argument number.
2018-09-23 23:15:12 -06:00
Tom Tromey 39a24317ac Report Python errors coming from gdb.post_event
PR python/14062 points out that errors coming from the gdb.post_event
callback are not reported.  This can make it hard to understand why
your Python code in gdb isn't working.

Because users have control over whether exceptions are printed at all,
it seems good to simply have post_event report errors in the usual
way.

2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/14062:
	* python/python.c (gdbpy_run_events): Do not ignore exceptions.

gdb/testsuite/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/14062:
	* gdb.python/python.exp: Add test for post_event error.
2018-09-23 23:15:12 -06:00
Tom Tromey f5769a2c69 Allow conversion of pointers to Python int
PR python/18170 questions why it's not possible to convert a pointer
value to a Python int.

Digging a bit shows that the Python 2.7 int() constructor will happily
return a long in some cases.  And, it seems gdb already understands
this in other places -- this is what gdb_py_object_from_longest
handles.

So, this patch simply extends valpy_int to allow pointer conversions,
as valpy_long does.

gdb/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/18170:
	* python/py-value.c (valpy_int): Allow conversion from pointer
	type.

gdb/testsuite/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/18170:
	* gdb.python/py-value.exp (test_value_numeric_ops): Add tests to
	convert pointers to int and long.
2018-09-23 23:15:12 -06:00
Tom Tromey 1c1e54f6b4 Preserve sign when converting gdb.Value to Python int
PR python/20126 points out that sometimes the conversion of a
gdb.Value can result in a negative Python integer.  This happens
because valpy_int does not examine the signedness of the value's type.

gdb/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/20126:
	* python/py-value.c (valpy_int): Respect type sign.

gdb/testsuite/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/20126:
	* gdb.python/py-value.exp (test_value_numeric_ops): Add
	signed-ness conversion tests.
2018-09-23 23:13:00 -06:00
Tom Tromey fb4fa9469c Allow more Python scalar conversions
PR python/18352 points out that the gdb Python code can't convert an
integer-valued gdb.Value to a Python float.  While writing the test I
noticed that, similarly, converting integer gdb.Values to float does
not work.  However, all of these cases seem reasonable.

gdb/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/18352;
	* python/py-value.c (valpy_float): Allow conversions from int or
	char.
	(valpy_int, valpy_long): Allow conversions from float.

gdb/testsuite/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	PR python/18352;
	* gdb.python/py-value.exp (test_float_conversion): New proc.
	Use it.
2018-09-23 23:12:59 -06:00
Tom Tromey 65773341ee Mark more file descriptors close-on-exec
I noticed a couple of spots in gdb that were opening files but not
marking the file descriptors as close-on-exec.  This patch fixes
these.

There are still a few more of these, but they are in code that I can't
compile, so I'd prefer not to touch.

gdb/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

	* ctf.c (ctf_start): Use gdb_fopen_cloexec.
	* common/scoped_mmap.c (mmap_file): Use gdb_open_cloexec.
2018-09-23 12:11:16 -06:00
Rainer Orth 1db88d2272 Also recognize __sighndlr on Solaris/x86
Unlike Solaris/SPARC, the __sighndlr function isn't recognized as part
of a signal handler, causing a couple of testcases to fail.

The following patch fixes that.  A followup patch will move this to
common code to avoid such unnecessary discrepancies between
Solaris/SPARC and x86 in the future.

While this fixes a couple of backtraces to now correctly print

#1  <signal handler called>

they often fail later with

#2  0x0ff3ffffff00857f in ?? ()
Backtrace stopped: Cannot access memory at address 0xff3000002e0886f

which needs further investigation.

Tested on amd64-pc-solaris2.11 (running the tests with both -m64 and
-m32).

	* amd64-sol2-tdep.c (amd64_sol2_sigtramp_p): Also recognize
	__sighndlr.
	* i386-sol2-tdep.c (i386_sol2_sigtramp_p): Likewise.
2018-09-23 19:49:14 +02:00
Jon Turney a44294f5ed
Remove a spurious target_terminal::ours() from windows_nat_target::wait()
This causes the inferior to stop with SIGTTIN if it tries to read from the
terminal after it has been continued.

See https://cygwin.com/ml/cygwin/2016-09/msg00285.html for reproduction.

Since MinGW doesn't have a tcsetpgrp(), I don't think this problem would be
observed there, but Cygwin does so target_terminal::ours() will call it.

Calling target_terminal::ours() here seems to be is no longer appropriate
after the "Merge async and sync code paths" changes (as the inferior is now
in a separate process group even in sync mode(?), which is always used on
Windows targets)

This call was added in commit c44537cf (and see
https://sourceware.org/ml/gdb-patches/2007-02/msg00167.html for what it
fixed, which is not regressed by this change)

When windows_nat_target::wait() is entered, the inferior is running (either
it's been just been started or attached to, or windows_continue() was
called), so grabbing the controlling terminal away from it here seems to be
wrong, since infrun.c takes care of calling target_terminal::ours() when the
inferior stops.

gdb/ChangeLog:

2018-08-02  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (windows_nat_target::wait): Remove a spurious
	target_terminal::ours().
2018-09-23 16:15:19 +01:00
Simon Marchi 0c0a40e0ab Fix build error in aarch64-linux-tdep.c on macOS
When building with --enable-targets=all on macOS, I get this error:

  CXX    aarch64-linux-tdep.o
/Users/simark/src/binutils-gdb/gdb/aarch64-linux-tdep.c:328:7: error: no matching function for call to 'store_integer'
      store_integer ((gdb_byte *)&vg_target, sizeof (uint64_t), byte_order,
      ^~~~~~~~~~~~~
/Users/simark/src/binutils-gdb/gdb/defs.h:556:13: note: candidate template ignored: requirement 'Or<is_same<unsigned long long, long>, is_same<unsigned long long, unsigned long> >::value' was not satisfied [with T = unsigned long long]
extern void store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order,
            ^

I believe it's because uint64_t is defined as "unsigned long long" on macOS,
even though "unsigned long" is also 64 bits.  Other 64-bits platforms define
uint64_t as "unsigned long".

This makes the type of the argument to store_integer (unsigned long long) not
match the requirement that it must be the same as ULONGEST, which is unsigned
long.

Fix it by changing the type of the vl variable to be ULONGEST, which is what
extract_unsigned_integer returns anyway.

gdb/ChangeLog:

	* aarch64-linux-tdep.c (aarch64_linux_supply_sve_regset): Change type
	of vl to ULONGEST.
2018-09-23 10:12:30 -04:00
Yacov Simhony 4daf19021f Remove redundant test in update_inserted_breakpoint_locations
Remove a redundant test in update_inserted_breakpoint_locations.

gdb/ChangeLog
2018-09-21  Yacov Simhony  <ysimhony@gmail.com>

	* breakpoint.c (update_inserted_breakpoint_locations): Remove
	redundant condition.
2018-09-21 07:55:23 -06:00
Rainer Orth c475f56919 More Solaris procfs cleanup
This procfs.c (and friends) cleanup patch grew along a couple of lines:

* First I noticed that PR_MODEL_NATIVE is always defined now that
  Solaris 10 is the minimum supported version.

* Then there was a cleanup that I'd missed when removing support for
  !NEW_PROC_API, IRIX, and Tru64 UNIX: given that sysset_t is no longer
  dynamic, there's no need for the special sysset_t_alloc, but we can
  just use XNEW instead.

* Then I found one of those ARI warning mails on gdb-patches, discovered
  how to run it myself and fixed a large number of the warnings, among
  them all uses of sprintf.

  I had to silence the warnings in only 3 instances of the same issue,
  namely references to LDT in function names which are due to the
  libthread_db API.

* Even so, there were several formatting glitches, like braces around
  single statements in an if, which I chose to fix while I was at it.

The result has been tested on amd64-pc-solaris2.11 and
amd64-pc-solaris2.11.

	* proc-utils.h (PROC_CTL_WORD_TYPE): Remove.

	* procfs.c: Don't check for PR_MODEL_NATIVE definition.
	* sparc-sol2-nat.c: Likewise.  Remove Linux, __arch64__ references.
	* sol-thread.c (ps_pdmodel): Don't guard definition.

	* procfs.c: Fix formatting.

	* procfs.c (sysset_t_alloc): Remove.
	(create_procinfo): Use XNEW instead of sysset_t_alloc.
	(procfs_debug_inferior): Likewise.
	(procfs_set_exec_trap): Likewise.
	(proc_set_traced_sysentry): Don't allocate argp dynamically.
	(proc_set_traced_sysexit): Likewise.

	* procfs.c (create_procinfo): Use xsnprintf to fix ARI warning.
	(dead_procinfo): Likewise.
	(proc_warn): Likewise.
	(proc_error): Likewise.
	(proc_get_LDT_entry): Likewise.
	(do_attach): Likewise.
	(procfs_target::pid_to_str): Likewise.
	(iterate_over_mappings): Likewise.

	* procfs.c (create_procinfo): Fix ARI warning.
	(proc_get_status): Likewise.
	(proc_stop_process): Likewise.
	(proc_run_process): Likewise.
	(proc_kill): Likewise.
	(proc_get_LDT_entry): Likewise.
	(procfs_find_LDT_entry): Likewise.
	(proc_update_threads): Likewise.
	(proc_iterate_over_threads): Likewise.
	(do_attach): Likewise.
	(procfs_xfer_memory): Likewise.
	(invalidate_cache): Likewise.
	(procfs_target::resume): Likewise.
	(procfs_init_inferior): Likewise.
	(procfs_set_exec_trap): Likewise.
	(procfs_target::thread_alive): Likewise.
	(procfs_target::pid_to_exec_file): Likewise.
	(iterate_over_mappings): Likewise.
	(procfs_target::make_corefile_notes): Likewise.
	* sol-thread.c (sol_thread_target::thread_alive): Likewise.

	* procfs.c (procfs_find_LDT_entry): Silence ARI warning.
	(procfs_find_LDT_entry): Likewise.
	* sol-thread.c (ps_lgetLDT): Likewise.
2018-09-20 20:01:05 +02:00
Hafiz Abid Qadeer a466edac5f Add '_' in the match pattern.
I was looking at GDB testcase results for arm-eabi target with qemu and
noticed that register groups returned by the qemu can have '_' in the
name e.g. 'cp_regs'. The reggroups.exp fails to recognize that as group
name. Fixed by adding '_' in the pattern.

2018-09-20  Hafiz Abid Qadeer  <abidh@codesourcery.com>

	gdb.base/reggroups.exp (fetch_reggroups): Add '_' in match pattern.
2018-09-20 16:46:00 +01:00
Rainer Orth 4206c05ea1 Provide pid_to_exec_file on Solaris (PR tdep/17903)
While looking through gdb.log, I found that two tests FAIL like this:

warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x00400dc4 in ?? ()
(gdb) FAIL: gdb.base/attach.exp: attach2, with no file

The other is gdb.base/quit-live.exp.  I've implemented the following
patch that fixes both failures, only then detecting that I'd previously
reported the issue as PR tdep/17903.

Tested on amd64-pc-solaris2.10 and amd64-pc-solaris2.11.

	PR tdep/17903
	* procfs.c (procfs_target): Declare pid_to_exec_file.
	(procfs_target::pid_to_exec_file): New.
2018-09-20 11:23:27 +02:00
Rainer Orth 3d282ac370 Handle missing Solaris auxv entries
Currently, three tests FAIL on Solaris 11.4+ (amd64-pc-solaris2.11 and
sparcv9-sun-solaris2.11):

info auxv
[...]
2009 AT_SUN_HWCAP         Machine-dependent CPU capability hints 0x3f5ff7
2023 ???                                                 0x0
0    AT_NULL              End of vector                  0x0
(gdb) WARNING: Unrecognized tag value: 2023 ???  0x0

FAIL: gdb.base/auxv.exp: info auxv on live process

info auxv
4294969310 ???                                                 0x7fffbfffe410
9225589753816 ???                                                 0x7fffbfffe45c
[...]
WARNING: Unrecognized tag value: 4294969310 ???  0x7fffbfffe410

WARNING: Unrecognized tag value: 9225589753816 ???  0x7fffbfffe45c

WARNING: Unrecognized tag value: 140733193388037 ???  0x6
[...]
2009 AT_SUN_HWCAP         Machine-dependent CPU capability hints 0x3f5ff7
2023 ???                                                 0x0
0    AT_NULL              End of vector                  0x0
(gdb) WARNING: Unrecognized tag value: 2023 ???  0x0

UNRESOLVED: gdb.base/auxv.exp: info auxv on native core dump

info auxv
[...]
2009 AT_SUN_HWCAP         Machine-dependent CPU capability hints 0x3f5ff7
2023 ???                                                 0x0
0    AT_NULL              End of vector                  0x0
(gdb) WARNING: Unrecognized tag value: 2023 ???  0x0

FAIL: gdb.base/auxv.exp: info auxv on gcore-created dump

The following patch fixes this by introducing the missing AT_SUN_*
values from Solaris 11.4+ <sys/auxv.h>.  This lets the live and
gcore-created dump tests PASS.

I don't know yet what's the reason for those weird 'Unrecognized tag
value' warnings with native core dumps is; elfdump -n certainly doesn't
show them.  However, native core dumps still need quite some work
(mostly in bfd) in this and other areas.

Tested on amd64-pc-solaris2.11.

	gdb:
	* auxv.c (default_print_auxv_entry): Reflect AT_SUN_CAP_HW1
	renaming.
	Handle AT_SUN_EMULATOR, AT_SUN_BRANDNAME, AT_SUN_BRAND_AUX1,
	AT_SUN_BRAND_AUX2, AT_SUN_BRAND_AUX3, AT_SUN_CAP_HW2.

	include:
	* elf/common.h (AT_SUN_HWCAP): Rename to ...
	(AT_SUN_CAP_HW1): ... this.  Retain old name for backward
	compatibility.
	(AT_SUN_EMULATOR, AT_SUN_BRANDNAME, AT_SUN_BRAND_AUX1)
	(AT_SUN_BRAND_AUX2, AT_SUN_BRAND_AUX3, AT_SUN_CAP_HW2): Define.
2018-09-20 10:23:46 +02:00
Rainer Orth 8c93fae615 Missed last ChangeLog entry. 2018-09-20 10:17:41 +02:00
Rainer Orth 8674be7924 Fold i386-v4-nat.c into i386-sol2-nat.c
I've been carrying around the following patch for some time.  I noticed
that both i386-sol2-nat.c and i386-v4-nat.c are Solaris-only now and it
seems confusing to carry both around.

So this patch merges i386-v4-nat.c into i386-sol2-nat.c, simplifying it
in a couple of places, like removing checks for macros that are always
defined.

Tested on 64-bit Solaris 11.5/x86 (amd64-pc-solaris2.11) and 32-bit
Solaris 11.3/x86 (i386-pc-solaris2.11) half a year ago.

	* i386-v4-nat.c (regmap, supply_gregset, fill_gregset)
	(supply_fpregset, fill_fpregset): Move ...
	* i386-sol2-nat.c [PR_MODEL_NATIVE != PR_MODEL_LP64]: ... here.
	Remove HAVE_GREGSET_T, HAVE_FPREGET_T guards.
	Remove references to ioctl-based procfs.
	Include <sys/reg.h>.
	Remove PR_MODEL_NATIVE guards.
	* configure.nat <sol2, i386> (NATDEPFILES): Remove i386-v4-nat.o.
	* Makefile.in (ALLDEPFILES): Remove i386-v4-nat.c.
2018-09-20 10:10:07 +02:00
Sandra Loosemore 4ee9b0c53a Skip GDB tab-completion tests if no readline.
2018-09-18  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.base/complete-empty.exp: Skip tab-completion tests if
	no readline.
	* gdb.base/utf8-identifiers.exp: Likewise.
	* gdb.cp/cpcompletion.exp: Likewise.
	* gdb.linespec/cpcompletion.exp: Likewise.
	* gdb.linespec/cpls-abi-tag.exp: Likewise.
	* gdb.linespec/cpls-ops.exp: Likewise.
2018-09-19 19:05:39 -07:00
Xavier Roirand 79b32f4a3a Darwin: Handle unrelocated dyld.
On Darwin, debugging an helloworld program with GDB does
not work and ends with:

  (gdb) set startup-with-shell off
  (gdb) start
  Temporary breakpoint 1 at 0x100000fb4: file /tmp/helloworld.c, line 1.
  Starting program: /private/tmp/helloworld
  [New Thread 0x2703 of process 18906]
  [New Thread 0x2603 of process 18906]

  [1]+  Stopped                 ./gdb/gdb /tmp/helloworld

When debugging with lldb, instead of having the STOP signal, we can
see that a breakpoint is not set to a proper location:

  Warning:
  Cannot insert breakpoint -1.
  Cannot access memory at address 0xf726

  Command aborted.

The inserted breakpoint is the one used when GDB has to stop the target
when a shared library is loaded or unloaded. The notifier address used
for adding the breakpoint is wrong thus the above failure.
This notifier address is an offset relative to dyld base address, so
the value calculation has to be updated to reflect this.

This was tested on High Sierra by trying to run a simple "hello world"
program.

gdb/ChangeLog:

	PR gdb/20981:
        * solib-darwin.c (darwin_get_dyld_bfd): New function.
        (darwin_solib_get_all_image_info_addr_at_init): Update call.
        (darwin_handle_solib_event): New function.
        (darwin_solib_create_inferior_hook): Handle unrelocated dyld.

Change-Id: I7dde5008c9158f17b78dc89bd7f4bd8a12d4a6e1
2018-09-19 15:23:29 -06:00
John Baldwin 07147793e6 Add missing spaces after inet_ntop invocations.
gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_print_sockaddr_in): Style fix.
	(fbsd_print_sockaddr_in6): Likewise.
2018-09-19 12:22:07 -07:00
Richard Bunt 23be8da739 Logical short circuiting with argument lists
When evaluating Fortran expressions such as the following:

	print truth_table(1,1) .OR. truth_table(2,1)

where truth_table(1,1) evaluates to true, the debugger would report that
it could not perform substring operations on this type. This patch
addresses this issue.

Investigation revealed that EVAL_SKIP was not being handled correctly
for all types serviced by the OP_F77_UNDETERMINED_ARGLIST case in
evaluate_subexp_standard. While skipping an undetermined argument list
the type is resolved to be an integer (as this is what evaluate_subexp
returns when skipping) and so it was not possible to delegate to the
appropriate case (e.g. array, function call).

The solution implemented here updates OP_VAR_VALUE to return correct
type information when skipping. This way OP_F77_UNDETERMINED_ARGLIST
can delegate the skipping to the appropriate case or routine, which
should know how to skip/evaluate the type in question.

koenig.exp was updated to include a testcase which exercises the
modified skip logic in OP_VAR_VALUE, as it falls through from
OP_ADL_FUNC.

This patch has been tested for regressions with GCC 7.3 on aarch64,
ppc64le and x86_64.

gdb/ChangeLog:

	* eval.c (skip_undetermined_arglist): Skip argument list helper.
	(evaluate_subexp_standard): Return a dummy type when
	honoring EVAL_SKIP in OP_VAR_VALUE and handle skipping in the
	OP_F77_UNDETERMINED_ARGLIST case.
	* expression.h (enum noside): Update comment.

gdb/testsuite/ChangeLog:

	* gdb.cp/koenig.exp: Extend to test logical short circuiting.
	* gdb.fortran/short-circuit-argument-list.exp: New file.
	* gdb.fortran/short-circuit-argument-list.f90: New test.
2018-09-19 10:43:56 +01:00
Rainer Orth 7307a73aed Handle 64-bit Solaris/x86 ld.so.1
The next patch from the solaris-userland github repo

	https://github.com/oracle/solaris-userland/tree/master/components/gdb/patches

(007-solib-svr4.patch) is equally trivial, creating partity between
Solaris/SPARC and x86.

Tested on amd64-pc-solaris2.11.

2018-09-19  George Vasick <george.vasick@oracle.com>

	* solib-svr4.c (svr4_same_1): Also handle amd64 ld.so.1.
2018-09-19 11:29:19 +02:00
Rainer Orth 13db92d3f4 Fix /proc pathname sizes on Solaris
I'm slowly working my way through the gdb patches from the
solaris-userland repo

	https://github.com/oracle/solaris-userland/tree/master/components/gdb/patches

This one (001-fix-proc-name-size.patch) should be obvious given the
patches' comment:

# In Solaris, PID_MAX is 999999 (6 digit pid).
# In Solaris, lwpid_t is an unsigned int, so theoretically the lwp id
# could be 10 digits.

Tested on i386-pc-solaris2.11.

2018-09-19  Stefan Teleman <stefan.teleman@oracle.com>
	    April Chin <april.chin@oracle.com>
	    Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* procfs.c (MAX_PROC_NAME_SIZE): Allow for 6-digit PID_MAX and
	uint_t lwpid_t.
	(create_procinfo): Print pids in /proc without leading zeros.
2018-09-19 11:21:32 +02:00
Sandra Loosemore 3d50f17063 Add gcc_target_options hook for nios2.
2018-09-18  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* nios2-tdep.c (nios2_gcc_target_options): New.
	(nios2_gdb_arch_init): Install new hook.
2018-09-18 20:57:07 -07:00
Simon Marchi b567ca638c Carry the gnulib getcwd backport as a patch
Commit

  e2fc52e745 ("Fix PR gdb/23558: Use system's 'getcwd' when cross-compiling GDB")

backported some changes from a future gnulib version to our import.
However, this means that every time someone wants to change our gnulib
import (e.g. add a module), they must make sure not to include that
backported change.  It also means that someone running the
update-gnulib.sh script without changes will get some diffs and wonder
why.

Instead, I suggest we carry that backport as a patch applied by the
update-gnulib.sh script after running the import tool.  It will make it
clear what backport or local modification we have and should make
running update-gnulib.sh give a reproducible result.

There is a hunk in the configure file in this patch, this is because the
commit that backported the getcwd bits didn't include the re-generated
configure.

Note: you'll need this patch as well to get deterministic results:

  Generate aclocal-m4-deps.mk more deterministically and portably.
  https://sourceware.org/ml/gdb-patches/2018-09/msg00643.html

gdb/ChangeLog:

	* patches/0001-Fix-PR-gdb-23558-Use-system-s-getcwd-when-cross-comp.patch:
	New file.
	* update-gnulib.sh: Apply patch.
	* configure: Re-generate.
2018-09-18 23:40:55 -04:00
John Baldwin 73f1bd769a Make the "info proc" documentation more consistent.
Remove "running" in a few places since "info proc" can be used with
core dumps as well as running processes on both Linux and FreeBSD.

Use "the specified process" in the description of most "info proc"
subcommands.

Use "additional information" instead of "/proc process information" in
the "info proc" description to more closely match the language in the
manual.

gdb/ChangeLog:

	* infcmd.c (_initialize_infcmd): Remove "running" from "info proc"
	description.  Make "info proc" command descriptions more
	consistent.

gdb/doc/ChangeLog:

	* gdb.texinfo (info proc): Remove "running".
	(info proc mappings): Replace "program" with "process".
2018-09-18 14:05:48 -07:00
John Baldwin 8b11311136 Document the 'info proc files' command.
gdb/ChangeLog:

	* NEWS: Mention 'info proc files' command.

gdb/doc/ChangeLog:

	* gdb.texinfo (Process Information): Document "info proc files"
	command.
2018-09-18 14:05:48 -07:00
John Baldwin 7e69672e4d Support 'info proc files' on live FreeBSD processes.
This walks the list of struct kinfo_file objects returned by a call to
kinfo_getfile outputting a description of each open file descriptor.

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_nat_target::info_proc): List open file
	descriptors for IP_FILES and IP_ALL.
2018-09-18 14:05:47 -07:00
John Baldwin 57c2a98a4c Add support for 'info proc files' on FreeBSD core dumps.
Walk the list of struct kinfo_file objects in the
NT_FREEBSD_PROCSTAT_FILES core dump note outputting a description of
each open file descriptor.  For sockets, the local and remote socket
addresses are displayed in place of the file name field.  For UNIX
local domain sockets, only a single address is displayed since most
UNIX sockets only have one valid address and printing both pathnames
could be quite long.  The output format was somewhat inspired by the
output of the "procstat -f" command on FreeBSD, but with a few less
details and some fields were condensed.

gdb/ChangeLog:

	* fbsd-tdep.c (KF_FLAGS, KF_OFFSET, KF_VNODE_TYPE, KF_SOCK_DOMAIN)
	(KF_SOCK_TYPE, KF_SOCK_PROTOCOL, KF_SA_LOCAL, KF_SA_PEER)
	(KINFO_FILE_TYPE_SOCKET, KINFO_FILE_TYPE_PIPE)
	(KINFO_FILE_TYPE_FIFO, KINFO_FILE_TYPE_KQUEUE)
	(KINFO_FILE_TYPE_CRYPTO, KINFO_FILE_TYPE_MQUEUE)
	(KINFO_FILE_TYPE_SHM, KINFO_FILE_TYPE_SEM, KINFO_FILE_TYPE_PTS)
	(KINFO_FILE_TYPE_PROCDESC, KINFO_FILE_FD_TYPE_ROOT)
	(KINFO_FILE_FD_TYPE_JAIL, KINFO_FILE_FD_TYPE_TRACE)
	(KINFO_FILE_FD_TYPE_CTTY, KINFO_FILE_FLAG_READ)
	(KINFO_FILE_FLAG_WRITE, KINFO_FILE_FLAG_APPEND)
	(KINFO_FILE_FLAG_ASYNC, KINFO_FILE_FLAG_FSYNC)
	(KINFO_FILE_FLAG_NONBLOCK, KINFO_FILE_FLAG_DIRECT)
	(KINFO_FILE_FLAG_HASLOCK, KINFO_FILE_FLAG_EXEC)
	(KINFO_FILE_VTYPE_VREG, KINFO_FILE_VTYPE_VDIR)
	(KINFO_FILE_VTYPE_VCHR, KINFO_FILE_VTYPE_VLNK)
	(KINFO_FILE_VTYPE_VSOCK, KINFO_FILE_VTYPE_VFIFO, FBSD_AF_UNIX)
	(FBSD_AF_INET, FBSD_AF_INET6, FBSD_SOCK_STREAM, FBSD_SOCK_DGRAM)
	(FBSD_SOCK_SEQPACKET, FBSD_IPPROTO_ICMP, FBSD_IPPROTO_TCP)
	(FBSD_IPPROTO_UDP, FBSD_IPPROTO_SCTP): New defines.
	(struct fbsd_sockaddr_in, struct fbsd_sockaddr_in6)
	(struct fbsd_sockaddr_un): New types.
	(fbsd_file_fd, fbsd_file_type, fbsd_file_flags, fbsd_ipproto)
	(fbsd_print_sockaddr_in, fbsd_print_sockaddr_in6)
	(fbsd_info_proc_files_header, fbsd_info_proc_files_entry)
	(fbsd_core_info_proc_files): New functions.
	(fbsd_core_info_proc): List open file descriptors for IP_FILES and
	IP_ALL.
	* fbsd-tdep.h (fbsd_info_proc_files_header)
	(fbsd_info_proc_files_entry): New.
2018-09-18 14:05:47 -07:00
John Baldwin e98ee8c458 Add a new 'info proc files' subcommand of 'info proc'.
This command displays a list of open file descriptors.

gdb/ChangeLog:

	* defs.h (enum info_proc_what) [IP_FILES]: New value.
	* infcmd.c (info_proc_cmd_files): New function.
	(_initialize_infcmd): Register 'info proc files' command.
2018-09-18 14:05:47 -07:00
John Baldwin 725e299974 Import gnulib's inet_ntop module.
An upcoming patch to fbsd-tdep.c uses inet_ntop to format IP addresses.

gdb/ChangeLog:

	* gnulib/aclocal-m4-deps.mk: Re-generate.
	* gnulib/aclocal.m4: Re-generate.
	* gnulib/config.in: Re-generate.
	* gnulib/configure: Re-generate.
	* gnulib/import/Makefile.am: Re-generate.
	* gnulib/import/Makefile.in: Re-generate.
	* gnulib/import/m4/gnulib-cache.m4: Re-generate.
	* gnulib/import/m4/gnulib-comp.m4: Re-generate.
	* gnulib/import/arpa_inet.in.h: New file.
	* gnulib/import/inet_ntop.c: New file.
	* gnulib/import/m4/arpa_inet_h.m4: New file.
	* gnulib/import/m4/inet_ntop.m4: New file.
	* gnulib/import/m4/netinet_in_h.m4: New file.
	* gnulib/import/m4/socklen.m4: New file.
	* gnulib/import/m4/sockpfaf.m4: New file.
	* gnulib/import/m4/stdalign.m4: New file.
	* gnulib/import/m4/sys_uio_h.m4: New file.
	* gnulib/import/netinet_in.in.h: New file.
	* gnulib/import/stdalign.in.h: New file.
	* gnulib/import/sys_socket.c: New file.
	* gnulib/import/sys_socket.in.h: New file.
	* gnulib/import/sys_uio.in.h: New file.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add inet_ntop
	module.
2018-09-18 14:05:47 -07:00
John Baldwin 2afffa7f62 Generate aclocal-m4-deps.mk more deterministically and portably.
Sort the list of files generated by find to make the order of the
entries deterministic.  When sorting, use explicit "C" collation.  Use
an explicit tab character instead of '\t' as some sed implementations
treat '\t' as an escaped 't' instead of a tab.

gdb/ChangeLog:

	* gnulib/aclocal-m4-deps.mk: New file.
	* gnulib/update-gnulib.sh: Generate "aclocal-m4-deps.mk"
	deterministically.
2018-09-18 14:05:47 -07:00
John Baldwin 9f235e09e4 Use KF_PATH to verify the size of a struct kinfo_file.
fbsd_core_vnode_path needs to use the offset of the kf_path member of
struct kinfo_file as the minimum size of a struct kinfo_file object.
However, it was using KVE_PATH instead due to a copy and paste bug.

While here, fix another copy and paste bug in the error message for a
truncated kinfo_file object.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_core_vnode_path): Use KF_PATH instead of
	KVE_PATH.
2018-09-18 14:05:47 -07:00
Sergio Durigan Junior 5031d0ae0b Expect optional "arch=" when executing "-stack-list-frames" on gdb.arch/amd64-invalid-stack-top.exp
Another case of incomplete regexp.  The problem is very similar to the
one happening with gdb.arch/amd64-invalid-stack-middle.exp.

The output when GDB is compiled with "--enable-targets" is:

  (gdb) interpreter-exec mi "-stack-list-frames"
  ^done,stack=[frame={level="0",addr="0x00000000004005e7",func="func2",arch="i386:x86-64"}]

While the output when "--enable-targets" is not specified is:

  (gdb) interpreter-exec mi "-stack-list-frames"
  ^done,stack=[frame={level="0",addr="0x00000000004005e7",func="func2"}]

The fix is, again, to extend the current regexp and expect for the
optional "arch=" part.  With this patch, the test now passes on both
scenarios.

OK?

gdb/testsuite/ChangeLog:
2018-09-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.arch/amd64-invalid-stack-top.exp: Expect optional
	"arch=" keyword when executing "-stack-list-frames".
2018-09-18 13:54:02 -04:00
Sergio Durigan Junior b4c0d1a440 Expect optional "arch=" when executing "-stack-list-frames" on gdb.arch/amd64-invalid-stack-middle.exp
While regression-testing GDB on Fedora Rawhide, I saw the following
output when running gdb.arch/amd64-invalid-stack-middle.exp's
"-stack-list-frames" test:

  (gdb) interpreter-exec mi "-stack-list-frames"
  ^done,stack=[frame={level="0",addr="0x000000000040115a",func="breakpt",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/fedora/gdb/master/gdb-8.2.50.20180917/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="27",arch="i386:x86-64"},frame={level="1",addr="0x000000000040116a",func="func5",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/fedora/gdb/master/gdb-8.2.50.20180917/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="32",arch="i386:x86-64"},frame={level="2",addr="0x000000000040117a",func="func4",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/fedora/gdb/master/gdb-8.2.50.20180917/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="38",arch="i386:x86-64"},frame={level="3",addr="0x000000000040118a",func="func3",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/fedora/gdb/master/gdb-8.2.50.20180917/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="44",arch="i386:x86-64"}]

This test is currently failing on Rawhide.  However, this output is
almost the same as I get on my local Fedora 28 machine (where the test
is passing):

  (gdb) interpreter-exec mi "-stack-list-frames"
  ^done,stack=[frame={level="0",addr="0x00000000004005da",func="breakpt",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/work/src/git/binutils-gdb/binutils-gdb/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="27"},frame={level="1",addr="0x00000000004005ea",func="func5",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/work/src/git/binutils-gdb/binutils-gdb/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="32"},frame={level="2",addr="0x00000000004005fa",func="func4",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/work/src/git/binutils-gdb/binutils-gdb/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="38"},frame={level="3",addr="0x000000000040060a",func="func3",file="amd64-invalid-stack-middle.c",fullname="/home/sergio/work/src/git/binutils-gdb/binutils-gdb/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.c",line="44"}]

With the exception that there's an "arch=" keyword on Fedora Rawhide's
version.  This is because, on Rawhide, I've compiled GDB with
"--enable-targets=xyz,kqp,etc.", while locally I haven't.

This is easy to fix: we just have to extend the regexp and expect for
the optional "arch=" keyword there.  It's what this patch does.  With
it applied, the test now passes everywhere.

OK?

gdb/testsuite/ChangeLog:
2018-09-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.arch/amd64-invalid-stack-middle.exp: Expect optional
	"arch=" keyword when executing "-stack-list-frames".
2018-09-18 13:53:28 -04:00
Sergio Durigan Junior 7a6d2b458f Expect for "@" when doing "complete break ada" on gdb.ada/complete.exp
Currently, gdb.ada/complete.exp's "complete break ada" test fails
because the regexp used to match the command's output doesn't expect
"@", but we have an output like:

  ...
  complete break ada
  break ada.assertions.assert
  break ada.calendar.arithmetic.difference
  break ada.calendar.arithmetic_operations.add
  break ada.calendar.arithmetic_operations.add.cold
  break ada.calendar.arithmetic_operations.add@plt
  break ada.calendar.arithmetic_operations.difference
  break ada.calendar.arithmetic_operations.difference@plt
  ...

This patch adds "@" to the regexp, unbreaking the test.

OK?

gdb/testsuite/ChangeLog:
2018-09-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.ada/complete.exp: Expect for "@" when doing "complete
	break ada".
2018-09-18 13:50:51 -04:00
Tom Tromey 40f03055a2 Remove remaining cleanups from compile-object-load.c
This removes the remaining cleanups from compile-object-load.c.

gdb/ChangeLog
2018-09-18  Tom Tromey  <tom@tromey.com>

	* compile/compile-object-load.c (struct
	link_hash_table_cleanup_data): Add constructor and destructor.
	Use DISABLE_COPY_AND_ASSIGN.
	(~link_hash_table_cleanup_data): Rename from
	link_hash_table_free.  Now a destructor.
	(copy_sections): Use gdb::unique_xmalloc_ptr.  Remove cleanups.
2018-09-18 10:18:04 -06:00
Tom Tromey c9e0a7e333 Remove munmap_listp_free_cleanup
This removes munmap_listp_free_cleanup, replacing it with a
std::unique_ptr at one spot and an explicit delete in another.  It
seemed simplest to completely change this data structure.

gdb/ChangeLog
2018-09-18  Tom Tromey  <tom@tromey.com>

	* compile/compile-object-run.c (do_module_cleanup): Use delete.
	* compile/compile-object-load.c (struct munmap_list): Move to
	header file.
	(munmap_list::add): Rename from munmap_list_add; rewrite.
	(munmap_list::~munmap_list): Rename from munmap_list_free.
	(munmap_listp_free_cleanup): Remove.
	(compile_object_load): Update.
	* compile/compile-object-load.h (struct munmap_list): Move from
	compile-object-load.c.  Rewrite.
2018-09-18 10:18:04 -06:00
Alan Hayward 3ff2c72e14 Aarch64 SVE: Fix stack smashing when calling functions
Using "call" on a function that passes arguments via float registers can cause
gdb to overflow buffers.

Ensure enough memory is reserved to hold a full FP register.

This fixes gdb.base/callfuncs.exp for Aarch64 SVE.

2018-09-18  Alan Hayward  <alan.hayward@arm.com>

	* aarch64-tdep.c (pass_in_v): Use register size.
	(aarch64_extract_return_value): Likewise.
	(aarch64_store_return_value): Likewise.
2018-09-18 16:24:27 +01:00
Rainer Orth 206c1947c1 Cast RLIM_INFINITY to rlim_t to fix 64-bit Solaris 10 build
gdb doesn't currently build on 64-bit Solaris 10:

/vol/src/gnu/gdb/hg/master/local/gdb/utils.c: In function ‘void dump_core()’:
/vol/src/gnu/gdb/hg/master/local/gdb/utils.c:223:55: error: narrowing conversion
 of ‘-3’ from ‘long int’ to ‘rlim_t’ {aka ‘long unsigned int’} inside {
} [-Wnarrowing]
   struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY };
                                                       ^
/vol/src/gnu/gdb/hg/master/local/gdb/utils.c:223:55: error: narrowing conversion
 of ‘-3’ from ‘long int’ to ‘rlim_t’ {aka ‘long unsigned int’} inside {
} [-Wnarrowing]

This was introduced by

2018-08-27  Tom Tromey  <tom@tromey.com>

	PR build/23087:
	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Remove -Wno-narrowing.

and can be fixed by the following patch.

Solaris 11 isn't affected because there <sys/resource.h> has

#define	RLIM_INFINITY	((rlim_t)-3l)

instead of

#define RLIM_INFINITY   (-3l)

on Solaris 10.

Tested on amd64-pc-solaris2.10 and amd64-pc-solaris2.11.

	* utils.c (dump_core) [HAVE_SETRLIMIT]: Cast RLIM_INFINITY to
	rlim_t.
2018-09-18 09:14:11 +02:00
Philippe Waroquiers 6eb5dbce1e [OBVIOUS] ChangeLog for obvious enable frame-filter help fix.
ChangeLog for 62b1765c90
2018-09-18 00:54:31 +02:00