예제 #1
0
파일: cgdbrc.c 프로젝트: denizt/cgdb
static int command_parse_unmap(int param)
{
    struct kui_map_set *kui_map_choice;
    int key, val;
    char *key_token;
    extern int enter_map_id;

    enter_map_id = 1;

    if ((strcmp(get_token(), "unmap") == 0) ||
            (strcmp(get_token(), "unm") == 0))
        kui_map_choice = kui_map;
    else
        kui_map_choice = kui_imap;

    key = yylex();
    if (key != IDENTIFIER) {
        enter_map_id = 0;
        return -1;
    }
    key_token = cgdb_strdup(get_token());

    val = kui_ms_deregister_map(kui_map_choice, key_token);
    if (val == -1) {
        free(key_token);
        enter_map_id = 0;
        return -1;
    }

    enter_map_id = 0;

    return 0;
}
예제 #2
0
파일: tgdb.cpp 프로젝트: ibuclaw/cgdb
void tgdb_request_complete(struct tgdb * tgdb, const char *line)
{
    tgdb_request_ptr request_ptr;

    request_ptr = (tgdb_request_ptr)cgdb_malloc(sizeof (struct tgdb_request));
    request_ptr->header = TGDB_REQUEST_COMPLETE;
    request_ptr->choice.complete.line = (const char *)cgdb_strdup(line);

    tgdb_run_or_queue_request(tgdb, request_ptr, false);
}
예제 #3
0
파일: tgdb.cpp 프로젝트: ibuclaw/cgdb
static void tgdb_prompt_changed(void *context, const std::string &prompt)
{
    struct tgdb *tgdb = (struct tgdb*)context;

    struct tgdb_response *response =
        tgdb_create_response(TGDB_UPDATE_CONSOLE_PROMPT_VALUE);
    response->choice.update_console_prompt_value.prompt_value =
            cgdb_strdup(prompt.c_str());
    tgdb_send_response(tgdb, response);
}
예제 #4
0
파일: tgdb.cpp 프로젝트: ibuclaw/cgdb
void
tgdb_request_run_console_command(struct tgdb *tgdb, const char *command)
{
    tgdb_request_ptr request_ptr;

    request_ptr = (tgdb_request_ptr)cgdb_malloc(sizeof (struct tgdb_request));

    request_ptr->header = TGDB_REQUEST_CONSOLE_COMMAND;
    request_ptr->choice.console_command.command = (const char *)
            cgdb_strdup(command);

    tgdb_run_or_queue_request(tgdb, request_ptr, false);
}
예제 #5
0
파일: highlight.c 프로젝트: rsenn/cgdb
void highlight(struct list_node *node)
{
    if ( node->language == TOKENIZER_LANGUAGE_UNKNOWN ) {
        /* Just copy the lines from the original buffer if no highlighting
         * is possible */
        int i;
        node->buf.length = node->orig_buf.length;
        node->buf.max_width = node->orig_buf.max_width;
        node->buf.tlines = cgdb_malloc ( sizeof ( char * ) * node->orig_buf.length );
        for ( i = 0; i < node->orig_buf.length; i++ )
            node->buf.tlines[i] = cgdb_strdup ( node->orig_buf.tlines[i] );
    } else
        highlight_node ( node );
}
예제 #6
0
/**
 * Used to get all of the possible tab completion options for LINE.
 *
 * \param tgdb
 * An instance of the tgdb library to operate on.
 *
 * \param line
 * The line to tab complete.
 *
 * \return
 * Will return as a tgdb request command on success, otherwise NULL.
 */
