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

dc7ef9
commit 4a27f119f59a44395e0a34b1526cee709e1d3fce
dc7ef9
Author: Keith Seitz <keiths@redhat.com>
dc7ef9
Date:   Fri Oct 27 10:57:23 2017 -0700
dc7ef9
dc7ef9
    Use SaL symbol name when reporting breakpoint locations
dc7ef9
    
dc7ef9
    Currently, "info break" can show some (perhaps) unexpected results when
dc7ef9
    setting a breakpoint on an inlined function:
dc7ef9
    
dc7ef9
    (gdb) list
dc7ef9
    1       #include <stdio.h>
dc7ef9
    2
dc7ef9
    3       static inline void foo()
dc7ef9
    4       {
dc7ef9
    5               printf("Hello world\n");
dc7ef9
    6       }
dc7ef9
    7
dc7ef9
    8       int main()
dc7ef9
    9       {
dc7ef9
    10              foo();
dc7ef9
    11              return 0;
dc7ef9
    12      }
dc7ef9
    13
dc7ef9
    (gdb) b foo
dc7ef9
    Breakpoint 1 at 0x400434: file foo.c, line 5.
dc7ef9
    (gdb) i b
dc7ef9
    Num     Type           Disp Enb Address            What
dc7ef9
    1       breakpoint     keep y   0x0000000000400434 in main at foo.c:5
dc7ef9
    
dc7ef9
    GDB reported that we understood what "foo" was, but we then report that the
dc7ef9
    breakpoint is actually set in main. While that is literally true, we can
dc7ef9
    do a little better.
dc7ef9
    
dc7ef9
    This is accomplished by copying the symbol for which the breakpoint was set
dc7ef9
    into the bp_location.  From there, print_breakpoint_location can use this
dc7ef9
    information to print out symbol information (if available) instead of calling
dc7ef9
    find_pc_sect_function.
dc7ef9
    
dc7ef9
    With the patch installed,
dc7ef9
    
dc7ef9
    (gdb) i b
dc7ef9
    Num     Type           Disp Enb Address            What
dc7ef9
    1       breakpoint     keep y   0x0000000000400434 in foo at foo.c:5
dc7ef9
    
dc7ef9
    gdb/ChangeLog:
dc7ef9
    
dc7ef9
            * breakpoint.c (print_breakpoint_location): Use the symbol saved
dc7ef9
            in the bp_location, falling back to find_pc_sect_function when
dc7ef9
            needed.
dc7ef9
            (add_location_to_breakpoint): Save sal->symbol.
dc7ef9
            * breakpoint.h (struct bp_location) <symbol>: New field.
dc7ef9
            * symtab.c (find_function_start_sal): Save the symbol into the SaL.
dc7ef9
            * symtab.h (struct symtab_and_line) <symbol>: New field.
dc7ef9
    
dc7ef9
    gdb/testsuite/ChangeLog:
dc7ef9
    
dc7ef9
            * gdb.opt/inline-break.exp (break_info_1): New procedure.
dc7ef9
            Test "info break" for every inlined function breakpoint.
dc7ef9
dc7ef9
### a/gdb/ChangeLog
dc7ef9
### b/gdb/ChangeLog
dc7ef9
## -1,3 +1,13 @@
dc7ef9
+2017-10-27  Keith Seitz  <keiths@redhat.com>
dc7ef9
+
dc7ef9
+	* breakpoint.c (print_breakpoint_location): Use the symbol saved
dc7ef9
+	in the bp_location, falling back to find_pc_sect_function when
dc7ef9
+	needed.
dc7ef9
+	(add_location_to_breakpoint): Save sal->symbol.
dc7ef9
+	* breakpoint.h (struct bp_location) <symbol>: New field.
dc7ef9
+	* symtab.c (find_function_start_sal): Save the symbol into the SaL.
dc7ef9
+	* symtab.h (struct symtab_and_line) <symbol>: New field.
dc7ef9
+
dc7ef9
 2017-10-26  Patrick Frants  <osscontribute@gmail.com>
dc7ef9
 
dc7ef9
 	PR gdb/13669
dc7ef9
Index: gdb-7.6.1/gdb/breakpoint.c
dc7ef9
===================================================================
dc7ef9
--- gdb-7.6.1.orig/gdb/breakpoint.c	2017-10-27 21:38:34.569392186 +0200
dc7ef9
+++ gdb-7.6.1/gdb/breakpoint.c	2017-10-27 21:38:37.699416969 +0200
dc7ef9
@@ -5703,8 +5703,11 @@
dc7ef9
     ui_out_field_string (uiout, "what", b->addr_string);
