gdb: include location number in breakpoint error message

This commit improves the output of this previous commit:

  commit 2dc3457a454a35d0617dc1f9cc1db77468471f95
  Date:   Fri Oct 14 13:22:55 2022 +0100

      gdb: include breakpoint number in testing condition error message

The earlier commit extended the error message:

  Error in testing breakpoint condition:

to include the breakpoint number, e.g.:

  Error in testing breakpoint condition 3:

This commit extends takes this further, and includes the location
number if the breakpoint has multiple locations, so we might now see:

  Error in testing breakpoint condition 3.2:

Just as with how GDB reports a normal breakpoint stop, if a breakpoint
only has a single location then the location number is not included,
this keeps things nice and consistent.

I've extended one of the tests to cover the new functionality.

Approved-By: Pedro Alves <pedro@palves.net>
This commit is contained in:
Andrew Burgess 2023-07-07 16:36:26 +01:00
parent c432a27df3
commit 3f3ffaca04
3 changed files with 45 additions and 15 deletions

View File

@ -5544,9 +5544,17 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
}
catch (const gdb_exception_error &ex)
{
exception_fprintf (gdb_stderr, ex,
"Error in testing condition for breakpoint %d:\n",
b->number);
int locno = bpstat_locno (bs);
if (locno != 0)
exception_fprintf
(gdb_stderr, ex,
"Error in testing condition for breakpoint %d.%d:\n",
b->number, locno);
else
exception_fprintf
(gdb_stderr, ex,
"Error in testing condition for breakpoint %d:\n",
b->number);
/* If the pc value changed as a result of evaluating the
condition then we probably stopped within an inferior

View File

@ -15,16 +15,26 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
int
static inline int __attribute__((__always_inline__))
foo ()
{
return 0; /* Breakpoint here. */
return 0; /* Multi-location breakpoint here. */
}
static int __attribute__((noinline))
bar ()
{
int res = foo (); /* Single-location breakpoint here. */
return res;
}
int
main ()
{
int res = foo ();
int res = bar ();
res = foo ();
return res;
}

View File

@ -44,10 +44,7 @@ if { [is_address_zero_readable] } {
return
}
# Where the breakpoint will be placed.
set bp_line [gdb_get_line_number "Breakpoint here"]
proc run_test { cond_eval access_type } {
proc run_test { cond_eval access_type lineno nloc } {
clean_restart ${::binfile}
if { ![runto_main] } {
@ -59,17 +56,23 @@ proc run_test { cond_eval access_type } {
}
# Setup the conditional breakpoint and record its number.
gdb_breakpoint "${::srcfile}:${::bp_line} if (*(${access_type} *) 0) == 0"
gdb_breakpoint "${::srcfile}:${lineno} if (*(${access_type} *) 0) == 0"
set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*"]
if { $nloc > 1 } {
set bp_num_pattern "${bp_num}.1"
} else {
set bp_num_pattern "${bp_num}"
}
gdb_test "continue" \
[multi_line \
"Continuing\\." \
"Error in testing condition for breakpoint ${bp_num}:" \
"Error in testing condition for breakpoint ${bp_num_pattern}:" \
"Cannot access memory at address 0x0" \
"" \
"Breakpoint ${bp_num}, foo \\(\\) at \[^\r\n\]+:${::bp_line}" \
"${::decimal}\\s+\[^\r\n\]+Breakpoint here\[^\r\n\]+"]
"Breakpoint ${bp_num_pattern}, \(foo\|bar\) \\(\\) at \[^\r\n\]+:${lineno}" \
"${::decimal}\\s+\[^\r\n\]+ breakpoint here\\. \[^\r\n\]+"]
}
# If we're using a remote target then conditions could be evaulated
@ -97,8 +100,17 @@ gdb_test_multiple "show breakpoint condition-evaluation" "" {
}
}
# Where the breakpoint will be placed.
set bp_line_multi_loc [gdb_get_line_number "Multi-location breakpoint here"]
set bp_line_single_loc [gdb_get_line_number "Single-location breakpoint here"]
foreach_with_prefix access_type { "char" "short" "int" "long long" } {
foreach_with_prefix cond_eval $cond_eval_modes {
run_test $cond_eval $access_type
with_test_prefix "multi-loc" {
run_test $cond_eval $access_type $bp_line_multi_loc 2
}
with_test_prefix "single-loc" {
run_test $cond_eval $access_type $bp_line_single_loc 1
}
}
}