[RFAv4] Show locno for 'multi location' breakpoint hit msg+conv var $_hit_bbnum $_hit_locno.

Message ID 20221112224146.3148234-1-philippe.waroquiers@skynet.be
State Committed
Headers
Series [RFAv4] Show locno for 'multi location' breakpoint hit msg+conv var $_hit_bbnum $_hit_locno. |

Commit Message

Philippe Waroquiers Nov. 12, 2022, 10:41 p.m. UTC
  Before this patch, when a breakpoint that has multiple locations is reached,
GDB printed:
  Thread 1 "zeoes" hit Breakpoint 1, some_func () at somefunc1.c:5

This patch changes the message so that bkpt_print_id prints the precise
encountered breakpoint:
  Thread 1 "zeoes" hit Breakpoint 1.2, some_func () at somefunc1.c:5

In mi mode, bkpt_print_id also (optionally) prints a new table field "locno":
  locno is printed when the breakpoint hit has more than one location.
Note that according to the GDB user manual node 'GDB/MI Development and Front
Ends', it is ok to add new fields without changing the MI version.

Also, when a breakpoint is reached, the convenience variables
$_hit_bpnum and $_hit_locno are set to the encountered breakpoint number
and location number.

$_hit_bpnum and $_hit_locno can a.o. be used in the command list of a
breakpoint, to disable the specific encountered breakpoint, e.g.
   disable $_hit_bpnum.$_hit_locno

In case the breakpoint has only one location, $_hit_locno is set to
the value 1, so as to allow a command such as:
  disable $_hit_bpnum.$_hit_locno
to disable the breakpoint even when the breakpoint has only one location.

This also fixes a strange behaviour: when a breakpoint X has only
one location,
  enable|disable X.1
is accepted but transforms the breakpoint in a multiple locations
breakpoint having only one location.

The changes in RFA v4 handle the comments of Tom Tromey:
 - Changed convenience var names from $bkptno/$locno to
   $_hit_bpnum/$_hit_locno.
 - updated the tests and user manual accordingly.
   User manual also explictly describes that $_hit_locno is set to 1
   for a breakpoint with a single location.
 - The variable values are now set in bpstat_do_actions_1 so that
   they are set for silent breakpoints, and when several breakpoints
   are hit at the same time, that the variables are set to the printed
   breakpoint.

The changes in RFA v3 handle the additional comments of Eli:
 GDB/NEW:
  - Use max 80-column
  - Use 'code location' instead of 'location'.
  - Fix typo $bkpno
  - Ensure that disable $bkptno and disable $bkptno.$locno have
    each their explanation inthe example
  - Reworded the 'breakpoint-hit' paragraph.
 gdb.texinfo:
  - Use 'code location' instead of 'location'.
  - Add a note to clarify the distinction between $bkptno and $bpnum.
  - Use @kbd instead of examples with only one command.

Compared to RFA v1, the changes in v2 handle the comments given by
Keith Seitz and Eli Zaretskii:
  - Use %s for the result of paddress
  - Use bkptno_numopt_re instead of 2 different -re cases
  - use C@t{++}
  - Add index entries for $bkptno and $locno
  - Added an example for "locno" in the mi interface
  - Added examples in the Break command manual.
---
 gdb/NEWS                                      |  26 ++++
 gdb/ada-lang.c                                |   2 +-
 gdb/break-catch-syscall.c                     |   2 +-
 gdb/break-catch-throw.c                       |   2 +-
 gdb/breakpoint.c                              | 130 +++++++++++++++---
 gdb/breakpoint.h                              |  14 ++
 gdb/doc/gdb.texinfo                           |  94 ++++++++++++-
 gdb/testsuite/gdb.ada/bp_inlined_func.exp     |   2 +-
 gdb/testsuite/gdb.ada/operator_bp.exp         |   4 +-
 gdb/testsuite/gdb.base/break.exp              |   9 +-
 .../gdb.base/condbreak-multi-context.exp      |   8 +-
 gdb/testsuite/gdb.base/ctxobj.exp             |  28 +++-
 gdb/testsuite/gdb.base/ena-dis-br.exp         |  41 +++---
 gdb/testsuite/gdb.base/foll-exec-mode.exp     |   6 +-
 gdb/testsuite/gdb.base/pie-fork.exp           |   4 +-
 gdb/testsuite/gdb.base/step-over-exit.exp     |   4 +-
 gdb/testsuite/gdb.cp/mb-inline.exp            |   4 +-
 gdb/testsuite/gdb.cp/mb-templates.exp         |   6 +-
 gdb/testsuite/gdb.cp/ovldbreak.exp            |   6 +-
 gdb/testsuite/gdb.gdb/python-helper.exp       |   4 +-
 .../gdb.mi/interrupt-thread-group.exp         |   2 +-
 .../gdb.mi/user-selected-context-sync.exp     |  35 +++--
 gdb/testsuite/gdb.multi/multi-arch-exec.exp   |   3 +-
 .../gdb.multi/run-only-second-inf.exp         |   2 +-
 .../gdb.multi/watchpoint-multi-exit.exp       |   4 +-
 gdb/testsuite/gdb.multi/watchpoint-multi.exp  |   4 +-
 gdb/testsuite/lib/gdb.exp                     |  11 +-
 gdb/testsuite/lib/mi-support.exp              |  20 ++-
 28 files changed, 381 insertions(+), 96 deletions(-)
  

Comments

Tom Tromey Nov. 18, 2022, 8:17 p.m. UTC | #1
>>>>> "Philippe" == Philippe Waroquiers via Gdb-patches <gdb-patches@sourceware.org> writes:

Philippe> Before this patch, when a breakpoint that has multiple locations is reached,
Philippe> GDB printed:
Philippe>   Thread 1 "zeoes" hit Breakpoint 1, some_func () at somefunc1.c:5

Philippe> This patch changes the message so that bkpt_print_id prints the precise
Philippe> encountered breakpoint:
Philippe>   Thread 1 "zeoes" hit Breakpoint 1.2, some_func () at somefunc1.c:5

[...]

Thank you.  This is ok, please check it in.

Tom
  
Simon Marchi Nov. 20, 2022, 2:06 a.m. UTC | #2
On 11/12/22 17:41, Philippe Waroquiers via Gdb-patches wrote:
> Before this patch, when a breakpoint that has multiple locations is reached,
> GDB printed:
>   Thread 1 "zeoes" hit Breakpoint 1, some_func () at somefunc1.c:5
> 
> This patch changes the message so that bkpt_print_id prints the precise
> encountered breakpoint:
>   Thread 1 "zeoes" hit Breakpoint 1.2, some_func () at somefunc1.c:5
> 
> In mi mode, bkpt_print_id also (optionally) prints a new table field "locno":
>   locno is printed when the breakpoint hit has more than one location.
> Note that according to the GDB user manual node 'GDB/MI Development and Front
> Ends', it is ok to add new fields without changing the MI version.
> 
> Also, when a breakpoint is reached, the convenience variables
> $_hit_bpnum and $_hit_locno are set to the encountered breakpoint number
> and location number.
> 
> $_hit_bpnum and $_hit_locno can a.o. be used in the command list of a
> breakpoint, to disable the specific encountered breakpoint, e.g.
>    disable $_hit_bpnum.$_hit_locno
> 
> In case the breakpoint has only one location, $_hit_locno is set to
> the value 1, so as to allow a command such as:
>   disable $_hit_bpnum.$_hit_locno
> to disable the breakpoint even when the breakpoint has only one location.
> 
> This also fixes a strange behaviour: when a breakpoint X has only
> one location,
>   enable|disable X.1
> is accepted but transforms the breakpoint in a multiple locations
> breakpoint having only one location.
> 
> The changes in RFA v4 handle the comments of Tom Tromey:
>  - Changed convenience var names from $bkptno/$locno to
>    $_hit_bpnum/$_hit_locno.
>  - updated the tests and user manual accordingly.
>    User manual also explictly describes that $_hit_locno is set to 1
>    for a breakpoint with a single location.
>  - The variable values are now set in bpstat_do_actions_1 so that
>    they are set for silent breakpoints, and when several breakpoints
>    are hit at the same time, that the variables are set to the printed
>    breakpoint.
> 
> The changes in RFA v3 handle the additional comments of Eli:
>  GDB/NEW:
>   - Use max 80-column
>   - Use 'code location' instead of 'location'.
>   - Fix typo $bkpno
>   - Ensure that disable $bkptno and disable $bkptno.$locno have
>     each their explanation inthe example
>   - Reworded the 'breakpoint-hit' paragraph.
>  gdb.texinfo:
>   - Use 'code location' instead of 'location'.
>   - Add a note to clarify the distinction between $bkptno and $bpnum.
>   - Use @kbd instead of examples with only one command.
> 
> Compared to RFA v1, the changes in v2 handle the comments given by
> Keith Seitz and Eli Zaretskii:
>   - Use %s for the result of paddress
>   - Use bkptno_numopt_re instead of 2 different -re cases
>   - use C@t{++}
>   - Add index entries for $bkptno and $locno
>   - Added an example for "locno" in the mi interface
>   - Added examples in the Break command manual.

Hi Philippe,

I am getting some new failures starting with your patch, at least when
building with ASan.  I bisected using gdb.mi/mi-break.exp as a test:


PASS: gdb.mi/mi-break.exp: mi-mode=main: test_breakpoint_commands: intermediate stop and continue, mi running
=================================================================

==1105569==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000055110 at pc 0x55eabe71b268 bp 0x7ffcc2697a20 sp 0x7ffcc2697a10

