Exemple #1
0
Fichier : io.cpp Projet : cgdb/cgdb
ssize_t io_read(int fd, void *buf, size_t count)
{
    ssize_t amountRead;

  tgdb_read:

    if ((amountRead = read(fd, buf, count)) == -1) {    /* error */
        if (errno == EINTR)
            goto tgdb_read;
        else if (errno != EIO) {
            logger_write_pos(logger, __FILE__, __LINE__,
                    "error reading from fd");
            return -1;
        } else {
            return 0;           /* Happens on EOF for some reason */
        }

    } else if (amountRead == 0) {   /* EOF */
        return 0;
    } else {
        char *str = sys_quote_nonprintables((char *)buf, amountRead);
        clog_debug(CLOG(TGDB_LOGGER), "%s", str);
        sbfree(str);
    }

    return amountRead;
}
Exemple #2
0
/**
 * Send a command to gdb.
 *
 * @param tgdb
 * An instance of tgdb
 *
 * @param request 
 * The command request to issue the command for
 */
static void tgdb_run_request(struct tgdb *tgdb, struct tgdb_request *request)
{
    std::string command;

    if (request->header == TGDB_REQUEST_CONSOLE_COMMAND ||
        request->header == TGDB_REQUEST_COMPLETE ||
        request->header == TGDB_REQUEST_DEBUGGER_COMMAND) {
        tgdb->make_console_ready_callback = true;
    }

    tgdb->is_gdb_ready_for_next_command = 0;

    tgdb_get_gdb_command(tgdb, request, command);

    /* Add a newline to the end of the command if it doesn't exist */
    if (*command.rbegin() != '\n') {
        command.push_back('\n');
    }

    /* Send what we're doing to log file */
    char *str = sys_quote_nonprintables(command.c_str(), -1);
    clog_debug(CLOG_GDBIO, "%s", str);
    sbfree(str);

    /* A command for the debugger */
    commands_set_current_request_type(tgdb->c, request->header);

    io_writen(tgdb->debugger_stdin, command.c_str(), command.size());

    // Alert the GUI a command was sent
    tgdb->callbacks.request_sent_callback(
            tgdb->callbacks.context, request, command);

    tgdb_request_destroy(request);
}