/**
 * Knowing the user's home directory, TGDB can initialize the m_logger interface
 *
 * \param tgdb
 * The tgdb context.
 *
 * \param config_dir 
 * The path to the user's config directory
 *
 * \return
 * -1 on error, or 0 on success
 */
int Ctgdb::Initialize_logger_interface(char *config_dir)
{

	/* Get the home directory */
	const char *tgdb_log_file = "tgdb_log.txt";
	char tgdb_log_path[FSUTIL_PATH_MAX];

	fs_util_get_path (config_dir, tgdb_log_file, tgdb_log_path);

	/* Initialize the logger */
	if (num_loggers == 0)
	{
		m_logger = logger_create ();

		if (!m_logger)
		{
			printf ("Error: Could not create log file\n");
			return -1;
		}
	}

	++num_loggers;

	if (logger_set_file (m_logger, tgdb_log_path) == -1)
	{
		printf ("Error: Could not open log file\n");
		return -1;
	}

	return 0;
}
Esempio n. 2
0
File: cgdb.c Progetto: i4fumi/cgdb
int init_readline(void)
{
    int slavefd, masterfd;
    int length;

    slavefd = pty_pair_get_slavefd(pty_pair);
    if (slavefd == -1)
        return -1;

    masterfd = pty_pair_get_masterfd(pty_pair);
    if (masterfd == -1)
        return -1;

    if (tty_off_xon_xoff(slavefd) == -1)
        return -1;

    /* The 16 is because I don't know how many char's the directory separator 
     * is going to be, I expect it to be 1, but who knows. */
    length = strlen(cgdb_home_dir) + strlen(readline_history_filename) + 16;
    readline_history_path = (char *) malloc(sizeof (char) * length);
    fs_util_get_path(cgdb_home_dir, readline_history_filename,
            readline_history_path);
    rline = rline_initialize(slavefd, rlctx_send_user_command, tab_completion,
            "dumb");
    rline_read_history(rline, readline_history_path);
    return 0;
}
Esempio n. 3
0
struct annotate_two *a2_create_context(const char *debugger,
        int argc, char **argv, const char *config_dir, struct logger *logger_in)
{

    struct annotate_two *a2 = initialize_annotate_two();
    char a2_debug_file[FSUTIL_PATH_MAX];

    if (!tgdb_setup_config_file(a2, config_dir)) {
        logger_write_pos(logger_in, __FILE__, __LINE__,
                "tgdb_init_config_file error");
        return NULL;
    }

    /* Initialize the debug file that a2_tgdb writes to */
    fs_util_get_path(config_dir, "a2_tgdb_debug.txt", a2_debug_file);
    io_debug_init(a2_debug_file);

    a2->debugger_pid =
            invoke_debugger(debugger, argc, argv,
            &a2->debugger_stdin, &a2->debugger_out, 0, a2->a2_gdb_init_file);

    /* Couldn't invoke process */
    if (a2->debugger_pid == -1)
        return NULL;

    return a2;
}
Esempio n. 4
0
void if_display_help(void)
{
    char cgdb_help_file[MAXLINE];
    int ret_val = 0;

    fs_util_get_path(PKGDATADIR, "cgdb.txt", cgdb_help_file);
    ret_val = source_set_exec_line(src_win, cgdb_help_file, 1);
    if (ret_val == 0)
        if_draw();
    else if (ret_val == 5)      /* File does not exist */
        if_display_message("No such file: %s", 0, cgdb_help_file);
}
Esempio n. 5
0
void if_display_help(void)
{
    char cgdb_help_file[FSUTIL_PATH_MAX];
    int ret_val = 0;

    fs_util_get_path(PKGDATADIR, "cgdb.txt", cgdb_help_file);

    /* File doesn't exist. Try to find cgdb.txt in the build dir in case
     * the user is running a built cgdb binary directly. */
    if (!fs_verify_file_exists(cgdb_help_file))
        fs_util_get_path(TOPBUILDDIR, "doc/cgdb.txt", cgdb_help_file);

    ret_val = source_set_exec_line(src_viewer, cgdb_help_file, 1, 0);

    if (ret_val == 0)
    {
        src_viewer->cur->language = TOKENIZER_LANGUAGE_CGDBHELP;
        source_highlight(src_viewer->cur);
        if_draw();
    }
    else if (ret_val == 5)      /* File does not exist */
        if_display_message("No such file: ", WIN_REFRESH, 0, "%s", cgdb_help_file);
}
Esempio n. 6
0
File: cgdb.c Progetto: i4fumi/cgdb
static int init_home_dir(void)
{
    /* Get the home directory */
    char *home_dir = getenv("HOME");
    const char *cgdb_dir = ".cgdb";

    /* Create the config directory */
    if (!fs_util_create_dir_in_base(home_dir, cgdb_dir)) {
        logger_write_pos(logger, __FILE__, __LINE__,
                "fs_util_create_dir_in_base error");
        return -1;
    }

    fs_util_get_path(home_dir, cgdb_dir, cgdb_home_dir);

    return 0;
}
/* 
 * Gets the users home dir and creates the config directory.
 *
 * \param tgdb
 * The tgdb context.
 *
 * \param config_dir 
 * Should be FSUTIL_PATH_MAX in size on way in.
 * On way out, it will be the path to the config dir
 *
 * \return
 * -1 on error, or 0 on success
 */
