gdb: include location number in breakpoint error message
authorAndrew Burgess <aburgess@redhat.com>
Fri, 7 Jul 2023 15:36:26 +0000 (16:36 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 10 Jul 2023 09:49:59 +0000 (10:49 +0100)
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>
gdb/breakpoint.c
gdb/testsuite/gdb.base/bp-cond-failure.c
gdb/testsuite/gdb.base/bp-cond-failure.exp

index da6c8de9d144854869ab50a91c679df589076a8f..d898167b7e1bbdc722e8b57b786fc4c5ab47a9fb 100644 (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
index 2a9974b47ce947547ba34099c47edc80ccd4fd27..8c226edd8b41ad73e5ed5e6e4e2274110bf1a0d9 100644 (file)
    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;
 }
index cb5722037727d4690936a241b6429d95391535b2..5fb5b0f46998cb110999e9c21ab5800c14d695da 100644 (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
+       }
     }
 }