Automatic date update in version.in
[binutils-gdb.git] / gprofng / src / collect.h
blobc500dee386c7bb7fc99b22cf710a79f31ffb0e89
1 /* Copyright (C) 2021 Free Software Foundation, Inc.
2 Contributed by Oracle.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #ifndef _COLLECT_H
22 #define _COLLECT_H
24 #include <Application.h>
26 extern "C"
28 typedef void (*SignalHandler)(int);
31 class Coll_Ctrl;
32 class Elf;
34 #define MAXLABELS 10 /* maximum number of -C arguments */
35 #define STDEBUFSIZE 24000
37 enum { MAX_LD_PRELOAD_TYPES = 3 };
39 struct Process
41 Process (pid_t _pid) : pid (_pid) { }
42 pid_t pid;
45 struct DtraceTool
47 DtraceTool (char*);
48 ~DtraceTool ();
50 char *name; // Tool name as specified by -D flag
51 char *params; // Tool parameters
52 char *dfile; // Extracted d-script
53 char *mfile; // Extracted metadata file
54 char *ofile; // Output file
55 pid_t pid;
58 // collect object
59 class collect : Application
61 public:
62 collect (int argc, char *argv[], char **envp);
63 virtual ~collect ();
64 void start (int argc, char *argv[]);
65 void writeStr (int f, const char *buf);
67 // the collector control class
68 Coll_Ctrl *cc;
70 private:
71 enum Exec_status
73 EXEC_OK = 0, // found as runnable executable
74 EXEC_ELF_NOSHARE, // found, but built unshared
75 EXEC_IS_JAR, // found as a .jar file
76 EXEC_IS_CLASS, // found as a .class file but name missing .class
77 EXEC_IS_CLASSCLASS, // found as a .class file with explicit .class
78 EXEC_OPEN_FAIL, // could not be opened
79 EXEC_ELF_LIB, // internal error: bad elf library
80 EXEC_ELF_HEADER, // executable, with bad ELF header
81 EXEC_ELF_ARCH, // executable, but unrunnable architecture
82 EXEC_ISDIR, // a directory, not a file
83 EXEC_NOT_EXEC, // a file, but not executable
84 EXEC_NOT_FOUND // a directory, not a file
87 // override methods in base class
88 void usage ();
89 void short_usage ();
90 void show_hwc_usage ();
91 int check_args (int argc, char *argv[]);
92 void check_target (int, char **);
93 Exec_status check_executable (char *);
94 Exec_status check_executable_arch (Elf *);
95 char *status_str (Exec_status, char *);
96 int do_flag (const char *);
97 char *find_java (void);
98 char *java_path;
99 char *java_how;
100 int putenv_libcollector ();
101 int putenv_libcollector_ld_audits ();
102 int putenv_libcollector_ld_preloads ();
103 int putenv_libcollector_ld_misc ();
104 void add_ld_preload (const char *lib);
105 int putenv_ld_preloads ();
106 int putenv_memso ();
107 int env_strip (char *env, const char *str);
108 int putenv_purged_ld_preloads (const char *var);
109 int putenv_append (const char *var, const char *val);
110 void get_count_data ();
111 void prepare_dbx ();
112 int traceme (const char *file, char *const argv[]);
113 int checkflagterm (const char *);
114 void dupflagseen (char);
115 void dupflagseen (const char *);
116 void validate_config (int);
117 void validate_java (const char *, const char *, int);
118 int set_output ();
119 void reset_output ();
121 /* Logging warning messages */
122 char **collect_warnings;
123 int collect_warnings_idx;
124 void warn_open ();
125 void warn_close ();
126 void warn_write (const char *format, ...);
127 void warn_comment (const char *kind, int num, char *s = NULL, int len = 0);
128 char *warnfilename;
129 FILE *warn_file;
131 /* MPI experiment handling */
132 void setup_MPI_expt (); /* the founder experiment */
133 void write_MPI_founder_log ();
134 void close_MPI_founder_log (int, int);
135 void spawn_MPI_job (); /* run the MPI job */
136 void copy_collect_args (char ***); /* copy collect args for an MPI target */
137 int disabled;
138 int jseen_global; /* if -j flag was seen */
139 int verbose;
140 bool mem_so_me; /* if T, preload mem.so, not libcollector */
141 int origargc;
142 char **arglist;
143 char **origargv;
144 char **origenvp;
145 int targ_index; // index of name of target in origargv
146 bool is_64;
147 int nargs;
148 int njargs;
149 char *jargs;
150 int nlabels;
151 char *label[MAXLABELS];
152 char *sp_preload_list[MAX_LD_PRELOAD_TYPES + 1]; // +1 for NULL termination
153 char *sp_libpath_list[MAX_LD_PRELOAD_TYPES + 1]; // +1 for NULL termination
156 #endif /* ! _COLLECT_H */