LCOV - code coverage report
Current view: top level - mnt/wasteland/wcohen/systemtap_write/systemtap - session.h (source / functions) Hit Total Coverage
Test: stap.info Lines: 14 14 100.0 %
Date: 2013-03-08 Functions: 9 11 81.8 %
Branches: 13 22 59.1 %

           Branch data     Line data    Source code
       1                 :            : // -*- C++ -*-
       2                 :            : // Copyright (C) 2005-2012 Red Hat Inc.
       3                 :            : //
       4                 :            : // This file is part of systemtap, and is free software.  You can
       5                 :            : // redistribute it and/or modify it under the terms of the GNU General
       6                 :            : // Public License (GPL); either version 2, or (at your option) any
       7                 :            : // later version.
       8                 :            : 
       9                 :            : #ifndef SESSION_H
      10                 :            : #define SESSION_H
      11                 :            : 
      12                 :            : #include "config.h"
      13                 :            : #include <libintl.h>
      14                 :            : #include <locale.h>
      15                 :            : 
      16                 :            : #include <list>
      17                 :            : #include <string>
      18                 :            : #include <vector>
      19                 :            : #include <iostream>
      20                 :            : #include <sstream>
      21                 :            : #include <map>
      22                 :            : #include <set>
      23                 :            : #include <stdexcept>
      24                 :            : 
      25                 :            : extern "C" {
      26                 :            : #include <signal.h>
      27                 :            : #include <elfutils/libdw.h>
      28                 :            : }
      29                 :            : 
      30                 :            : #include "privilege.h"
      31                 :            : #include "util.h"
      32                 :            : 
      33                 :            : // forward decls for all referenced systemtap types
      34                 :            : class stap_hash;
      35                 :            : class match_node;
      36                 :            : struct stapfile;
      37                 :            : struct vardecl;
      38                 :            : struct token;
      39                 :            : struct functiondecl;
      40                 :            : struct derived_probe;
      41                 :            : struct be_derived_probe_group;
      42                 :            : struct dwarf_derived_probe_group;
      43                 :            : struct kprobe_derived_probe_group;
      44                 :            : struct hwbkpt_derived_probe_group;
      45                 :            : struct perf_derived_probe_group;
      46                 :            : struct uprobe_derived_probe_group;
      47                 :            : struct utrace_derived_probe_group;
      48                 :            : struct itrace_derived_probe_group;
      49                 :            : struct task_finder_derived_probe_group;
      50                 :            : struct timer_derived_probe_group;
      51                 :            : struct netfilter_derived_probe_group;
      52                 :            : struct profile_derived_probe_group;
      53                 :            : struct mark_derived_probe_group;
      54                 :            : struct tracepoint_derived_probe_group;
      55                 :            : struct hrtimer_derived_probe_group;
      56                 :            : struct procfs_derived_probe_group;
      57                 :            : struct dynprobe_derived_probe_group;
      58                 :            : struct embeddedcode;
      59                 :            : struct stapdfa;
      60                 :            : class translator_output;
      61                 :            : struct unparser;
      62                 :            : struct semantic_error;
      63                 :            : struct module_cache;
      64                 :            : struct update_visitor;
      65                 :            : struct compile_server_cache;
      66                 :            : 
      67                 :            : // XXX: a generalized form of this descriptor could be associated with
      68                 :            : // a vardecl instead of out here at the systemtap_session level.
      69                 :            : struct statistic_decl
      70                 :            : {
      71                 :     461426 :   statistic_decl()
      72                 :            :     : type(none),
      73                 :     461426 :       linear_low(0), linear_high(0), linear_step(0)
      74                 :     461426 :   {}
      75                 :            :   enum { none, linear, logarithmic } type;
      76                 :            :   int64_t linear_low;
      77                 :            :   int64_t linear_high;
      78                 :            :   int64_t linear_step;
      79                 :        135 :   bool operator==(statistic_decl const & other)
      80                 :            :   {
      81                 :            :     return type == other.type
      82                 :            :       && linear_low == other.linear_low
      83                 :            :       && linear_high == other.linear_high
      84 [ +  + ][ +  - ]:        135 :       && linear_step == other.linear_step;
         [ +  - ][ +  - ]
      85                 :            :   }
      86                 :            : };
      87                 :            : 
      88                 :            : struct macrodecl; // defined in parse.h
      89                 :            : 
      90                 :            : struct systemtap_session
      91                 :            : {
      92                 :            : private:
      93                 :            :   // disable implicit constructors by not implementing these
      94                 :            :   systemtap_session (const systemtap_session& other);
      95                 :            :   systemtap_session& operator= (const systemtap_session& other);
      96                 :            : 
      97                 :            :   // copy constructor used by ::clone()
      98                 :            :   systemtap_session (const systemtap_session& other,
      99                 :            :                      const std::string& arch,
     100                 :            :                      const std::string& kern);
     101                 :            : 
     102                 :            : public:
     103                 :            :   systemtap_session ();
     104                 :            :   ~systemtap_session ();
     105                 :            : 
     106                 :            :   // To reset the tmp_dir
     107                 :            :   void create_tmp_dir();
     108                 :            :   void remove_tmp_dir();
     109                 :            :   void reset_tmp_dir();
     110                 :            : 
     111                 :            :   // NB: It is very important for all of the above (and below) fields
     112                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     113                 :            :   void setup_kernel_release (const char* kstr);
     114                 :            :   void insert_loaded_modules ();
     115                 :            : 
     116                 :            :   // command line parsing
     117                 :            :   int  parse_cmdline (int argc, char * const argv []);
     118                 :            :   bool parse_cmdline_runtime (const std::string& opt_runtime);
     119                 :            :   void version ();
     120                 :            :   void usage (int exitcode);
     121                 :            :   void check_options (int argc, char * const argv []);
     122                 :            :   static const char* morehelp;
     123                 :            : 
     124                 :            :   // NB: It is very important for all of the above (and below) fields
     125                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     126                 :            : 
     127                 :            :   // command line args
     128                 :            :   std::string script_file; // FILE
     129                 :            :   std::string cmdline_script; // -e PROGRAM
     130                 :            :   bool have_script;
     131                 :            :   std::vector<std::string> include_path;
     132                 :            :   int include_arg_start;
     133                 :            :   std::vector<std::string> c_macros;
     134                 :            :   std::vector<std::string> args;
     135                 :            :   std::vector<std::string> kbuildflags; // -B var=val
     136                 :            :   std::vector<std::string> globalopts; // -G var=val
     137                 :            :   std::vector<std::string> modinfos; // --modinfo tag=value
     138                 :            : 
     139                 :            :   std::string release;
     140                 :            :   std::string kernel_release;
     141                 :            :   std::string kernel_base_release;
     142                 :            :   std::string kernel_build_tree;
     143                 :            :   std::string kernel_source_tree;
     144                 :            :   std::map<std::string,std::string> kernel_config;
     145                 :            :   std::set<std::string> kernel_exports;
     146                 :            :   std::set<std::string> kernel_functions;
     147                 :            :   int parse_kernel_config ();
     148                 :            :   int parse_kernel_exports ();
     149                 :            :   int parse_kernel_functions ();
     150                 :            : 
     151                 :            :   std::string sysroot;
     152                 :            :   std::map<std::string,std::string> sysenv;
     153                 :            :   bool update_release_sysroot;
     154                 :            :   std::string machine;
     155                 :            :   std::string architecture;
     156                 :            :   bool native_build;
     157                 :            :   std::string runtime_path;
     158                 :            :   bool runtime_specified;
     159                 :            :   std::string data_path;
     160                 :            :   std::string module_name;
     161                 :            :   const std::string module_filename() const;
     162                 :            :   std::string stapconf_name;
     163                 :            :   std::string output_file;
     164                 :            :   std::string size_option;
     165                 :            :   std::string cmd;
     166                 :            :   std::string compatible; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0)
     167                 :            :   int target_pid;
     168                 :            :   int last_pass;
     169                 :            :   unsigned perpass_verbose[5];
     170                 :            :   unsigned verbose;
     171                 :            :   bool timing;
     172                 :            :   bool save_module;
     173                 :            :   bool modname_given;
     174                 :            :   bool keep_tmpdir;
     175                 :            :   bool guru_mode;
     176                 :            :   bool listing_mode;
     177                 :            :   bool listing_mode_vars;
     178                 :            :   bool bulk_mode;
     179                 :            :   bool unoptimized;
     180                 :            :   bool suppress_warnings;
     181                 :            :   bool panic_warnings;
     182                 :            :   int buffer_size;
     183                 :            :   bool prologue_searching;
     184                 :            :   bool tapset_compile_coverage;
     185                 :            :   bool need_uprobes;
     186                 :            :   bool need_unwind;
     187                 :            :   bool need_symbols;
     188                 :            :   std::string uprobes_path;
     189                 :            :   std::string uprobes_hash;
     190                 :            :   bool load_only; // flight recorder mode
     191                 :            :   bool omit_werror;
     192                 :            :   privilege_t privilege;
     193                 :            :   bool privilege_set;
     194                 :            :   bool systemtap_v_check;
     195                 :            :   bool tmpdir_opt_set;
     196                 :            :   bool dump_probe_types;
     197                 :            :   int download_dbinfo;
     198                 :            :   bool suppress_handler_errors;
     199                 :            :   bool suppress_time_limits;
     200                 :            : 
     201                 :            :   enum { kernel_runtime, dyninst_runtime } runtime_mode;
     202                 :      73575 :   bool runtime_usermode_p() const { return runtime_mode == dyninst_runtime; }
     203                 :            : 
     204                 :            :   // NB: It is very important for all of the above (and below) fields
     205                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     206                 :            : 
     207                 :            :   // Client/server
     208                 :            : #if HAVE_NSS
     209                 :            :   static bool NSPR_Initialized; // only once for all sessions
     210                 :            :   void NSPR_init ();
     211                 :            : #endif
     212                 :            :   bool client_options;
     213                 :            :   std::string client_options_disallowed_for_unprivileged;
     214                 :            :   std::vector<std::string> server_status_strings;
     215                 :            :   std::vector<std::string> specified_servers;
     216                 :            :   bool automatic_server_mode;
     217                 :            :   std::string server_trust_spec;
     218                 :            :   std::vector<std::string> server_args;
     219                 :            :   std::string winning_server;
     220                 :            :   compile_server_cache* server_cache;
     221                 :            : 
     222                 :            :   // NB: It is very important for all of the above (and below) fields
     223                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     224                 :            : 
     225                 :            :   // Mechanism for retrying compilation with a compile server should it fail due
     226                 :            :   // to lack of resources on the local host.
     227                 :            :   // Once it has been decided not to try the server (e.g. syntax error),
     228                 :            :   // that decision cannot be changed.
     229                 :            :   int try_server_status;
     230                 :            :   bool use_server_on_error;
     231                 :            : 
     232                 :            :   enum { try_server_unset, dont_try_server, do_try_server };
     233                 :            :   void init_try_server ();
     234                 :            :   void set_try_server (int t = do_try_server);
     235                 :        580 :   bool try_server () const { return try_server_status == do_try_server; }
     236                 :            : 
     237                 :            :   // NB: It is very important for all of the above (and below) fields
     238                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     239                 :            : 
     240                 :            :   // Remote execution
     241                 :            :   std::vector<std::string> remote_uris;
     242                 :            :   bool use_remote_prefix;
     243                 :            :   typedef std::map<std::pair<std::string, std::string>, systemtap_session*> session_map_t;
     244                 :            :   session_map_t subsessions;
     245                 :            :   systemtap_session* clone(const std::string& arch, const std::string& release);
     246                 :            : 
     247                 :            :   // NB: It is very important for all of the above (and below) fields
     248                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     249                 :            : 
     250                 :            :   // Cache data
     251                 :            :   bool use_cache;               // control all caching
     252                 :            :   bool use_script_cache;        // control caching of pass-3/4 output
     253                 :            :   bool poison_cache;            // consider the cache to be write-only
     254                 :            :   std::string cache_path;       // usually ~/.systemtap/cache
     255                 :            :   std::string hash_path;        // path to the cached script module
     256                 :            :   std::string stapconf_path;    // path to the cached stapconf
     257                 :            :   stap_hash *base_hash;         // hash common to all caching
     258                 :            : 
     259                 :            :   // dwarfless operation
     260                 :            :   bool consult_symtab;
     261                 :            :   std::string kernel_symtab_path;
     262                 :            : 
     263                 :            :   // Skip bad $ vars
     264                 :            :   bool skip_badvars;
     265                 :            : 
     266                 :            :   // NB: It is very important for all of the above (and below) fields
     267                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     268                 :            : 
     269                 :            :   // temporary directory for module builds etc.
     270                 :            :   // hazardous - it is "rm -rf"'d at exit
     271                 :            :   std::string tmpdir;
     272                 :            :   std::string translated_source; // C source code
     273                 :            : 
     274                 :            :   match_node* pattern_root;
     275                 :            :   void register_library_aliases();
     276                 :            : 
     277                 :            :   // data for various preprocessor library macros
     278                 :            :   std::map<std::string, macrodecl*> library_macros;
     279                 :            :   std::vector<stapfile*> library_macro_files; // for error reporting purposes
     280                 :            : 
     281                 :            :   // parse trees for the various script files
     282                 :            :   stapfile* user_file;
     283                 :            :   std::vector<stapfile*> library_files;
     284                 :            : 
     285                 :            :   // filters to run over all code before symbol resolution
     286                 :            :   //   e.g. @cast expansion
     287                 :            :   std::vector<update_visitor*> code_filters;
     288                 :            : 
     289                 :            :   // resolved globals/functions/probes for the run as a whole
     290                 :            :   std::vector<stapfile*> files;
     291                 :            :   std::vector<vardecl*> globals;
     292                 :            :   std::map<std::string,functiondecl*> functions;
     293                 :            :   // probe counter name -> probe associated with counter
     294                 :            :   std::map<std::string, std::pair<std::string,derived_probe*> > perf_counters;
     295                 :            :   std::vector<derived_probe*> probes; // see also *_probes groups below
     296                 :            :   std::vector<embeddedcode*> embeds;
     297                 :            :   std::map<std::string, statistic_decl> stat_decls;
     298                 :            :   std::map<std::string, stapdfa*> dfas;
     299                 :            :   unsigned dfa_counter; // used to give unique names
     300                 :            :   // track things that are removed
     301                 :            :   std::vector<vardecl*> unused_globals;
     302                 :            :   std::vector<derived_probe*> unused_probes; // see also *_probes groups below
     303                 :            :   std::vector<functiondecl*> unused_functions;
     304                 :            :   // XXX: vector<*> instead please?
     305                 :            : 
     306                 :            :   // Every probe in these groups must also appear in the
     307                 :            :   // session.probes vector.
     308                 :            :   be_derived_probe_group* be_derived_probes;
     309                 :            :   dwarf_derived_probe_group* dwarf_derived_probes;
     310                 :            :   kprobe_derived_probe_group* kprobe_derived_probes;
     311                 :            :   hwbkpt_derived_probe_group* hwbkpt_derived_probes;
     312                 :            :   perf_derived_probe_group* perf_derived_probes;
     313                 :            :   uprobe_derived_probe_group* uprobe_derived_probes;
     314                 :            :   utrace_derived_probe_group* utrace_derived_probes;
     315                 :            :   itrace_derived_probe_group* itrace_derived_probes;
     316                 :            :   task_finder_derived_probe_group* task_finder_derived_probes;
     317                 :            :   timer_derived_probe_group* timer_derived_probes;
     318                 :            :   netfilter_derived_probe_group* netfilter_derived_probes;
     319                 :            :   profile_derived_probe_group* profile_derived_probes;
     320                 :            :   mark_derived_probe_group* mark_derived_probes;
     321                 :            :   tracepoint_derived_probe_group* tracepoint_derived_probes;
     322                 :            :   hrtimer_derived_probe_group* hrtimer_derived_probes;
     323                 :            :   procfs_derived_probe_group* procfs_derived_probes;
     324                 :            :   dynprobe_derived_probe_group* dynprobe_derived_probes;
     325                 :            : 
     326                 :            :   // NB: It is very important for all of the above (and below) fields
     327                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     328                 :            : 
     329                 :            :   // unparser data
     330                 :            :   translator_output* op;
     331                 :            :   std::vector<translator_output*> auxiliary_outputs;
     332                 :            :   unparser* up;
     333                 :            : 
     334                 :            :   // some symbol addresses
     335                 :            :   // XXX: these belong elsewhere; perhaps the dwflpp instance
     336                 :            :   Dwarf_Addr sym_kprobes_text_start;
     337                 :            :   Dwarf_Addr sym_kprobes_text_end;
     338                 :            :   Dwarf_Addr sym_stext;
     339                 :            : 
     340                 :            :   // List of libdwfl module names to extract symbol/unwind data for.
     341                 :            :   std::set<std::string> unwindsym_modules;
     342                 :            :   bool unwindsym_ldd;
     343                 :            :   struct module_cache* module_cache;
     344                 :            :   std::vector<std::string> build_ids;
     345                 :            : 
     346                 :            :   // NB: It is very important for all of the above (and below) fields
     347                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     348                 :            : 
     349                 :            :   std::set<std::string> seen_errors;
     350                 :            :   std::set<std::string> seen_warnings;
     351         [ +  + ]:       9593 :   unsigned num_errors () { return seen_errors.size() + (panic_warnings ? seen_warnings.size() : 0); }
     352                 :            : 
     353                 :            :   std::set<std::string> rpms_to_install;
     354                 :            : 
     355                 :            :   translator_output* op_create_auxiliary();
     356                 :            : 
     357                 :            :   // void print_error (const parse_error& e);
     358                 :            :   const token* last_token;
     359                 :            :   void print_token (std::ostream& o, const token* tok);
     360                 :            :   void print_error (const semantic_error& e);
     361                 :            :   void print_error_source (std::ostream&, std::string&, const token* tok);
     362                 :            :   void print_warning (const std::string& w, const token* tok = 0);
     363                 :            :   void printscript(std::ostream& o);
     364                 :            : 
     365                 :            :   // NB: It is very important for all of the above (and below) fields
     366                 :            :   // to be cleared in the systemtap_session ctor (session.cxx).
     367                 :            : };
     368                 :            : 
     369                 :            : 
     370         [ -  + ]:         47 : struct exit_exception: public std::runtime_error
     371                 :            : {
     372                 :            :   int rc;
     373                 :         47 :   exit_exception (int rc):
     374         [ +  - ]:         47 :     runtime_error (_F("early exit requested, rc=%d", rc)), rc(rc) {}
     375                 :            : };
     376                 :            : 
     377                 :            : 
     378                 :            : // global counter of SIGINT/SIGTERM's received
     379                 :            : extern int pending_interrupts;
     380                 :            : 
     381                 :            : // Interrupt exception subclass for catching
     382                 :            : // interrupts (i.e. ctrl-c).
     383         [ -  + ]:         18 : struct interrupt_exception: public std::runtime_error
     384                 :            : {
     385                 :         18 :   interrupt_exception ():
     386 [ +  - ][ +  - ]:         18 :     runtime_error (_("interrupt received")){}
                 [ +  - ]
     387                 :            : };
     388                 :            : 
     389                 :            : void assert_no_interrupts();
     390                 :            : 
     391                 :            : #endif // SESSION_H
     392                 :            : 
     393                 :            : /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */

Generated by: LCOV version 1.9