Home | History | Annotate | Line # | Download | only in libcc1
      1      1.1  mrg /* The library used by gdb.
      2  1.1.1.8  mrg    Copyright (C) 2014-2024 Free Software Foundation, Inc.
      3      1.1  mrg 
      4      1.1  mrg This file is part of GCC.
      5      1.1  mrg 
      6      1.1  mrg GCC is free software; you can redistribute it and/or modify it under
      7      1.1  mrg the terms of the GNU General Public License as published by the Free
      8      1.1  mrg Software Foundation; either version 3, or (at your option) any later
      9      1.1  mrg version.
     10      1.1  mrg 
     11      1.1  mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     12      1.1  mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13      1.1  mrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14      1.1  mrg for more details.
     15      1.1  mrg 
     16      1.1  mrg You should have received a copy of the GNU General Public License
     17      1.1  mrg along with GCC; see the file COPYING3.  If not see
     18      1.1  mrg <http://www.gnu.org/licenses/>.  */
     19      1.1  mrg 
     20      1.1  mrg #include <cc1plugin-config.h>
     21      1.1  mrg #include <vector>
     22      1.1  mrg #include <string>
     23      1.1  mrg #include <sys/socket.h>
     24      1.1  mrg #include <sys/types.h>
     25      1.1  mrg #include <unistd.h>
     26      1.1  mrg #include <sys/wait.h>
     27      1.1  mrg #include <stdio.h>
     28      1.1  mrg #include <errno.h>
     29      1.1  mrg #include <sys/stat.h>
     30      1.1  mrg #include <stdlib.h>
     31      1.1  mrg #include "marshall-cp.hh"
     32      1.1  mrg #include "rpc.hh"
     33      1.1  mrg #include "connection.hh"
     34      1.1  mrg #include "names.hh"
     35      1.1  mrg #include "callbacks.hh"
     36      1.1  mrg #include "libiberty.h"
     37  1.1.1.4  mrg #include "compiler-name.hh"
     38  1.1.1.7  mrg #include "compiler.hh"
     39  1.1.1.7  mrg #include "gdbctx.hh"
     40      1.1  mrg 
     41      1.1  mrg // The C compiler context that we hand back to our caller.
     42  1.1.1.7  mrg struct libcp1 : public cc1_plugin::base_gdb_plugin<gcc_cp_context>
     43      1.1  mrg {
     44  1.1.1.7  mrg   explicit libcp1 (const gcc_cp_fe_vtable *);
     45      1.1  mrg 
     46  1.1.1.7  mrg   void add_callbacks () override;
     47      1.1  mrg 
     48  1.1.1.7  mrg   gcc_cp_oracle_function *binding_oracle = nullptr;
     49  1.1.1.7  mrg   gcc_cp_symbol_address_function *address_oracle = nullptr;
     50  1.1.1.7  mrg   gcc_cp_enter_leave_user_expr_scope_function *enter_scope = nullptr;
     51  1.1.1.7  mrg   gcc_cp_enter_leave_user_expr_scope_function *leave_scope = nullptr;
     52  1.1.1.7  mrg   void *oracle_datum = nullptr;
     53      1.1  mrg };
     54      1.1  mrg 
     55  1.1.1.7  mrg libcp1::libcp1 (const gcc_cp_fe_vtable *cv)
     56  1.1.1.7  mrg   : cc1_plugin::base_gdb_plugin<gcc_cp_context> ("libcp1plugin",
     57  1.1.1.7  mrg 						 CP_COMPILER_NAME,
     58  1.1.1.8  mrg 						 cv->cp_version)
     59      1.1  mrg {
     60      1.1  mrg   cp_ops = cv;
     61      1.1  mrg }
     62      1.1  mrg 
     63      1.1  mrg 
     64      1.1  mrg 
     66      1.1  mrg // Enclose these functions in an anonymous namespace because they
     67      1.1  mrg // shouldn't be exported, but they can't be static because they're
     68      1.1  mrg // used as template arguments.
     69      1.1  mrg namespace {
     70      1.1  mrg   // This is a wrapper function that is called by the RPC system and
     71      1.1  mrg   // that then forwards the call to the library user.  Note that the
     72      1.1  mrg   // return value is not used; the type cannot be 'void' due to
     73      1.1  mrg   // limitations in our simple RPC.
     74      1.1  mrg   int
     75      1.1  mrg   cp_call_binding_oracle (cc1_plugin::connection *conn,
     76      1.1  mrg 		       enum gcc_cp_oracle_request request,
     77      1.1  mrg 		       const char *identifier)
     78  1.1.1.7  mrg   {
     79      1.1  mrg     libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
     80      1.1  mrg 
     81      1.1  mrg     self->binding_oracle (self->oracle_datum, self, request, identifier);
     82      1.1  mrg     return 1;
     83      1.1  mrg   }
     84      1.1  mrg 
     85      1.1  mrg   // This is a wrapper function that is called by the RPC system and
     86      1.1  mrg   // that then forwards the call to the library user.
     87      1.1  mrg   gcc_address
     88      1.1  mrg   cp_call_symbol_address (cc1_plugin::connection *conn, const char *identifier)
     89  1.1.1.7  mrg   {
     90      1.1  mrg     libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
     91      1.1  mrg 
     92      1.1  mrg     return self->address_oracle (self->oracle_datum, self, identifier);
     93      1.1  mrg   }
     94      1.1  mrg 
     95      1.1  mrg   int
     96      1.1  mrg   cp_call_enter_scope (cc1_plugin::connection *conn)
     97  1.1.1.7  mrg   {
     98      1.1  mrg     libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
     99      1.1  mrg 
    100      1.1  mrg     self->enter_scope (self->oracle_datum, self);
    101      1.1  mrg     return 1;
    102      1.1  mrg   }
    103      1.1  mrg 
    104      1.1  mrg   int
    105      1.1  mrg   cp_call_leave_scope (cc1_plugin::connection *conn)
    106  1.1.1.7  mrg   {
    107      1.1  mrg     libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr);
    108      1.1  mrg 
    109      1.1  mrg     self->leave_scope (self->oracle_datum, self);
    110      1.1  mrg     return 1;
    111      1.1  mrg   }
    112      1.1  mrg } /* anonymous namespace */
    113      1.1  mrg 
    114      1.1  mrg 
    115      1.1  mrg 
    117      1.1  mrg static void
    118      1.1  mrg set_callbacks (struct gcc_cp_context *s,
    119      1.1  mrg 	       gcc_cp_oracle_function *binding_oracle,
    120      1.1  mrg 	       gcc_cp_symbol_address_function *address_oracle,
    121      1.1  mrg 	       gcc_cp_enter_leave_user_expr_scope_function *enter_scope,
    122      1.1  mrg 	       gcc_cp_enter_leave_user_expr_scope_function *leave_scope,
    123      1.1  mrg 	       void *datum)
    124      1.1  mrg {
    125      1.1  mrg   libcp1 *self = (libcp1 *) s;
    126      1.1  mrg 
    127      1.1  mrg   self->binding_oracle = binding_oracle;
    128      1.1  mrg   self->address_oracle = address_oracle;
    129      1.1  mrg   self->enter_scope = enter_scope;
    130      1.1  mrg   self->leave_scope = leave_scope;
    131      1.1  mrg   self->oracle_datum = datum;
    132      1.1  mrg }
    133      1.1  mrg 
    134      1.1  mrg static const struct gcc_cp_fe_vtable cp_vtable =
    135      1.1  mrg {
    136      1.1  mrg   GCC_CP_FE_VERSION_0,
    137      1.1  mrg   set_callbacks,
    138  1.1.1.7  mrg 
    139      1.1  mrg #define GCC_METHOD0(R, N) \
    140  1.1.1.7  mrg   cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N>,
    141      1.1  mrg #define GCC_METHOD1(R, N, A) \
    142  1.1.1.7  mrg   cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A>,
    143      1.1  mrg #define GCC_METHOD2(R, N, A, B) \
    144  1.1.1.7  mrg   cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B>,
    145      1.1  mrg #define GCC_METHOD3(R, N, A, B, C) \
    146  1.1.1.7  mrg   cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C>,
    147      1.1  mrg #define GCC_METHOD4(R, N, A, B, C, D) \
    148  1.1.1.7  mrg   cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D>,
    149      1.1  mrg #define GCC_METHOD5(R, N, A, B, C, D, E) \
    150  1.1.1.7  mrg   cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D, E>,
    151      1.1  mrg #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
    152      1.1  mrg   cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D, E, F, G>,
    153      1.1  mrg 
    154      1.1  mrg #include "gcc-cp-fe.def"
    155      1.1  mrg 
    156      1.1  mrg #undef GCC_METHOD0
    157      1.1  mrg #undef GCC_METHOD1
    158      1.1  mrg #undef GCC_METHOD2
    159      1.1  mrg #undef GCC_METHOD3
    160      1.1  mrg #undef GCC_METHOD4
    161      1.1  mrg #undef GCC_METHOD5
    162      1.1  mrg #undef GCC_METHOD7
    163      1.1  mrg };
    164      1.1  mrg 
    165  1.1.1.7  mrg 
    166  1.1.1.7  mrg 
    168      1.1  mrg void
    169  1.1.1.7  mrg libcp1::add_callbacks ()
    170  1.1.1.7  mrg {
    171  1.1.1.7  mrg   cc1_plugin::callback_ftype *fun
    172  1.1.1.7  mrg     = cc1_plugin::invoker<int, enum gcc_cp_oracle_request,
    173  1.1.1.7  mrg 			  const char *>::invoke<cp_call_binding_oracle>;
    174  1.1.1.7  mrg   connection->add_callback ("binding_oracle", fun);
    175  1.1.1.7  mrg 
    176      1.1  mrg   fun = cc1_plugin::invoker<gcc_address,
    177  1.1.1.7  mrg 			    const char *>::invoke<cp_call_symbol_address>;
    178  1.1.1.7  mrg   connection->add_callback ("address_oracle", fun);
    179      1.1  mrg 
    180  1.1.1.7  mrg   fun = cc1_plugin::invoker<int>::invoke<cp_call_enter_scope>;
    181  1.1.1.7  mrg   connection->add_callback ("enter_scope", fun);
    182      1.1  mrg 
    183      1.1  mrg   fun = cc1_plugin::invoker<int>::invoke<cp_call_leave_scope>;
    184      1.1  mrg   connection->add_callback ("leave_scope", fun);
    185      1.1  mrg }
    186      1.1  mrg 
    187      1.1  mrg extern "C" gcc_cp_fe_context_function gcc_cp_fe_context;
    188      1.1  mrg 
    189      1.1  mrg #ifdef __GNUC__
    190      1.1  mrg #pragma GCC visibility push(default)
    191      1.1  mrg #endif
    192      1.1  mrg 
    193      1.1  mrg extern "C"
    194      1.1  mrg struct gcc_cp_context *
    195      1.1  mrg gcc_cp_fe_context (enum gcc_base_api_version base_version,
    196      1.1  mrg 		    enum gcc_cp_api_version cp_version)
    197      1.1  mrg {
    198      1.1  mrg   if ((base_version != GCC_FE_VERSION_0 && base_version != GCC_FE_VERSION_1)
    199  1.1.1.7  mrg       || cp_version != GCC_CP_FE_VERSION_0)
    200      1.1  mrg     return NULL;
    201               
    202                 return new libcp1 (&cp_vtable);
    203               }
    204