MIList * CLIGetListInfo(MICommand *cmd) { MIList * oobs; MIOOBRecord * oob; char * text; int lineno; char * endptr; MIList * lines = MIListNew(); CLILineInfo * line; if (!cmd->completed || cmd->output == NULL || cmd->output->oobs == NULL) { return NULL; } if (cmd->output->rr != NULL && cmd->output->rr->resultClass == MIResultRecordERROR) { return NULL; } oobs = cmd->output->oobs; for (MIListSet(oobs); (oob = (MIOOBRecord *)MIListGet(oobs)) != NULL; ) { text = oob->cstring; if (*text == '\0') { continue; } while (*text == ' ') { text++; } // ignore lines that are not prefixed with a line number if (!isdigit(*text)) { continue; } endptr = NULL; lineno = (int)strtol(text, &endptr, 10); // bypass the first "\t" (added by GDB) endptr += 2; line = CLILineInfoNew(); line->line_no = lineno; line->line = strdup(endptr); MIListAdd(lines, (void *)line); } return lines; }
/* * Append source list to destination list */ void MIListAppend(MIList *dst, MIList *src) { void * e; MIListSet(src); while ( (e = MIListGet(src)) != (void *)NULL) { MIListAdd(dst, e); } }
MIList * CLIGetVariablesFromInfoScopeInfo(MICommand *cmd) { MIList * oobs; MIOOBRecord * oob; char * text; char * sym = NULL; MIList * syms = MIListNew(); if (!cmd->completed || cmd->output == NULL || cmd->output->oobs == NULL) { return NULL; } if (cmd->output->rr != NULL && cmd->output->rr->resultClass == MIResultRecordERROR) { return NULL; } oobs = cmd->output->oobs; for (MIListSet(oobs); (oob = (MIOOBRecord *)MIListGet(oobs)) != NULL; ) { text = oob->cstring; if (*text == '\0') { continue; } while (*text == ' ') { text++; } // ensure that this is a variable if (strstr(text, "is a variable") == NULL) { continue; } if (sscanf(text, "Symbol %ms is a variable", &sym) != 1) { continue; } MIListAdd(syms, (void *)sym); } return syms; }
CLIInfoThreadsInfo * CLIGetInfoThreadsInfo(MICommand *cmd) { MIList * oobs; MIOOBRecord * oob; CLIInfoThreadsInfo * info = CLIInfoThreadsInfoNew(); char * text = NULL; char * id = NULL; if (!cmd->completed || cmd->output == NULL || cmd->output->oobs == NULL) { return info; } if (cmd->output->rr != NULL && cmd->output->rr->resultClass == MIResultRecordERROR) { return info; } oobs = cmd->output->oobs; info->thread_ids = MIListNew(); for (MIListSet(oobs); (oob = (MIOOBRecord *)MIListGet(oobs)) != NULL; ) { text = oob->cstring; if (*text == '\0') { continue; } while (*text == ' ') { text++; } if (strncmp(text, "*", 1) == 0) { text += 2;//escape "* "; if (isdigit(*text)) { info->current_thread_id = strtol(text, &text, 10); } continue; } if (isdigit(*text)) { if (info->thread_ids == NULL) info->thread_ids = MIListNew(); id = strchr(text, ' '); if (id != NULL) { *id = '\0'; MIListAdd(info->thread_ids, (void *)strdup(text)); } } } return info; }
MIList * MIMemoryDataParse(MIValue* miValue) { MIList * data = MIListNew(); MIList * values = miValue->values; MIValue * value; if (values != NULL) { for (MIListSet(values); (value = (MIValue *)MIListGet(values)) != NULL; ) { if (value->type == MIValueTypeConst) { MIListAdd(data, (void *) strdup(value->cstring)); } } } return data; }
MIList * MIGetMemoryList(MIValue *miValue) { MIList * memories = MIListNew(); MIList * values = miValue->values; MIValue * value; if (values != NULL) { for (MIListSet(values); (value = (MIValue *)MIListGet(values)) != NULL;) { if (value->type == MIValueTypeTuple) { MIListAdd(memories, (void *)MIMemoryParse(value)); } } } return memories; }
MIList * CLIGetPtypeFieldList(MICommand *cmd) { MIList * oobs; MIOOBRecord * oob; char * text = NULL; char * field; MIList * result = MIListNew(); if (!cmd->completed || cmd->output == NULL || cmd->output->oobs == NULL) return NULL; oobs = cmd->output->oobs; for (MIListSet(oobs); (oob = (MIOOBRecord *)MIListGet(oobs)) != NULL; ) { text = oob->cstring; if (*text == '\0') { continue; } if (strncmp(text, "type = ", 7) == 0) { continue; } if (strncmp(text, "}", 1) == 0) { continue; } field = fix_type(text); if (field[strlen(field)-1] == ';') { field[strlen(field)-1] = '\0'; MIListAdd(result, (void *)field); } else { free(field); } } return result; }
void CLIGetSigHandleList(MICommand *cmd, MIList** signals) { MIList *oobs; MIOOBRecord *oob; MISignalInfo *sig; char *text = NULL; char *token; char *pch; int i; const char* delims[] = { " ", "\\" }; *signals = MIListNew(); if (!cmd->completed || cmd->output == NULL || cmd->output->oobs == NULL) return; oobs = cmd->output->oobs; for (MIListSet(oobs); (oob = (MIOOBRecord *)MIListGet(oobs)) != NULL; ) { text = oob->cstring; if (*text == '\0' || *text == '\\') { continue; } if (strncmp(text, "Signal", 6) != 0 && strncmp(text, "Use", 3) != 0 && strncmp(text, "info", 4) != 0) { token = strdup(text); pch = strstr(token, delims[0]); if (pch == NULL) { continue; } sig = MISignalInfoNew(); for (i=0; pch != NULL; i++,pch=strstr(token, delims[1])) { if (*pch == '\0') { break; } *pch = '\0'; pch++; while (*pch == ' ' || *pch =='t') { //remove whitespace or t character pch++; } if (*pch == '\\') { //ignore '\\t' again pch += 2; } switch(i) { case 0: sig->name = strdup(token); break; case 1: sig->stop = getBoolean(token); break; case 2: sig->print = getBoolean(token); break; case 3: sig->pass = getBoolean(token); break; case 4: sig->desc = strdup(token); break; } token = strdup(pch); } free(token); free(pch); MIListAdd(*signals, (void *)sig); } } }