READ of size 8 at 0x606000055110 thread T0

    #0 0x55eabe71b267 in set_hit_convenience_vars /home/simark/src/binutils-gdb/gdb/breakpoint.c:4581

    #1 0x55eabe71b7b5 in bpstat_do_actions_1 /home/simark/src/binutils-gdb/gdb/breakpoint.c:4698

    #2 0x55eabe71ba45 in bpstat_do_actions() /home/simark/src/binutils-gdb/gdb/breakpoint.c:4731

    #3 0x55eabefd4b62 in inferior_event_handler(inferior_event_type) /home/simark/src/binutils-gdb/gdb/inf-loop.c:70

    #4 0x55eabf03f005 in fetch_inferior_event() /home/simark/src/binutils-gdb/gdb/infrun.c:4270

    #5 0x55eabefd4a4f in inferior_event_handler(inferior_event_type) /home/simark/src/binutils-gdb/gdb/inf-loop.c:41

    #6 0x55eabf0661c2 in infrun_async_inferior_event_handler /home/simark/src/binutils-gdb/gdb/infrun.c:9554

    #7 0x55eabe6728bb in check_async_event_handlers() /home/simark/src/binutils-gdb/gdb/async-event.c:337

    #8 0x55eac00a6cda in gdb_do_one_event(int) /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:221

    #9 0x55eabf1ebbfb in start_event_loop /home/simark/src/binutils-gdb/gdb/main.c:411

    #10 0x55eabf1ebf15 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:471

    #11 0x55eabf1f03cb in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1330

    #12 0x55eabf1f045b in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1345

    #13 0x55eabe4bfe6d in main /home/simark/src/binutils-gdb/gdb/gdb.c:32

    #14 0x7fad6ce2a28f  (/usr/lib/libc.so.6+0x2328f)

    #15 0x7fad6ce2a349 in __libc_start_main (/usr/lib/libc.so.6+0x23349)

    #16 0x55eabe4bfc34 in _start ../sysdeps/x86_64/start.S:115



0x606000055110 is located 16 bytes inside of 56-byte region [0x606000055100,0x606000055138)

freed by thread T0 here:

    #0 0x7fad6de0b78a in operator delete(void*, unsigned long) /usr/src/debug/gcc/libsanitizer/asan/asan_new_delete.cpp:164

    #1 0x55eabe71a14e in bpstat_clear(bpstat**) /home/simark/src/binutils-gdb/gdb/breakpoint.c:4370

    #2 0x55eabf03380d in clear_proceed_status_thread /home/simark/src/binutils-gdb/gdb/infrun.c:2781

    #3 0x55eabf033e9e in clear_proceed_status(int) /home/simark/src/binutils-gdb/gdb/infrun.c:2808

    #4 0x55eabeff4dab in continue_1(int) /home/simark/src/binutils-gdb/gdb/infcmd.c:659

    #5 0x55eabeff5531 in continue_command /home/simark/src/binutils-gdb/gdb/infcmd.c:752

    #6 0x55eabe92b954 in do_simple_func /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:95

    #7 0x55eabe939998 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:2543

    #8 0x55eabf9986c2 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:692

    #9 0x55eabe973c1d in execute_control_command_1 /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:528

    #10 0x55eabe974b41 in execute_control_command(command_line*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:708

    #11 0x55eabe71b652 in bpstat_do_actions_1 /home/simark/src/binutils-gdb/gdb/breakpoint.c:4661

    #12 0x55eabe71ba45 in bpstat_do_actions() /home/simark/src/binutils-gdb/gdb/breakpoint.c:4731

    #13 0x55eabefd4b62 in inferior_event_handler(inferior_event_type) /home/simark/src/binutils-gdb/gdb/inf-loop.c:70

    #14 0x55eabf03f005 in fetch_inferior_event() /home/simark/src/binutils-gdb/gdb/infrun.c:4270

    #15 0x55eabefd4a4f in inferior_event_handler(inferior_event_type) /home/simark/src/binutils-gdb/gdb/inf-loop.c:41

    #16 0x55eabf0661c2 in infrun_async_inferior_event_handler /home/simark/src/binutils-gdb/gdb/infrun.c:9554

    #17 0x55eabe6728bb in check_async_event_handlers() /home/simark/src/binutils-gdb/gdb/async-event.c:337

    #18 0x55eac00a6cda in gdb_do_one_event(int) /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:221

    #19 0x55eabf1ebbfb in start_event_loop /home/simark/src/binutils-gdb/gdb/main.c:411

    #20 0x55eabf1ebf15 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:471

    #21 0x55eabf1f03cb in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1330

    #22 0x55eabf1f045b in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1345

    #23 0x55eabe4bfe6d in main /home/simark/src/binutils-gdb/gdb/gdb.c:32

    #24 0x7fad6ce2a28f  (/usr/lib/libc.so.6+0x2328f)



previously allocated by thread T0 here:

    #0 0x7fad6de0a672 in operator new(unsigned long) /usr/src/debug/gcc/libsanitizer/asan/asan_new_delete.cpp:95

    #1 0x55eabe7222ef in build_bpstat_chain(address_space const*, unsigned long, target_waitstatus const&) /home/simark/src/binutils-gdb/gdb/breakpoint.c:5591

    #2 0x55eabf04dcfa in handle_signal_stop /home/simark/src/binutils-gdb/gdb/infrun.c:6334

    #3 0x55eabf04a8fb in handle_inferior_event /home/simark/src/binutils-gdb/gdb/infrun.c:5866

    #4 0x55eabf03ecb3 in fetch_inferior_event() /home/simark/src/binutils-gdb/gdb/infrun.c:4231

    #5 0x55eabefd4a4f in inferior_event_handler(inferior_event_type) /home/simark/src/binutils-gdb/gdb/inf-loop.c:41

    #6 0x55eabf0661c2 in infrun_async_inferior_event_handler /home/simark/src/binutils-gdb/gdb/infrun.c:9554

    #7 0x55eabe6728bb in check_async_event_handlers() /home/simark/src/binutils-gdb/gdb/async-event.c:337

    #8 0x55eac00a6cda in gdb_do_one_event(int) /home/simark/src/binutils-gdb/gdbsupport/event-loop.cc:221

    #9 0x55eabf1ebbfb in start_event_loop /home/simark/src/binutils-gdb/gdb/main.c:411

    #10 0x55eabf1ebf15 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:471

    #11 0x55eabf1f03cb in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1330

    #12 0x55eabf1f045b in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1345

    #13 0x55eabe4bfe6d in main /home/simark/src/binutils-gdb/gdb/gdb.c:32

    #14 0x7fad6ce2a28f  (/usr/lib/libc.so.6+0x2328f)



SUMMARY: AddressSanitizer: heap-use-after-free /home/simark/src/binutils-gdb/gdb/breakpoint.c:4581 in set_hit_convenience_vars


Here are the other failures I get.  I didn't check if they were caused
by your patch, but since they appeared at the same time, it's likely.

 - gdb.threads/multi-create-ns-info-thr.exp
 - gdb.base/dprintf-execution-x-script.exp
 - gdb.base/commands.exp
 - gdb.base/bp-cmds-execution-x-script.exp
 - gdb.base/bp-cmds-continue-ctrl-c.exp

Simon
  
Philippe Waroquiers Nov. 20, 2022, 8:35 a.m. UTC | #3
On Sat, 2022-11-19 at 21:06 -0500, Simon Marchi wrote:
> 
> Here are the other failures I get.  I didn't check if they were caused
> by your patch, but since they appeared at the same time, it's likely.
> 
>  - gdb.threads/multi-create-ns-info-thr.exp
>  - gdb.base/dprintf-execution-x-script.exp
>  - gdb.base/commands.exp
>  - gdb.base/bp-cmds-execution-x-script.exp
>  - gdb.base/bp-cmds-continue-ctrl-c.exp
> 
valgrind also shows a use after free e.g. in gdb.base/commands.exp

Will investigate further ...

Thanks
Philippe
  
Philippe Waroquiers Nov. 20, 2022, 10:54 a.m. UTC | #4
On Sun, 2022-11-20 at 09:35 +0100, Philippe Waroquiers via Gdb-patches wrote:
> On Sat, 2022-11-19 at 21:06 -0500, Simon Marchi wrote:
> > 
> > Here are the other failures I get.  I didn't check if they were caused
> > by your patch, but since they appeared at the same time, it's likely.
> > 
> >  - gdb.threads/multi-create-ns-info-thr.exp
> >  - gdb.base/dprintf-execution-x-script.exp
> >  - gdb.base/commands.exp
> >  - gdb.base/bp-cmds-execution-x-script.exp
> >  - gdb.base/bp-cmds-continue-ctrl-c.exp
> > 
> valgrind also shows a use after free e.g. in gdb.base/commands.exp
> 
> Will investigate further ...

I have sent
  [RFA] Fix use after free introduced by $_hit_bpnum/$_hit_locno variables.
https://sourceware.org/pipermail/gdb-patches/2022-November/194014.html

that should fix the user after free.

Sorry for the breakage, thanks for reporting the issue.

Note that I did some verifications with valgrind, which highlighted some leaks:
  * some thread related data structure (probably not a big leak, there are not a lot of
    threads)
  * in command execution related to the mi interpreter
  * seems like some more big leaks in the dwarf reader
(see below)

If I have some more time this week-end, I might investigate the dwarf reader leaks first.

Philippe

Here are leaks reported when running gdb.mi/mi-break.exp

