diff options
author | fxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-03-15 12:39:47 +0000 |
---|---|---|
committer | fxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-03-15 12:39:47 +0000 |
commit | 99798ba40e3813d50822f00275793e2880383fc7 (patch) | |
tree | 62c7c06768cd766d8d1a1c1c50f8a53ec3cebf53 /libgfortran/runtime/main.c | |
parent | a1758a1397ab575a19ef3d19cbf15122b0950515 (diff) | |
download | gcc-99798ba40e3813d50822f00275793e2880383fc7.tar.gz |
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122954 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/runtime/main.c')
-rw-r--r-- | libgfortran/runtime/main.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c index cfd77f29be9..76e4aef724c 100644 --- a/libgfortran/runtime/main.c +++ b/libgfortran/runtime/main.c @@ -32,9 +32,15 @@ Boston, MA 02110-1301, USA. */ #include <string.h> #include <math.h> #include <stddef.h> +#include <limits.h> +#include "config.h" #include "libgfortran.h" +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + /* Stupid function to be sure the constructor is always linked in, even in the case of static linking. See PR libfortran/22298 for details. */ void @@ -92,6 +98,44 @@ get_args (int *argc, char ***argv) } +static const char *exe_path; + +/* Save the path under which the program was called, for use in the + backtrace routines. */ +void +store_exe_path (const char * argv0) +{ +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + +#ifndef DIR_SEPARATOR +#define DIR_SEPARATOR '/' +#endif + + char buf[PATH_MAX], *cwd, *path; + + if (argv0[0] == '/') + { + exe_path = argv0; + return; + } + + cwd = getcwd (buf, sizeof (buf)); + + /* exe_path will be cwd + "/" + argv[0] + "\0" */ + path = malloc (strlen (cwd) + 1 + strlen (argv0) + 1); + st_sprintf (path, "%s%c%s", cwd, DIR_SEPARATOR, argv0); + exe_path = path; +} + +/* Return the full path of the executable. */ +char * +full_exe_path (void) +{ + return (char *) exe_path; +} + /* Initialize the runtime library. */ static void __attribute__((constructor)) |