Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "Debug.h" |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 18 | |
| 19 | #include <algorithm> |
| 20 | #include <iostream> |
| 21 | #include <map> |
| 22 | #include <memory> |
Adam Lesinski | d13fb24 | 2015-05-12 20:40:48 -0700 | [diff] [blame] | 23 | #include <queue> |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 24 | #include <set> |
| 25 | #include <vector> |
| 26 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 27 | #include "android-base/logging.h" |
| 28 | |
| 29 | #include "ResourceTable.h" |
| 30 | #include "ResourceValues.h" |
| 31 | #include "ValueVisitor.h" |
| 32 | #include "util/Util.h" |
| 33 | |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 34 | namespace aapt { |
| 35 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 36 | namespace { |
| 37 | |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 38 | class PrintVisitor : public ValueVisitor { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 39 | public: |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 40 | using ValueVisitor::Visit; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 41 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 42 | void Visit(Attribute* attr) override { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 43 | std::cout << "(attr) type="; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 44 | attr->PrintMask(&std::cout); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 45 | static constexpr uint32_t kMask = |
| 46 | android::ResTable_map::TYPE_ENUM | android::ResTable_map::TYPE_FLAGS; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 47 | if (attr->type_mask & kMask) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 48 | for (const auto& symbol : attr->symbols) { |
| 49 | std::cout << "\n " << symbol.symbol.name.value().entry; |
| 50 | if (symbol.symbol.id) { |
| 51 | std::cout << " (" << symbol.symbol.id.value() << ")"; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 52 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 53 | std::cout << " = " << symbol.value; |
| 54 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 55 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 56 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 57 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 58 | void Visit(Style* style) override { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 59 | std::cout << "(style)"; |
| 60 | if (style->parent) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 61 | const Reference& parent_ref = style->parent.value(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 62 | std::cout << " parent="; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 63 | if (parent_ref.name) { |
| 64 | if (parent_ref.private_reference) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 65 | std::cout << "*"; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 66 | } |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 67 | std::cout << parent_ref.name.value() << " "; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 68 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 69 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 70 | if (parent_ref.id) { |
| 71 | std::cout << parent_ref.id.value(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 72 | } |
| 73 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 74 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 75 | for (const auto& entry : style->entries) { |
| 76 | std::cout << "\n "; |
| 77 | if (entry.key.name) { |
| 78 | const ResourceName& name = entry.key.name.value(); |
| 79 | if (!name.package.empty()) { |
| 80 | std::cout << name.package << ":"; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 81 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 82 | std::cout << name.entry; |
| 83 | } |
| 84 | |
| 85 | if (entry.key.id) { |
| 86 | std::cout << "(" << entry.key.id.value() << ")"; |
| 87 | } |
| 88 | |
| 89 | std::cout << "=" << *entry.value; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 90 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 91 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 92 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 93 | void Visit(Array* array) override { |
| 94 | array->Print(&std::cout); |
| 95 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 96 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 97 | void Visit(Plural* plural) override { |
| 98 | plural->Print(&std::cout); |
| 99 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 100 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 101 | void Visit(Styleable* styleable) override { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 102 | std::cout << "(styleable)"; |
| 103 | for (const auto& attr : styleable->entries) { |
| 104 | std::cout << "\n "; |
| 105 | if (attr.name) { |
| 106 | const ResourceName& name = attr.name.value(); |
| 107 | if (!name.package.empty()) { |
| 108 | std::cout << name.package << ":"; |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 109 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 110 | std::cout << name.entry; |
| 111 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 112 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 113 | if (attr.id) { |
| 114 | std::cout << "(" << attr.id.value() << ")"; |
| 115 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 116 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 119 | void VisitItem(Item* item) override { |
| 120 | item->Print(&std::cout); |
| 121 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 124 | } // namespace |
| 125 | |
| 126 | void Debug::PrintTable(ResourceTable* table, const DebugPrintTableOptions& options) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 127 | PrintVisitor visitor; |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 128 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 129 | for (auto& package : table->packages) { |
| 130 | std::cout << "Package name=" << package->name; |
| 131 | if (package->id) { |
| 132 | std::cout << " id=" << std::hex << (int)package->id.value() << std::dec; |
| 133 | } |
| 134 | std::cout << std::endl; |
| 135 | |
| 136 | for (const auto& type : package->types) { |
| 137 | std::cout << "\n type " << type->type; |
| 138 | if (type->id) { |
| 139 | std::cout << " id=" << std::hex << (int)type->id.value() << std::dec; |
| 140 | } |
| 141 | std::cout << " entryCount=" << type->entries.size() << std::endl; |
| 142 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 143 | std::vector<const ResourceEntry*> sorted_entries; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 144 | for (const auto& entry : type->entries) { |
| 145 | auto iter = std::lower_bound( |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 146 | sorted_entries.begin(), sorted_entries.end(), entry.get(), |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 147 | [](const ResourceEntry* a, const ResourceEntry* b) -> bool { |
| 148 | if (a->id && b->id) { |
| 149 | return a->id.value() < b->id.value(); |
| 150 | } else if (a->id) { |
| 151 | return true; |
| 152 | } else { |
| 153 | return false; |
| 154 | } |
| 155 | }); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 156 | sorted_entries.insert(iter, entry.get()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 159 | for (const ResourceEntry* entry : sorted_entries) { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 160 | const ResourceId id(package->id.value_or_default(0), type->id.value_or_default(0), |
| 161 | entry->id.value_or_default(0)); |
| 162 | const ResourceName name(package->name, type->type, entry->name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 163 | |
| 164 | std::cout << " spec resource " << id << " " << name; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 165 | switch (entry->symbol_status.state) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 166 | case SymbolState::kPublic: |
| 167 | std::cout << " PUBLIC"; |
| 168 | break; |
| 169 | case SymbolState::kPrivate: |
| 170 | std::cout << " _PRIVATE_"; |
| 171 | break; |
| 172 | default: |
| 173 | break; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 174 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 175 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 176 | std::cout << std::endl; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 177 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 178 | for (const auto& value : entry->values) { |
| 179 | std::cout << " (" << value->config << ") "; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 180 | value->value->Accept(&visitor); |
| 181 | if (options.show_sources && !value->value->GetSource().path.empty()) { |
| 182 | std::cout << " src=" << value->value->GetSource(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 183 | } |
| 184 | std::cout << std::endl; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 185 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 186 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 187 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 188 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 191 | static size_t GetNodeIndex(const std::vector<ResourceName>& names, const ResourceName& name) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 192 | auto iter = std::lower_bound(names.begin(), names.end(), name); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 193 | CHECK(iter != names.end()); |
| 194 | CHECK(*iter == name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 195 | return std::distance(names.begin(), iter); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 198 | void Debug::PrintStyleGraph(ResourceTable* table, const ResourceName& target_style) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 199 | std::map<ResourceName, std::set<ResourceName>> graph; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 200 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 201 | std::queue<ResourceName> styles_to_visit; |
| 202 | styles_to_visit.push(target_style); |
| 203 | for (; !styles_to_visit.empty(); styles_to_visit.pop()) { |
| 204 | const ResourceName& style_name = styles_to_visit.front(); |
| 205 | std::set<ResourceName>& parents = graph[style_name]; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 206 | if (!parents.empty()) { |
| 207 | // We've already visited this style. |
| 208 | continue; |
| 209 | } |
| 210 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 211 | Maybe<ResourceTable::SearchResult> result = table->FindResource(style_name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 212 | if (result) { |
| 213 | ResourceEntry* entry = result.value().entry; |
| 214 | for (const auto& value : entry->values) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 215 | if (Style* style = ValueCast<Style>(value->value.get())) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 216 | if (style->parent && style->parent.value().name) { |
| 217 | parents.insert(style->parent.value().name.value()); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 218 | styles_to_visit.push(style->parent.value().name.value()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 219 | } |
Adam Lesinski | d13fb24 | 2015-05-12 20:40:48 -0700 | [diff] [blame] | 220 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 221 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 222 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 223 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 224 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 225 | std::vector<ResourceName> names; |
| 226 | for (const auto& entry : graph) { |
| 227 | names.push_back(entry.first); |
| 228 | } |
| 229 | |
| 230 | std::cout << "digraph styles {\n"; |
| 231 | for (const auto& name : names) { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 232 | std::cout << " node_" << GetNodeIndex(names, name) << " [label=\"" << name << "\"];\n"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | for (const auto& entry : graph) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 236 | const ResourceName& style_name = entry.first; |
| 237 | size_t style_node_index = GetNodeIndex(names, style_name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 238 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 239 | for (const auto& parent_name : entry.second) { |
| 240 | std::cout << " node_" << style_node_index << " -> " |
| 241 | << "node_" << GetNodeIndex(names, parent_name) << ";\n"; |
Adam Lesinski | d13fb24 | 2015-05-12 20:40:48 -0700 | [diff] [blame] | 242 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 243 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 244 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 245 | std::cout << "}" << std::endl; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 248 | void Debug::DumpHex(const void* data, size_t len) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 249 | const uint8_t* d = (const uint8_t*)data; |
| 250 | for (size_t i = 0; i < len; i++) { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 251 | std::cerr << std::hex << std::setfill('0') << std::setw(2) << (uint32_t)d[i] << " "; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 252 | if (i % 8 == 7) { |
| 253 | std::cerr << "\n"; |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 254 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 255 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 256 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 257 | if (len - 1 % 8 != 7) { |
| 258 | std::cerr << std::endl; |
| 259 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 262 | namespace { |
| 263 | |
| 264 | class XmlPrinter : public xml::Visitor { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 265 | public: |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 266 | using xml::Visitor::Visit; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 267 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 268 | void Visit(xml::Element* el) override { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 269 | const size_t previous_size = prefix_.size(); |
| 270 | |
| 271 | for (const xml::NamespaceDecl& decl : el->namespace_decls) { |
| 272 | std::cerr << prefix_ << "N: " << decl.prefix << "=" << decl.uri |
| 273 | << " (line=" << decl.line_number << ")\n"; |
| 274 | prefix_ += " "; |
| 275 | } |
| 276 | |
| 277 | std::cerr << prefix_ << "E: "; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 278 | if (!el->namespace_uri.empty()) { |
| 279 | std::cerr << el->namespace_uri << ":"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 280 | } |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 281 | std::cerr << el->name << " (line=" << el->line_number << ")\n"; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 282 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 283 | for (const xml::Attribute& attr : el->attributes) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 284 | std::cerr << prefix_ << " A: "; |
| 285 | if (!attr.namespace_uri.empty()) { |
| 286 | std::cerr << attr.namespace_uri << ":"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 287 | } |
Adam Lesinski | 4ca5697 | 2017-04-26 21:49:53 -0700 | [diff] [blame] | 288 | std::cerr << attr.name; |
| 289 | |
| 290 | if (attr.compiled_attribute) { |
| 291 | std::cerr << "(" << attr.compiled_attribute.value().id.value_or_default(ResourceId(0x0)) |
| 292 | << ")"; |
| 293 | } |
Shane Farmer | 6ed4061 | 2017-09-06 10:00:07 -0700 | [diff] [blame] | 294 | std::cerr << "="; |
| 295 | if (attr.compiled_value != nullptr) { |
| 296 | std::cerr << *attr.compiled_value; |
| 297 | } else { |
| 298 | std::cerr << attr.value; |
| 299 | } |
| 300 | std::cerr << "\n"; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 303 | prefix_ += " "; |
| 304 | xml::Visitor::Visit(el); |
| 305 | prefix_.resize(previous_size); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 306 | } |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 307 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 308 | void Visit(xml::Text* text) override { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 309 | std::cerr << prefix_ << "T: '" << text->text << "'\n"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | private: |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 313 | std::string prefix_; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 316 | } // namespace |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 317 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 318 | void Debug::DumpXml(xml::XmlResource* doc) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 319 | XmlPrinter printer; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 320 | doc->root->Accept(&printer); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 321 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 322 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 323 | } // namespace aapt |