==2133857== 
==2133857== HEAP SUMMARY:
==2133857==     in use at exit: 24,643,711 bytes in 24,500 blocks
==2133857==   total heap usage: 402,114 allocs, 377,614 frees, 176,035,340 bytes allocated
==2133857== 
==2133857== VALGRIND_GDB_ERROR_BEGIN
==2133857== 632 bytes in 1 blocks are definitely lost in loss record 6,861 of 7,483
==2133857==    at 0x4839F01: operator new(unsigned long) (vg_replace_malloc.c:434)
==2133857==    by 0x7CA7B5: new_thread (thread.c:247)
==2133857==    by 0x7CA7B5: add_thread_silent(process_stratum_target*, ptid_t) (thread.c:281)
==2133857==    by 0x5D7A25: inf_ptrace_target::create_inferior(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, int) (inf-ptrace.c:100)
==2133857==    by 0x624FC4: linux_nat_target::create_inferior(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, int) (linux-nat.c:978)
==2133857==    by 0x5E2EE1: run_command_1(char const*, int, run_how) (infcmd.c:469)
==2133857==    by 0x48DFD4: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:2543)
==2133857==    by 0x7D0781: execute_command(char const*, int) (top.c:692)
==2133857==    by 0x6761E1: mi_execute_cli_command(char const*, bool, char const*) (mi-main.c:2135)
==2133857==    by 0x6764F1: mi_cmd_exec_run(char const*, char**, int) (mi-main.c:477)
==2133857==    by 0x673B40: mi_cmd_execute(mi_parse*) (mi-main.c:2109)
==2133857==    by 0x675FDF: captured_mi_execute_command (mi-main.c:1816)
==2133857==    by 0x675FDF: mi_execute_command(char const*, int) (mi-main.c:1941)
==2133857==    by 0x66525B: mi_execute_command_wrapper (mi-interp.c:281)
==2133857==    by 0x66525B: mi_execute_command_input_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) (mi-interp.c:310)
==2133857==    by 0x571A27: gdb_readline_no_editing_callback(void*) (event-top.c:925)
==2133857==    by 0x571DDF: stdin_event_handler(int, void*) (event-top.c:541)
==2133857==    by 0x97D9C5: gdb_wait_for_event(int) [clone .part.0] (event-loop.cc:694)
==2133857==    by 0x97E1F3: gdb_wait_for_event (event-loop.cc:593)
==2133857==    by 0x97E1F3: gdb_do_one_event(int) (event-loop.cc:264)
==2133857==    by 0x647F19: start_event_loop (main.c:411)
==2133857==    by 0x647F19: captured_command_loop() (main.c:471)
==2133857==    by 0x649A44: captured_main (main.c:1330)
==2133857==    by 0x649A44: gdb_main(captured_main_args*) (main.c:1345)
==2133857==    by 0x3A0A0B: main (gdb.c:32)
==2133857== 
==2133857== VALGRIND_GDB_ERROR_END
==2133857== VALGRIND_GDB_ERROR_BEGIN
==2133857== 3,269 (32 direct, 3,237 indirect) bytes in 1 blocks are definitely lost in loss record 7,179 of 7,483
==2133857==    at 0x483E1E8: calloc (vg_replace_malloc.c:1340)
==2133857==    by 0x3F54B0: xcalloc (alloc.c:97)
==2133857==    by 0x609636: xcnew<ui_interp_info> (poison.h:122)
==2133857==    by 0x609636: get_interp_info (interps.c:63)
==2133857==    by 0x609636: interp_lookup_existing (interps.c:205)
==2133857==    by 0x609636: interp_lookup(ui*, char const*) (interps.c:228)
==2133857==    by 0x6099B2: set_top_level_interpreter(char const*) (interps.c:249)
==2133857==    by 0x7CD891: new_ui_command(char const*, int) (top.c:398)
==2133857==    by 0x48DFD4: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:2543)
==2133857==    by 0x7D0781: execute_command(char const*, int) (top.c:692)
==2133857==    by 0x572CBC: command_handler(char const*) (event-top.c:616)
==2133857==    by 0x57304C: command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) (event-top.c:860)
==2133857==    by 0x573660: gdb_rl_callback_handler(char*) (event-top.c:246)
==2133857==    by 0x87B65F: rl_callback_read_char (callback.c:290)
==2133857==    by 0x5720CD: gdb_rl_callback_read_char_wrapper_noexcept() (event-top.c:188)
==2133857==    by 0x573540: gdb_rl_callback_read_char_wrapper(void*) (event-top.c:221)
==2133857==    by 0x571DDF: stdin_event_handler(int, void*) (event-top.c:541)
==2133857==    by 0x97D9C5: gdb_wait_for_event(int) [clone .part.0] (event-loop.cc:694)
==2133857==    by 0x97E1F3: gdb_wait_for_event (event-loop.cc:593)
==2133857==    by 0x97E1F3: gdb_do_one_event(int) (event-loop.cc:264)
==2133857==    by 0x647F19: start_event_loop (main.c:411)
==2133857==    by 0x647F19: captured_command_loop() (main.c:471)
==2133857==    by 0x649A44: captured_main (main.c:1330)
==2133857==    by 0x649A44: gdb_main(captured_main_args*) (main.c:1345)
==2133857==    by 0x3A0A0B: main (gdb.c:32)
==2133857== 
==2133857== VALGRIND_GDB_ERROR_END
==2133857== VALGRIND_GDB_ERROR_BEGIN
==2133857== 43,165 bytes in 1,801 blocks are definitely lost in loss record 7,450 of 7,483
==2133857==    at 0x483979B: malloc (vg_replace_malloc.c:393)
==2133857==    by 0x3F5434: xmalloc (alloc.c:57)
==2133857==    by 0x96B83E: xstrdup (xstrdup.c:34)
==2133857==    by 0x5380F1: dw2_get_file_names_reader (read.c:2825)
==2133857==    by 0x5380F1: dw2_get_file_names(dwarf2_per_cu_data*, dwarf2_per_objfile*) (read.c:2851)
==2133857==    by 0x538D1C: dw_expand_symtabs_matching_file_matcher(dwarf2_per_objfile*, gdb::function_view<bool (char const*, bool)>) (read.c:4149)
==2133857==    by 0x557855: cooked_index_functions::expand_symtabs_matching(objfile*, gdb::function_view<bool (char const*, bool)>, lookup_name_info const*, gdb::function_view<bool (char const*)>, gdb::function_view<bool (compunit_symtab*)>, enum_flags<block_search_flag_values>, domain_enum, search_domain) (read.c:18679)
==2133857==    by 0x777F5A: objfile::map_symtabs_matching_filename(char const*, char const*, gdb::function_view<bool (symtab*)>) (symfile-debug.c:207)
==2133857==    by 0x78B23C: iterate_over_symtabs(char const*, gdb::function_view<bool (symtab*)>) (symtab.c:633)
==2133857==    by 0x78B2F4: lookup_symtab(char const*) (symtab.c:647)
==2133857==    by 0x464FCA: classify_name(parser_state*, block const*, bool, bool) (c-exp.y:3086)
==2133857==    by 0x46705F: c_yylex() (c-exp.y:3254)
==2133857==    by 0x467B3B: c_yyparse() (c-exp.c.tmp:2037)
==2133857==    by 0x46FB3B: c_parse(parser_state*) (c-exp.y:3420)
==2133857==    by 0x6A312D: parse_exp_in_context(char const**, unsigned long, block const*, int, bool, innermost_block_tracker*, std::unique_ptr<expr_completion_base, std::default_delete<expr_completion_base> >*) (parse.c:515)
==2133857==    by 0x6A33C0: parse_exp_1(char const**, unsigned long, block const*, int, innermost_block_tracker*) (parse.c:428)
==2133857==    by 0x44EFF8: create_breakpoint(gdbarch*, location_spec*, char const*, int, char const*, bool, int, int, bptype, int, auto_boolean, breakpoint_ops const*, int, int, int, unsigned int) (breakpoint.c:9034)
==2133857==    by 0x65B884: mi_cmd_break_insert_1(int, char const*, char**, int) [clone .constprop.0] (mi-cmd-break.c:360)
==2133857==    by 0x673B40: mi_cmd_execute(mi_parse*) (mi-main.c:2109)
==2133857==    by 0x675FDF: captured_mi_execute_command (mi-main.c:1816)
==2133857==    by 0x675FDF: mi_execute_command(char const*, int) (mi-main.c:1941)
==2133857==    by 0x66525B: mi_execute_command_wrapper (mi-interp.c:281)
==2133857==    by 0x66525B: mi_execute_command_input_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) (mi-interp.c:310)
==2133857==    by 0x571A27: gdb_readline_no_editing_callback(void*) (event-top.c:925)
==2133857==    by 0x571DDF: stdin_event_handler(int, void*) (event-top.c:541)
==2133857==    by 0x97D9C5: gdb_wait_for_event(int) [clone .part.0] (event-loop.cc:694)
==2133857==    by 0x97E1F3: gdb_wait_for_event (event-loop.cc:593)
==2133857==    by 0x97E1F3: gdb_do_one_event(int) (event-loop.cc:264)
==2133857==    by 0x647F19: start_event_loop (main.c:411)
==2133857==    by 0x647F19: captured_command_loop() (main.c:471)
==2133857==    by 0x649A44: captured_main (main.c:1330)
==2133857==    by 0x649A44: gdb_main(captured_main_args*) (main.c:1345)
==2133857==    by 0x3A0A0B: main (gdb.c:32)
==2133857==
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 0642d7637b8..12576f2be43 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -73,6 +73,26 @@ 
   For both /r and /b GDB is now better at using whitespace in order to
   align the disassembled instruction text.
 
+* When a breakpoint with multiple code locations is hit, GDB now prints
+  the code location using the syntax <breakpoint_number>.<location_number>
+  such as in:
+     Thread 1 "zeoes" hit Breakpoint 2.3, some_func () at zeoes.c:8
+
+* When a breakpoint is hit, GDB now sets the convenience variables $_hit_bpnum
+  and $_hit_locno to the hit breakpoint number and code location number.
+  This allows to disable the last hit breakpoint using
+     (gdb) disable $_hit_bpnum
+   or disable only the specific breakpoint code location using
+     (gdb) disable $_hit_bpnum.$_hit_locno
+  These commands can be used inside the command list of a breakpoint to
+  automatically disable the just encountered breakpoint (or the just
+  encountered specific breakpoint code location).
+  When a breakpoint has only one location, $_hit_locno is set to 1 so that
+     (gdb) disable $_hit_bpnum.$_hit_locno
+  and
+     (gdb) disable $_hit_bpnum
+  are both disabling the breakpoint.
+
 * New commands
 
 maintenance set ignore-prologue-end-flag on|off
