int main() { Stack *pila1; pila1 = stack_create(); stack_data(pila1)[0] = 2; stack_data(pila1)[1] = 8; stack_data(pila1)[2] = 14; stack_back(pila1) = 2; pila1 = stack_push(pila1,4); pila1 = stack_pop(pila1); stack_print(pila1); int i; for(i = 0; i<=stack_back(pila1) && stack_back(pila1) != stack_maxstack(pila1) ; i++) stack_data(pila)[i] = 3; pila1 = stack_reverse(pila1); stack_print(pila1); stack_destroy(pila1); }
extracted_ptree_iterator(const extracted_ptree& extracted_ptree, const pqrs::string::replacement& replacement, const boost::property_tree::ptree& pt) : extracted_ptree_(extracted_ptree), stack_size_(extracted_ptree.stack_.size() + 1) { if (! pt.empty()) { extracted_ptree_.stack_.push(stack_data(pt, replacement)); extract_include_(); } }
void extract_include_(void) const { if (ended_()) return; const auto& xml_compiler = extracted_ptree_.xml_compiler_; auto& top = extracted_ptree_.stack_.top(); const auto& it = *(top.it); if (it.first != "include") return; // ---------------------------------------- // replacement std::tr1::shared_ptr<pqrs::string::replacement> replacement_ptr(new pqrs::string::replacement); if (! it.second.empty()) { replacement_loader loader(xml_compiler, *replacement_ptr); loader.traverse(extracted_ptree(extracted_ptree_, top.parent_replacement, it.second)); } auto end = replacement_ptr->end(); for (const auto& i : top.parent_replacement) { if (replacement_ptr->find(i.first) == end) { (*replacement_ptr)[i.first] = i.second; } } // ---------------------------------------- std::string xml_file_path; { auto path = it.second.get_optional<std::string>("<xmlattr>.path"); if (path) { if (extracted_ptree_.included_files_.empty()) { throw xml_compiler_logic_error("included_files_.empty() in extracted_ptree_iterator::extract_include_."); } xml_file_path = xml_compiler.make_file_path(pqrs::file_path::dirname(extracted_ptree_.included_files_.back()), *path); } } if (! xml_file_path.empty()) { for (const auto& i : extracted_ptree_.included_files_) { if (i == xml_file_path) { xml_compiler.error_information_.set("An infinite include loop is detected:\n" + xml_file_path); return; } } ptree_ptr pt_ptr; xml_compiler.read_xml_(pt_ptr, xml_file_path, *replacement_ptr); if (pt_ptr) { // Skip <include> next time. ++(top.it); // Do not call collapse_ here. // (Keep included_files_ to detect an infinite include loop.) if (! pt_ptr->empty()) { auto root_node = pt_ptr->begin(); const auto& root_children = root_node->second; if (! root_children.empty()) { extracted_ptree_.stack_.push(stack_data(pt_ptr, replacement_ptr, root_children)); extracted_ptree_.included_files_.push_back(xml_file_path); extract_include_(); } } collapse_(); } } }
StackValueCollection* interpretedVFrame::expressions() const { return stack_data(true); }
StackValueCollection* interpretedVFrame::locals() const { return stack_data(false); }
// This test is disable because it is for generating test data. TEST(libbacktrace, DISABLED_generate_offline_testdata) { // Create a thread to generate the needed stack and registers information. const size_t stack_size = 16 * 1024; void* stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); ASSERT_NE(MAP_FAILED, stack); uintptr_t stack_addr = reinterpret_cast<uintptr_t>(stack); pthread_attr_t attr; ASSERT_EQ(0, pthread_attr_init(&attr)); ASSERT_EQ(0, pthread_attr_setstack(&attr, reinterpret_cast<void*>(stack), stack_size)); pthread_t thread; OfflineThreadArg arg; arg.exit_flag = 0; ASSERT_EQ(0, pthread_create(&thread, &attr, OfflineThreadFunc, &arg)); // Wait for the offline thread to generate the stack and unw_context information. sleep(1); // Copy the stack information. std::vector<uint8_t> stack_data(reinterpret_cast<uint8_t*>(stack), reinterpret_cast<uint8_t*>(stack) + stack_size); arg.exit_flag = 1; ASSERT_EQ(0, pthread_join(thread, nullptr)); ASSERT_EQ(0, munmap(stack, stack_size)); std::unique_ptr<BacktraceMap> map(BacktraceMap::Create(getpid())); ASSERT_TRUE(map != nullptr); backtrace_stackinfo_t stack_info; stack_info.start = stack_addr; stack_info.end = stack_addr + stack_size; stack_info.data = stack_data.data(); // Generate offline testdata. std::string testdata; // 1. Dump pid, tid testdata += android::base::StringPrintf("pid: %d tid: %d\n", getpid(), arg.tid); // 2. Dump maps for (auto it = map->begin(); it != map->end(); ++it) { testdata += android::base::StringPrintf( "map: start: %" PRIxPTR " end: %" PRIxPTR " offset: %" PRIxPTR " load_bias: %" PRIxPTR " flags: %d name: %s\n", it->start, it->end, it->offset, it->load_bias, it->flags, it->name.c_str()); } // 3. Dump registers testdata += android::base::StringPrintf("registers: %zu ", sizeof(arg.unw_context)); testdata += RawDataToHexString(&arg.unw_context, sizeof(arg.unw_context)); testdata.push_back('\n'); // 4. Dump stack testdata += android::base::StringPrintf( "stack: start: %" PRIx64 " end: %" PRIx64 " size: %zu ", stack_info.start, stack_info.end, stack_data.size()); testdata += RawDataToHexString(stack_data.data(), stack_data.size()); testdata.push_back('\n'); // 5. Dump function symbols std::vector<FunctionSymbol> function_symbols = GetFunctionSymbols(); for (const auto& symbol : function_symbols) { testdata += android::base::StringPrintf( "function: start: %" PRIxPTR " end: %" PRIxPTR" name: %s\n", symbol.start, symbol.end, symbol.name.c_str()); } ASSERT_TRUE(android::base::WriteStringToFile(testdata, "offline_testdata")); }