int Ctgdb::Initialize_config_dir (char *config_dir)
{
	/* Get the home directory */
	char *home_dir = getenv ("HOME");
	const char *tgdb_dir = ".tgdb";

	/* Create the config directory */
	if (!fs_util_create_dir_in_base (home_dir, tgdb_dir))
	{
		Logger_write_pos( __FILE__, __LINE__,
				"fs_util_create_dir_in_base error");
		return -1;
	}

	fs_util_get_path (home_dir, tgdb_dir, config_dir);

	return 0;
}
Esempio n. 8
0
/* tgdb_setup_config_file: 
 * -----------------------
 *  Creates a config file for the user.
 *
 *  Pre: The directory already has read/write permissions. This should have
 *       been checked by tgdb-base.
 *
 *  Return: 1 on success or 0 on error
 */
static int tgdb_setup_config_file(struct annotate_two *a2, const char *dir)
{
    FILE *fp;

    strncpy(a2->config_dir, dir, strlen(dir) + 1);

    fs_util_get_path(dir, "a2_gdb_init", a2->a2_gdb_init_file);

    if ((fp = fopen(a2->a2_gdb_init_file, "w"))) {
        fprintf(fp, "set annotate 2\n" "set height 0\n");
        fclose(fp);
    } else {
        logger_write_pos(logger, __FILE__, __LINE__, "fopen error '%s'",
                a2->a2_gdb_init_file);
        return 0;
    }

    return 1;
}
Esempio n. 9
0
File: cgdb.c Progetto: i4fumi/cgdb
int main(int argc, char *argv[])
{
/* Uncomment to debug and attach */
#if 0
    int c;

    read(0, &c, 1);
#endif

    parse_long_options(&argc, &argv);

    current_line = ibuf_init();

    cgdbrc_init();

    if (create_and_init_pair() == -1) {
        fprintf(stderr, "%s:%d Unable to create PTY pair", __FILE__, __LINE__);
        exit(-1);
    }

    /* First create tgdb, because it has the error log */
    if (start_gdb(argc, argv) == -1) {
        fprintf(stderr, "%s:%d Unable to invoke GDB", __FILE__, __LINE__);
        exit(-1);
    }

    /* From here on, the logger is initialized */

    /* Create the home directory */
    if (init_home_dir() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__,
                "Unable to create home dir ~/.cgdb");
        cleanup();
        exit(-1);
    }

    if (init_readline() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "Unable to init readline");
        cleanup();
        exit(-1);
    }

    if (tty_cbreak(STDIN_FILENO, &term_attributes) == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "tty_cbreak error");
        cleanup();
        exit(-1);
    }

    if (init_kui() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "init_kui error");
        cleanup();
        exit(-1);
    }

    /* Initialize the display */
    switch (if_init()) {
        case 1:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "Unable to initialize the curses library");
            cleanup();
            exit(-1);
        case 2:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "Unable to handle signal: SIGWINCH");
            cleanup();
            exit(-1);
        case 3:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "Unable to setup highlighting groups");
            cleanup();
            exit(-1);
        case 4:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "New GDB window failed -- out of memory?");
            cleanup();
            exit(-1);
    }

    /* Initialize the pipe that is used for resize */
    if (init_resize_pipe() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "init_resize_pipe error");
        cleanup();
        exit(-1);
    }

    {
        char config_file[FSUTIL_PATH_MAX];
        FILE *config;

        fs_util_get_path(cgdb_home_dir, "cgdbrc", config_file);
        config = fopen(config_file, "r");
        if (config) {
            command_parse_file(config);
            fclose(config);
        }
    }

    /* Enter main loop */
    main_loop();

    /* Shut down curses and exit */
    cleanup();
    return 0;
}