Blame SOURCES/gdb-rhbz1228556-bpt-inlined-func-name-2of2.patch

15e4b0
commit 4a27f119f59a44395e0a34b1526cee709e1d3fce
15e4b0
Author: Keith Seitz <keiths@redhat.com>
15e4b0
Date:   Fri Oct 27 10:57:23 2017 -0700
15e4b0
15e4b0
    Use SaL symbol name when reporting breakpoint locations
15e4b0
    
15e4b0
    Currently, "info break" can show some (perhaps) unexpected results when
15e4b0
    setting a breakpoint on an inlined function:
15e4b0
    
15e4b0
    (gdb) list
15e4b0
    1       #include <stdio.h>
15e4b0
    2
15e4b0
    3       static inline void foo()
15e4b0
    4       {
15e4b0
    5               printf("Hello world\n");
15e4b0
    6       }
15e4b0
    7
15e4b0
    8       int main()
15e4b0
    9       {
15e4b0
    10              foo();
15e4b0
    11              return 0;
15e4b0
    12      }
15e4b0
    13
15e4b0
    (gdb) b foo
15e4b0
    Breakpoint 1 at 0x400434: file foo.c, line 5.
15e4b0
    (gdb) i b
15e4b0
    Num     Type           Disp Enb Address            What
15e4b0
    1       breakpoint     keep y   0x0000000000400434 in main at foo.c:5
15e4b0
    
15e4b0
    GDB reported that we understood what "foo" was, but we then report that the
15e4b0
    breakpoint is actually set in main. While that is literally true, we can
15e4b0
    do a little better.
15e4b0
    
15e4b0
    This is accomplished by copying the symbol for which the breakpoint was set
15e4b0
    into the bp_location.  From there, print_breakpoint_location can use this
15e4b0
    information to print out symbol information (if available) instead of calling
15e4b0
    find_pc_sect_function.
15e4b0
    
15e4b0
    With the patch installed,
15e4b0
    
15e4b0
    (gdb) i b
15e4b0
    Num     Type           Disp Enb Address            What
15e4b0
    1       breakpoint     keep y   0x0000000000400434 in foo at foo.c:5
15e4b0
    
15e4b0
    gdb/ChangeLog:
15e4b0
    
15e4b0
            * breakpoint.c (print_breakpoint_location): Use the symbol saved
15e4b0
            in the bp_location, falling back to find_pc_sect_function when
15e4b0
            needed.
15e4b0
            (add_location_to_breakpoint): Save sal->symbol.
15e4b0
            * breakpoint.h (struct bp_location) <symbol>: New field.
15e4b0
            * symtab.c (find_function_start_sal): Save the symbol into the SaL.
15e4b0
            * symtab.h (struct symtab_and_line) <symbol>: New field.
15e4b0
    
15e4b0
    gdb/testsuite/ChangeLog:
15e4b0
    
15e4b0
            * gdb.opt/inline-break.exp (break_info_1): New procedure.
15e4b0
            Test "info break" for every inlined function breakpoint.
15e4b0
15e4b0
### a/gdb/ChangeLog
15e4b0
### b/gdb/ChangeLog
15e4b0
## -1,3 +1,13 @@
15e4b0
+2017-10-27  Keith Seitz  <keiths@redhat.com>
15e4b0
+
15e4b0
+	* breakpoint.c (print_breakpoint_location): Use the symbol saved
15e4b0
+	in the bp_location, falling back to find_pc_sect_function when
15e4b0
+	needed.
15e4b0
+	(add_location_to_breakpoint): Save sal->symbol.
15e4b0
+	* breakpoint.h (struct bp_location) <symbol>: New field.
15e4b0
+	* symtab.c (find_function_start_sal): Save the symbol into the SaL.
15e4b0
+	* symtab.h (struct symtab_and_line) <symbol>: New field.
15e4b0
+
15e4b0
 2017-10-26  Patrick Frants  <osscontribute@gmail.com>
15e4b0
 
15e4b0
 	PR gdb/13669
