int context_read_mem(Context * ctx, ContextAddress address, void * buf, size_t size) { ContextAddress word_addr; unsigned word_size = context_word_size(ctx); assert(is_dispatch_thread()); assert(!ctx->exited); trace(LOG_CONTEXT, "context: read memory ctx %#lx, id %s, address %#lx, size %zu", ctx, ctx->id, address, size); assert(word_size <= sizeof(unsigned long)); for (word_addr = address & ~((ContextAddress)word_size - 1); word_addr < address + size; word_addr += word_size) { unsigned long word = 0; errno = 0; word = ptrace(PTRACE_PEEKDATA, EXT(ctx)->pid, (char *)word_addr, 0); if (errno != 0) { int err = errno; trace(LOG_CONTEXT, "error: ptrace(PTRACE_PEEKDATA, ...) failed: ctx %#lx, id %s, addr %#lx, error %d %s", ctx, ctx->id, word_addr, err, errno_to_str(err)); errno = err; return -1; } if (word_addr < address || word_addr + word_size > address + size) { size_t i; for (i = 0; i < word_size; i++) { if (word_addr + i >= address && word_addr + i < address + size) { ((char *)buf)[word_addr + i - address] = ((char *)&word)[i]; } } } else { memcpy((char *)buf + (word_addr - address), &word, word_size); } } return check_breakpoints_on_memory_read(ctx, address, buf, size); }
int context_read_mem(Context * ctx, ContextAddress address, void * buf, size_t size) { if (address < 0x100) { /* TODO: need proper handling of Access Violation exception in VxWorks version of context_read_mem() */ errno = ERR_INV_ADDRESS; return -1; } #ifdef _WRS_PERSISTENT_SW_BP vxdbgMemRead((void *)address, buf, size); #else bcopy((void *)address, buf, size); #endif if (check_breakpoints_on_memory_read(ctx, address, buf, size) < 0) return -1; return 0; }
int read_dwarf_object_property(Context * Ctx, int Frame, ObjectInfo * Obj, int Attr, PropertyValue * Value) { Trap trap; memset(Value, 0, sizeof(PropertyValue)); Value->mContext = Ctx; Value->mFrame = Frame; Value->mObject = Obj; Value->mAttr = Attr; Value->mBigEndian = Obj->mCompUnit->mFile->big_endian; if (Attr == AT_location && Obj->mLowPC != 0) { Value->mValue = Obj->mLowPC; return 0; } sCompUnit = Obj->mCompUnit; sCache = (DWARFCache *)sCompUnit->mFile->dwarf_dt_cache; sDebugSection = sCompUnit->mSection; dio_EnterDebugSection(&sCompUnit->mDesc, sDebugSection, Obj->mID - sDebugSection->addr); if (set_trap(&trap)) { gop_gAttr = Attr; gop_gForm = 0; dio_ReadEntry(get_object_property_callback); clear_trap(&trap); } dio_ExitSection(); sCompUnit = NULL; sCache = NULL; sDebugSection = NULL; if (trap.error) return -1; switch (Value->mForm = gop_gForm) { case FORM_REF : case FORM_REF_ADDR : case FORM_REF1 : case FORM_REF2 : case FORM_REF4 : case FORM_REF8 : case FORM_REF_UDATA : { ObjectInfo * RefObj = find_object(sCache, gop_gFormRef); PropertyValue ValueAddr; if (read_and_evaluate_dwarf_object_property(Ctx, Frame, 0, RefObj, AT_location, &ValueAddr) < 0) return -1; if (ValueAddr.mAccessFunc != NULL) { ValueAddr.mAccessFunc(&ValueAddr, 0, &Value->mValue); } else { static U1_T Buf[8]; PropertyValue ValueSize; ContextAddress Addr; size_t Size; Addr = (ContextAddress)get_numeric_property_value(&ValueAddr); if (read_and_evaluate_dwarf_object_property(Ctx, Frame, Addr, RefObj, AT_byte_size, &ValueSize) < 0) return -1; Size = (size_t)get_numeric_property_value(&ValueSize); if (Size < 1 || Size > sizeof(Buf)) { errno = ERR_INV_DATA_TYPE; return -1; } if (context_read_mem(Ctx, Addr, Buf, Size) < 0) return -1; check_breakpoints_on_memory_read(Ctx, Addr, Buf, Size); Value->mAddr = Buf; Value->mSize = Size; } } break; case FORM_DATA1 : case FORM_DATA2 : case FORM_DATA4 : case FORM_DATA8 : case FORM_FLAG : case FORM_BLOCK1 : case FORM_BLOCK2 : case FORM_BLOCK4 : case FORM_BLOCK : Value->mAddr = gop_gFormDataAddr; Value->mSize = gop_gFormDataSize; break; case FORM_SDATA : case FORM_UDATA : Value->mValue = gop_gFormData; break; default: errno = ENOENT; return -1; } return 0; }