tgdb_request_ptr Ctgdb::Request_complete(const char *line)
{
	tgdb_request_ptr request_ptr;

	request_ptr = (tgdb_request_ptr)
		cgdb_malloc (sizeof (struct tgdb_request));
	if (!request_ptr)
		return NULL;

	request_ptr->header = TGDB_REQUEST_COMPLETE;
	request_ptr->choice.complete.line = (const char *)
		cgdb_strdup (line);

	return request_ptr;
}
예제 #7
0
파일: tgdb.cpp 프로젝트: ibuclaw/cgdb
void
tgdb_request_modify_breakpoint(struct tgdb *tgdb, const char *file, int line,
    uint64_t addr, enum tgdb_breakpoint_action b)
{
    tgdb_request_ptr request_ptr;

    request_ptr = (tgdb_request_ptr)cgdb_malloc(sizeof (struct tgdb_request));

    request_ptr->header = TGDB_REQUEST_MODIFY_BREAKPOINT;
    request_ptr->choice.modify_breakpoint.file = file ? cgdb_strdup(file) : NULL;
    request_ptr->choice.modify_breakpoint.line = line;
    request_ptr->choice.modify_breakpoint.addr = addr;
    request_ptr->choice.modify_breakpoint.b = b;

    tgdb_run_or_queue_request(tgdb, request_ptr, false);
}
예제 #8
0
/** 
 * Will send a command to the debugger immediatly. No queueing will be done
 * at this point.
 *
 * \param tgdb
 * The TGDB context to use.
 *
 * \param command 
 * The command to run.
 *
 *  NOTE: This function assummes valid commands are being sent to it. 
 *        Error checking should be done before inserting into queue.
 */
int Ctgdb::Deliver_command(struct tgdb_command *command)
{
	IS_SUBSYSTEM_READY_FOR_NEXT_COMMAND = 0;

	/* Here is where the command is actually given to the debugger.
	 * Before this is done, if the command is a GUI command, we save it,
	 * so that later, it can be printed to the client. Its for debugging
	 * purposes only, or for people who want to know the commands there
	 * debugger is being given.
	 */
	if (command->command_choice == TGDB_CUSTOME_COMMAND_FRONT_END)
	{
		last_gui_command = cgdb_strdup (command->tgdb_command_data);
		m_target = (ITarget*) command->target;
	}
	else
	{
		m_target = NULL; 
	}

	/* A command for the debugger */
	if (tgdb_client_prepare_for_command (tcc, command) == -1)
		return -1;

	/* A regular command from the client */
	io_debug_write_fmt ("<%s>", command->tgdb_command_data);

	io_writen (debugger_stdin, command->tgdb_command_data,
			strlen (command->tgdb_command_data));

	/* Uncomment this if you wish to see all of the commands, that are 
	 * passed to GDB. */
#if 0
	{
		char *s = strdup (client_command->tgdb_client_command_data);
		int length = strlen (s);
		s[length - 1] = '\0';
		fprintf (stderr, "[%s]\n", s);
		s[length - 1] = ' ';
		free (s);
		s = NULL;
	}
#endif

	return 0;
}
예제 #9
0
/**
 * Modify's a breakpoint.
 *
 * \param tgdb
 * An instance of the tgdb library to operate on.
 *
 * \param file
 * The file to set the breakpoint in.
 *
 * \param line
 * The line in FILE to set the breakpoint in.
 *
 * \param b
 * Determines what the user wants to do with the breakpoint.
 *
 * @return
 * Will return as a tgdb request command on success, otherwise NULL.
 */
tgdb_request_ptr Ctgdb::Request_modify_breakpoint(const char *file,
		int line, 
		enum tgdb_breakpoint_action b)
{
	tgdb_request_ptr request_ptr;
	request_ptr = (tgdb_request_ptr)
		cgdb_malloc (sizeof (struct tgdb_request));
	if (!request_ptr)
		return NULL;

	request_ptr->header = TGDB_REQUEST_MODIFY_BREAKPOINT;
	request_ptr->choice.modify_breakpoint.file = (const char *)
		cgdb_strdup (file);
	request_ptr->choice.modify_breakpoint.line = line;
	request_ptr->choice.modify_breakpoint.b = b;

	return request_ptr;
}
예제 #10
0
/**
 * This sends a console command to the debugger (GDB).
 *
 * \param tgdb
 * An instance of the tgdb library to operate on.
 *
 * \param command
 * The null terminated command to pass to GDB as a console command.
 * 
 * \return
 * Will return as a tgdb request command on success, otherwise NULL.
 */