15e4b0
--- a/gdb/breakpoint.c
15e4b0
+++ b/gdb/breakpoint.c
15e4b0
@@ -5956,8 +5956,11 @@ print_breakpoint_location (struct breakpoint *b,
15e4b0
     uiout->field_string ("what", event_location_to_string (b->location.get ()));
15e4b0
   else if (loc && loc->symtab)
15e4b0
     {
15e4b0
-      struct symbol *sym 
15e4b0
-	= find_pc_sect_function (loc->address, loc->section);
15e4b0
+      const struct symbol *sym = loc->symbol;
15e4b0
+
15e4b0
+      if (sym == NULL)
15e4b0
+	sym = find_pc_sect_function (loc->address, loc->section);
15e4b0
+
15e4b0
       if (sym)
15e4b0
 	{
15e4b0
 	  uiout->text ("in ");
15e4b0
@@ -8743,6 +8746,7 @@ add_location_to_breakpoint (struct breakpoint *b,
15e4b0
   loc->gdbarch = loc_gdbarch;
15e4b0
   loc->line_number = sal->line;
15e4b0
   loc->symtab = sal->symtab;
15e4b0
+  loc->symbol = sal->symbol;
15e4b0
 
15e4b0
   set_breakpoint_location_function (loc,
15e4b0
 				    sal->explicit_pc || sal->explicit_line);
15e4b0
--- a/gdb/breakpoint.h
15e4b0
+++ b/gdb/breakpoint.h
15e4b0
@@ -486,6 +486,11 @@ public:
15e4b0
      to find the corresponding source file name.  */
15e4b0
 
15e4b0
   struct symtab *symtab;
15e4b0
+
15e4b0
+  /* The symbol found by the location parser, if any.  This may be used to
15e4b0
+     ascertain when an event location was set at a different location than
15e4b0
+     the one originally selected by parsing, e.g., inlined symbols.  */
15e4b0
+  const struct symbol *symbol = NULL;
15e4b0
 };
15e4b0
 
15e4b0
 /* The possible return values for print_bpstat, print_it_normal,
15e4b0
### a/gdb/testsuite/ChangeLog
15e4b0
### b/gdb/testsuite/ChangeLog
15e4b0
## -1,3 +1,8 @@
15e4b0
+2017-10-27  Keith Seitz  <keiths@redhat.com>
15e4b0
+
15e4b0
+	* gdb.opt/inline-break.exp (break_info_1): New procedure.
15e4b0
+	Test "info break" for every inlined function breakpoint.
15e4b0
+
15e4b0
 2017-10-27  Yao Qi  <yao.qi@linaro.org>
15e4b0
 
15e4b0
 	* gdb.arch/insn-reloc.c (can_relocate_bl): Mark "x30" clobbered.
15e4b0
--- a/gdb/testsuite/gdb.opt/inline-break.exp
15e4b0
+++ b/gdb/testsuite/gdb.opt/inline-break.exp
15e4b0
@@ -24,6 +24,62 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
15e4b0
     return -1
15e4b0
 }
15e4b0
 
15e4b0
+# Return a string that may be used to match the output of "info break NUM".
15e4b0
+#
15e4b0
+# Optional arguments:
15e4b0
+#
15e4b0
+# source    - the name of the source file
15e4b0
+# func      - the name of the function
15e4b0
+# disp      - the event disposition
15e4b0
+# enabled   - enable state
15e4b0
+# locs      - number of locations
15e4b0
+# line      - source line number (ignored without -source)
15e4b0
+
15e4b0
+proc break_info_1 {num args} {
15e4b0
+    global decimal
15e4b0
+
15e4b0
+    # Column delimiter
15e4b0
+    set c {[\t ]+}
15e4b0
+
15e4b0
+    # Row delimiter
15e4b0
+    set end {[\r\n \t]+}
15e4b0
+
15e4b0
+    # Table header
15e4b0
+    set header "[join [list Num Type Disp Enb Address What] ${c}]"
15e4b0
+
15e4b0
+    # Get/configure any optional parameters.
15e4b0
+    parse_args [list {source ""} {func ".*"} {disp "keep"} \
15e4b0
+		    {enabled "y"} {locs 1} [list line $decimal] \
15e4b0
+		    {type "breakpoint"}]
15e4b0
+
15e4b0
+    if {$source != ""} {
15e4b0
+	set source "$source:$line"
15e4b0
+    }
15e4b0
+
15e4b0
+    # Result starts with the standard header.
15e4b0
+    set result "$header${end}"
15e4b0
+
15e4b0
+    # Set up for multi-location breakpoint marker.
15e4b0
+    if {$locs == 1} {
15e4b0
+	set multi ".*"
15e4b0
+    } else {
15e4b0
+	set multi "<MULTIPLE>${end}"
15e4b0
+    }
15e4b0
+    append result "[join [list $num $type $disp $enabled $multi] $c]"
15e4b0
+
15e4b0
+    # Add location info.
15e4b0
+    for {set i 1} {$i <= $locs} {incr i} {
15e4b0
+	if {$locs > 1} {
15e4b0
+	    append result "[join [list $num.$i $enabled] $c].*"
15e4b0
+	}
15e4b0
+
15e4b0
+	#  Add function/source file info.
15e4b0
+	append result "in $func at .*$source${end}"
15e4b0
+    }
15e4b0
+
15e4b0
+    return $result
15e4b0
+}
15e4b0
+
15e4b0
 #
15e4b0
 # func1 is a static inlined function that is called once.
15e4b0
 # The result should be a single-location breakpoint.
15e4b0
@@ -111,3 +167,22 @@ gdb_test "print func1" \
15e4b0
 #
15e4b0
 gdb_test "print func2" \
15e4b0
     "\\\$.* = {int \\(int\\)} .* <func2>"
15e4b0
+
15e4b0
+# Test that "info break" reports the location of the breakpoints "inside"
15e4b0
+# the inlined functions
15e4b0
+
15e4b0
+set results(1) [break_info_1 1 -source $srcfile -func "func1"]
15e4b0
+set results(2) [break_info_1 2 -locs 2 -source $srcfile -func "func2"]
15e4b0
+set results(3) [break_info_1 3 -source $srcfile -func "func3b"]
15e4b0
+set results(4) [break_info_1 4 -locs 2 -source $srcfile -func "func4b"]
15e4b0
+set results(5) [break_info_1 5 -locs 2 -source $srcfile -func "func5b"]
15e4b0
+set results(6) [break_info_1 6 -locs 3 -source $srcfile -func "func6b"]
15e4b0
+set results(7) [break_info_1 7 -locs 2 -source $srcfile -func "func7b"]
15e4b0
+set results(8) [break_info_1 8 -locs 3 -source $srcfile -func "func8b"]
15e4b0
+
15e4b0
+for {set i 1} {$i <= [array size results]} {incr i} {
15e4b0
+    send_log "Expecting: $results($i)\n"
15e4b0
+    gdb_test "info break $i" $results($i)
15e4b0
+}
15e4b0
+
15e4b0
+unset -nocomplain results