1 /* Copyright (C) 2021 Free Software Foundation, Inc.
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)
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. */
24 #include <Application.h>
28 typedef void (*SignalHandler
)(int);
34 #define MAXLABELS 10 /* maximum number of -C arguments */
35 #define STDEBUFSIZE 24000
37 enum { MAX_LD_PRELOAD_TYPES
= 3 };
41 Process (pid_t _pid
) : pid (_pid
) { }
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
59 class collect
: Application
62 collect (int argc
, char *argv
[], char **envp
);
64 void start (int argc
, char *argv
[]);
65 void writeStr (int f
, const char *buf
);
67 // the collector control class
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
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);
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 ();
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 ();
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);
119 void reset_output ();
121 /* Logging warning messages */
122 char **collect_warnings
;
123 int collect_warnings_idx
;
126 void warn_write (const char *format
, ...);
127 void warn_comment (const char *kind
, int num
, char *s
= NULL
, int len
= 0);
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 */
138 int jseen_global
; /* if -j flag was seen */
140 bool mem_so_me
; /* if T, preload mem.so, not libcollector */
145 int targ_index
; // index of name of target in origargv
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 */