source: rtems-tools/rtemstoolkit/rld.h

Last change on this file was 0f481ad, checked in by Chris Johns <chrisj@…>, on 05/24/18 at 06:02:59

rtemstoolkit: Add an output routine for a std::exception.

The output routine is used by a number of tools.

  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/**
17 * @file
18 *
19 * @ingroup rtems-ld
20 *
21 * @brief RTEMS Linker readies the RTEMS object files for dynamic linking.
22 *
23 */
24
25#if !defined (_RLD_H_)
26#define _RLD_H_
27
28#include <algorithm>
29#include <cctype>
30#include <functional>
31#include <iostream>
32#include <list>
33#include <locale>
34#include <sstream>
35#include <string>
36
37/**
38 * Path handling for Windows.
39 */
40#if __WIN32__
41#define RLD_PATH_SEPARATOR        '\\'
42#define RLD_PATH_SEPARATOR_STR    "\\"
43#define RLD_PATHSTR_SEPARATOR     ';'
44#define RLD_PATHSTR_SEPARATOR_STR ";"
45#define RLD_DRIVE_SEPARATOR       (1)
46#define RLD_LINE_SEPARATOR        "\r\n"
47#else
48#define RLD_PATH_SEPARATOR        '/'
49#define RLD_PATH_SEPARATOR_STR    "/"
50#define RLD_PATHSTR_SEPARATOR     ':'
51#define RLD_PATHSTR_SEPARATOR_STR ":"
52#define RLD_DRIVE_SEPARATOR       (0)
53#define RLD_LINE_SEPARATOR        "\n"
54#endif
55
56namespace rld
57{
58  /**
59   * Forward declarations.
60   */
61  namespace files
62  {
63    class file;
64    class image;
65    class archive;
66    class object;
67    class cache;
68    typedef std::list < object* > object_list;
69  }
70}
71
72#include <rld-elf-types.h>
73#include <rld-symbols.h>
74#include <rld-elf.h>
75#include <rld-files.h>
76
77/**
78 * The debug levels.
79 */
80#define RLD_VERBOSE_OFF        (0)
81#define RLD_VERBOSE_INFO       (1)
82#define RLD_VERBOSE_DETAILS    (2)
83#define RLD_VERBOSE_TRACE      (3)
84#define RLD_VERBOSE_TRACE_SYMS (4)
85#define RLD_VERBOSE_TRACE_FILE (5)
86#define RLD_VERBOSE_FULL_DEBUG (6)
87
88namespace rld
89{
90  /**
91   * General error.
92   */
93  struct error
94  {
95    const std::string what;
96    const std::string where;
97
98    error (const std::ostringstream& what, const std::string& where) :
99      what (what.str ()), where (where) {
100    }
101
102    error (const std::string& what, const std::string& where) :
103      what (what), where (where) {
104    }
105  };
106
107  /**
108   * Handle a standard exception.
109   */
110  void output_std_exception (std::exception e, std::ostream& out);
111
112  /**
113   * A convenience macro to make where a file and line number.
114   */
115  #define rld_error_at(_what) \
116    rld::error (_what, std::string (__FILE__) + ":" + to_string (__LINE__))
117
118  /**
119   * Convert a supported type to a string.
120   */
121  template <class T>
122  std::string to_string (T t, std::ios_base & (*f)(std::ios_base&) = std::dec)
123  {
124    std::ostringstream oss;
125    oss << f << t;
126    return oss.str();
127  }
128
129  /**
130   * A container of strings.
131   */
132  typedef std::vector < std::string > strings;
133
134  /**
135   * Does a string start with another string ?
136   */
137  bool starts_with(const std::string& s1, const std::string& s2);
138
139  /**
140   * Trim from start.
141   */
142  const std::string ltrim (const std::string& s);
143
144  /**
145   * Trim from end.
146   */
147  const std::string rtrim (const std::string& s);
148
149  /**
150   * Trim from both ends.
151   */
152  const std::string trim (const std::string& s);
153
154  /**
155   * Dequote a string.
156   */
157  const std::string dequote (const std::string& s);
158
159  /**
160   * Find and replace.
161   */
162  const std::string find_replace(const std::string& sin,
163                                 const std::string& out,
164                                 const std::string& in);
165
166  /**
167   * Split the string in a contain of strings based on the the
168   * delimiter. Optionally trim any white space or include empty string.
169   *
170   * @todo The split should optionally honour string quoting.
171   */
172  const strings split (strings&           se,
173                       const std::string& s,
174                       char               delimiter = ' ',
175                       bool               strip_quotes = true,
176                       bool               strip_whitespace = true,
177                       bool               empty = false);
178
179  /**
180   * Join the strings together with the separator.
181   */
182  const std::string join (const strings& ss, const std::string& separator);
183
184  /**
185   * Convert a string to lower case.
186   */
187  const std::string tolower (const std::string& sin);
188
189  /**
190   * Parse version string of format major.minor.revision where revieion can be
191   * a git hash.
192   */
193  void version_parse (const std::string& str,
194                      uint64_t&          major,
195                      uint64_t&          minor,
196                      uint64_t&          revision);
197
198  /**
199   * Increment the verbose level.
200   */
201  void verbose_inc ();
202
203  /**
204   * Return the verbose level. Setting the flag more than once raises the
205   * level.
206   */
207  int verbose (int level = 0);
208
209  /**
210   * The version string.
211   */
212  const std::string version ();
213
214  /**
215   * Get the major version number.
216   */
217  uint64_t version_major ();
218
219  /**
220   * Get the minor version number.
221   */
222  uint64_t version_minor ();
223
224  /**
225   * Get the revision version number.
226   */
227  uint64_t version_revision ();
228
229  /**
230   * Container of strings to hold the results of a split.
231   */
232  typedef std::vector < std::string > strings;
233
234  /**
235   * Set the command line.
236   */
237  void set_cmdline (int argc, char* argv[]);
238
239  /**
240   * Get the command line.
241   */
242  const std::string get_cmdline ();
243
244  /**
245   * Set the progname.
246   */
247  void set_progname (const std::string& progname);
248
249  /**
250   * Get the progname. This is an absolute path.
251   */
252  const std::string get_progname ();
253
254  /**
255   * Get the program name.
256   */
257  const std::string get_program_name ();
258
259  /**
260   * Get the program path.
261   */
262  const std::string get_program_path ();
263
264  /**
265   * Get the current install prefix. If the path to the executable has 'bin' as
266   * the executable's parent directory it is assumed the executable has been
267   * installed under a standard PREFIX. If "bin" is not found return the
268   * executable's absolute path.
269   */
270  const std::string get_prefix ();
271
272  /**
273   * Map of the cache and the symbol table.
274   */
275  void map (rld::files::cache& cache, rld::symbols::table& symbols);
276
277  /**
278   * Warn if externals in referenced object files are not used.
279   */
280  void warn_unused_externals (rld::files::object_list& objects);
281}
282
283#endif
Note: See TracBrowser for help on using the repository browser.