tgdb_request_ptr Ctgdb::Request_run_console_command(const char *command)
{
	tgdb_request_ptr request_ptr;
	if (!command)
		return NULL;

	request_ptr = (tgdb_request_ptr)
		cgdb_malloc (sizeof (struct tgdb_request));
	if (!request_ptr)
		return NULL;

	request_ptr->header = TGDB_REQUEST_CONSOLE_COMMAND;
	request_ptr->choice.console_command.command = (const char *)
		cgdb_strdup (command);


	return request_ptr;
}
예제 #11
0
파일: cgdb.c 프로젝트: i4fumi/cgdb
/**
 * Create a tab completion context.
 *
 * \param matches
 * See tab_completion field documentation
 * 
 * \param num_matches
 * See tab_completion field documentation
 *
 * \param max_length
 * See tab_completion field documentation
 *
 * \return
 * The next context, or NULL on error.
 */
static tab_completion_ptr
tab_completion_create(char **matches, int num_matches, int max_length)
{
    int i;
    tab_completion_ptr comptr;

    comptr = (tab_completion_ptr) cgdb_malloc(sizeof (struct
                    tab_completion_ctx));

    comptr->matches = cgdb_malloc(sizeof (char *) * (num_matches + 1));
    for (i = 0; i <= num_matches; ++i)
        comptr->matches[i] = cgdb_strdup(matches[i]);

    comptr->num_matches = num_matches;
    comptr->max_length = max_length;
    comptr->total = 1;
    comptr->lines = 0;
    comptr->state = TAB_COMPLETION_START;

    return comptr;
}
예제 #12
0
/**
 * This gets the absolute path and the relative path from the given file, 
 * FILE. The file parameter should have been returned by 
 * tgdb_request_inferiors_source_files. It can return both relative and 
 * absolute filenames.
 *
 * Basically, if the parameter file is a relative path OR an absolute path, 
 * both the relative path and the absolute path will be returned in the 
 * response.
 *
 * If this functions succeeds TGDB_ABSOLUTE_SOURCE_ACCEPTED will be returned.
 * Otherwise, TGDB_ABSOLUTE_SOURCE_DENIED gets returned.
 *
 * \param tgdb
 * An instance of the tgdb library to operate on.
 *
 * \param file
 * The relative filename to get the absolute path of. If this is passed in as
 * NULL, then this function will return NULL.
 *
 * \return
 * Will return as a tgdb request command on success, otherwise NULL.
 */