dc7ef9
   else if (loc && loc->symtab)
dc7ef9
     {
dc7ef9
-      struct symbol *sym 
dc7ef9
-	= find_pc_sect_function (loc->address, loc->section);
dc7ef9
+      const struct symbol *sym = loc->symbol;
dc7ef9
+
dc7ef9
+      if (sym == NULL)
dc7ef9
+	sym = find_pc_sect_function (loc->address, loc->section);
dc7ef9
+
dc7ef9
       if (sym)
dc7ef9
 	{
dc7ef9
 	  ui_out_text (uiout, "in ");
dc7ef9
@@ -8851,6 +8854,7 @@
dc7ef9
   loc->gdbarch = loc_gdbarch;
dc7ef9
   loc->line_number = sal->line;
dc7ef9
   loc->symtab = sal->symtab;
dc7ef9
+  loc->symbol = sal->symbol;
dc7ef9
 
dc7ef9
   set_breakpoint_location_function (loc,
dc7ef9
 				    sal->explicit_pc || sal->explicit_line);
dc7ef9
Index: gdb-7.6.1/gdb/breakpoint.h
dc7ef9
===================================================================
dc7ef9
--- gdb-7.6.1.orig/gdb/breakpoint.h	2017-10-27 21:38:33.271381909 +0200
dc7ef9
+++ gdb-7.6.1/gdb/breakpoint.h	2017-10-27 21:38:37.700416977 +0200
dc7ef9
@@ -476,6 +476,11 @@
dc7ef9
      to find the corresponding source file name.  */
dc7ef9
 
dc7ef9
   struct symtab *symtab;
dc7ef9
+
dc7ef9
+  /* The symbol found by the location parser, if any.  This may be used to
dc7ef9
+     ascertain when an event location was set at a different location than
dc7ef9
+     the one originally selected by parsing, e.g., inlined symbols.  */
dc7ef9
+  const struct symbol *symbol;
dc7ef9
 };
dc7ef9
 
dc7ef9
 /* Return values for bpstat_explains_signal.  Note that the order of
dc7ef9
Index: gdb-7.6.1/gdb/testsuite/gdb.opt/inline-break.exp
dc7ef9
===================================================================
dc7ef9
--- gdb-7.6.1.orig/gdb/testsuite/gdb.opt/inline-break.exp	2013-01-01 07:41:25.000000000 +0100
dc7ef9
+++ gdb-7.6.1/gdb/testsuite/gdb.opt/inline-break.exp	2017-10-27 21:41:42.869884103 +0200
dc7ef9
@@ -24,6 +24,100 @@
dc7ef9
     return -1
dc7ef9
 }
dc7ef9
 
dc7ef9
+# RHEL-7:
dc7ef9
+proc parse_args { argset } {
dc7ef9
+    upvar args args
dc7ef9
+
dc7ef9
+    foreach argument $argset {
dc7ef9
+        if {[llength $argument] == 1} {
dc7ef9
+            # No default specified, so we assume that we should set
dc7ef9
+            # the value to 1 if the arg is present and 0 if it's not.
dc7ef9
+            # It is assumed that no value is given with the argument.
dc7ef9
+            set result [lsearch -exact $args "-$argument"]
dc7ef9
+            if {$result != -1} then {
dc7ef9
+                uplevel 1 [list set $argument 1]
dc7ef9
+                set args [lreplace $args $result $result]
dc7ef9
+            } else {
dc7ef9
+                uplevel 1 [list set $argument 0]
dc7ef9
+            }
dc7ef9
+        } elseif {[llength $argument] == 2} {
dc7ef9
+            # There are two items in the argument.  The second is a
dc7ef9
+            # default value to use if the item is not present.
dc7ef9
+            # Otherwise, the variable is set to whatever is provided
dc7ef9
+            # after the item in the args.
dc7ef9
+            set arg [lindex $argument 0]
dc7ef9
+            set result [lsearch -exact $args "-[lindex $arg 0]"]
dc7ef9
+            if {$result != -1} then {
dc7ef9
+                uplevel 1 [list set $arg [lindex $args [expr $result+1]]]
dc7ef9
+                set args [lreplace $args $result [expr $result+1]]
dc7ef9
+            } else {
dc7ef9
+                uplevel 1 [list set $arg [lindex $argument 1]]
dc7ef9
+            }
dc7ef9
+        } else {
dc7ef9
+            error "Badly formatted argument \"$argument\" in argument set"
dc7ef9
+        }
dc7ef9
+    }
dc7ef9
+
dc7ef9
+    # The remaining args should be checked to see that they match the
dc7ef9
+    # number of items expected to be passed into the procedure...
dc7ef9
+}
dc7ef9
+
dc7ef9
+# Return a string that may be used to match the output of "info break NUM".
dc7ef9
+#
dc7ef9
+# Optional arguments:
dc7ef9
+#
dc7ef9
+# source    - the name of the source file
dc7ef9
+# func      - the name of the function
dc7ef9
+# disp      - the event disposition
dc7ef9
+# enabled   - enable state
dc7ef9
+# locs      - number of locations
dc7ef9
+# line      - source line number (ignored without -source)
dc7ef9
+
dc7ef9
+proc break_info_1 {num args} {
dc7ef9
+    global decimal
dc7ef9
+
dc7ef9
+    # Column delimiter
dc7ef9
+    set c {[\t ]+}
dc7ef9
+
dc7ef9
+    # Row delimiter
dc7ef9
+    set end {[\r\n \t]+}
dc7ef9
+
dc7ef9
+    # Table header
dc7ef9
+    set header "[join [list Num Type Disp Enb Address What] ${c}]"
dc7ef9
+
dc7ef9
+    # Get/configure any optional parameters.
dc7ef9
+    parse_args [list {source ""} {func ".*"} {disp "keep"} \
dc7ef9
+		    {enabled "y"} {locs 1} [list line $decimal] \
dc7ef9
+		    {type "breakpoint"}]
dc7ef9
+
dc7ef9
+    if {$source != ""} {
dc7ef9
+	set source "$source:$line"
dc7ef9
+    }
dc7ef9
+
dc7ef9
+    # Result starts with the standard header.
dc7ef9
+    set result "$header${end}"
dc7ef9
+
dc7ef9
+    # Set up for multi-location breakpoint marker.
dc7ef9
+    if {$locs == 1} {
dc7ef9
+	set multi ".*"
dc7ef9
+    } else {
dc7ef9
+	set multi "<MULTIPLE>${end}"
dc7ef9
+    }
dc7ef9
+    append result "[join [list $num $type $disp $enabled $multi] $c]"
dc7ef9
+
dc7ef9
+    # Add location info.
dc7ef9
+    for {set i 1} {$i <= $locs} {incr i} {
dc7ef9
+	if {$locs > 1} {
dc7ef9
+	    append result "[join [list $num.$i $enabled] $c].*"
dc7ef9
+	}
dc7ef9
+
dc7ef9
+	#  Add function/source file info.
dc7ef9
+	append result "in $func at .*$source${end}"
dc7ef9
+    }
dc7ef9
+
dc7ef9
+    return $result
dc7ef9
+}
dc7ef9
+
dc7ef9
 #
dc7ef9
 # func1 is a static inlined function that is called once.
dc7ef9
 # The result should be a single-location breakpoint.
dc7ef9
@@ -111,3 +205,22 @@
dc7ef9
 #
dc7ef9
 gdb_test "print func2" \
dc7ef9
     "\\\$.* = {int \\(int\\)} .* <func2>"
dc7ef9
+
dc7ef9
+# Test that "info break" reports the location of the breakpoints "inside"
dc7ef9
+# the inlined functions
dc7ef9
+
dc7ef9
+set results(1) [break_info_1 1 -source $srcfile -func "func1"]
dc7ef9
+set results(2) [break_info_1 2 -locs 2 -source $srcfile -func "func2"]
dc7ef9
+set results(3) [break_info_1 3 -source $srcfile -func "func3b"]
dc7ef9
+set results(4) [break_info_1 4 -locs 2 -source $srcfile -func "func4b"]
dc7ef9
+set results(5) [break_info_1 5 -locs 2 -source $srcfile -func "func5b"]
dc7ef9
+set results(6) [break_info_1 6 -locs 3 -source $srcfile -func "func6b"]
dc7ef9
+set results(7) [break_info_1 7 -locs 2 -source $srcfile -func "func7b"]
dc7ef9
+set results(8) [break_info_1 8 -locs 3 -source $srcfile -func "func8b"]
dc7ef9
+
dc7ef9
+for {set i 1} {$i <= [array size results]} {incr i} {
dc7ef9
+    send_log "Expecting: $results($i)\n"
dc7ef9
+    gdb_test "info break $i" $results($i)
dc7ef9
+}
dc7ef9
+
dc7ef9
+unset -nocomplain results