Home | History | Annotate | Line # | Download | only in gdb.base
break-fun-addr.exp revision 1.1
      1  1.1  christos # Copyright 2016 Free Software Foundation, Inc.
      2  1.1  christos 
      3  1.1  christos # This program is free software; you can redistribute it and/or modify
      4  1.1  christos # it under the terms of the GNU General Public License as published by
      5  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos # (at your option) any later version.
      7  1.1  christos #
      8  1.1  christos # This program is distributed in the hope that it will be useful,
      9  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos # GNU General Public License for more details.
     12  1.1  christos #
     13  1.1  christos # You should have received a copy of the GNU General Public License
     14  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos # The purpose of this testcase is to verify that, when using a breakpoint
     17  1.1  christos # location of the form "*<EXPR>" (Eg: "*main"), GDB is able to start
     18  1.1  christos # the program and stop at the correct location.  With programs built
     19  1.1  christos # as PIE, this means that GDB needs to re-evaluate the location once
     20  1.1  christos # the program as started, since PIE ensures that the address of all
     21  1.1  christos # symbols have changed after load.
     22  1.1  christos #
     23  1.1  christos # PIE is not always supported by the target system, so instead of
     24  1.1  christos # creating a testcase building executables with PIE, this testcase
     25  1.1  christos # takes a slightly different approach.  It builds a first program,
     26  1.1  christos # breaks on *main, and then runs to that breakpoint. It then builds
     27  1.1  christos # a second program, different from the first one, and loads that
     28  1.1  christos # executable within the same GDB session.  Similarly to the PIE case,
     29  1.1  christos # the address of main should be different, and therefore GDB should
     30  1.1  christos # recalculate it.  We verify that by checking that running to that
     31  1.1  christos # breakpoint still works, and that we land at the first instruction
     32  1.1  christos # of that function in both cases.
     33  1.1  christos 
     34  1.1  christos set testfile1 "break-fun-addr1"
     35  1.1  christos set srcfile1 ${testfile1}.c
     36  1.1  christos set binfile1 [standard_output_file ${testfile1}]
     37  1.1  christos 
     38  1.1  christos if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable {debug}] != "" } {
     39  1.1  christos     untested "Couldn't compile ${srcfile1}"
     40  1.1  christos     return -1
     41  1.1  christos }
     42  1.1  christos 
     43  1.1  christos # Start the debugger with the first executable, put a breakpoint
     44  1.1  christos # on the first instruction of function "main" ("*main"), then
     45  1.1  christos # run to that breakpoint.
     46  1.1  christos 
     47  1.1  christos clean_restart ${binfile1}
     48  1.1  christos 
     49  1.1  christos with_test_prefix "${binfile1}" {
     50  1.1  christos 
     51  1.1  christos     gdb_test "break *main" \
     52  1.1  christos         "Breakpoint.*at.* file .*$srcfile1, line .*" \
     53  1.1  christos 
     54  1.1  christos     gdb_run_cmd
     55  1.1  christos     gdb_test "" \
     56  1.1  christos              "Breakpoint.* main \\(\\) at .*$srcfile1:.*" \
     57  1.1  christos              "run to breakpoint at *main"
     58  1.1  christos 
     59  1.1  christos     # Verify also that we stopped at the start of the function...
     60  1.1  christos     gdb_test "p \$pc == main" " = 1"
     61  1.1  christos }
     62  1.1  christos 
     63  1.1  christos set testfile2 "break-fun-addr2"
     64  1.1  christos set srcfile2 ${testfile2}.c
     65  1.1  christos set binfile2 [standard_output_file ${testfile2}]
     66  1.1  christos 
     67  1.1  christos if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
     68  1.1  christos     untested "Couldn't compile ${srcfile2}"
     69  1.1  christos     return -1
     70  1.1  christos }
     71  1.1  christos 
     72  1.1  christos # Now, keeping the same GDB process (so as to keep the same breakpoint),
     73  1.1  christos # start a new debugging session with a different executable.
     74  1.1  christos gdb_load ${binfile2}
     75  1.1  christos 
     76  1.1  christos with_test_prefix "${binfile2}" {
     77  1.1  christos 
     78  1.1  christos     gdb_run_cmd
     79  1.1  christos     gdb_test "" \
     80  1.1  christos              "Breakpoint.* main \\(\\) at .*$srcfile2:.*" \
     81  1.1  christos              "run to breakpoint at *main"
     82  1.1  christos 
     83  1.1  christos     gdb_test "p \$pc == main" " = 1"
     84  1.1  christos }
     85