tgdb_request_ptr Ctgdb::Request_filename_pair(const char *file)
{
	tgdb_request_ptr request_ptr;

	if (!file)
		return NULL;

	request_ptr = (tgdb_request_ptr)
		cgdb_malloc (sizeof (struct tgdb_request));
	if (!request_ptr)
		return NULL;

	request_ptr->header = TGDB_REQUEST_FILENAME_PAIR;

	if (file) {
		request_ptr->choice.filename_pair.file = (const char *)
			cgdb_strdup (file);
	} else
		request_ptr->choice.filename_pair.file = NULL;


	return request_ptr;
}
예제 #13
0
파일: filedlg.cpp 프로젝트: ibuclaw/cgdb
int filedlg_add_file_choice(struct filedlg *fd, const char *file_choice)
{
    int length;
    int index, i;
    int equal = 1;              /* Not set to 0, because 0 *is* equal */

    if (file_choice == NULL || *file_choice == '\0')
        return -1;

    /* Make sure file exists. If temp files are used to create an
     * executable, and the temp files are deleted, they pollute the
     * file open dialog with files you can't actually open.
     *
     * The downside to not showing them all is that a user might
     * not understand why certain files aren't showing up. O well.
     */
    if (file_choice[0] != '*') {
        if (fs_verify_file_exists(file_choice) == 0)
            return -4;
    }

    /* find index to insert by comparing:
     * Absolute paths go to the end
     * Relative paths go before the absolute paths 
     */
    for (i = 0; i < sbcount(fd->buf->files); i++) {
        /* Don't add duplicate entry's ... gdb outputs duplicates */
        if ((equal = strcmp(fd->buf->files[i], file_choice)) == 0)
            return -3;
        else if (equal < 0) {
            /* Inserting filename, stop before relative path */
            if ((file_choice[0] != '.' && file_choice[0] != '/')
                    && fd->buf->files[i][0] == '.')
                break;

            /* Inserting filename, stop before absolute path */
            if (file_choice[0] != '/' && fd->buf->files[i][0] == '/')
                break;

        } else if (equal > 0) { /* Found ( file_choice is greater ) */
            /* Inserting Absolute path, it goes to the end */
            if (file_choice[0] == '/' && fd->buf->files[i][0] != '/')
                continue;

            /* Inserting relative path, continue until before absolute or relative path */
            if (file_choice[0] == '.' && (fd->buf->files[i][0] != '.'
                            && fd->buf->files[i][0] != '/'))
                continue;

            break;
        }
    }

    index = i;

    sbpush(fd->buf->files, NULL);

    /* shift everything down and then insert into index */
    for (i = sbcount(fd->buf->files) - 1; i > index; i--)
        fd->buf->files[i] = fd->buf->files[i - 1];

    fd->buf->files[index] = cgdb_strdup(file_choice);

    if ((length = strlen(file_choice)) > fd->buf->max_width)
        fd->buf->max_width = length;

    return 0;
}
예제 #14
0
int invoke_debugger(const char *path,
        int argc, char *argv[], int *in, int *out, int choice, char *filename)
{
    pid_t pid;
    const char *const GDB = "gdb";
    const char *const NW = "--nw";
    const char *const X = "-x";
    const char *const ANNOTATE_TWO = "--annotate=2";
    const char *const GDBMI = "-i=mi2";
    char *F = filename;
    char **local_argv;
    int i, j = 0, extra = 6;
    int malloc_size = argc + extra;
    char slavename[64];
    int masterfd;

    /* Copy the argv into the local_argv, and NULL terminate it.
     * sneak in the path name, the user did not type that */
    local_argv = (char **) cgdb_malloc((malloc_size) * sizeof (char *));
    if (path)
        local_argv[j++] = cgdb_strdup(path);
    else
        local_argv[j++] = cgdb_strdup(GDB);

    /* NOTE: These options have to come first, since if the user
     * typed '--args' to GDB, everything at the end of the 
     * users options become parameters to the inferior.
     */
    local_argv[j++] = cgdb_strdup(NW);

    /* add the init file that the user did not type */
    if (choice == 0)
        local_argv[j++] = cgdb_strdup(ANNOTATE_TWO);
    else if (choice == 1)
        local_argv[j++] = cgdb_strdup(GDBMI);

    local_argv[j++] = cgdb_strdup(X);
    local_argv[j++] = cgdb_strdup(F);

    /* copy in all the data the user entered */
    for (i = 0; i < argc; i++)
        local_argv[j++] = cgdb_strdup(argv[i]);

    local_argv[j] = NULL;

    if (fs_util_file_exists_in_path(local_argv[0]) == -1) {
        logger_write_pos(logger, __FILE__, __LINE__,
                         "Debugger \"%s\" not found", local_argv[0]);
        pty_free_memory(slavename, masterfd, argc, local_argv);
        return -1;
    }
    /* Fork into two processes with a shared pty pipe */
    pid = pty_fork(&masterfd, slavename, SLAVE_SIZE, NULL, NULL);

    if (pid == -1) {            /* error, free memory and return  */
        pty_free_memory(slavename, masterfd, argc, local_argv);
        logger_write_pos(logger, __FILE__, __LINE__, "fork failed");
        return -1;
    } else if (pid == 0) {      /* child */
        FILE *fd = fopen(slavename, "r");

        if (fd)
            tty_set_echo(fileno(fd), 0);

        /* If this is not called, when user types ^c SIGINT gets sent to gdb */
        setsid();

        execvp(local_argv[0], local_argv);

        /* Will get here if exec failed. This will happen when the 
         * - "gdb" is not on the users path, or if 
         * - user specified a different program via the -d option and it was
         *   not able to be exec'd.
         */
        exit(0);
    }

    *in = masterfd;
    *out = masterfd;

    free_memory(malloc_size, local_argv);
    return pid;
}