/*---------------------------------------------------------------------------*/ static void call_stack(lua_State* L, int n) { lua_Debug ar; if(lua_getstack(L, n, &ar) == 1) { lua_getinfo(L, "nSlu", &ar); const char* indent; if(n == 0) { indent = "-> "; lua_tinker::print_error(L, "[[--call stack--]]"); } else { indent = " "; } if(ar.name) lua_tinker::print_error(L, "%s%s() -- <<line %d>> at [%s]", indent, ar.name, ar.currentline, ar.source); else lua_tinker::print_error(L, "%sunknown -- <<line %d>> [%s]", indent, ar.currentline, ar.source); call_stack(L, n+1); } }
/*---------------------------------------------------------------------------*/ static void call_stack(lua_State* L, int n) { lua_Debug ar; if(lua_getstack(L, n, &ar) == 1) { lua_getinfo(L, "nSlu", &ar); const char* indent; if(n == 0) { indent = "->\t"; lua_tinker::print_error(L, "\t<call stack>"); } else { indent = "\t"; } if(ar.name) lua_tinker::print_error(L, "%s%s() : line %d [%s : line %d]", indent, ar.name, ar.currentline, ar.source, ar.linedefined); else lua_tinker::print_error(L, "%sunknown : line %d [%s : line %d]", indent, ar.currentline, ar.source, ar.linedefined); call_stack(L, n+1); } }
static void call_stack(lua_State* L, int n, std::string& temp) { lua_Debug ar; if (lua_getstack(L, n, &ar) == 1) { lua_getinfo(L, "nSlu", &ar); char txt[4096]; const char* indent; if (n == 0) { indent = "->\t"; sprintf(txt, "%s", "\t<call stack> \n"); temp += txt; } else { indent = "\t"; } if (ar.name) { sprintf(txt, "%s%s() : line %d [%s : line %d] \n", indent, ar.name, ar.currentline, ar.source, ar.linedefined); } else { sprintf(txt, "%sunknown : line %d [%s : line %d] \n", indent, ar.currentline, ar.source, ar.linedefined); } temp += txt; call_stack(L, n + 1, temp); } }
/*---------------------------------------------------------------------------*/ int lua_tinker::on_error(lua_State *L) { print_error(L, "%s", lua_tostring(L, -1)); call_stack(L, 0); return 0; }
int on_error(lua_State *L) { print_error(L, "%s", lua_tostring(L, -1)); call_stack(L, 0); assert( false ); return 0; }
/*---------------------------------------------------------------------------*/ int lua_tinker::on_error(lua_State *L) { std::string temp; temp += lua_tostring(L, -1); temp += "\n"; call_stack(L, 0, temp); lua_tinker::print_error(L, "%s", temp.c_str()); return 0; }
function_def_by_id<TCallId,TAllFuncs>::return_type run_step_impl( const TAllFuncs &allDefs, const TTodoFuncs &todoFuncs, TDoneStacks &doneStack, const CallStep<TCallId,TCallArgSrc> &call ) { stack_entry_t stackStorage[1024]; multi_stack call_stack(stackStorage, defs.head, tailStack); return run_step_impl(allDefs, todoFuncs.tail, call_stack, call); }
/*---------------------------------------------------------------------------*/ int lua_tinker::on_error(lua_State *L) { print_error(L, "\n==============================\n"); print_error(L, "%s\n", lua_tostring(L, -1)); print_error(L, "==============================\n"); call_stack(L, 0); print_error(L, "==============================\n"); lua_getglobal(L, "_DumpLocals"); lua_pcall(L, 0,0,0); lua_pop(L, 1); lua_getglobal(L, "_ReloadBreak"); lua_pcall(L, 0,0,0); lua_pop(L, 1); return 0; }
bool ReservedMemoryRegion::remove_uncommitted_region(address addr, size_t sz) { // uncommit stack guard pages if (flag() == mtThreadStack && !same_region(addr, sz)) { return true; } assert(addr != NULL, "Invalid address"); assert(sz > 0, "Invalid size"); if (all_committed()) { assert(_committed_regions.is_empty(), "Sanity check"); assert(contain_region(addr, sz), "Reserved region does not contain this region"); set_all_committed(false); VirtualMemorySummary::record_uncommitted_memory(sz, flag()); if (same_region(addr, sz)) { return true; } else { CommittedMemoryRegion rgn(base(), size(), *call_stack()); if (rgn.base() == addr || rgn.end() == (addr + sz)) { rgn.exclude_region(addr, sz); return add_committed_region(rgn); } else { // split this region // top of the whole region address top =rgn.end(); // use this region for lower part size_t exclude_size = rgn.end() - addr; rgn.exclude_region(addr, exclude_size); if (add_committed_region(rgn)) { // higher part address high_base = addr + sz; size_t high_size = top - high_base; CommittedMemoryRegion high_rgn(high_base, high_size, NativeCallStack::EMPTY_STACK); return add_committed_region(high_rgn); } else { return false; } } } } else { // we have to walk whole list to remove the committed regions in // specified range LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head(); LinkedListNode<CommittedMemoryRegion>* prev = NULL; VirtualMemoryRegion uncommitted_rgn(addr, sz); while (head != NULL && !uncommitted_rgn.is_empty()) { CommittedMemoryRegion* crgn = head->data(); // this committed region overlaps to region to uncommit if (crgn->overlap_region(uncommitted_rgn.base(), uncommitted_rgn.size())) { if (crgn->same_region(uncommitted_rgn.base(), uncommitted_rgn.size())) { // find matched region, remove the node will do VirtualMemorySummary::record_uncommitted_memory(uncommitted_rgn.size(), flag()); _committed_regions.remove_after(prev); return true; } else if (crgn->contain_region(uncommitted_rgn.base(), uncommitted_rgn.size())) { // this committed region contains whole uncommitted region VirtualMemorySummary::record_uncommitted_memory(uncommitted_rgn.size(), flag()); return remove_uncommitted_region(head, uncommitted_rgn.base(), uncommitted_rgn.size()); } else if (uncommitted_rgn.contain_region(crgn->base(), crgn->size())) { // this committed region has been uncommitted size_t exclude_size = crgn->end() - uncommitted_rgn.base(); uncommitted_rgn.exclude_region(uncommitted_rgn.base(), exclude_size); VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag()); LinkedListNode<CommittedMemoryRegion>* tmp = head; head = head->next(); _committed_regions.remove_after(prev); continue; } else if (crgn->contain_address(uncommitted_rgn.base())) { size_t toUncommitted = crgn->end() - uncommitted_rgn.base(); crgn->exclude_region(uncommitted_rgn.base(), toUncommitted); uncommitted_rgn.exclude_region(uncommitted_rgn.base(), toUncommitted); VirtualMemorySummary::record_uncommitted_memory(toUncommitted, flag()); } else if (uncommitted_rgn.contain_address(crgn->base())) { size_t toUncommitted = uncommitted_rgn.end() - crgn->base(); crgn->exclude_region(crgn->base(), toUncommitted); uncommitted_rgn.exclude_region(uncommitted_rgn.end() - toUncommitted, toUncommitted); VirtualMemorySummary::record_uncommitted_memory(toUncommitted, flag()); } } prev = head; head = head->next(); } } return true; }
bool ReservedMemoryRegion::remove_uncommitted_region(address addr, size_t sz) { // uncommit stack guard pages if (flag() == mtThreadStack && !same_region(addr, sz)) { return true; } assert(addr != NULL, "Invalid address"); assert(sz > 0, "Invalid size"); if (all_committed()) { assert(_committed_regions.is_empty(), "Sanity check"); assert(contain_region(addr, sz), "Reserved region does not contain this region"); set_all_committed(false); VirtualMemorySummary::record_uncommitted_memory(sz, flag()); if (same_region(addr, sz)) { return true; } else { CommittedMemoryRegion rgn(base(), size(), *call_stack()); if (rgn.base() == addr || rgn.end() == (addr + sz)) { rgn.exclude_region(addr, sz); return add_committed_region(rgn); } else { // split this region // top of the whole region address top =rgn.end(); // use this region for lower part size_t exclude_size = rgn.end() - addr; rgn.exclude_region(addr, exclude_size); if (add_committed_region(rgn)) { // higher part address high_base = addr + sz; size_t high_size = top - high_base; CommittedMemoryRegion high_rgn(high_base, high_size, NativeCallStack::EMPTY_STACK); return add_committed_region(high_rgn); } else { return false; } } } } else { CommittedMemoryRegion del_rgn(addr, sz, *call_stack()); address end = addr + sz; LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head(); LinkedListNode<CommittedMemoryRegion>* prev = NULL; CommittedMemoryRegion* crgn; while (head != NULL) { crgn = head->data(); if (crgn->same_region(addr, sz)) { VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag()); _committed_regions.remove_after(prev); return true; } // del_rgn contains crgn if (del_rgn.contain_region(crgn->base(), crgn->size())) { VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag()); head = head->next(); _committed_regions.remove_after(prev); continue; // don't update head or prev } // Found addr in the current crgn. There are 2 subcases: if (crgn->contain_address(addr)) { // (1) Found addr+size in current crgn as well. (del_rgn is contained in crgn) if (crgn->contain_address(end - 1)) { VirtualMemorySummary::record_uncommitted_memory(sz, flag()); return remove_uncommitted_region(head, addr, sz); // done! } else { // (2) Did not find del_rgn's end in crgn. size_t size = crgn->end() - del_rgn.base(); crgn->exclude_region(addr, size); VirtualMemorySummary::record_uncommitted_memory(size, flag()); } } else if (crgn->contain_address(end - 1)) { // Found del_rgn's end, but not its base addr. size_t size = del_rgn.end() - crgn->base(); crgn->exclude_region(crgn->base(), size); VirtualMemorySummary::record_uncommitted_memory(size, flag()); return true; // should be done if the list is sorted properly! } prev = head; head = head->next(); } } return true; }