@@ -140,6 +160,12 @@  GNU/Linux/LoongArch (gdbserver)	loongarch*-*-linux*
 
 GNU/Linux/CSKY (gdbserver) csky*-*linux*
 
+* MI changes
+
+ ** The async record stating the stopped reason 'breakpoint-hit' now
+    contains an optional field locno giving the code location number
+    when the breakpoint has multiple code locations.
+
 * Python API
 
   ** GDB will now reformat the doc string for gdb.Command and
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 383f96bdc45..5054bdb2957 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12356,7 +12356,7 @@  ada_catchpoint::print_it (const bpstat *bs) const
 
   uiout->text (disposition == disp_del
 	       ? "\nTemporary catchpoint " : "\nCatchpoint ");
-  uiout->field_signed ("bkptno", number);
+  print_num_locno (bs, uiout);
   uiout->text (", ");
 
   /* ada_exception_name_addr relies on the selected frame being the
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 805bb86cee6..3829d8286f3 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -218,7 +218,7 @@  syscall_catchpoint::print_it (const bpstat *bs) const
 						: EXEC_ASYNC_SYSCALL_RETURN));
       uiout->field_string ("disp", bpdisp_text (b->disposition));
     }
-  uiout->field_signed ("bkptno", b->number);
+  print_num_locno (bs, uiout);
 
   if (last.kind () == TARGET_WAITKIND_SYSCALL_ENTRY)
     uiout->text (" (call to syscall ");
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index 6557ee71449..0da3cbfb021 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -254,7 +254,7 @@  exception_catchpoint::print_it (const bpstat *bs) const
   bp_temp = disposition == disp_del;
   uiout->text (bp_temp ? "Temporary catchpoint "
 		       : "Catchpoint ");
-  uiout->field_signed ("bkptno", number);
+  print_num_locno (bs, uiout);
   uiout->text ((kind == EX_EVENT_THROW ? " (exception thrown), "
 		: (kind == EX_EVENT_CATCH ? " (exception caught), "
 		   : " (exception rethrown), ")));
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 490708938ec..7f6400db624 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -817,6 +817,19 @@  get_breakpoint (int num)
   return nullptr;
 }
 
+/* Return TRUE if NUM refer to an existing breakpoint that has
+   multiple code locations.  */
+
+static bool
+has_multiple_locations (int num)
+{
+  for (breakpoint *b : all_breakpoints ())
+    if (b->number == num)
+      return b->loc != nullptr && b->loc->next != nullptr;
+
+  return false;
+}
+
 
 
 /* Mark locations as "conditions have changed" in case the target supports
@@ -4441,15 +4454,7 @@  bpstat_explains_signal (bpstat *bsp, enum gdb_signal sig)
   return false;
 }
 
-/* Put in *NUM the breakpoint number of the first breakpoint we are
-   stopped at.  *BSP upon return is a bpstat which points to the
-   remaining breakpoints stopped at (but which is not guaranteed to be
-   good for anything but further calls to bpstat_num).
-
-   Return 0 if passed a bpstat which does not indicate any breakpoints.
-   Return -1 if stopped at a breakpoint that has been deleted since
-   we set it.
-   Return 1 otherwise.  */
+/* See breakpoint.h.  */
 
 int
 bpstat_num (bpstat **bsp, int *num)
@@ -4471,6 +4476,57 @@  bpstat_num (bpstat **bsp, int *num)
   return 1;
 }
 
+/* See breakpoint.h  */
+
+int
+bpstat_locno (const bpstat *bs)
+{
+  const struct breakpoint *b = bs->breakpoint_at;
+  const struct bp_location *bl = bs->bp_location_at.get ();
+
+  int locno = 0;
+
+  if (b != nullptr && b->loc->next != nullptr)
+    {
+      const bp_location *bl_i;
+
+      for (bl_i = b->loc;
+	   bl_i != bl && bl_i->next != nullptr;
+	   bl_i = bl_i->next)
+	locno++;
+
+      if (bl_i == bl)
+	locno++;
+      else
+	{
+	  warning (_("location number not found for breakpoint %d address %s."),
+		   b->number, paddress (bl->gdbarch, bl->address));
+	  locno = 0;
+	}
+    }
+
+  return locno;
+}
+
+/* See breakpoint.h.  */
+
+void
+print_num_locno (const bpstat *bs, struct ui_out *uiout)
+{
+  struct breakpoint *b = bs->breakpoint_at;
+
+  if (b == nullptr)
+    uiout->text (_("deleted breakpoint"));
+  else
+    {
+      uiout->field_signed ("bkptno", b->number);
+
+      int locno = bpstat_locno (bs);
+      if (locno != 0)
+	uiout->message (".%pF", signed_field ("locno", locno));
+    }
+}
+
 /* See breakpoint.h.  */
 
 void
@@ -4518,6 +4574,20 @@  command_line_is_silent (struct command_line *cmd)
   return cmd && (strcmp ("silent", cmd->line) == 0);
 }
 
+/* Sets the $_hit_bpnum and $_hit_locno to the bpnum and locno of bs.  */
+static void
+set_hit_convenience_vars (bpstat *bs)
+{
+  const struct breakpoint *b = bs->breakpoint_at;
+  if (b != nullptr)
+    {
+      int locno = bpstat_locno (bs);
+      set_internalvar_integer (lookup_internalvar ("_hit_bpnum"), b->number);
+      set_internalvar_integer (lookup_internalvar ("_hit_locno"),
+			       (locno > 0 ? locno : 1));
+    }
+}
+
 /* Execute all the commands associated with all the breakpoints at
    this location.  Any of these commands could cause the process to
    proceed beyond this point, etc.  We look out for such changes by
@@ -4532,6 +4602,7 @@  bpstat_do_actions_1 (bpstat **bsp)
 {
   bpstat *bs;
   bool again = false;
+  bpstat *bs_print_hit_var;
 
   /* Avoid endless recursion if a `source' command is contained
      in bs->commands.  */
@@ -4546,11 +4617,25 @@  bpstat_do_actions_1 (bpstat **bsp)
   /* This pointer will iterate over the list of bpstat's.  */
   bs = *bsp;
 
+  /* The $_hit_* convenience variables are set before running the
+     commands of bs.  In case we have several bs, after the loop,
+     we set again the variables to the first bs to print.  */
+  bs_print_hit_var = nullptr;
+
   breakpoint_proceeded = 0;
   for (; bs != NULL; bs = bs->next)
     {
       struct command_line *cmd = NULL;
 
+      /* Set the _hit_* convenience variables before running the commands of
+	 each bs.  If this is the first bs to be printed, remember it so as to
+	 set the convenience variable again to this bs after the loop so that in
+	 case of multiple breakpoints, the variables are set to the breakpoint
+	 printed for the user.  */
+      set_hit_convenience_vars (bs);
+      if (bs_print_hit_var == nullptr && bs->print)
+	bs_print_hit_var = bs;
+
       /* Take ownership of the BSP's command tree, if it has one.
 
 	 The command tree could legitimately contain commands like
@@ -4606,6 +4691,12 @@  bpstat_do_actions_1 (bpstat **bsp)
 	  break;
 	}
     }
+
+  /* Now that we have executed the commands of all bs, set the _hit_*
+     convenience variables to the printed bs.  */
+  if (bs_print_hit_var != nullptr)
+    set_hit_convenience_vars (bs_print_hit_var);
+
   return again;
 }
 
@@ -4817,7 +4908,7 @@  bpstat_print (bpstat *bs, target_waitkind kind)
     {
       val = print_bp_stop_message (bs);
       if (val == PRINT_SRC_ONLY 
-	  || val == PRINT_SRC_AND_LOC 
+	  || val == PRINT_SRC_AND_LOC
 	  || val == PRINT_NOTHING)
 	return val;
     }
@@ -9209,7 +9300,7 @@  ranged_breakpoint::print_it (const bpstat *bs) const
 		      async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
       uiout->field_string ("disp", bpdisp_text (disposition));
     }
-  uiout->field_signed ("bkptno", number);
+  print_num_locno (bs, uiout);
   uiout->text (", ");
 
   return PRINT_SRC_AND_LOC;
@@ -11630,12 +11721,13 @@  ordinary_breakpoint::print_it (const bpstat *bs) const
 			   async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
       uiout->field_string ("disp", bpdisp_text (disposition));
     }
+
   if (bp_temp)
-    uiout->message ("Temporary breakpoint %pF, ",
-		    signed_field ("bkptno", number));
+    uiout->text ("Temporary breakpoint ");
   else
-    uiout->message ("Breakpoint %pF, ",
-		    signed_field ("bkptno", number));
+    uiout->text ("Breakpoint ");
+  print_num_locno (bs, uiout);
+  uiout->text (", ");
 
   return PRINT_SRC_AND_LOC;
 }
