Home | History | Annotate | Line # | Download | only in gdb.dwarf2
dw2-step-between-inline-func-blocks.c revision 1.1.1.1
      1 /* This testcase is part of GDB, the GNU debugger.
      2 
      3    Copyright 2024 Free Software Foundation, Inc.
      4 
      5    This program is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation; either version 3 of the License, or
      8    (at your option) any later version.
      9 
     10    This program is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17 
     18 /* Used to insert labels within function foo.  */
     19 #define LABEL(N) asm ("foo_label_" #N ": .globl foo_label_" #N)
     20 
     21 volatile int global_var = 0;
     22 
     23 /* The contents of this '#if 0' block exist so the generated debug can
     24    point to these as the source lines.  */
     25 #if 0
     26 
     27 void
     28 bar (void)	/* bar decl line */
     29 {
     30   /* bar line 1 */
     31   /* bar line 2 */
     32   /* bar line 3 */
     33   /* bar line 4 */
     34 }
     35 
     36 void
     37 foo (void)	/* foo decl line */
     38 {
     39   /* foo line 1 */
     40   /* foo line 2 */
     41   /* foo line 3 */
     42   /* foo line 4 */
     43 }
     44 
     45 #endif
     46 
     47 extern void *foo_label_6 (void);
     48 
     49 void
     50 foo (void)
     51 {
     52   /* This label is used to find the start of 'foo' when generating the
     53      debug information.  */
     54   asm ("foo_label: .globl foo_label");
     55   ++global_var;
     56 
     57   LABEL (1);
     58   ++global_var;
     59 
     60   LABEL (2);
     61   ++global_var;
     62 
     63   LABEL (3);
     64   ++global_var;
     65 
     66   /* This goto will always trigger, but we make it conditional so that the
     67      compiler doesn't optimise out the code between the goto and the
     68      destination.
     69 
     70      Also 'goto *ADDR' is a GCC extension, but it is critical that the
     71      destination address be a global label so that we can generate DWARF
     72      that has ranges that start exactly at the destination address.  */
     73   if (global_var > 0)
     74     goto *(&foo_label_6);
     75 
     76   LABEL (4);
     77   ++global_var;
     78 
     79   LABEL (5);
     80   ++global_var;
     81 
     82   LABEL (6);
     83   ++global_var;
     84 
     85   LABEL (7);
     86   ++global_var;
     87 
     88   LABEL (8);
     89   ++global_var;
     90 
     91   LABEL (9);
     92   ++global_var;
     93 }
     94 
     95 int
     96 main (void)
     97 {
     98   asm ("main_label: .globl main_label");
     99   foo ();
    100 }
    101