(root)/
gcc-13.2.0/
gcc/
testsuite/
jit.dg/
test-debuginfo.c
       1  /* Essentially this test checks that debug info are generated for globals
       2     locals and functions, including type info. The comment bellow is used
       3     as fake code (does not affect the test, use for manual debugging). */
       4  /*
       5  int a_global_for_test_debuginfo;
       6  int main (int argc, char **argv)
       7  {
       8      int a_local_for_test_debuginfo = 2;
       9      return a_global_for_test_debuginfo + a_local_for_test_debuginfo;
      10  }
      11  */
      12  #include "libgccjit.h"
      13  
      14  /* We don't want set_options() in harness.h to set -O3 so our little local
      15     is optimized away. */
      16  #define TEST_ESCHEWS_SET_OPTIONS
      17  static void set_options (gcc_jit_context *ctxt, const char *argv0)
      18  {
      19      gcc_jit_context_set_bool_option(ctxt, GCC_JIT_BOOL_OPTION_DEBUGINFO, 1);
      20  }
      21  
      22  #define TEST_COMPILING_TO_FILE
      23  #define OUTPUT_KIND      GCC_JIT_OUTPUT_KIND_EXECUTABLE
      24  #define OUTPUT_FILENAME  "jit-debuginfo.o"
      25  #include "harness.h"
      26  
      27  #define LOC(row, col) gcc_jit_context_new_location(ctxt, "test-debuginfo.c", row, col)
      28  
      29  void
      30  create_code (gcc_jit_context *ctxt, void* p)
      31  {
      32    gcc_jit_type *int_type = gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_INT);
      33  
      34    gcc_jit_lvalue *bar = gcc_jit_context_new_global(ctxt, 
      35      LOC(5,1), GCC_JIT_GLOBAL_EXPORTED, 
      36      int_type, "a_global_for_test_debuginfo");
      37  
      38    gcc_jit_param *argc_para = gcc_jit_context_new_param(ctxt, LOC(6,15), 
      39      int_type, "argc");
      40    gcc_jit_param *argv_para = gcc_jit_context_new_param(ctxt, LOC(6,28), 
      41      gcc_jit_type_get_pointer(
      42        gcc_jit_type_get_pointer(
      43          gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_CHAR))),
      44      "argc");
      45  
      46    gcc_jit_param *params[] = {argc_para, argv_para};
      47  
      48    gcc_jit_function *foo_fn = gcc_jit_context_new_function(ctxt, LOC(6,5), 
      49      GCC_JIT_FUNCTION_EXPORTED, int_type, "main", 2, params, 0);
      50    gcc_jit_block *start_block = gcc_jit_function_new_block(foo_fn, 
      51      "start_block");
      52  
      53    gcc_jit_lvalue *a = gcc_jit_function_new_local(foo_fn, LOC(8,5), 
      54      int_type, "a_local_for_test_debuginfo");
      55    gcc_jit_block_add_assignment(start_block, LOC(8,36), a, 
      56      gcc_jit_context_new_rvalue_from_int(ctxt, int_type, 2));
      57    gcc_jit_rvalue *add = gcc_jit_context_new_binary_op(ctxt, LOC(9,40), 
      58      GCC_JIT_BINARY_OP_PLUS, int_type, 
      59      gcc_jit_lvalue_as_rvalue(a), gcc_jit_lvalue_as_rvalue(bar));
      60  
      61    gcc_jit_block_end_with_return(start_block, LOC(9,5), add);
      62  }
      63  
      64  #undef LOC
      65  
      66  /* jit-check-debug-info fires up gdb and checks that the variables have 
      67     debug info */
      68  
      69  /*  { dg-final { jit-check-debug-info "jit-debuginfo.o" {"info variables\n"} "int\\s+a_global_for_test_debuginfo;" } } */
      70  /*  { dg-final { jit-check-debug-info "jit-debuginfo.o" {"pt main\n"} "int\\s*\\(\\s*int\\s*,\\s*char\\s*\\*\\*\\s*\\)"} } */
      71  /*  { dg-final { jit-check-debug-info "jit-debuginfo.o" {"start\n" "info locals\n"} "a_local_for_test_debuginfo"} } */
      72  /*  { dg-final { jit-check-debug-info "jit-debuginfo.o" {"start\n" "pt a_local_for_test_debuginfo\n"} "int"} } */