|
Packit |
8ea169 |
/*
|
|
Packit |
8ea169 |
Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
|
|
Packit |
8ea169 |
Copyright (C) 2009 Red Hat, Inc.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
8ea169 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
8ea169 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
8ea169 |
(at your option) any later version.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
8ea169 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8ea169 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8ea169 |
GNU General Public License for more details.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
You should have received a copy of the GNU General Public License along
|
|
Packit |
8ea169 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
8ea169 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
#define CCPP_CONF "CCpp.conf"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
static const char *dump_dir_name = ".";
|
|
Packit |
8ea169 |
/* 60 seconds was too limiting on slow machines */
|
|
Packit |
8ea169 |
static int exec_timeout_sec = 240;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int main(int argc, char **argv)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
/* I18n */
|
|
Packit |
8ea169 |
setlocale(LC_ALL, "");
|
|
Packit |
8ea169 |
#if ENABLE_NLS
|
|
Packit |
8ea169 |
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
Packit |
8ea169 |
textdomain(PACKAGE);
|
|
Packit |
8ea169 |
#endif
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
abrt_init(argv);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
char *i_opt = NULL;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* Can't keep these strings/structs static: _() doesn't support that */
|
|
Packit |
8ea169 |
const char *program_usage_string = _(
|
|
Packit |
8ea169 |
"& [options] -d DIR\n"
|
|
Packit |
8ea169 |
"\n"
|
|
Packit |
8ea169 |
"Analyzes coredump in problem directory DIR, generates and saves backtrace"
|
|
Packit |
8ea169 |
);
|
|
Packit |
8ea169 |
enum {
|
|
Packit |
8ea169 |
OPT_v = 1 << 0,
|
|
Packit |
8ea169 |
OPT_d = 1 << 1,
|
|
Packit |
8ea169 |
OPT_i = 1 << 2,
|
|
Packit |
8ea169 |
OPT_t = 1 << 3,
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
/* Keep enum above and order of options below in sync! */
|
|
Packit |
8ea169 |
struct options program_options[] = {
|
|
Packit |
8ea169 |
OPT__VERBOSE(&g_verbose),
|
|
Packit |
8ea169 |
OPT_STRING( 'd', NULL, &dump_dir_name , "DIR" , _("Problem directory")),
|
|
Packit |
8ea169 |
OPT_STRING( 'i', NULL, &i_opt , "DIR1[:DIR2]...", _("Additional debuginfo directories")),
|
|
Packit |
8ea169 |
OPT_INTEGER('t', NULL, &exec_timeout_sec, _("Kill gdb if it runs for more than NUM seconds")),
|
|
Packit |
8ea169 |
OPT_END()
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
/*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
export_abrt_envvars(0);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
map_string_t *settings = new_map_string();
|
|
Packit |
8ea169 |
if (!load_abrt_plugin_conf_file(CCPP_CONF, settings))
|
|
Packit |
8ea169 |
error_msg("Can't load '%s'", CCPP_CONF);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
const char *value = get_map_string_item_or_NULL(settings, "DebuginfoLocation");
|
|
Packit |
8ea169 |
char *debuginfo_location;
|
|
Packit |
8ea169 |
if (value)
|
|
Packit |
8ea169 |
debuginfo_location = xstrdup(value);
|
|
Packit |
8ea169 |
else
|
|
Packit |
8ea169 |
debuginfo_location = xstrdup(LOCALSTATEDIR"/cache/abrt-di");
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
free_map_string(settings);
|
|
Packit |
8ea169 |
char *debuginfo_dirs = NULL;
|
|
Packit |
8ea169 |
if (i_opt)
|
|
Packit |
8ea169 |
debuginfo_dirs = xasprintf("%s:%s", debuginfo_location, i_opt);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* Create gdb backtrace */
|
|
Packit |
8ea169 |
char *backtrace = get_backtrace(dump_dir_name, exec_timeout_sec,
|
|
Packit |
8ea169 |
(debuginfo_dirs) ? debuginfo_dirs : debuginfo_location);
|
|
Packit |
8ea169 |
free(debuginfo_location);
|
|
Packit |
8ea169 |
if (!backtrace)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
backtrace = xstrdup("");
|
|
Packit |
8ea169 |
log_warning("get_backtrace() returns NULL, broken core/gdb?");
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
free(debuginfo_dirs);
|
|
Packit |
8ea169 |
free_abrt_conf_data();
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* Store gdb backtrace */
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
|
|
Packit |
8ea169 |
if (!dd)
|
|
Packit |
8ea169 |
return 1;
|
|
Packit |
8ea169 |
dd_save_text(dd, FILENAME_BACKTRACE, backtrace);
|
|
Packit |
8ea169 |
dd_close(dd);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* Don't be completely silent. gdb run takes a few seconds,
|
|
Packit |
8ea169 |
* it is useful to let user know it (maybe) worked.
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
log_warning(_("Backtrace is generated and saved, %u bytes"), (int)strlen(backtrace));
|
|
Packit |
8ea169 |
free(backtrace);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return 0;
|
|
Packit |
8ea169 |
}
|