| 284 | } |
| 285 | |
| 286 | string |
| 287 | to_string(const value &v) |
| 288 | { |
| 289 | switch (v.get_type()) { |
| 290 | case value::type::invalid: |
| 291 | return "<invalid value type>"; |
| 292 | case value::type::address: |
| 293 | return "0x" + to_hex(v.as_address()); |
| 294 | case value::type::block: { |
| 295 | size_t size; |
| 296 | const char *b = (const char*)v.as_block(&size); |
| 297 | string res = ::to_string(size) + " byte block:"; |
| 298 | for (size_t pos = 0; pos < size; ++pos) { |
| 299 | res += ' '; |
| 300 | res += to_hex(b[pos]); |
| 301 | } |
| 302 | return res; |
| 303 | } |
| 304 | case value::type::constant: |
| 305 | return "0x" + to_hex(v.as_uconstant()); |
| 306 | case value::type::uconstant: |
| 307 | return ::to_string(v.as_uconstant()); |
| 308 | case value::type::sconstant: |
| 309 | return ::to_string(v.as_sconstant()); |
| 310 | case value::type::exprloc: |
| 311 | // XXX |
| 312 | return "<exprloc>"; |
| 313 | case value::type::flag: |
| 314 | return v.as_flag() ? "true" : "false"; |
| 315 | case value::type::line: |
| 316 | return "<line 0x" + to_hex(v.as_sec_offset()) + ">"; |
| 317 | case value::type::loclist: |
| 318 | return "<loclist 0x" + to_hex(v.as_sec_offset()) + ">"; |
| 319 | case value::type::mac: |
| 320 | return "<mac 0x" + to_hex(v.as_sec_offset()) + ">"; |
| 321 | case value::type::rangelist: |
| 322 | return "<rangelist 0x" + to_hex(v.as_sec_offset()) + ">"; |
| 323 | case value::type::reference: { |
| 324 | die d = v.as_reference(); |
| 325 | auto tu = dynamic_cast<const type_unit*>(&d.get_unit()); |
| 326 | if (tu) |
| 327 | return "<.debug_types+0x" + to_hex(d.get_section_offset()) + ">"; |
| 328 | return "<0x" + to_hex(d.get_section_offset()) + ">"; |
| 329 | } |
| 330 | case value::type::string: |
| 331 | return v.as_string(); |
| 332 | } |
| 333 | return "<unexpected value type " + to_string(v.get_type()) + ">"; |
| 334 | } |
| 335 | |
| 336 | DWARFPP_END_NAMESPACE |
no test coverage detected