/** * Process the commands that were created by the client * * \param tgdb * The TGDB context * * \return * -1 on error, 0 on success */ int Ctgdb::Process_client_commands() { struct tgdb_list *client_command_list; tgdb_list_iterator *iterator; struct tgdb_command *command; client_command_list = tgdb_client_get_client_commands (tcc); iterator = tgdb_list_get_first (client_command_list); while (iterator) { command = (struct tgdb_command *) tgdb_list_get_item (iterator); if (Run_or_queue_command(command) == -1) { Logger_write_pos( __FILE__, __LINE__, "Run_or_queue_command failed"); return -1; } iterator = tgdb_list_next (iterator); } /* free the list of client commands */ tgdb_list_clear (client_command_list); return 0; }
/** * Gets a response from TGDB. * This should be called after tgdb_recv_debugger_data * * \param tgdb * An instance of the tgdb library to operate on. * * @return * A valid response if responses still exist. * Null if no more responses exist. */ struct tgdb_response * Ctgdb::Get_response() { struct tgdb_response *command; if (command_list_iterator == NULL) return NULL; command = (struct tgdb_response *) tgdb_list_get_item (command_list_iterator); command_list_iterator = tgdb_list_next (command_list_iterator); return command; }
/** * Return to readline a possible completion. * * \param text * The text that is being completed. It can be a subset of the full current * line (rl_line_buffer) at the prompt. * * \param matches * The current number of matches so far * * \return * A possible match, or NULL if none left. */ char * rline_rl_completion_entry_function (const char *text, int matches) { if (rline_local_iter) { /** * 'local' is a possible completion. 'text' is the data to be completed. * 'word' is the current possible match started off at the same point * in local, that text is started in rl_line_buffer. * * In C++ if you do "b 'classname::functionam<Tab>". This will complete * the line like "b 'classname::functioname'". */ char *local = tgdb_list_get_item (rline_local_iter); char *word = local + rl_point - strlen (text); rline_local_iter = tgdb_list_next (rline_local_iter); return strdup (word); } return NULL; }
static void process_commands(struct tgdb *tgdb) { struct tgdb_response *item; while ((item = tgdb_get_response(tgdb)) != NULL) { switch (item->header) { /* This updates all the breakpoints */ case TGDB_UPDATE_BREAKPOINTS: { struct sviewer *sview = if_get_sview(); char *file; struct tgdb_list *list = item->choice.update_breakpoints.breakpoint_list; tgdb_list_iterator *iterator; struct tgdb_breakpoint *tb; source_clear_breaks(if_get_sview()); iterator = tgdb_list_get_first(list); while (iterator) { /* For each breakpoint */ tb = (struct tgdb_breakpoint *) tgdb_list_get_item(iterator); file = tb->file; if (tb->enabled) source_enable_break(sview, file, tb->line); else source_disable_break(sview, file, tb->line); iterator = tgdb_list_next(iterator); } if_show_file(NULL, 0); break; } /* This means a source file or line number changed */ case TGDB_UPDATE_FILE_POSITION: { struct tgdb_file_position *tfp; tfp = item->choice.update_file_position.file_position; /* Update the file */ source_reload(if_get_sview(), tfp->absolute_path, 0); if_show_file(tfp->absolute_path, tfp->line_number); source_set_relative_path(if_get_sview(), tfp->absolute_path, tfp->relative_path); break; } /* This is a list of all the source files */ case TGDB_UPDATE_SOURCE_FILES: { struct tgdb_list *list = item->choice.update_source_files.source_files; tgdb_list_iterator *i = tgdb_list_get_first(list); char *s; if_clear_filedlg(); while (i) { s = tgdb_list_get_item(i); if_add_filedlg_choice(s); i = tgdb_list_next(i); } if_set_focus(FILE_DLG); kui_input_acceptable = 1; break; } /* The user is trying to get a list of source files that make up * the debugged program but libtgdb is claiming that gdb knows * none. */ case TGDB_SOURCES_DENIED: if_display_message("Error:", 0, " No sources available! Was the program compiled with debug?"); kui_input_acceptable = 1; break; /* This is the absolute path to the last file the user requested */ case TGDB_FILENAME_PAIR: { const char *apath = item->choice.filename_pair.absolute_path; const char *rpath = item->choice.filename_pair.relative_path; if_show_file((char *) apath, 1); source_set_relative_path(if_get_sview(), apath, rpath); break; } /* The source file requested does not exist */ case TGDB_ABSOLUTE_SOURCE_DENIED: { struct tgdb_source_file *file = item->choice.absolute_source_denied.source_file; if_show_file(NULL, 0); /* com can be NULL when tgdb orig requests main file */ if (file->absolute_path != NULL) if_display_message("No such file:", 0, " %s", file->absolute_path); break; } case TGDB_INFERIOR_EXITED: { /* * int *status = item->data; * This could eventually go here, but for now, the update breakpoint * display function makes the status bar go back to the name of the file. * * if_display_message ( "Program exited with value", 0, " %d", *status ); */ /* Clear the cache */ break; } case TGDB_UPDATE_COMPLETIONS: { struct tgdb_list *list = item->choice.update_completions.completion_list; do_tab_completion(list); break; } case TGDB_UPDATE_CONSOLE_PROMPT_VALUE: { const char *new_prompt = item->choice.update_console_prompt_value.prompt_value; change_prompt(new_prompt); break; } case TGDB_QUIT: cleanup(); exit(0); break; /* Default */ default: break; } } }