binutils-gdb/gdb/testsuite/gdb.base/asmlabel.c

31 lines
964 B
C
Raw Normal View History

minsyms.c: Scan backwards over all zero sized symbols. The comment for the code in question says: /* If the minimal symbol has a zero size, save it but keep scanning backwards looking for one with a non-zero size. A zero size may mean that the symbol isn't an object or function (e.g. a label), or it may just mean that the size was not specified. */ As written, the code in question will only scan past the first symbol of zero size. My change fixes the implementation to match the comment. Having this correct is important when the compiler generates several local labels that are left in place by the linker. (I've been told that the linker should eliminate these symbols, but I know of one architecture for which this is not happening.) I've created a test case called asmlabel.c. It's pretty simple: main (int argc, char **argv) { asm ("L0:"); v = 0; asm ("L1:"); v = 1; /* set L1 breakpoint here */ asm ("L2:"); v = 2; /* set L2 breakpoint here */ return 0; } If breakpoints are placed on the lines indicated by the comments, this is the behavior of GDB built without my patch: (gdb) continue Continuing. Breakpoint 2, L1 () at asmlabel.c:26 26 v = 1; /* set L1 breakpoint here */ Note that L1 appears as the function instead of main. This is not what we want to happen. With my patch in place, we see the desired behavior instead: (gdb) continue Continuing. Breakpoint 2, main (argc=1, argv=0x7fffffffdb88) at asmlabel.c:26 26 v = 1; /* set L1 breakpoint here */ gdb/ChangeLog: * minsyms.c (lookup_minimal_symbol_by_pc_section_1): Scan backwards over all zero-sized symbols. gdb/testsuite/ChangeLog: * gdb.base/asmlabel.exp: New test. * gdb.base/asmlabel.c: New test case.
2015-11-14 21:15:45 +01:00
/* This testcase is part of GDB, the GNU debugger.
Copyright 2015-2017 Free Software Foundation, Inc.
minsyms.c: Scan backwards over all zero sized symbols. The comment for the code in question says: /* If the minimal symbol has a zero size, save it but keep scanning backwards looking for one with a non-zero size. A zero size may mean that the symbol isn't an object or function (e.g. a label), or it may just mean that the size was not specified. */ As written, the code in question will only scan past the first symbol of zero size. My change fixes the implementation to match the comment. Having this correct is important when the compiler generates several local labels that are left in place by the linker. (I've been told that the linker should eliminate these symbols, but I know of one architecture for which this is not happening.) I've created a test case called asmlabel.c. It's pretty simple: main (int argc, char **argv) { asm ("L0:"); v = 0; asm ("L1:"); v = 1; /* set L1 breakpoint here */ asm ("L2:"); v = 2; /* set L2 breakpoint here */ return 0; } If breakpoints are placed on the lines indicated by the comments, this is the behavior of GDB built without my patch: (gdb) continue Continuing. Breakpoint 2, L1 () at asmlabel.c:26 26 v = 1; /* set L1 breakpoint here */ Note that L1 appears as the function instead of main. This is not what we want to happen. With my patch in place, we see the desired behavior instead: (gdb) continue Continuing. Breakpoint 2, main (argc=1, argv=0x7fffffffdb88) at asmlabel.c:26 26 v = 1; /* set L1 breakpoint here */ gdb/ChangeLog: * minsyms.c (lookup_minimal_symbol_by_pc_section_1): Scan backwards over all zero-sized symbols. gdb/testsuite/ChangeLog: * gdb.base/asmlabel.exp: New test. * gdb.base/asmlabel.c: New test case.
2015-11-14 21:15:45 +01:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
static volatile int v = -1;
int
main (int argc, char **argv)
{
asm ("L0:");
v = 0;
asm ("L1:");
v = 1; /* set L1 breakpoint here */
asm ("L2:");
v = 2; /* set L2 breakpoint here */
return 0;
}