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

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