binutils-gdb/gdb/location.h

290 lines
9.2 KiB
C
Raw Normal View History

/* Data structures and API for event locations in GDB.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
Normalize include guards in gdb While working on my other scripts to deal with gdb headers, I noticed that some files were missing include guards. I wrote a script to add the missing ones, but found that using the obvious names for the guards ran into clashes -- for example, gdb/nat/linux-nat.h used "LINUX_NAT_H", but this was also the script's choice for gdb/linux-nat.h. So, I changed the script to normalize all include guards in gdb. This patch is the result. As usual the script is available here: https://github.com/tromey/gdb-refactoring-scripts Tested by rebuilding; I also ran it through "Fedora-x86_64-m64" on the buildbot. gdb/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * yy-remap.h: Add include guard. * xtensa-tdep.h: Add include guard. * xcoffread.h: Rename include guard. * varobj-iter.h: Add include guard. * tui/tui.h: Rename include guard. * tui/tui-winsource.h: Rename include guard. * tui/tui-wingeneral.h: Rename include guard. * tui/tui-windata.h: Rename include guard. * tui/tui-win.h: Rename include guard. * tui/tui-stack.h: Rename include guard. * tui/tui-source.h: Rename include guard. * tui/tui-regs.h: Rename include guard. * tui/tui-out.h: Rename include guard. * tui/tui-layout.h: Rename include guard. * tui/tui-io.h: Rename include guard. * tui/tui-hooks.h: Rename include guard. * tui/tui-file.h: Rename include guard. * tui/tui-disasm.h: Rename include guard. * tui/tui-data.h: Rename include guard. * tui/tui-command.h: Rename include guard. * tic6x-tdep.h: Add include guard. * target/waitstatus.h: Rename include guard. * target/wait.h: Rename include guard. * target/target.h: Rename include guard. * target/resume.h: Rename include guard. * target-float.h: Rename include guard. * stabsread.h: Add include guard. * rs6000-tdep.h: Add include guard. * riscv-fbsd-tdep.h: Add include guard. * regformats/regdef.h: Rename include guard. * record.h: Rename include guard. * python/python.h: Rename include guard. * python/python-internal.h: Rename include guard. * python/py-stopevent.h: Rename include guard. * python/py-ref.h: Rename include guard. * python/py-record.h: Rename include guard. * python/py-record-full.h: Rename include guard. * python/py-record-btrace.h: Rename include guard. * python/py-instruction.h: Rename include guard. * python/py-events.h: Rename include guard. * python/py-event.h: Rename include guard. * procfs.h: Add include guard. * proc-utils.h: Add include guard. * p-lang.h: Add include guard. * or1k-tdep.h: Rename include guard. * observable.h: Rename include guard. * nto-tdep.h: Rename include guard. * nat/x86-linux.h: Rename include guard. * nat/x86-linux-dregs.h: Rename include guard. * nat/x86-gcc-cpuid.h: Add include guard. * nat/x86-dregs.h: Rename include guard. * nat/x86-cpuid.h: Rename include guard. * nat/ppc-linux.h: Rename include guard. * nat/mips-linux-watch.h: Rename include guard. * nat/linux-waitpid.h: Rename include guard. * nat/linux-ptrace.h: Rename include guard. * nat/linux-procfs.h: Rename include guard. * nat/linux-osdata.h: Rename include guard. * nat/linux-nat.h: Rename include guard. * nat/linux-namespaces.h: Rename include guard. * nat/linux-btrace.h: Rename include guard. * nat/glibc_thread_db.h: Rename include guard. * nat/gdb_thread_db.h: Rename include guard. * nat/gdb_ptrace.h: Rename include guard. * nat/fork-inferior.h: Rename include guard. * nat/amd64-linux-siginfo.h: Rename include guard. * nat/aarch64-sve-linux-sigcontext.h: Rename include guard. * nat/aarch64-sve-linux-ptrace.h: Rename include guard. * nat/aarch64-linux.h: Rename include guard. * nat/aarch64-linux-hw-point.h: Rename include guard. * mn10300-tdep.h: Add include guard. * mips-linux-tdep.h: Add include guard. * mi/mi-parse.h: Rename include guard. * mi/mi-out.h: Rename include guard. * mi/mi-main.h: Rename include guard. * mi/mi-interp.h: Rename include guard. * mi/mi-getopt.h: Rename include guard. * mi/mi-console.h: Rename include guard. * mi/mi-common.h: Rename include guard. * mi/mi-cmds.h: Rename include guard. * mi/mi-cmd-break.h: Rename include guard. * m2-lang.h: Add include guard. * location.h: Rename include guard. * linux-record.h: Rename include guard. * linux-nat.h: Add include guard. * linux-fork.h: Add include guard. * i386-darwin-tdep.h: Rename include guard. * hppa-linux-offsets.h: Add include guard. * guile/guile.h: Rename include guard. * guile/guile-internal.h: Rename include guard. * gnu-nat.h: Rename include guard. * gdb-stabs.h: Rename include guard. * frv-tdep.h: Add include guard. * f-lang.h: Add include guard. * event-loop.h: Add include guard. * darwin-nat.h: Rename include guard. * cp-abi.h: Rename include guard. * config/sparc/nm-sol2.h: Rename include guard. * config/nm-nto.h: Rename include guard. * config/nm-linux.h: Add include guard. * config/i386/nm-i386gnu.h: Rename include guard. * config/djgpp/nl_types.h: Rename include guard. * config/djgpp/langinfo.h: Rename include guard. * compile/gcc-cp-plugin.h: Add include guard. * compile/gcc-c-plugin.h: Add include guard. * compile/compile.h: Rename include guard. * compile/compile-object-run.h: Rename include guard. * compile/compile-object-load.h: Rename include guard. * compile/compile-internal.h: Rename include guard. * compile/compile-cplus.h: Rename include guard. * compile/compile-c.h: Rename include guard. * common/xml-utils.h: Rename include guard. * common/x86-xstate.h: Rename include guard. * common/version.h: Rename include guard. * common/vec.h: Rename include guard. * common/tdesc.h: Rename include guard. * common/selftest.h: Rename include guard. * common/scoped_restore.h: Rename include guard. * common/scoped_mmap.h: Rename include guard. * common/scoped_fd.h: Rename include guard. * common/safe-iterator.h: Rename include guard. * common/run-time-clock.h: Rename include guard. * common/refcounted-object.h: Rename include guard. * common/queue.h: Rename include guard. * common/ptid.h: Rename include guard. * common/print-utils.h: Rename include guard. * common/preprocessor.h: Rename include guard. * common/pathstuff.h: Rename include guard. * common/observable.h: Rename include guard. * common/netstuff.h: Rename include guard. * common/job-control.h: Rename include guard. * common/host-defs.h: Rename include guard. * common/gdb_wait.h: Rename include guard. * common/gdb_vecs.h: Rename include guard. * common/gdb_unlinker.h: Rename include guard. * common/gdb_unique_ptr.h: Rename include guard. * common/gdb_tilde_expand.h: Rename include guard. * common/gdb_sys_time.h: Rename include guard. * common/gdb_string_view.h: Rename include guard. * common/gdb_splay_tree.h: Rename include guard. * common/gdb_setjmp.h: Rename include guard. * common/gdb_ref_ptr.h: Rename include guard. * common/gdb_optional.h: Rename include guard. * common/gdb_locale.h: Rename include guard. * common/gdb_assert.h: Rename include guard. * common/filtered-iterator.h: Rename include guard. * common/filestuff.h: Rename include guard. * common/fileio.h: Rename include guard. * common/environ.h: Rename include guard. * common/common-utils.h: Rename include guard. * common/common-types.h: Rename include guard. * common/common-regcache.h: Rename include guard. * common/common-inferior.h: Rename include guard. * common/common-gdbthread.h: Rename include guard. * common/common-exceptions.h: Rename include guard. * common/common-defs.h: Rename include guard. * common/common-debug.h: Rename include guard. * common/cleanups.h: Rename include guard. * common/buffer.h: Rename include guard. * common/btrace-common.h: Rename include guard. * common/break-common.h: Rename include guard. * cli/cli-utils.h: Rename include guard. * cli/cli-style.h: Rename include guard. * cli/cli-setshow.h: Rename include guard. * cli/cli-script.h: Rename include guard. * cli/cli-interp.h: Rename include guard. * cli/cli-decode.h: Rename include guard. * cli/cli-cmds.h: Rename include guard. * charset-list.h: Add include guard. * buildsym-legacy.h: Rename include guard. * bfin-tdep.h: Add include guard. * ax.h: Rename include guard. * arm-linux-tdep.h: Add include guard. * arm-fbsd-tdep.h: Add include guard. * arch/xtensa.h: Rename include guard. * arch/tic6x.h: Add include guard. * arch/i386.h: Add include guard. * arch/arm.h: Rename include guard. * arch/arm-linux.h: Rename include guard. * arch/arm-get-next-pcs.h: Rename include guard. * arch/amd64.h: Add include guard. * arch/aarch64-insn.h: Rename include guard. * arch-utils.h: Rename include guard. * annotate.h: Add include guard. * amd64-darwin-tdep.h: Rename include guard. * aarch64-linux-tdep.h: Add include guard. * aarch64-fbsd-tdep.h: Add include guard. * aarch32-linux-nat.h: Add include guard. gdb/gdbserver/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * x86-tdesc.h: Rename include guard. * x86-low.h: Add include guard. * wincecompat.h: Rename include guard. * win32-low.h: Add include guard. * utils.h: Rename include guard. * tracepoint.h: Rename include guard. * tdesc.h: Rename include guard. * target.h: Rename include guard. * server.h: Rename include guard. * remote-utils.h: Rename include guard. * regcache.h: Rename include guard. * nto-low.h: Rename include guard. * notif.h: Add include guard. * mem-break.h: Rename include guard. * lynx-low.h: Add include guard. * linux-x86-tdesc.h: Add include guard. * linux-s390-tdesc.h: Add include guard. * linux-ppc-tdesc-init.h: Add include guard. * linux-low.h: Add include guard. * linux-aarch64-tdesc.h: Add include guard. * linux-aarch32-low.h: Add include guard. * inferiors.h: Rename include guard. * i387-fp.h: Rename include guard. * hostio.h: Rename include guard. * gdbthread.h: Rename include guard. * gdb_proc_service.h: Rename include guard. * event-loop.h: Rename include guard. * dll.h: Rename include guard. * debug.h: Rename include guard. * ax.h: Rename include guard.
2019-01-27 20:51:36 +01:00
#ifndef LOCATION_H
#define LOCATION_H
struct language_defn;
struct event_location;
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* An enumeration of possible signs for a line offset. */
enum offset_relative_sign
{
/* No sign */
LINE_OFFSET_NONE,
/* A plus sign ("+") */
LINE_OFFSET_PLUS,
/* A minus sign ("-") */
LINE_OFFSET_MINUS,
/* A special "sign" for unspecified offset. */
LINE_OFFSET_UNKNOWN
};
/* A line offset in a location. */
struct line_offset
{
/* Line offset and any specified sign. */
int offset;
enum offset_relative_sign sign;
};
/* An enumeration of the various ways to specify a stop event
location (used with create_breakpoint). */
enum event_location_type
{
/* A traditional linespec. */
LINESPEC_LOCATION,
/* An address in the inferior. */
ADDRESS_LOCATION,
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* An explicit location. */
EXPLICIT_LOCATION,
/* A probe location. */
PROBE_LOCATION
};
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* A traditional linespec. */
struct linespec_location
{
/* Whether the function name is fully-qualified or not. */
symbol_name_match_type match_type;
/* The linespec. */
char *spec_string;
};
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* An explicit location. This structure is used to bypass the
parsing done on linespecs. It still has the same requirements
as linespecs, though. For example, source_filename requires
at least one other field. */
struct explicit_location
{
/* The source filename. Malloc'd. */
char *source_filename;
/* The function name. Malloc'd. */
char *function_name;
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* Whether the function name is fully-qualified or not. */
symbol_name_match_type func_name_match_type;
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* The name of a label. Malloc'd. */
char *label_name;
/* A line offset relative to the start of the symbol
identified by the above fields or the current symtab
if the other fields are NULL. */
struct line_offset line_offset;
};
/* Return the type of the given event location. */
extern enum event_location_type
event_location_type (const struct event_location *);
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* Return a malloc'd explicit string representation of the given
explicit location. The location must already be canonicalized/valid. */
extern char *
Mass rename `explicit' -> `explicit_loc'. BuildBot reminded me that "explicit" is a reserved keyword in C++. This patch simply renames all the (illegal) uses of "explicit". This should fix the build errors with --enable-build-with-cxx bots. gdb/ChangeLog * break-catch-throw.c (re_set_exception_catchpoint) Rename reserved C++ keyword "explicit" to "explicit_loc". * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint, update_static_tracepoint): Rename reserved C++ keyword "explicit" to "explicit_loc". * completer.c (collect_explicit_location_matches) (explicit_location_completer): Rename reserved C++ keyword "explicit" to "explicit_loc". * linespec.c (struct linespec) <explicit>: Rename to "explicit_loc". (canonicalize_linespec, create_sals_line_offset) (convert_linespec_to_sals, convert_explicit_location_to_sals) (event_location_to_sals, decode_objc): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.c (struct event_location) <explicit>: Rename to "explicit_loc". (initialize_explicit_location, new_explicit_location) (explicit_location_to_string_internal, explicit_location_to_linespec): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.h (explicit_location_to_string) (explicit_location_to_linespec, initialize_explicit_location) (new_explicit_location): Rename reserved C++ keyword "explicit" to "explicit_loc". * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Rename reserved C++ keyword "explicit" to "explicit_loc".
2015-08-13 18:48:12 +02:00
explicit_location_to_string (const struct explicit_location *explicit_loc);
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* Return a malloc'd linespec string representation of the given
explicit location. The location must already be canonicalized/valid. */
extern char *
Mass rename `explicit' -> `explicit_loc'. BuildBot reminded me that "explicit" is a reserved keyword in C++. This patch simply renames all the (illegal) uses of "explicit". This should fix the build errors with --enable-build-with-cxx bots. gdb/ChangeLog * break-catch-throw.c (re_set_exception_catchpoint) Rename reserved C++ keyword "explicit" to "explicit_loc". * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint, update_static_tracepoint): Rename reserved C++ keyword "explicit" to "explicit_loc". * completer.c (collect_explicit_location_matches) (explicit_location_completer): Rename reserved C++ keyword "explicit" to "explicit_loc". * linespec.c (struct linespec) <explicit>: Rename to "explicit_loc". (canonicalize_linespec, create_sals_line_offset) (convert_linespec_to_sals, convert_explicit_location_to_sals) (event_location_to_sals, decode_objc): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.c (struct event_location) <explicit>: Rename to "explicit_loc". (initialize_explicit_location, new_explicit_location) (explicit_location_to_string_internal, explicit_location_to_linespec): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.h (explicit_location_to_string) (explicit_location_to_linespec, initialize_explicit_location) (new_explicit_location): Rename reserved C++ keyword "explicit" to "explicit_loc". * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Rename reserved C++ keyword "explicit" to "explicit_loc".
2015-08-13 18:48:12 +02:00
explicit_location_to_linespec (const struct explicit_location *explicit_loc);
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* Return a string representation of the LOCATION.
This function may return NULL for unspecified linespecs,
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
e.g, LINESPEC_LOCATION and spec_string is NULL.
The result is cached in LOCATION. */
extern const char *
event_location_to_string (struct event_location *location);
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
/* A deleter for a struct event_location. */
struct event_location_deleter
{
void operator() (event_location *location) const;
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
};
/* A unique pointer for event_location. */
typedef std::unique_ptr<event_location, event_location_deleter>
event_location_up;
/* Create a new linespec location. */
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
extern event_location_up new_linespec_location
(const char **linespec, symbol_name_match_type match_type);
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* Return the linespec location of the given event_location (which
must be of type LINESPEC_LOCATION). */
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
extern const linespec_location *
get_linespec_location (const struct event_location *location);
Fix regression introduced in "break *<EXPR>" by explicit location patches. A relatively recent patch support for explicit locations, and part of that patch cleaned up the way we parse breakpoint locations. Unfortunatly, a small regression crept in for "*<EXPR>" breakpoint locations. In particular, on PIE programs, one can see the issue by doing the following, with any program: (gdb) b *main Breakpoint 1 at 0x51a: file hello.c, line 3. (gdb) run Starting program: /[...]/hello Error in re-setting breakpoint 1: Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x51a Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x51a Just for the record, this regression was introduced by: commit a06efdd6effd149a1d392df8d62824e44872003a Date: Tue Aug 11 17:09:35 2015 -0700 Subject: Explicit locations: introduce address locations What happens is that the patch makes the implicit assumption that the address computed the first time is static, as if it was designed to only support litteral expressions (Eg. "*0x1234"). This allows the shortcut of not re-computing the breakpoint location's address when re-setting breakpoints. However, this does not work in general, as demonstrated in the example above. This patch plugs that hole simply by saving the original expression used to compute the address as part of the address location, so as to then re-evaluate that expression during breakpoint re-set. gdb/ChangeLog: * location.h (new_address_location): Add new parameters "addr_string" and "addr_string_len". (get_address_string_location): Add declaration. * location.c (new_address_location): Add new parameters "addr_string" and "addr_string_len". If not NULL, store a copy of the addr_string in the new location as well. (get_address_string_location): New function. (string_to_event_location): Update call to new_address_location. * linespec.c (event_location_to_sals) <ADDRESS_LOCATION>: Save the event location in the parser's state before passing it to convert_address_location_to_sals. * breakpoint.c (create_thread_event_breakpoint): Update call to new_address_location. (init_breakpoint_sal): Get the event location's string, if any, and use it to update call to new_address_location. * python/py-finishbreakpoint.c (bpfinishpy_init): Update call to new_address_location. * spu-tdep.c (spu_catch_start): Likewise. * config/djgpp/fnchange.lst: Add entries for gdb/testsuite/gdb.base/break-fun-addr1.c and gdb/testsuite/gdb.base/break-fun-addr2.c. gdb/testsuite/ChangeLog: * gdb.base/break-fun-addr.exp: New file. * gdb.base/break-fun-addr1.c: New file. * gdb.base/break-fun-addr2.c: New file.
2015-12-08 19:04:56 +01:00
/* Create a new address location.
ADDR is the address corresponding to this event_location.
ADDR_STRING, a string of ADDR_STRING_LEN characters, is
the expression that was parsed to determine the address ADDR. */
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
extern event_location_up new_address_location (CORE_ADDR addr,
const char *addr_string,
int addr_string_len);
/* Return the address location (a CORE_ADDR) of the given event_location
(which must be of type ADDRESS_LOCATION). */
extern CORE_ADDR
get_address_location (const struct event_location *location);
Fix regression introduced in "break *<EXPR>" by explicit location patches. A relatively recent patch support for explicit locations, and part of that patch cleaned up the way we parse breakpoint locations. Unfortunatly, a small regression crept in for "*<EXPR>" breakpoint locations. In particular, on PIE programs, one can see the issue by doing the following, with any program: (gdb) b *main Breakpoint 1 at 0x51a: file hello.c, line 3. (gdb) run Starting program: /[...]/hello Error in re-setting breakpoint 1: Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x51a Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x51a Just for the record, this regression was introduced by: commit a06efdd6effd149a1d392df8d62824e44872003a Date: Tue Aug 11 17:09:35 2015 -0700 Subject: Explicit locations: introduce address locations What happens is that the patch makes the implicit assumption that the address computed the first time is static, as if it was designed to only support litteral expressions (Eg. "*0x1234"). This allows the shortcut of not re-computing the breakpoint location's address when re-setting breakpoints. However, this does not work in general, as demonstrated in the example above. This patch plugs that hole simply by saving the original expression used to compute the address as part of the address location, so as to then re-evaluate that expression during breakpoint re-set. gdb/ChangeLog: * location.h (new_address_location): Add new parameters "addr_string" and "addr_string_len". (get_address_string_location): Add declaration. * location.c (new_address_location): Add new parameters "addr_string" and "addr_string_len". If not NULL, store a copy of the addr_string in the new location as well. (get_address_string_location): New function. (string_to_event_location): Update call to new_address_location. * linespec.c (event_location_to_sals) <ADDRESS_LOCATION>: Save the event location in the parser's state before passing it to convert_address_location_to_sals. * breakpoint.c (create_thread_event_breakpoint): Update call to new_address_location. (init_breakpoint_sal): Get the event location's string, if any, and use it to update call to new_address_location. * python/py-finishbreakpoint.c (bpfinishpy_init): Update call to new_address_location. * spu-tdep.c (spu_catch_start): Likewise. * config/djgpp/fnchange.lst: Add entries for gdb/testsuite/gdb.base/break-fun-addr1.c and gdb/testsuite/gdb.base/break-fun-addr2.c. gdb/testsuite/ChangeLog: * gdb.base/break-fun-addr.exp: New file. * gdb.base/break-fun-addr1.c: New file. * gdb.base/break-fun-addr2.c: New file.
2015-12-08 19:04:56 +01:00
/* Return the expression (a string) that was used to compute the address
of the given event_location (which must be of type ADDRESS_LOCATION). */
extern const char *
get_address_string_location (const struct event_location *location);
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
/* Create a new probe location. */
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
extern event_location_up new_probe_location (const char *probe);
/* Return the probe location (a string) of the given event_location
(which must be of type PROBE_LOCATION). */
extern const char *
get_probe_location (const struct event_location *location);
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* Initialize the given explicit location. */
Mass rename `explicit' -> `explicit_loc'. BuildBot reminded me that "explicit" is a reserved keyword in C++. This patch simply renames all the (illegal) uses of "explicit". This should fix the build errors with --enable-build-with-cxx bots. gdb/ChangeLog * break-catch-throw.c (re_set_exception_catchpoint) Rename reserved C++ keyword "explicit" to "explicit_loc". * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint, update_static_tracepoint): Rename reserved C++ keyword "explicit" to "explicit_loc". * completer.c (collect_explicit_location_matches) (explicit_location_completer): Rename reserved C++ keyword "explicit" to "explicit_loc". * linespec.c (struct linespec) <explicit>: Rename to "explicit_loc". (canonicalize_linespec, create_sals_line_offset) (convert_linespec_to_sals, convert_explicit_location_to_sals) (event_location_to_sals, decode_objc): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.c (struct event_location) <explicit>: Rename to "explicit_loc". (initialize_explicit_location, new_explicit_location) (explicit_location_to_string_internal, explicit_location_to_linespec): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.h (explicit_location_to_string) (explicit_location_to_linespec, initialize_explicit_location) (new_explicit_location): Rename reserved C++ keyword "explicit" to "explicit_loc". * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Rename reserved C++ keyword "explicit" to "explicit_loc".
2015-08-13 18:48:12 +02:00
extern void
initialize_explicit_location (struct explicit_location *explicit_loc);
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* Create a new explicit location. If not NULL, EXPLICIT is checked for
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
validity. If invalid, an exception is thrown. */
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
extern event_location_up
Mass rename `explicit' -> `explicit_loc'. BuildBot reminded me that "explicit" is a reserved keyword in C++. This patch simply renames all the (illegal) uses of "explicit". This should fix the build errors with --enable-build-with-cxx bots. gdb/ChangeLog * break-catch-throw.c (re_set_exception_catchpoint) Rename reserved C++ keyword "explicit" to "explicit_loc". * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint, update_static_tracepoint): Rename reserved C++ keyword "explicit" to "explicit_loc". * completer.c (collect_explicit_location_matches) (explicit_location_completer): Rename reserved C++ keyword "explicit" to "explicit_loc". * linespec.c (struct linespec) <explicit>: Rename to "explicit_loc". (canonicalize_linespec, create_sals_line_offset) (convert_linespec_to_sals, convert_explicit_location_to_sals) (event_location_to_sals, decode_objc): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.c (struct event_location) <explicit>: Rename to "explicit_loc". (initialize_explicit_location, new_explicit_location) (explicit_location_to_string_internal, explicit_location_to_linespec): Rename reserved C++ keyword "explicit" to "explicit_loc". * location.h (explicit_location_to_string) (explicit_location_to_linespec, initialize_explicit_location) (new_explicit_location): Rename reserved C++ keyword "explicit" to "explicit_loc". * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Rename reserved C++ keyword "explicit" to "explicit_loc".
2015-08-13 18:48:12 +02:00
new_explicit_location (const struct explicit_location *explicit_loc);
Explicit locations: introduce explicit locations This patch add support for explicit locations and switches many linespec locations to this new location type. This patch also converts all linespec locations entered by the user to an explicit representation internally (thus bypassing the linespec parser when resetting the breakpoint). This patch does not introduce any user-visible changes. gdb/ChangeLog: * break-catch-throw.c (re_set_exception_catchpoint): Convert linespec into explicit location. * breakpoint.c (create_overlay_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Convert linespec into explicit location. (update_static_tracepoint): Convert linespec into explicit location. * linespec.c (enum offset_relative_sign, struct line_offset): Move location.h. (struct linespec) <expression, expr_pc, source_filename> <function_name, label_name, line_offset>: Replace with ... <explicit>: ... this. <is_linespec>: New member. (PARSER_EXPLICIT): New accessor macro. (undefined_label_error): New function. (source_file_not_found_error): New function. (linespec_parse_basic): The parser result is now an explicit location. Use PARSER_EXPLICIT to access it. Use undefined_label_error. (canonicalize_linespec): Convert canonical linespec into explicit location. Move string representation of location to explicit_location_to_linespec and use it and explicit_location_to_string to save string representations of the canonical location. (create_sals_line_offset, convert_linespec_to_sals): `ls' contains an explicit location. Update all references. (convert_explicit_location_to_sals): New function. (parse_linespec): Use PARSER_EXPLICIT to access the parser result's explicit location. (linespec_state_constructor): Initialize is_linespec. Use PARSER_EXPLICIT. (linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's result. (event_location_to_sals): For linespec locations, set is_linespec. Handle explicit locations. (decode_objc): 'ls' contains an explicit location now. Update all references. (symtabs_from_filename): Use source_file_not_found_error. * location.c (struct event_location.u) <explicit>: New member. (initialize_explicit_location): New function. (initialize_event_location): Initialize explicit locations. (new_explicit_location, get_explicit_location) (get_explicit_location_const): New functions. (explicit_to_string_internal): New function; most of contents moved from canonicalize_linespec. (explicit_location_to_string): New function. (explicit_location_to_linespec): New function. (copy_event_location, delete_event_location) (event_location_to_string_const, event_location_empty_p): Handle explicit locations. * location.h (enum offset_relative_sign, struct line_offset): Move here from linespec.h. (enum event_location_type): Add EXPLICIT_LOCATION. (struct explicit_location): New structure. (explicit_location_to_string): Declare. (explicit_location_to_linespec): Declare. (new_explicit_location, get_explicit_locationp (get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-12 02:09:35 +02:00
/* Return the explicit location of the given event_location
(which must be of type EXPLICIT_LOCATION). */
extern struct explicit_location *
get_explicit_location (struct event_location *location);
/* A const version of the above. */
extern const struct explicit_location *
get_explicit_location_const (const struct event_location *location);
/* Return a copy of the given SRC location. */
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
extern event_location_up
copy_event_location (const struct event_location *src);
/* Attempt to convert the input string in *ARGP into an event_location.
ARGP is advanced past any processed input. Returns an event_location
(malloc'd) if an event location was successfully found in *ARGP,
NULL otherwise.
This function may call error() if *ARGP looks like properly formed,
but invalid, input, e.g., if it is called with missing argument parameters
or invalid options.
This function is intended to be used by CLI commands and will parse
explicit locations in a CLI-centric way. Other interfaces should use
string_to_event_location_basic if they want to maintain support for
legacy specifications of probe, address, and linespec locations.
MATCH_TYPE should be either WILD or FULL. If -q/--qualified is specified
in the input string, it will take precedence over this parameter. */
extern event_location_up string_to_event_location
(const char **argp, const struct language_defn *langauge,
symbol_name_match_type match_type = symbol_name_match_type::WILD);
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* Like string_to_event_location, but does not attempt to parse
explicit locations. MATCH_TYPE indicates how function names should
be matched. */
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
extern event_location_up
Constify some linespec functions This changes a few linespec functions to work on "const char *" and then fixes up all the callers. This allows further constification elsewhere. gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * tracepoint.c (info_scope_command): Constify. * python/python.c (gdbpy_decode_line): Constify. * python/py-breakpoint.c (bppy_init): Constify. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Constify. * location.h: (new_linespec_location) (string_to_event_location_basic, string_to_event_location): Constify. * location.c (new_linespec_location) (string_to_event_location_basic, string_to_event_location): Constify. * linespec.h (decode_line_with_current_source) (decode_line_with_last_displayed, linespec_lex_to_end): Constify. * linespec.c (linespec_lex_to_end) (decode_line_with_current_source) (decode_line_with_last_displayed): Constify. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Constify. * cli/cli-cmds.c (edit_command, list_command): Constify. * breakpoint.h (until_break_command, watch_command_wrapper) (awatch_command_wrapper, rwatch_command_wrapper) (init_ada_exception_breakpoint): Constify. * breakpoint.c (break_command_1, dprintf_command) (break_range_command, watch_command_wrapper) (rwatch_command_wrapper, awatch_command_wrapper) (until_break_command, init_ada_exception_breakpoint) (strace_marker_create_sals_from_location, trace_command) (ftrace_command, strace_command, struct tracepoint): Constify. * ax-gdb.c (agent_command_1): Constify. * ada-lang.c (ada_exception_sal): Constify.
2017-09-13 02:32:41 +02:00
string_to_event_location_basic (const char **argp,
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
const struct language_defn *language,
symbol_name_match_type match_type);
Rewrite/enhance explicit locations completer, parse left->right One of the most annoying (to me) things about GDB's completion is when you have overloads in your program, and you want to set a breakpoint in one of them: void function(int); // set breakpoint here. void function(long); (gdb) b -f func[TAB] (gdb) b -f function( # ok, gdb completed as much as possible. (gdb) b -f function([TAB] # show me the overloads, please. <_all_ symbols in the program are shown...> E.g., when debugging GDB, that'd be: (gdb) b -f function([TAB] (anonymous namespace)::get_global()::global pt_insn_get_offset@plt scm_new_port_table_entry asprintf pt_pkt_alloc_decoder scm_new_port_table_entry@plt asprintf@plt pt_pkt_alloc_decoder@plt scm_out_of_range bt_ctf_get_char_array pt_pkt_sync_forward scm_out_of_range@plt bt_ctf_get_char_array@plt pt_pkt_sync_forward@plt scm_putc bt_ctf_get_uint64 pwrite scm_putc@plt bt_ctf_get_uint64@plt pwrite@plt scm_reverse_x bt_ctf_iter_read_event PyErr_Restore scm_reverse_x@plt bt_ctf_iter_read_event@plt PyErr_Restore@plt scm_set_port_filename_x <snip...> Now that's a load of completely useless completions. The reason GDB offers those is that the completer relies on readline figuring out the completion word point in the input line based on the language's word break characters, which include "(". So readline tells the completer to complete on "", the string that is after '('. Likewise, if you type "function(i[TAB]" to try to complete to "int", you're out of luck. GDB shows you all the symbols in the program that start with "i"... This makes sense for the expression completer, as what you'd want to type is e.g., a global variable, say: (gdb) print function(i[TAB] but, it makes no sense when specifying a function name for a breakpoint location. To get around that limitation, users need to quote the function name, like: (gdb) b -f 'function([TAB] function(int) function(long) (gdb) b 'function(i[TAB] (gdb) b 'function(int)' # now completes correctly! Note that the quoting is only necessary for completion. Creating the breakpoint does not require the quoting: (gdb) b -f function(int) [RET] Breakpoint 1 at .... This patch removes this limitation. ( Actually, it's a necessary patch, though not sufficient. That'll start working correctly by the end of the series. With this patch, if try it, you'll see: (gdb) b -f function(i[TAB] (gdb) b -f function i.e., gdb strips everything after the "(". That's caused by some code in symtab.c that'll be eliminated further down the series. These patches are all unfortunately interrelated, which is also the reason new tests only appear much later in the series. But let's ignore that reality for the remainder of the description. ) So... this patch gets rid of the need for quoting. It does that by adding a way for a completer to control the exact completion word point that readline should start the completion request for, instead of letting readline try to figure it out using the current language's word break chars array, and often failing. In the case above, we want the completer to figure out that it's completing a function name that starts with "function(i". It now does. It took me a while to figure out a way to ask readline to "use this exact word point", and for a while I feared that it'd be impossible with current readline (and having to rely on master readline for core functionality is something I'd like to avoid very much). Eventually, after several different attempts, I came up with what is described in the comment above gdb_custom_word_point_brkchars in the patch. With this patch, the handle_brkchars phase of the explicit location completer advances the expected word point as it parses the input line left to right, until it figures out exactly what we're completing, instead of expecting readline to break the string using the word break characters, and then having the completer heuristically fix up a bad decision by parsing the input string backwards. This allows correctly knowning that we're completing a symbol name after -function, complete functions without quoting, etc. Later, we'll make use of this same mechanims to implement a proper linespec completer that avoids need for quoting too. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * cli/cli-cmds.c (complete_command): Get the completion result out of the handle_brkchars tracker if used a custom word point. * completer.c: Include "linespec.h". (enum explicit_location_match_type) <MATCH_LINE>: New enumerator. (advance_to_expression_complete_word_point): New. (completion_tracker::completes_to_completion_word): New. (complete_files_symbols): Pass down complete_symbol_mode::EXPRESSION. (explicit_options, probe_options): New. (collect_explicit_location_matches): Complete on the explictit_loc->foo instead of word. Use linespec_complete_function. Handle MATCH_LINE. Handle offering keyword and options completions. (backup_text_ptr): Delete. (skip_keyword): New. (complete_explicit_location): Remove 'word' parameter. Add language, quoted_arg_start and quoted_arg_end parameters. Rewrite, parsing left to right. (location_completer): Rewrite. (location_completer_handle_brkchars): New function. (symbol_completer): Pass down complete_symbol_mode::EXPRESSION. (enum complete_line_internal_reason): Adjust comments. (completion_tracker::discard_completions): New. (completer_handle_brkchars_func_for_completer): Handle location_completer. (gdb_custom_word_point_brkchars) (gdb_org_rl_basic_quote_characters): New. (gdb_completion_word_break_characters_throw) (completion_find_completion_word): Handle trackers that use a custom word point. (completion_tracker::advance_custom_word_point_by): New. (completion_tracker::build_completion_result): Don't rely on readline appending the quote char. (gdb_rl_attempted_completion_function_throw): Handle trackers that use a custom word point. (gdb_rl_attempted_completion_function): Restore rl_basic_quote_characters. * completer.h (class completion_tracker): Extend intro comment. (completion_tracker::set_quote_char) (completion_tracker::quote_char) (completion_tracker::set_use_custom_word_point) (completion_tracker::use_custom_word_point) (completion_tracker::custom_word_point) (completion_tracker::set_custom_word_point) (completion_tracker::advance_custom_word_point_by) (completion_tracker::completes_to_completion_word) (completion_tracker::discard_completions): New methods. (completion_tracker::m_quote_char) (completion_tracker::m_use_custom_word_point) (completion_tracker::m_custom_word_point): New fields. (advance_to_expression_complete_word_point): Declare. * f-lang.c (f_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * language.h (struct language_defn) <la_collect_symbol_completion_matches>: Add complete_symbol_mode parameter. * linespec.c (linespec_keywords): Add NULL terminator. Make extern. (linespec_complete_function): New function. (linespec_lexer_lex_keyword): Adjust. * linespec.h (linespec_keywords, linespec_complete_function): New declarations. * location.c (find_end_quote): New function. (explicit_location_lex_one): Add explicit_completion_info parameter. Save quoting info. Don't throw if being called for completion. Don't handle Ada operators here. (is_cp_operator, skip_op_false_positives, first_of) (explicit_location_lex_one_function): New function. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. Handle it. Don't use explicit_location_lex_one to lex function names. Use explicit_location_lex_one_function instead. * location.h (struct explicit_completion_info): New. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. * symtab.c (default_collect_symbol_completion_matches_break_on): Add complete_symbol_mode parameter. Handle LINESPEC mode. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add complete_symbol_mode parameter. (collect_symbol_completion_matches_type): Pass down complete_symbol_mode::EXPRESSION. (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. Handle LINESPEC mode. * symtab.h (complete_symbol_mode): New. (default_collect_symbol_completion_matches_break_on) (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. gdb/testsuite/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * gdb.linespec/ls-errs.exp (do_test): Adjust expected output.
2017-07-17 21:21:33 +02:00
/* Structure filled in by string_to_explicit_location to aid the
completer. */
struct explicit_completion_info
{
/* Pointer to the last option found. E.g., in "b -sou src.c -fun
func", LAST_OPTION is left pointing at "-fun func". */
const char *last_option = NULL;
/* These point to the start and end of a quoted argument, iff the
last argument was quoted. If parsing finds an incomplete quoted
string (e.g., "break -function 'fun"), then QUOTED_ARG_START is
set to point to the opening \', and QUOTED_ARG_END is left NULL.
If the last option is not quoted, then both are set to NULL. */
const char *quoted_arg_start = NULL;
const char *quoted_arg_end = NULL;
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* True if we saw an explicit location option, as opposed to only
flags that affect both explicit locations and linespecs, like
"-qualified". */
bool saw_explicit_location_option = false;
Rewrite/enhance explicit locations completer, parse left->right One of the most annoying (to me) things about GDB's completion is when you have overloads in your program, and you want to set a breakpoint in one of them: void function(int); // set breakpoint here. void function(long); (gdb) b -f func[TAB] (gdb) b -f function( # ok, gdb completed as much as possible. (gdb) b -f function([TAB] # show me the overloads, please. <_all_ symbols in the program are shown...> E.g., when debugging GDB, that'd be: (gdb) b -f function([TAB] (anonymous namespace)::get_global()::global pt_insn_get_offset@plt scm_new_port_table_entry asprintf pt_pkt_alloc_decoder scm_new_port_table_entry@plt asprintf@plt pt_pkt_alloc_decoder@plt scm_out_of_range bt_ctf_get_char_array pt_pkt_sync_forward scm_out_of_range@plt bt_ctf_get_char_array@plt pt_pkt_sync_forward@plt scm_putc bt_ctf_get_uint64 pwrite scm_putc@plt bt_ctf_get_uint64@plt pwrite@plt scm_reverse_x bt_ctf_iter_read_event PyErr_Restore scm_reverse_x@plt bt_ctf_iter_read_event@plt PyErr_Restore@plt scm_set_port_filename_x <snip...> Now that's a load of completely useless completions. The reason GDB offers those is that the completer relies on readline figuring out the completion word point in the input line based on the language's word break characters, which include "(". So readline tells the completer to complete on "", the string that is after '('. Likewise, if you type "function(i[TAB]" to try to complete to "int", you're out of luck. GDB shows you all the symbols in the program that start with "i"... This makes sense for the expression completer, as what you'd want to type is e.g., a global variable, say: (gdb) print function(i[TAB] but, it makes no sense when specifying a function name for a breakpoint location. To get around that limitation, users need to quote the function name, like: (gdb) b -f 'function([TAB] function(int) function(long) (gdb) b 'function(i[TAB] (gdb) b 'function(int)' # now completes correctly! Note that the quoting is only necessary for completion. Creating the breakpoint does not require the quoting: (gdb) b -f function(int) [RET] Breakpoint 1 at .... This patch removes this limitation. ( Actually, it's a necessary patch, though not sufficient. That'll start working correctly by the end of the series. With this patch, if try it, you'll see: (gdb) b -f function(i[TAB] (gdb) b -f function i.e., gdb strips everything after the "(". That's caused by some code in symtab.c that'll be eliminated further down the series. These patches are all unfortunately interrelated, which is also the reason new tests only appear much later in the series. But let's ignore that reality for the remainder of the description. ) So... this patch gets rid of the need for quoting. It does that by adding a way for a completer to control the exact completion word point that readline should start the completion request for, instead of letting readline try to figure it out using the current language's word break chars array, and often failing. In the case above, we want the completer to figure out that it's completing a function name that starts with "function(i". It now does. It took me a while to figure out a way to ask readline to "use this exact word point", and for a while I feared that it'd be impossible with current readline (and having to rely on master readline for core functionality is something I'd like to avoid very much). Eventually, after several different attempts, I came up with what is described in the comment above gdb_custom_word_point_brkchars in the patch. With this patch, the handle_brkchars phase of the explicit location completer advances the expected word point as it parses the input line left to right, until it figures out exactly what we're completing, instead of expecting readline to break the string using the word break characters, and then having the completer heuristically fix up a bad decision by parsing the input string backwards. This allows correctly knowning that we're completing a symbol name after -function, complete functions without quoting, etc. Later, we'll make use of this same mechanims to implement a proper linespec completer that avoids need for quoting too. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * cli/cli-cmds.c (complete_command): Get the completion result out of the handle_brkchars tracker if used a custom word point. * completer.c: Include "linespec.h". (enum explicit_location_match_type) <MATCH_LINE>: New enumerator. (advance_to_expression_complete_word_point): New. (completion_tracker::completes_to_completion_word): New. (complete_files_symbols): Pass down complete_symbol_mode::EXPRESSION. (explicit_options, probe_options): New. (collect_explicit_location_matches): Complete on the explictit_loc->foo instead of word. Use linespec_complete_function. Handle MATCH_LINE. Handle offering keyword and options completions. (backup_text_ptr): Delete. (skip_keyword): New. (complete_explicit_location): Remove 'word' parameter. Add language, quoted_arg_start and quoted_arg_end parameters. Rewrite, parsing left to right. (location_completer): Rewrite. (location_completer_handle_brkchars): New function. (symbol_completer): Pass down complete_symbol_mode::EXPRESSION. (enum complete_line_internal_reason): Adjust comments. (completion_tracker::discard_completions): New. (completer_handle_brkchars_func_for_completer): Handle location_completer. (gdb_custom_word_point_brkchars) (gdb_org_rl_basic_quote_characters): New. (gdb_completion_word_break_characters_throw) (completion_find_completion_word): Handle trackers that use a custom word point. (completion_tracker::advance_custom_word_point_by): New. (completion_tracker::build_completion_result): Don't rely on readline appending the quote char. (gdb_rl_attempted_completion_function_throw): Handle trackers that use a custom word point. (gdb_rl_attempted_completion_function): Restore rl_basic_quote_characters. * completer.h (class completion_tracker): Extend intro comment. (completion_tracker::set_quote_char) (completion_tracker::quote_char) (completion_tracker::set_use_custom_word_point) (completion_tracker::use_custom_word_point) (completion_tracker::custom_word_point) (completion_tracker::set_custom_word_point) (completion_tracker::advance_custom_word_point_by) (completion_tracker::completes_to_completion_word) (completion_tracker::discard_completions): New methods. (completion_tracker::m_quote_char) (completion_tracker::m_use_custom_word_point) (completion_tracker::m_custom_word_point): New fields. (advance_to_expression_complete_word_point): Declare. * f-lang.c (f_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * language.h (struct language_defn) <la_collect_symbol_completion_matches>: Add complete_symbol_mode parameter. * linespec.c (linespec_keywords): Add NULL terminator. Make extern. (linespec_complete_function): New function. (linespec_lexer_lex_keyword): Adjust. * linespec.h (linespec_keywords, linespec_complete_function): New declarations. * location.c (find_end_quote): New function. (explicit_location_lex_one): Add explicit_completion_info parameter. Save quoting info. Don't throw if being called for completion. Don't handle Ada operators here. (is_cp_operator, skip_op_false_positives, first_of) (explicit_location_lex_one_function): New function. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. Handle it. Don't use explicit_location_lex_one to lex function names. Use explicit_location_lex_one_function instead. * location.h (struct explicit_completion_info): New. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. * symtab.c (default_collect_symbol_completion_matches_break_on): Add complete_symbol_mode parameter. Handle LINESPEC mode. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add complete_symbol_mode parameter. (collect_symbol_completion_matches_type): Pass down complete_symbol_mode::EXPRESSION. (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. Handle LINESPEC mode. * symtab.h (complete_symbol_mode): New. (default_collect_symbol_completion_matches_break_on) (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. gdb/testsuite/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * gdb.linespec/ls-errs.exp (do_test): Adjust expected output.
2017-07-17 21:21:33 +02:00
};
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
/* Attempt to convert the input string in *ARGP into an explicit location.
ARGP is advanced past any processed input. Returns an event_location
(malloc'd) if an explicit location was successfully found in *ARGP,
NULL otherwise.
Rewrite/enhance explicit locations completer, parse left->right One of the most annoying (to me) things about GDB's completion is when you have overloads in your program, and you want to set a breakpoint in one of them: void function(int); // set breakpoint here. void function(long); (gdb) b -f func[TAB] (gdb) b -f function( # ok, gdb completed as much as possible. (gdb) b -f function([TAB] # show me the overloads, please. <_all_ symbols in the program are shown...> E.g., when debugging GDB, that'd be: (gdb) b -f function([TAB] (anonymous namespace)::get_global()::global pt_insn_get_offset@plt scm_new_port_table_entry asprintf pt_pkt_alloc_decoder scm_new_port_table_entry@plt asprintf@plt pt_pkt_alloc_decoder@plt scm_out_of_range bt_ctf_get_char_array pt_pkt_sync_forward scm_out_of_range@plt bt_ctf_get_char_array@plt pt_pkt_sync_forward@plt scm_putc bt_ctf_get_uint64 pwrite scm_putc@plt bt_ctf_get_uint64@plt pwrite@plt scm_reverse_x bt_ctf_iter_read_event PyErr_Restore scm_reverse_x@plt bt_ctf_iter_read_event@plt PyErr_Restore@plt scm_set_port_filename_x <snip...> Now that's a load of completely useless completions. The reason GDB offers those is that the completer relies on readline figuring out the completion word point in the input line based on the language's word break characters, which include "(". So readline tells the completer to complete on "", the string that is after '('. Likewise, if you type "function(i[TAB]" to try to complete to "int", you're out of luck. GDB shows you all the symbols in the program that start with "i"... This makes sense for the expression completer, as what you'd want to type is e.g., a global variable, say: (gdb) print function(i[TAB] but, it makes no sense when specifying a function name for a breakpoint location. To get around that limitation, users need to quote the function name, like: (gdb) b -f 'function([TAB] function(int) function(long) (gdb) b 'function(i[TAB] (gdb) b 'function(int)' # now completes correctly! Note that the quoting is only necessary for completion. Creating the breakpoint does not require the quoting: (gdb) b -f function(int) [RET] Breakpoint 1 at .... This patch removes this limitation. ( Actually, it's a necessary patch, though not sufficient. That'll start working correctly by the end of the series. With this patch, if try it, you'll see: (gdb) b -f function(i[TAB] (gdb) b -f function i.e., gdb strips everything after the "(". That's caused by some code in symtab.c that'll be eliminated further down the series. These patches are all unfortunately interrelated, which is also the reason new tests only appear much later in the series. But let's ignore that reality for the remainder of the description. ) So... this patch gets rid of the need for quoting. It does that by adding a way for a completer to control the exact completion word point that readline should start the completion request for, instead of letting readline try to figure it out using the current language's word break chars array, and often failing. In the case above, we want the completer to figure out that it's completing a function name that starts with "function(i". It now does. It took me a while to figure out a way to ask readline to "use this exact word point", and for a while I feared that it'd be impossible with current readline (and having to rely on master readline for core functionality is something I'd like to avoid very much). Eventually, after several different attempts, I came up with what is described in the comment above gdb_custom_word_point_brkchars in the patch. With this patch, the handle_brkchars phase of the explicit location completer advances the expected word point as it parses the input line left to right, until it figures out exactly what we're completing, instead of expecting readline to break the string using the word break characters, and then having the completer heuristically fix up a bad decision by parsing the input string backwards. This allows correctly knowning that we're completing a symbol name after -function, complete functions without quoting, etc. Later, we'll make use of this same mechanims to implement a proper linespec completer that avoids need for quoting too. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * cli/cli-cmds.c (complete_command): Get the completion result out of the handle_brkchars tracker if used a custom word point. * completer.c: Include "linespec.h". (enum explicit_location_match_type) <MATCH_LINE>: New enumerator. (advance_to_expression_complete_word_point): New. (completion_tracker::completes_to_completion_word): New. (complete_files_symbols): Pass down complete_symbol_mode::EXPRESSION. (explicit_options, probe_options): New. (collect_explicit_location_matches): Complete on the explictit_loc->foo instead of word. Use linespec_complete_function. Handle MATCH_LINE. Handle offering keyword and options completions. (backup_text_ptr): Delete. (skip_keyword): New. (complete_explicit_location): Remove 'word' parameter. Add language, quoted_arg_start and quoted_arg_end parameters. Rewrite, parsing left to right. (location_completer): Rewrite. (location_completer_handle_brkchars): New function. (symbol_completer): Pass down complete_symbol_mode::EXPRESSION. (enum complete_line_internal_reason): Adjust comments. (completion_tracker::discard_completions): New. (completer_handle_brkchars_func_for_completer): Handle location_completer. (gdb_custom_word_point_brkchars) (gdb_org_rl_basic_quote_characters): New. (gdb_completion_word_break_characters_throw) (completion_find_completion_word): Handle trackers that use a custom word point. (completion_tracker::advance_custom_word_point_by): New. (completion_tracker::build_completion_result): Don't rely on readline appending the quote char. (gdb_rl_attempted_completion_function_throw): Handle trackers that use a custom word point. (gdb_rl_attempted_completion_function): Restore rl_basic_quote_characters. * completer.h (class completion_tracker): Extend intro comment. (completion_tracker::set_quote_char) (completion_tracker::quote_char) (completion_tracker::set_use_custom_word_point) (completion_tracker::use_custom_word_point) (completion_tracker::custom_word_point) (completion_tracker::set_custom_word_point) (completion_tracker::advance_custom_word_point_by) (completion_tracker::completes_to_completion_word) (completion_tracker::discard_completions): New methods. (completion_tracker::m_quote_char) (completion_tracker::m_use_custom_word_point) (completion_tracker::m_custom_word_point): New fields. (advance_to_expression_complete_word_point): Declare. * f-lang.c (f_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * language.h (struct language_defn) <la_collect_symbol_completion_matches>: Add complete_symbol_mode parameter. * linespec.c (linespec_keywords): Add NULL terminator. Make extern. (linespec_complete_function): New function. (linespec_lexer_lex_keyword): Adjust. * linespec.h (linespec_keywords, linespec_complete_function): New declarations. * location.c (find_end_quote): New function. (explicit_location_lex_one): Add explicit_completion_info parameter. Save quoting info. Don't throw if being called for completion. Don't handle Ada operators here. (is_cp_operator, skip_op_false_positives, first_of) (explicit_location_lex_one_function): New function. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. Handle it. Don't use explicit_location_lex_one to lex function names. Use explicit_location_lex_one_function instead. * location.h (struct explicit_completion_info): New. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. * symtab.c (default_collect_symbol_completion_matches_break_on): Add complete_symbol_mode parameter. Handle LINESPEC mode. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add complete_symbol_mode parameter. (collect_symbol_completion_matches_type): Pass down complete_symbol_mode::EXPRESSION. (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. Handle LINESPEC mode. * symtab.h (complete_symbol_mode): New. (default_collect_symbol_completion_matches_break_on) (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. gdb/testsuite/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * gdb.linespec/ls-errs.exp (do_test): Adjust expected output.
2017-07-17 21:21:33 +02:00
If COMPLETION_INFO is NULL, this function may call error() if *ARGP
looks like improperly formed input, e.g., if it is called with
missing argument parameters or invalid options. If COMPLETION_INFO
is not NULL, this function will not throw any exceptions. */
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
Introduce event_location_up This removes make_cleanup_delete_event_location and instead changes the various location functions to return an event_location_up, a new unique_ptr typedef. This is largely straightforward, but be sure to examine the init_breakpoint_sal change. I believe the code I deleted there is dead, because "location != NULL" can never be true in that branch; but you should double-check. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * tracepoint.c (scope_info): Update. * spu-tdep.c (spu_catch_start): Update. * python/python.c (gdbpy_decode_line): Update. * python/py-finishbreakpoint.c (bpfinishpy_init): Update. * python/py-breakpoint.c (bppy_init): Update. * probe.c (parse_probes): Update. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update. * location.h (event_location_deleter): New struct. (event_location_up): New typedef. (new_linespec_location, new_address_location, new_probe_location) (new_explicit_location, copy_event_location) (string_to_event_location, string_to_event_location_basic) (string_to_explicit_location): Update return type. (make_cleanup_delete_event_location): Remove. * location.c (new_linespec_location, new_address_location) (new_probe_location, new_explicit_location, copy_event_location): Return event_location_up. (delete_event_location_cleanup) (make_cleanup_delete_event_location): Remove. (string_to_explicit_location, string_to_event_location_basic) (string_to_event_location): Return event_location_up. * linespec.c (canonicalize_linespec, event_location_to_sals) (decode_line_with_current_source) (decode_line_with_last_displayed, decode_objc): Update. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update. * completer.c (location_completer): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint) (create_thread_event_breakpoint): Update. (init_breakpoint_sal): Update. Remove some dead code. (create_breakpoint_sal): Change type of "location". Update. (create_breakpoints_sal, create_breakpoint, break_command_1) (dprintf_command, break_range_command, until_break_command) (init_ada_exception_breakpoint) (strace_marker_create_sals_from_location) (update_static_tracepoint, trace_command, ftrace_command) (strace_command, create_tracepoint_from_upload): Update. * break-catch-throw.c (re_set_exception_catchpoint): Update. * ax-gdb.c (agent_command_1): Update.
2017-04-06 04:44:01 +02:00
extern event_location_up
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
string_to_explicit_location (const char **argp,
Rewrite/enhance explicit locations completer, parse left->right One of the most annoying (to me) things about GDB's completion is when you have overloads in your program, and you want to set a breakpoint in one of them: void function(int); // set breakpoint here. void function(long); (gdb) b -f func[TAB] (gdb) b -f function( # ok, gdb completed as much as possible. (gdb) b -f function([TAB] # show me the overloads, please. <_all_ symbols in the program are shown...> E.g., when debugging GDB, that'd be: (gdb) b -f function([TAB] (anonymous namespace)::get_global()::global pt_insn_get_offset@plt scm_new_port_table_entry asprintf pt_pkt_alloc_decoder scm_new_port_table_entry@plt asprintf@plt pt_pkt_alloc_decoder@plt scm_out_of_range bt_ctf_get_char_array pt_pkt_sync_forward scm_out_of_range@plt bt_ctf_get_char_array@plt pt_pkt_sync_forward@plt scm_putc bt_ctf_get_uint64 pwrite scm_putc@plt bt_ctf_get_uint64@plt pwrite@plt scm_reverse_x bt_ctf_iter_read_event PyErr_Restore scm_reverse_x@plt bt_ctf_iter_read_event@plt PyErr_Restore@plt scm_set_port_filename_x <snip...> Now that's a load of completely useless completions. The reason GDB offers those is that the completer relies on readline figuring out the completion word point in the input line based on the language's word break characters, which include "(". So readline tells the completer to complete on "", the string that is after '('. Likewise, if you type "function(i[TAB]" to try to complete to "int", you're out of luck. GDB shows you all the symbols in the program that start with "i"... This makes sense for the expression completer, as what you'd want to type is e.g., a global variable, say: (gdb) print function(i[TAB] but, it makes no sense when specifying a function name for a breakpoint location. To get around that limitation, users need to quote the function name, like: (gdb) b -f 'function([TAB] function(int) function(long) (gdb) b 'function(i[TAB] (gdb) b 'function(int)' # now completes correctly! Note that the quoting is only necessary for completion. Creating the breakpoint does not require the quoting: (gdb) b -f function(int) [RET] Breakpoint 1 at .... This patch removes this limitation. ( Actually, it's a necessary patch, though not sufficient. That'll start working correctly by the end of the series. With this patch, if try it, you'll see: (gdb) b -f function(i[TAB] (gdb) b -f function i.e., gdb strips everything after the "(". That's caused by some code in symtab.c that'll be eliminated further down the series. These patches are all unfortunately interrelated, which is also the reason new tests only appear much later in the series. But let's ignore that reality for the remainder of the description. ) So... this patch gets rid of the need for quoting. It does that by adding a way for a completer to control the exact completion word point that readline should start the completion request for, instead of letting readline try to figure it out using the current language's word break chars array, and often failing. In the case above, we want the completer to figure out that it's completing a function name that starts with "function(i". It now does. It took me a while to figure out a way to ask readline to "use this exact word point", and for a while I feared that it'd be impossible with current readline (and having to rely on master readline for core functionality is something I'd like to avoid very much). Eventually, after several different attempts, I came up with what is described in the comment above gdb_custom_word_point_brkchars in the patch. With this patch, the handle_brkchars phase of the explicit location completer advances the expected word point as it parses the input line left to right, until it figures out exactly what we're completing, instead of expecting readline to break the string using the word break characters, and then having the completer heuristically fix up a bad decision by parsing the input string backwards. This allows correctly knowning that we're completing a symbol name after -function, complete functions without quoting, etc. Later, we'll make use of this same mechanims to implement a proper linespec completer that avoids need for quoting too. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * cli/cli-cmds.c (complete_command): Get the completion result out of the handle_brkchars tracker if used a custom word point. * completer.c: Include "linespec.h". (enum explicit_location_match_type) <MATCH_LINE>: New enumerator. (advance_to_expression_complete_word_point): New. (completion_tracker::completes_to_completion_word): New. (complete_files_symbols): Pass down complete_symbol_mode::EXPRESSION. (explicit_options, probe_options): New. (collect_explicit_location_matches): Complete on the explictit_loc->foo instead of word. Use linespec_complete_function. Handle MATCH_LINE. Handle offering keyword and options completions. (backup_text_ptr): Delete. (skip_keyword): New. (complete_explicit_location): Remove 'word' parameter. Add language, quoted_arg_start and quoted_arg_end parameters. Rewrite, parsing left to right. (location_completer): Rewrite. (location_completer_handle_brkchars): New function. (symbol_completer): Pass down complete_symbol_mode::EXPRESSION. (enum complete_line_internal_reason): Adjust comments. (completion_tracker::discard_completions): New. (completer_handle_brkchars_func_for_completer): Handle location_completer. (gdb_custom_word_point_brkchars) (gdb_org_rl_basic_quote_characters): New. (gdb_completion_word_break_characters_throw) (completion_find_completion_word): Handle trackers that use a custom word point. (completion_tracker::advance_custom_word_point_by): New. (completion_tracker::build_completion_result): Don't rely on readline appending the quote char. (gdb_rl_attempted_completion_function_throw): Handle trackers that use a custom word point. (gdb_rl_attempted_completion_function): Restore rl_basic_quote_characters. * completer.h (class completion_tracker): Extend intro comment. (completion_tracker::set_quote_char) (completion_tracker::quote_char) (completion_tracker::set_use_custom_word_point) (completion_tracker::use_custom_word_point) (completion_tracker::custom_word_point) (completion_tracker::set_custom_word_point) (completion_tracker::advance_custom_word_point_by) (completion_tracker::completes_to_completion_word) (completion_tracker::discard_completions): New methods. (completion_tracker::m_quote_char) (completion_tracker::m_use_custom_word_point) (completion_tracker::m_custom_word_point): New fields. (advance_to_expression_complete_word_point): Declare. * f-lang.c (f_collect_symbol_completion_matches): Add complete_symbol_mode parameter. * language.h (struct language_defn) <la_collect_symbol_completion_matches>: Add complete_symbol_mode parameter. * linespec.c (linespec_keywords): Add NULL terminator. Make extern. (linespec_complete_function): New function. (linespec_lexer_lex_keyword): Adjust. * linespec.h (linespec_keywords, linespec_complete_function): New declarations. * location.c (find_end_quote): New function. (explicit_location_lex_one): Add explicit_completion_info parameter. Save quoting info. Don't throw if being called for completion. Don't handle Ada operators here. (is_cp_operator, skip_op_false_positives, first_of) (explicit_location_lex_one_function): New function. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. Handle it. Don't use explicit_location_lex_one to lex function names. Use explicit_location_lex_one_function instead. * location.h (struct explicit_completion_info): New. (string_to_explicit_location): Replace 'dont_throw' parameter with an explicit_completion_info pointer parameter. * symtab.c (default_collect_symbol_completion_matches_break_on): Add complete_symbol_mode parameter. Handle LINESPEC mode. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add complete_symbol_mode parameter. (collect_symbol_completion_matches_type): Pass down complete_symbol_mode::EXPRESSION. (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. Handle LINESPEC mode. * symtab.h (complete_symbol_mode): New. (default_collect_symbol_completion_matches_break_on) (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add complete_symbol_mode parameter. gdb/testsuite/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * gdb.linespec/ls-errs.exp (do_test): Adjust expected output.
2017-07-17 21:21:33 +02:00
const struct language_defn *language,
explicit_completion_info *completion_info);
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 02:09:36 +02:00
/* A convenience function for testing for unset locations. */
extern int event_location_empty_p (const struct event_location *location);
/* Set the location's string representation. If STRING is NULL, clear
the string representation. */
extern void
set_event_location_string (struct event_location *location,
const char *string);
Normalize include guards in gdb While working on my other scripts to deal with gdb headers, I noticed that some files were missing include guards. I wrote a script to add the missing ones, but found that using the obvious names for the guards ran into clashes -- for example, gdb/nat/linux-nat.h used "LINUX_NAT_H", but this was also the script's choice for gdb/linux-nat.h. So, I changed the script to normalize all include guards in gdb. This patch is the result. As usual the script is available here: https://github.com/tromey/gdb-refactoring-scripts Tested by rebuilding; I also ran it through "Fedora-x86_64-m64" on the buildbot. gdb/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * yy-remap.h: Add include guard. * xtensa-tdep.h: Add include guard. * xcoffread.h: Rename include guard. * varobj-iter.h: Add include guard. * tui/tui.h: Rename include guard. * tui/tui-winsource.h: Rename include guard. * tui/tui-wingeneral.h: Rename include guard. * tui/tui-windata.h: Rename include guard. * tui/tui-win.h: Rename include guard. * tui/tui-stack.h: Rename include guard. * tui/tui-source.h: Rename include guard. * tui/tui-regs.h: Rename include guard. * tui/tui-out.h: Rename include guard. * tui/tui-layout.h: Rename include guard. * tui/tui-io.h: Rename include guard. * tui/tui-hooks.h: Rename include guard. * tui/tui-file.h: Rename include guard. * tui/tui-disasm.h: Rename include guard. * tui/tui-data.h: Rename include guard. * tui/tui-command.h: Rename include guard. * tic6x-tdep.h: Add include guard. * target/waitstatus.h: Rename include guard. * target/wait.h: Rename include guard. * target/target.h: Rename include guard. * target/resume.h: Rename include guard. * target-float.h: Rename include guard. * stabsread.h: Add include guard. * rs6000-tdep.h: Add include guard. * riscv-fbsd-tdep.h: Add include guard. * regformats/regdef.h: Rename include guard. * record.h: Rename include guard. * python/python.h: Rename include guard. * python/python-internal.h: Rename include guard. * python/py-stopevent.h: Rename include guard. * python/py-ref.h: Rename include guard. * python/py-record.h: Rename include guard. * python/py-record-full.h: Rename include guard. * python/py-record-btrace.h: Rename include guard. * python/py-instruction.h: Rename include guard. * python/py-events.h: Rename include guard. * python/py-event.h: Rename include guard. * procfs.h: Add include guard. * proc-utils.h: Add include guard. * p-lang.h: Add include guard. * or1k-tdep.h: Rename include guard. * observable.h: Rename include guard. * nto-tdep.h: Rename include guard. * nat/x86-linux.h: Rename include guard. * nat/x86-linux-dregs.h: Rename include guard. * nat/x86-gcc-cpuid.h: Add include guard. * nat/x86-dregs.h: Rename include guard. * nat/x86-cpuid.h: Rename include guard. * nat/ppc-linux.h: Rename include guard. * nat/mips-linux-watch.h: Rename include guard. * nat/linux-waitpid.h: Rename include guard. * nat/linux-ptrace.h: Rename include guard. * nat/linux-procfs.h: Rename include guard. * nat/linux-osdata.h: Rename include guard. * nat/linux-nat.h: Rename include guard. * nat/linux-namespaces.h: Rename include guard. * nat/linux-btrace.h: Rename include guard. * nat/glibc_thread_db.h: Rename include guard. * nat/gdb_thread_db.h: Rename include guard. * nat/gdb_ptrace.h: Rename include guard. * nat/fork-inferior.h: Rename include guard. * nat/amd64-linux-siginfo.h: Rename include guard. * nat/aarch64-sve-linux-sigcontext.h: Rename include guard. * nat/aarch64-sve-linux-ptrace.h: Rename include guard. * nat/aarch64-linux.h: Rename include guard. * nat/aarch64-linux-hw-point.h: Rename include guard. * mn10300-tdep.h: Add include guard. * mips-linux-tdep.h: Add include guard. * mi/mi-parse.h: Rename include guard. * mi/mi-out.h: Rename include guard. * mi/mi-main.h: Rename include guard. * mi/mi-interp.h: Rename include guard. * mi/mi-getopt.h: Rename include guard. * mi/mi-console.h: Rename include guard. * mi/mi-common.h: Rename include guard. * mi/mi-cmds.h: Rename include guard. * mi/mi-cmd-break.h: Rename include guard. * m2-lang.h: Add include guard. * location.h: Rename include guard. * linux-record.h: Rename include guard. * linux-nat.h: Add include guard. * linux-fork.h: Add include guard. * i386-darwin-tdep.h: Rename include guard. * hppa-linux-offsets.h: Add include guard. * guile/guile.h: Rename include guard. * guile/guile-internal.h: Rename include guard. * gnu-nat.h: Rename include guard. * gdb-stabs.h: Rename include guard. * frv-tdep.h: Add include guard. * f-lang.h: Add include guard. * event-loop.h: Add include guard. * darwin-nat.h: Rename include guard. * cp-abi.h: Rename include guard. * config/sparc/nm-sol2.h: Rename include guard. * config/nm-nto.h: Rename include guard. * config/nm-linux.h: Add include guard. * config/i386/nm-i386gnu.h: Rename include guard. * config/djgpp/nl_types.h: Rename include guard. * config/djgpp/langinfo.h: Rename include guard. * compile/gcc-cp-plugin.h: Add include guard. * compile/gcc-c-plugin.h: Add include guard. * compile/compile.h: Rename include guard. * compile/compile-object-run.h: Rename include guard. * compile/compile-object-load.h: Rename include guard. * compile/compile-internal.h: Rename include guard. * compile/compile-cplus.h: Rename include guard. * compile/compile-c.h: Rename include guard. * common/xml-utils.h: Rename include guard. * common/x86-xstate.h: Rename include guard. * common/version.h: Rename include guard. * common/vec.h: Rename include guard. * common/tdesc.h: Rename include guard. * common/selftest.h: Rename include guard. * common/scoped_restore.h: Rename include guard. * common/scoped_mmap.h: Rename include guard. * common/scoped_fd.h: Rename include guard. * common/safe-iterator.h: Rename include guard. * common/run-time-clock.h: Rename include guard. * common/refcounted-object.h: Rename include guard. * common/queue.h: Rename include guard. * common/ptid.h: Rename include guard. * common/print-utils.h: Rename include guard. * common/preprocessor.h: Rename include guard. * common/pathstuff.h: Rename include guard. * common/observable.h: Rename include guard. * common/netstuff.h: Rename include guard. * common/job-control.h: Rename include guard. * common/host-defs.h: Rename include guard. * common/gdb_wait.h: Rename include guard. * common/gdb_vecs.h: Rename include guard. * common/gdb_unlinker.h: Rename include guard. * common/gdb_unique_ptr.h: Rename include guard. * common/gdb_tilde_expand.h: Rename include guard. * common/gdb_sys_time.h: Rename include guard. * common/gdb_string_view.h: Rename include guard. * common/gdb_splay_tree.h: Rename include guard. * common/gdb_setjmp.h: Rename include guard. * common/gdb_ref_ptr.h: Rename include guard. * common/gdb_optional.h: Rename include guard. * common/gdb_locale.h: Rename include guard. * common/gdb_assert.h: Rename include guard. * common/filtered-iterator.h: Rename include guard. * common/filestuff.h: Rename include guard. * common/fileio.h: Rename include guard. * common/environ.h: Rename include guard. * common/common-utils.h: Rename include guard. * common/common-types.h: Rename include guard. * common/common-regcache.h: Rename include guard. * common/common-inferior.h: Rename include guard. * common/common-gdbthread.h: Rename include guard. * common/common-exceptions.h: Rename include guard. * common/common-defs.h: Rename include guard. * common/common-debug.h: Rename include guard. * common/cleanups.h: Rename include guard. * common/buffer.h: Rename include guard. * common/btrace-common.h: Rename include guard. * common/break-common.h: Rename include guard. * cli/cli-utils.h: Rename include guard. * cli/cli-style.h: Rename include guard. * cli/cli-setshow.h: Rename include guard. * cli/cli-script.h: Rename include guard. * cli/cli-interp.h: Rename include guard. * cli/cli-decode.h: Rename include guard. * cli/cli-cmds.h: Rename include guard. * charset-list.h: Add include guard. * buildsym-legacy.h: Rename include guard. * bfin-tdep.h: Add include guard. * ax.h: Rename include guard. * arm-linux-tdep.h: Add include guard. * arm-fbsd-tdep.h: Add include guard. * arch/xtensa.h: Rename include guard. * arch/tic6x.h: Add include guard. * arch/i386.h: Add include guard. * arch/arm.h: Rename include guard. * arch/arm-linux.h: Rename include guard. * arch/arm-get-next-pcs.h: Rename include guard. * arch/amd64.h: Add include guard. * arch/aarch64-insn.h: Rename include guard. * arch-utils.h: Rename include guard. * annotate.h: Add include guard. * amd64-darwin-tdep.h: Rename include guard. * aarch64-linux-tdep.h: Add include guard. * aarch64-fbsd-tdep.h: Add include guard. * aarch32-linux-nat.h: Add include guard. gdb/gdbserver/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * x86-tdesc.h: Rename include guard. * x86-low.h: Add include guard. * wincecompat.h: Rename include guard. * win32-low.h: Add include guard. * utils.h: Rename include guard. * tracepoint.h: Rename include guard. * tdesc.h: Rename include guard. * target.h: Rename include guard. * server.h: Rename include guard. * remote-utils.h: Rename include guard. * regcache.h: Rename include guard. * nto-low.h: Rename include guard. * notif.h: Add include guard. * mem-break.h: Rename include guard. * lynx-low.h: Add include guard. * linux-x86-tdesc.h: Add include guard. * linux-s390-tdesc.h: Add include guard. * linux-ppc-tdesc-init.h: Add include guard. * linux-low.h: Add include guard. * linux-aarch64-tdesc.h: Add include guard. * linux-aarch32-low.h: Add include guard. * inferiors.h: Rename include guard. * i387-fp.h: Rename include guard. * hostio.h: Rename include guard. * gdbthread.h: Rename include guard. * gdb_proc_service.h: Rename include guard. * event-loop.h: Rename include guard. * dll.h: Rename include guard. * debug.h: Rename include guard. * ax.h: Rename include guard.
2019-01-27 20:51:36 +01:00
#endif /* LOCATION_H */