@@ -13281,9 +13373,13 @@  enable_disable_command (const char *args, int from_tty, bool enable)
 	  extract_bp_number_and_location (num, bp_num_range, bp_loc_range);
 
 	  if (bp_loc_range.first == bp_loc_range.second
-	      && bp_loc_range.first == 0)
+	      && (bp_loc_range.first == 0
+		  || (bp_loc_range.first == 1
+		      && bp_num_range.first == bp_num_range.second
+		      && !has_multiple_locations (bp_num_range.first))))
 	    {
-	      /* Handle breakpoint ids with formats 'x' or 'x-z'.  */
+	      /* Handle breakpoint ids with formats 'x' or 'x-z'
+		 or 'y.1' where y has only one code location.  */
 	      map_breakpoint_number_range (bp_num_range,
 					   enable
 					   ? enable_breakpoint
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 360fa760577..f7633d29cbf 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1241,6 +1241,20 @@  extern enum print_stop_action bpstat_print (bpstat *bs, target_waitkind kind);
    Return 1 otherwise.  */
 extern int bpstat_num (bpstat **, int *);
 
+/* If BS indicates a breakpoint and this breakpoint has several code locations,
+   return the location number of BS, otherwise return 0.  */
+
+extern int bpstat_locno (const bpstat *bs);
+
+/* Print BS breakpoint number optionally followed by a . and breakpoint locno.
+
+   For a breakpoint with only one code location, outputs the signed field
+   "bkptno" breakpoint number of BS (as returned by bpstat_num).
+   If BS has several code locations, outputs a '.' character followed by
+   the signed field "locno" (as returned by bpstat_locno).  */
+
+extern void print_num_locno (const bpstat *bs, struct ui_out *);
+
 /* Perform actions associated with the stopped inferior.  Actually, we
    just use this for breakpoint commands.  Perhaps other actions will
    go here later, but this is executed at a late time (from the
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ea66f4ee42d..1e2ed06a8ae 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -4368,9 +4368,75 @@  are operated on.
 @cindex latest breakpoint
 Breakpoints are set with the @code{break} command (abbreviated
 @code{b}).  The debugger convenience variable @samp{$bpnum} records the
-number of the breakpoint you've set most recently; see @ref{Convenience
-Vars,, Convenience Variables}, for a discussion of what you can do with
-convenience variables.
+number of the breakpoint you've set most recently:
+@smallexample
+(gdb) b main
+Breakpoint 1 at 0x11c6: file zeoes.c, line 24.
+(gdb) p $bpnum
+$1 = 1
+@end smallexample
+
+A breakpoint may be mapped to multiple code locations for example with
+inlined functions, Ada generics, C@t{++} templates or overloaded function names.
+@value{GDBN} then indicates the number of code locations in the breakpoint
+command output:
+@smallexample
+(gdb) b some_func
+Breakpoint 2 at 0x1179: some_func. (3 locations)
+(gdb) p $bpnum
+$2 = 2
+(gdb)
+@end smallexample
+
+@vindex $_hit_bpnum@r{, convenience variable}
+@vindex $_hit_locno@r{, convenience variable}
+When your program stops on a breakpoint, the convenience variables
+@samp{$_hit_bpnum} and @samp{$_hit_locno} are respectively set to the number of
+the encountered breakpoint and the number of the breakpoint's code location:
+@smallexample
+Thread 1 "zeoes" hit Breakpoint 2.1, some_func () at zeoes.c:8
+8	  printf("some func\n");
+(gdb) p $_hit_bpnum
+$5 = 2
+(gdb) p $_hit_locno
+$6 = 1
+(gdb)
+@end smallexample
+
+Note that @samp{$_hit_bpnum} and @samp{$bpnum} are not equivalent:
+@samp{$_hit_bpnum} is set to the breakpoint number @b{last hit}, while
+@samp{$bpnum} is set to the breakpoint number @b{last set}.
+
+
+If the encountered breakpoint has only one code location, @samp{$_hit_locno}
+is set to 1:
+@smallexample
+Breakpoint 1, main (argc=1, argv=0x7fffffffe018) at zeoes.c:24
+24	  if (argc > 1)
+(gdb) p $_hit_bpnum
+$3 = 1
+(gdb) p $_hit_locno
+$4 = 1
+(gdb)
+@end smallexample
+
+The @samp{$_hit_bpnum} and @samp{$_hit_locno} variables can typically be used
+in a breakpoint command list.
+(@pxref{Break Commands, ,Breakpoint Command Lists}).  For example, as
+part of the breakpoint command list, you can disable completely the
+encountered breakpoint using @kbd{disable $_hit_bpnum} or disable the
+specific encountered breakpoint location using
+@kbd{disable $_hit_bpnum.$_hit_locno}.
+If a breakpoint has only one location, @samp{$_hit_locno} is set to 1
+and the commands @kbd{disable $_hit_bpnum} and
+@kbd{disable $_hit_bpnum.$_hit_locno} both disable the breakpoint.
+
+You can also define aliases to easily disable the last hit location or
+last hit breakpoint:
+@smallexample
+(gdb) alias lld = disable $_hit_bpnum.$_hit_locno
+(gdb) alias lbd = disable $_hit_bpnum
+@end smallexample
 
 @table @code
 @item break @var{locspec}
@@ -5769,6 +5835,14 @@  Expressions}).
 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
 disabled within a @var{command-list}.
 
+Inside a command list, you can use the command
+@kbd{disable $_hit_bpnum} to disable the encountered breakpoint.
+
+If your breakpoint has several code locations, the command
+@kbd{disable $_hit_bpnum.$_hit_locno} will disable the specific breakpoint
+code location encountered.  If the breakpoint has only one location,
+this command will disable the encountered breakpoint.
+
 You can use breakpoint commands to start your program up again.  Simply
 use the @code{continue} command, or @code{step}, or any other command
 that resumes execution.
@@ -32805,6 +32879,20 @@  line="13",arch="i386:x86_64"@}
 (gdb)
 @end smallexample
 
+For a @samp{breakpoint-hit} stopped reason, when the breakpoint
+encountered has multiple locations, the field @samp{bkptno} is
+followed by the field @samp{locno}.
+
+@smallexample
+-exec-continue
+^running
+(gdb)
+@@Hello world
+*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",locno="3",frame=@{
+func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
+line="13",arch="i386:x86_64"@}
+(gdb)
+@end smallexample
 
 @subheading The @code{-exec-finish} Command
 @findex -exec-finish
diff --git a/gdb/testsuite/gdb.ada/bp_inlined_func.exp b/gdb/testsuite/gdb.ada/bp_inlined_func.exp
index 076e8c2425f..3f94c163819 100644
--- a/gdb/testsuite/gdb.ada/bp_inlined_func.exp
+++ b/gdb/testsuite/gdb.ada/bp_inlined_func.exp
@@ -42,7 +42,7 @@  gdb_test "break read_small" \
 for {set i 0} {$i < 4} {incr i} {
     with_test_prefix "iteration $i" {
 	gdb_test "continue" \
-	    "Breakpoint $decimal, b\\.read_small \\(\\).*" \
+	    "Breakpoint $bkptno_num_re, b\\.read_small \\(\\).*" \
 	    "stopped in read_small"
     }
 }
diff --git a/gdb/testsuite/gdb.ada/operator_bp.exp b/gdb/testsuite/gdb.ada/operator_bp.exp
index 655e7af479f..e3928419ed6 100644
--- a/gdb/testsuite/gdb.ada/operator_bp.exp
+++ b/gdb/testsuite/gdb.ada/operator_bp.exp
@@ -56,7 +56,7 @@  foreach op { "*" "/" "mod" "rem" "**" "<" "<=" ">" ">=" "=" "and" "or" "xor" "&"
 foreach op { "+" "-" "*" "/" "mod" "rem" "**" "<" "<=" ">" ">=" "=" "and" "or" "xor" "&" "abs" "not"} {
     set op_re [string_to_regexp $op]
     gdb_test "continue" \
-             "Breakpoint $decimal, ops\\.\"$op_re\" .*"\
+             "Breakpoint $bkptno_numopt_re, ops\\.\"$op_re\" .*"\
              "continue to \"$op\""
 }
 
@@ -86,7 +86,7 @@  foreach op { "*" "/" "mod" "rem" "**" "<" "<=" ">" ">=" "=" "and" "or" "xor" "&"
 foreach op { "+" "-" "*" "/" "mod" "rem" "**" "<" "<=" ">" ">=" "=" "and" "or" "xor" "&" "abs" "not"} {
     set op_re [string_to_regexp $op]
     gdb_test "continue" \
-             "Breakpoint $decimal, ops\\.\"$op_re\" .*"\
+             "Breakpoint $bkptno_numopt_re, ops\\.\"$op_re\" .*"\
              "continue to ops.\"$op\""
 }
 
diff --git a/gdb/testsuite/gdb.base/break.exp b/gdb/testsuite/gdb.base/break.exp
index 4421459154f..cb5831ac610 100644
--- a/gdb/testsuite/gdb.base/break.exp
+++ b/gdb/testsuite/gdb.base/break.exp
@@ -541,13 +541,14 @@  if ![runto_main] then {
 gdb_test_multiple "break $bp_location1" \
     "set to-be-silent break bp_location1" {
 	-re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" {
+	    set bpno $expect_out(1,string)
 	    pass "set to-be-silent break bp_location1"
 	}
     }
 
-gdb_test "commands $expect_out(1,string)\nsilent\nend" ">end" "set silent break bp_location1"
+gdb_test "commands $bpno\nsilent\nend" ">end" "set silent break bp_location1"
 
-gdb_test "info break $expect_out(1,string)" \
+gdb_test "info break $bpno" \
     "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \
     "info silent break bp_location1"
 
@@ -557,6 +558,10 @@  gdb_test "continue" "Continuing." \
 gdb_test "bt" "#0  main .* at .*:$bp_location1.*" \
     "stopped for silent break bp_location1"
 
+# Verify the $_hit_bpnum convenience variable is set to the silent hit bpno.
+gdb_test "printf \"%d\\n\", \$_hit_bpnum" "$bpno" \
+    "Silent breakpoint hit \$_hit_bpnum is silent $bpno"
+ 
 # Verify that GDB can at least parse a breakpoint with the
 # "thread" keyword.  (We won't attempt to test here that a
 # thread-specific breakpoint really triggers appropriately.
diff --git a/gdb/testsuite/gdb.base/condbreak-multi-context.exp b/gdb/testsuite/gdb.base/condbreak-multi-context.exp
index b540df973a3..742315178e3 100644
--- a/gdb/testsuite/gdb.base/condbreak-multi-context.exp
+++ b/gdb/testsuite/gdb.base/condbreak-multi-context.exp
@@ -140,11 +140,11 @@  with_test_prefix "scenario 1" {
     gdb_run_cmd
 
     # Check our conditional breakpoints.
-    gdb_test "" ".*Breakpoint \[0-9\]+, A::func .*" \
+    gdb_test "" ".*Breakpoint $bkptno_num_re, A::func .*" \
 	"run until A::func"
     gdb_test "print a" " = 10"
 
-    gdb_test "continue" "Continuing.*Breakpoint \[0-9\]+, C::func .*" \
+    gdb_test "continue" "Continuing.*Breakpoint $bkptno_num_re, C::func .*" \
 	"run until C::func"
     gdb_test "print c" " = 30"
 
@@ -208,11 +208,11 @@  with_test_prefix "scenario 2" {
     gdb_run_cmd
 
     # Check that we hit enabled locations only.
-    gdb_test "" ".*Breakpoint \[0-9\]+, A::func .*" \
+    gdb_test "" ".*Breakpoint $bkptno_num_re, A::func .*" \
 	"run until A::func"
     gdb_test "print a" " = 10"
 
-    gdb_test "continue" "Continuing.*Breakpoint \[0-9\]+, C::func .*" \
+    gdb_test "continue" "Continuing.*Breakpoint $bkptno_num_re, C::func .*" \
 	"run until C::func"
     gdb_test "print c" " = 30"
 
diff --git a/gdb/testsuite/gdb.base/ctxobj.exp b/gdb/testsuite/gdb.base/ctxobj.exp
index 9c010f54d79..3ca8111896c 100644
--- a/gdb/testsuite/gdb.base/ctxobj.exp
+++ b/gdb/testsuite/gdb.base/ctxobj.exp
@@ -67,9 +67,17 @@  gdb_test "break ctxobj-f.c:$bp_location" \
          "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \
          "break in get_version functions"
 
-gdb_test "continue" \
-         "Breakpoint $decimal, get_version_1 \\(\\).*" \
-         "continue to get_version_1"
+global expect_out
+set test "continue to get_version_1"
+gdb_test_multiple "continue" $test {
+    -re "Breakpoint ($bkptno_num_re), get_version_1 \\(\\).*" {
+	set bpno $expect_out(1,string)
+	pass $test
+    }
+}
+# Verify $_hit_bpnum.$_hit_locno convenience variables are set to the hit bpno.
+gdb_test "printf \"%d.%d\\n\", \$_hit_bpnum, \$_hit_locno" "$bpno" \
+    "$test \$_hit_bpnum.\$_hit_locno is $bpno"
 
 # Try printing "this_version_num".  There are two global variables
 # with that name, and some systems such as GNU/Linux merge them
@@ -100,10 +108,16 @@  gdb_test "print this_version_num == v" \
         "print libctxobj1's this_version_num from symtab"
 
 # Do the same, but from get_version_2.
-
-gdb_test "continue" \
-         "Breakpoint $decimal, get_version_2 \\(\\).*" \
-         "continue to get_version_2"
+set test "continue to get_version_2"
+gdb_test_multiple "continue" $test {
+    -re "Breakpoint ($bkptno_num_re), get_version_2 \\(\\).*" {
+	set bpno $expect_out(1,string)
+	pass $test
+    }
+}
+# Verify the $_hit_bpnum.$_hit_locno convenience variables are set to the hit bpno.
+gdb_test "printf \"%d.%d\\n\", \$_hit_bpnum, \$_hit_locno" "$bpno" \
+    "$test \$_hit_bpnum.\$_hit_locno is $bpno"
 
 gdb_test "print this_version_num == v" \
          " = 1" \
diff --git a/gdb/testsuite/gdb.base/ena-dis-br.exp b/gdb/testsuite/gdb.base/ena-dis-br.exp
index 24925cf7185..93ac124dbc4 100644
--- a/gdb/testsuite/gdb.base/ena-dis-br.exp
+++ b/gdb/testsuite/gdb.base/ena-dis-br.exp
@@ -67,14 +67,21 @@  gdb_test "info break $bp" \
 # See the comments in condbreak.exp for "run until breakpoint at
 # marker1" for an explanation of the xfail below.
 set test "continue to break marker1"
+set bpno 0
 gdb_test_multiple "continue" "$test" {
-    -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
+    -re "Breakpoint (\[0-9\]*), marker1.*$gdb_prompt $" {
+	set bpno $expect_out(1,string)
 	pass "$test"
     }
-    -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
+    -re "Breakpoint (\[0-9\]*), $hex in marker1.*$gdb_prompt $" {
+	set bpno $expect_out(1,string)
 	xfail "$test"
     }
 }
+# Verify the $_hit_bbnum convenience variable is equal to the hit bpno.
+gdb_test "print \$_hit_bpnum" " = $bpno" "$test \$_hit_bpnum is $bpno"
+# Verify the $_hit_locno is 1, as there is only one code location.
+gdb_test "print \$_hit_locno" " = 1" "$test \$_hit_locno is 1"
 
 gdb_test_no_output "delete $bp" "delete break marker1"
 
@@ -359,7 +366,8 @@  with_test_prefix "4th breakpoint" {
 }
 
 # Perform tests for disable/enable commands on multiple
-# locations and breakpoints.
+# code locations and breakpoints.  If a breakpoint has only one code location,
+# enable/disable num  and enable/disable num.1 should be equivalent.
 #
 # WHAT - the command to test (disable/enable).
 #
@@ -372,7 +380,7 @@  proc test_ena_dis_br { what } {
     global b3
     global b4
     global gdb_prompt
-    
+
     # OPPOS    - the command opposite to WHAT.
     # WHAT_RES - whether breakpoints are expected to end
     #            up enabled or disabled.
@@ -395,13 +403,13 @@  proc test_ena_dis_br { what } {
 	set p2 "pass"
     }
 
-    # Now enable(disable) $b.1 $b2.1.
+    # Now enable(disable) $b1.1 $b2.1.
     gdb_test_no_output "$what $b1.1 $b2.1" "$what \$b1.1 \$b2.1"
     set test1 "${what}d \$b1.1 and \$b2.1"
 
     # Now $b1.1 and $b2.1 should be enabled(disabled).
     gdb_test_multiple "info break" "$test1" {
-       -re "(${b1}.1)(\[^\n\r\]*)( n.*)(${b2}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" {
+       -re "(${b1})(\[^\n\r\]*)( n.*)(${b2})(\[^\n\r\]*)( n.*)$gdb_prompt $" {
            $p1 "$test1"
        }
        -re ".*$gdb_prompt $" {
@@ -420,19 +428,16 @@  proc test_ena_dis_br { what } {
        "${what}d \$b1"
 
     gdb_test_no_output "$oppos $b3" "$oppos \$b3"
+    # Now $b4 $b3 should be enabled(disabled)
+    set test1 "${what}d \$b4 and \$b3"
+    gdb_test "info break" "(${b3})(\[^\n\r]*)( $oppos_res.*).*(${b4})(\[^\n\r\]*)( $oppos_res.*)" "$test1"
+
     gdb_test_no_output "$what $b4 $b3.1" "$what \$b4 \$b3.1"
-    set test1 "${what}d \$b4 and \$b3.1,remain ${oppos}d \$b3"
+    set test1 "${what}d \$b4 and \$b3.1, changing \$b3"
+
+    # Now $b4 $b3 should be enabled(disabled)
+    gdb_test "info break" "(${b3})(\[^\n\r]*)( $what_res.*).*(${b4})(\[^\n\r\]*)( $what_res.*)" "$test1"
 
-    # Now $b4 $b3.1 should be enabled(disabled) and
-    # $b3 should remain disabled(enabled).
-    gdb_test_multiple "info break" "$test1" {
-       -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b3}.1)(\[^\n\r\]*)( n.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" {
-           $p1 "$test1"
-       }
-       -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" {
-           $p2 "$test1"
-       }
-    }
 
     # Now enable(disable) '$b4.1 fooobaar'.  This should error on
     # fooobaar.
@@ -443,7 +448,7 @@  proc test_ena_dis_br { what } {
 
     # $b4.1 should be enabled(disabled).
     gdb_test_multiple "info break" "$test1" {
-        -re "(${b4}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" {
+        -re "(${b4})(\[^\n\r\]*)( n.*)$gdb_prompt $" {
            $p1 "$test1"
        }
        -re ".*$gdb_prompt $" {
diff --git a/gdb/testsuite/gdb.base/foll-exec-mode.exp b/gdb/testsuite/gdb.base/foll-exec-mode.exp
index 918f3e4fd5f..cb6d975a767 100644
--- a/gdb/testsuite/gdb.base/foll-exec-mode.exp
+++ b/gdb/testsuite/gdb.base/foll-exec-mode.exp
@@ -99,7 +99,7 @@  proc do_catch_exec_test { } {
 # before re-running.
 
 proc do_follow_exec_mode_tests { mode cmd infswitch } {
-    global binfile srcfile srcfile2 testfile testfile2
+    global binfile srcfile srcfile2 testfile testfile2 bkptno_numopt_re
     global gdb_prompt
 
     with_test_prefix "$mode,$cmd,$infswitch" {
@@ -125,7 +125,7 @@  proc do_follow_exec_mode_tests { mode cmd infswitch } {
 	# Set up the output we expect to see after we execute past the exec.
 	#
 	set execd_line [gdb_get_line_number "after-exec" $srcfile2]
-	set expected_re ".*xecuting new program: .*${testfile2}.*Breakpoint .,.*${srcfile2}:${execd_line}.*$gdb_prompt $"
+	set expected_re ".*xecuting new program: .*${testfile2}.*Breakpoint ${bkptno_numopt_re},.*${srcfile2}:${execd_line}.*$gdb_prompt $"
 
 	# Set a breakpoint after the exec call if we aren't single-stepping
 	# past it.
@@ -189,7 +189,7 @@  proc do_follow_exec_mode_tests { mode cmd infswitch } {
 		send_gdb "y\n"
 		exp_continue
 	    }
-	    -re "Starting program: .*$expected_inf.*Breakpoint .,.*\r\n$gdb_prompt $" {
+	    -re "Starting program: .*$expected_inf.*Breakpoint $bkptno_numopt_re,.*\r\n$gdb_prompt $" {
 		pass $test
 	    }
 	}
diff --git a/gdb/testsuite/gdb.base/pie-fork.exp b/gdb/testsuite/gdb.base/pie-fork.exp
index efc357d39a2..19e9d3a5537 100644
--- a/gdb/testsuite/gdb.base/pie-fork.exp
+++ b/gdb/testsuite/gdb.base/pie-fork.exp
@@ -54,10 +54,10 @@  proc_with_prefix test_detach_on_fork_follow_child {} {
 proc_with_prefix test_no_detach_on_fork {} {
     setup_test "off"
 
-    gdb_test "continue" "\r\nThread 1.1 .* hit Breakpoint 2, break_here.*" \
+    gdb_test "continue" "\r\nThread 1.1 .* hit Breakpoint 2.1, break_here.*" \
 	     "continue from thread 1.1"
     gdb_test "thread 2.1"
-    gdb_test "continue" "\r\nThread 2.1 .* hit Breakpoint 2, break_here.*" \
+    gdb_test "continue" "\r\nThread 2.1 .* hit Breakpoint 2.2, break_here.*" \
 	     "continue from thread 2.1"
 }
 
diff --git a/gdb/testsuite/gdb.base/step-over-exit.exp b/gdb/testsuite/gdb.base/step-over-exit.exp
index f8bd99980fe..575319c564c 100644
--- a/gdb/testsuite/gdb.base/step-over-exit.exp
+++ b/gdb/testsuite/gdb.base/step-over-exit.exp
@@ -91,7 +91,7 @@  delete_breakpoints
 
 gdb_test "break marker"
 
-gdb_test "continue" "Continuing\\..*Breakpoint $decimal, .*" \
+gdb_test "continue" "Continuing\\..*Breakpoint $bkptno_num_re, .*" \
     "continue to marker, first time"
 
 # Step 2, create a breakpoint which evaluates false, and force it
@@ -120,5 +120,5 @@  gdb_test "inferior 1" ".*Switching to inferior 1.*" \
 # Switch back to the parent process, continue to the marker to
 # test GDBserver's state is still correct.
 
-gdb_test "continue" "Continuing\\..*Breakpoint $decimal, .*" \
+gdb_test "continue" "Continuing\\..*Breakpoint $bkptno_numopt_re, .*" \
     "continue to marker, second time"
diff --git a/gdb/testsuite/gdb.cp/mb-inline.exp b/gdb/testsuite/gdb.cp/mb-inline.exp
index bf74df4fee8..fffb9a57008 100644
--- a/gdb/testsuite/gdb.cp/mb-inline.exp
+++ b/gdb/testsuite/gdb.cp/mb-inline.exp
@@ -42,7 +42,7 @@  gdb_test "info break" \
     "\[\r\n\]1\.1.* y .* at .*$hdrfile:$bp_location.*\[\r\n\]1\.2.* y .* at .*$hdrfile:$bp_location.*"
 
 gdb_run_cmd
-gdb_test "" "Breakpoint \[0-9\]+,.*foo \\(i=0\\).*" "run to breakpoint"
+gdb_test "" "Breakpoint $bkptno_num_re,.*foo \\(i=0\\).*" "run to breakpoint"
 
 gdb_test "continue" \
     ".*Breakpoint.*foo \\(i=1\\).*" \
@@ -55,7 +55,7 @@  gdb_test "continue" \
 gdb_test_no_output "disable 1.2" "disabling location: disable"
 
 gdb_run_cmd
-gdb_test "" "Breakpoint \[0-9\]+,.*foo \\(i=0\\).*" "disabling location: run to breakpoint"
+gdb_test "" "Breakpoint $bkptno_num_re,.*foo \\(i=0\\).*" "disabling location: run to breakpoint"
 
 gdb_test_multiple "info break" "disabled breakpoint 1.2" {
     -re "1\.2.* n .* at .*$hdrfile:$bp_location.*$gdb_prompt $" {
diff --git a/gdb/testsuite/gdb.cp/mb-templates.exp b/gdb/testsuite/gdb.cp/mb-templates.exp
index 5d4c886825e..72476d0c6f7 100644
--- a/gdb/testsuite/gdb.cp/mb-templates.exp
+++ b/gdb/testsuite/gdb.cp/mb-templates.exp
@@ -38,7 +38,7 @@  gdb_run_cmd
 
 set test "initial condition: run to breakpoint"
 gdb_test_multiple "" $test {
-    -re "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*$gdb_prompt $" {
+    -re "Breakpoint $bkptno_num_re,.*foo<int> \\(i=1\\).*$gdb_prompt $" {
 	pass $test
 	break
     }
@@ -63,7 +63,7 @@  gdb_test_no_output {condition $bpnum i==1} \
     "separate condition: set condition"
     
 gdb_run_cmd
-gdb_test "" "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*" "separate condition: run to breakpoint"
+gdb_test "" "Breakpoint $bkptno_num_re,.*foo<int> \\(i=1\\).*" "separate condition: run to breakpoint"
 
 gdb_test "continue" \
     ".*Breakpoint.*foo<double> \\(i=1\\).*" \
@@ -75,7 +75,7 @@  gdb_test "continue" \
 gdb_test_no_output {disable $bpnum.1} "disabling location: disable"
 
 gdb_run_cmd
-gdb_test "" "Breakpoint \[0-9\]+,.*foo<double> \\(i=1\\).*" "disabling location: run to breakpoint"
+gdb_test "" "Breakpoint $bkptno_num_re,.*foo<double> \\(i=1\\).*" "disabling location: run to breakpoint"
 
 # Try disabling entire breakpoint
 gdb_test_no_output {enable $bpnum.1} "disabling location: enable"
diff --git a/gdb/testsuite/gdb.cp/ovldbreak.exp b/gdb/testsuite/gdb.cp/ovldbreak.exp
index 06adf82ecbb..0ed9eae055b 100644
--- a/gdb/testsuite/gdb.cp/ovldbreak.exp
+++ b/gdb/testsuite/gdb.cp/ovldbreak.exp
@@ -380,7 +380,7 @@  gdb_test "info break" $bptable "breakpoint info (after setting on all)"
 
 # Run through each breakpoint.
 proc continue_to_bp_overloaded {bpnumber might_fail line argtype argument} {
-    global gdb_prompt hex decimal srcfile
+    global gdb_prompt hex decimal srcfile bkptno_num_re
 
     if {$argument == ""} {
         set actuals ""
@@ -398,11 +398,11 @@  proc continue_to_bp_overloaded {bpnumber might_fail line argtype argument} {
     }
 
     gdb_test_multiple "continue" "continue to bp overloaded : $argtype" {
-        -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}(, )?$actuals\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
+        -re "Continuing.\r\n\r\nBreakpoint $bkptno_num_re, foo::overload1arg \\(this=${hex}(, )?$actuals\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
             pass "continue to bp overloaded : $argtype"
         }
 
-        -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}, arg=.*\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
+        -re "Continuing.\r\n\r\nBreakpoint $bkptno_num_re, foo::overload1arg \\(this=${hex}, arg=.*\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
             if $might_kfail {
                 kfail "c++/8130" "continue to bp overloaded : $argtype"
             } else {
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
index ea362ef693d..3585ac9f0bf 100644
--- a/gdb/testsuite/gdb.gdb/python-helper.exp
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -49,7 +49,7 @@  gdb_exit
 # The main test.  This is called by the self-test framework once GDB
 # has been started on a copy of itself.
 proc test_python_helper {} {
-    global py_helper_script decimal hex gdb_prompt
+    global py_helper_script decimal hex gdb_prompt bkptno_numopt_re
     global inferior_spawn_id
 
     # Source the python helper script.  This script registers the
@@ -190,7 +190,7 @@  proc test_python_helper {} {
     # Send a command to the inner GDB, this should result in the outer
     # GDB stopping at the value_print breakpoint again.
     send_inferior "ptype global_c\n"
-    gdb_test -prompt $outer_prompt_re "" "Breakpoint $decimal, c_print_type.*" "hit breakpoint in outer gdb again"
+    gdb_test -prompt $outer_prompt_re "" "Breakpoint $bkptno_numopt_re, c_print_type.*" "hit breakpoint in outer gdb again"
 
     set answer [multi_line \
 		    "$decimal = " \
diff --git a/gdb/testsuite/gdb.mi/interrupt-thread-group.exp b/gdb/testsuite/gdb.mi/interrupt-thread-group.exp
index 19ccbe85e04..c080955049c 100644
--- a/gdb/testsuite/gdb.mi/interrupt-thread-group.exp
+++ b/gdb/testsuite/gdb.mi/interrupt-thread-group.exp
@@ -69,7 +69,7 @@  if { $use_second_inferior } {
 	"\\^running.*" \
 	"run inferior 2"
 
-    mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\""} \
+    mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\"" "locno=\"[0-9]+\""} \
 	"inferior i2 stops at all_threads_started"
 
     mi_send_resuming_command "exec-continue --thread-group i2" \
diff --git a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
index d78c96ddef1..9eec083068b 100644
--- a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
+++ b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
@@ -307,8 +307,13 @@  proc test_continue_to_start { mode inf } {
 
 	    # Consume MI event output.
 	    with_spawn_id $mi_spawn_id {
-		mi_expect_stop "breakpoint-hit" "main" "" "$srcfile" \
-		    "$decimal" {"" "disp=\"del\""} "stop at breakpoint in main"
+		if { $inf == 1 } {
+		    mi_expect_stop "breakpoint-hit" "main" "" "$srcfile" \
+			"$decimal" {"" "disp=\"del\""} "stop at breakpoint in main"
+		} else {
+		    mi_expect_stop "breakpoint-hit" "main" "" "$srcfile" \
+			"$decimal" {"" "disp=\"del\"" "locno=\"[0-9]+\""} "stop at breakpoint in main"
+		}
 	    }
 
 	    if { $mode == "all-stop" } {
@@ -330,9 +335,15 @@  proc test_continue_to_start { mode inf } {
 
 		    # Consume MI output.
 		    with_spawn_id $mi_spawn_id {
-			mi_expect_stop "breakpoint-hit" "child_sub_function" \
-			    "" "$srcfile" "$decimal" {"" "disp=\"del\""} \
-			    "thread $inf.$thread stops MI"
+			if { $inf == 1} {
+			    mi_expect_stop "breakpoint-hit" "child_sub_function" \
+				"" "$srcfile" "$decimal" {"" "disp=\"del\""} \
+				"thread $inf.$thread stops MI"
+			} else {
+			    mi_expect_stop "breakpoint-hit" "child_sub_function" \
+				"" "$srcfile" "$decimal" {"" "disp=\"del\"" "locno=\"[0-9]+\""} \
+				"thread $inf.$thread stops MI"
+			}
 		    }
 		}
 
@@ -359,9 +370,15 @@  proc test_continue_to_start { mode inf } {
 
 		# Consume MI output.
 		with_spawn_id $mi_spawn_id {
-		    mi_expect_stop "breakpoint-hit" "child_sub_function" \
-			"" "$srcfile" "$decimal" {"" "disp=\"del\""} \
-			"thread $inf.2 stops MI"
+		    if { $inf == 1} {
+			mi_expect_stop "breakpoint-hit" "child_sub_function" \
+			    "" "$srcfile" "$decimal" {"" "disp=\"del\""} \
+			    "thread $inf.2 stops MI"
+		    } else {
+			mi_expect_stop "breakpoint-hit" "child_sub_function" \
+			    "" "$srcfile" "$decimal" {"" "disp=\"del\"" "locno=\"[0-9]+\""} \
+			    "thread $inf.2 stops MI"
+		    }
 		}
 	    }
 	}
@@ -434,7 +451,7 @@  proc_with_prefix test_setup { mode } {
 
 	with_spawn_id $mi_spawn_id {
 	    mi_expect_stop "breakpoint-hit" "main" "" "$srcfile" "$decimal" \
-		{"" "disp=\"del\""} "main stop"
+		{"" "disp=\"del\"" "locno=\"[0-9]+\""} "main stop"
 	}
 
 	# Consume CLI output.
diff --git a/gdb/testsuite/gdb.multi/multi-arch-exec.exp b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
index a8e81e29ee9..3d77960988d 100644
--- a/gdb/testsuite/gdb.multi/multi-arch-exec.exp
+++ b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
@@ -148,6 +148,7 @@  proc build_executables { first_arch } {
 }
 
 proc do_test { first_arch mode selected_thread } {
+        global bkptno_numopt_re
 	set from_exec "$first_arch-multi-arch-exec"
 
 	clean_restart ${from_exec}
@@ -169,7 +170,7 @@  proc do_test { first_arch mode selected_thread } {
 
 	# Test that GDB updates the target description / arch successfuly
 	# after the exec.
-	gdb_test "continue" "Breakpoint 2, main.*" "continue across exec that changes architecture"
+	gdb_test "continue" "Breakpoint $bkptno_numopt_re, main.*" "continue across exec that changes architecture"
 }
 
 # Test both arch1=>arch2 and arch2=>arch1.
diff --git a/gdb/testsuite/gdb.multi/run-only-second-inf.exp b/gdb/testsuite/gdb.multi/run-only-second-inf.exp
index fec2575f904..b94689d0bfa 100644
--- a/gdb/testsuite/gdb.multi/run-only-second-inf.exp
+++ b/gdb/testsuite/gdb.multi/run-only-second-inf.exp
@@ -46,5 +46,5 @@  gdb_load $binfile
 if {[gdb_start_cmd] < 0} {
     fail "start the second inf"
 } else {
-    gdb_test "" ".*reakpoint ., main .*${srcfile}.*" "start the second inf"
+    gdb_test "" ".*reakpoint $bkptno_numopt_re, main .*${srcfile}.*" "start the second inf"
 }
diff --git a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
index cbccba19d12..3c079facced 100644
--- a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
+++ b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
@@ -27,7 +27,7 @@  if {[build_executable "failed to build" $testfile $srcfile {debug}]} {
 # child.  Can be either "kill", "detach", or "exit" (to continue it to
 # normal exit).
 proc do_test {dispose} {
-    global binfile
+    global binfile bkptno_numopt_re
 
     clean_restart $binfile
 
@@ -77,7 +77,7 @@  proc do_test {dispose} {
     #  Command aborted.
     #  (gdb)
     #
-    gdb_test "continue" "Breakpoint \[0-9\]+, marker .*" \
+    gdb_test "continue" "Breakpoint $bkptno_numopt_re, marker .*" \
 	"continue in inferior 1"
 }
 
diff --git a/gdb/testsuite/gdb.multi/watchpoint-multi.exp b/gdb/testsuite/gdb.multi/watchpoint-multi.exp
index e4329dca6c2..0fc1bee762f 100644
--- a/gdb/testsuite/gdb.multi/watchpoint-multi.exp
+++ b/gdb/testsuite/gdb.multi/watchpoint-multi.exp
@@ -84,11 +84,11 @@  if [skip_hw_watchpoint_multi_tests] {
 	"Hardware access \\(read/write\\) watchpoint \[0-9\]+: c\r\n\r\nOld value = 0\r\nNew value = 3\r\n.*" \
 	"catch c on inferior 2"
 
-    gdb_test "continue" "Breakpoint \[0-9\]+, marker_exit .*" "catch marker_exit in inferior 2"
+    gdb_test "continue" "Breakpoint $bkptno_numopt_re, marker_exit .*" "catch marker_exit in inferior 2"
 
     gdb_test "inferior 1" "witching to inferior 1 .*" "switch back to inferior 1 again"
 
     gdb_test "continue" "Hardware access \\(read/write\\) watchpoint \[0-9\]+: b\r\n\r\nOld value = 0\r\nNew value = 2\r\n.*" "catch b on inferior 1"
 }
 
-gdb_test "continue" "Breakpoint \[0-9\]+, marker_exit .*" "catch marker_exit in inferior 1"
+gdb_test "continue" "Breakpoint $bkptno_numopt_re, marker_exit .*" "catch marker_exit in inferior 1"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 1240c2ef6f3..9a6d1480d86 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -273,6 +273,14 @@  set inferior_exited_re "(?:\\\[Inferior \[0-9\]+ \\(\[^\n\r\]*\\) exited)"
 # E.g., $1, $2, etc.
 set valnum_re "\\\$$decimal"
 
+# A regular expression that matches a breakpoint hit with a breakpoint
+# having several code locations.
+set bkptno_num_re "$decimal\\.$decimal"
+
+# A regular expression that matches a breakpoint hit
+# with one or several code locations.
+set bkptno_numopt_re "($decimal\\.$decimal|$decimal)"
+
 ### Only procedures should come after this point.
 
 #
@@ -709,6 +717,7 @@  proc gdb_breakpoint { linespec args } {
 
 proc runto { linespec args } {
     global gdb_prompt
+    global bkptno_numopt_re
     global decimal
 
     delete_breakpoints
@@ -746,7 +755,7 @@  proc runto { linespec args } {
 	    }
 	    return 1
 	}
-	-re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { 
+	-re "Breakpoint $bkptno_numopt_re, \[0-9xa-f\]* in .*$gdb_prompt $" {
 	    if { $print_pass } {
 		pass $test_name
 	    }
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index b11457693be..a45c6f7be28 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1208,11 +1208,11 @@  proc mi_detect_async {} {
 # filename of a file without debug info.  ARGS should not include [] the
 # list of argument is enclosed in, and other regular expressions should
 # not include quotes.
-# If EXTRA is a list of one element, it's the regular expression
+# EXTRA can be a list of one, two or three elements.
+# The first element is the regular expression
 # for output expected right after *stopped, and before GDB prompt.
-# If EXTRA is a list of two elements, the first element is for
-# output right after *stopped, and the second element is output
-# right after reason field.  The regex after reason should not include
+# The third element is the regulation expression for the locno
+# right after bkptno field.  The locno regex should not include
 # the comma separating it from the following fields.
 #
 # When we fail to match output at all, -1 is returned.  If FILE does
@@ -1237,7 +1237,14 @@  proc mi_expect_stop { reason func args file line extra test } {
 
     set after_stopped ""
     set after_reason ""
-    if { [llength $extra] == 2 } {
+    set locno ""
+    if { [llength $extra] == 3 } {
+	set after_stopped [lindex $extra 0]
+	set after_reason [lindex $extra 1]
+	set after_reason "${after_reason},"
+	set locno [lindex $extra 2]
+	set locno "${locno},"
+    } elseif { [llength $extra] == 2 } {
 	set after_stopped [lindex $extra 0]
 	set after_reason [lindex $extra 1]
 	set after_reason "${after_reason},"
@@ -1311,10 +1318,12 @@  proc mi_expect_stop { reason func args file line extra test } {
     set ebn ""
     if { $reason == "breakpoint-hit" } {
 	set bn {bkptno="[0-9]+",}
+	set bn "${bn}${locno}"
     } elseif { $reason == "solib-event" } {
 	set bn ".*"
     } elseif { $reason == "exception-caught" } {
 	set ebn {bkptno="[0-9]+",}
+	set ebn "${ebn}${locno}"
 	set bn ".*"
 	set reason "breakpoint-hit"
     }
@@ -1328,6 +1337,7 @@  proc mi_expect_stop { reason func args file line extra test } {
     set a $after_reason
 
     verbose -log "mi_expect_stop: expecting: \\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
+
     gdb_expect {
 	-re "\\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"($line)\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
 	    pass "$test"