1#include <sysio/vm/backend.hpp>
8 void on_code_start(
const void* compiled_base,
const void* wasm_code_start) {
12 function_offsets.push_back(
static_cast<std::uint32_t
>(
reinterpret_cast<const char*
>(wasm_addr) -
reinterpret_cast<const char*
>(
wasm_base)));
15 void on_code_end(
const void* code_addr,
const void* wasm_addr) {}
39 return &mod.
exports[i].field_str;
49bool starts_with(std::string_view arg, std::string_view prefix) {
50 return arg.substr(0, prefix.size()) == prefix;
54 bool print_addresses =
false;
55 bool print_functions =
false;
57 std::vector<std::string> addresses;
58 std::string filename =
"a.out";
59 for(
int i = 1; i < argc; ++i) {
60 std::string arg =
argv[i];
61 if(arg ==
"-h" || arg ==
"--help") {
62 std::cerr <<
"Usage: " <<
argv[0] <<
" [-h] [-a] [-C] [-e wasm] [-f] [-s] [-i] [-p] address..." << std::endl;
64 }
else if(arg ==
"-a" || arg ==
"--addresses") {
65 print_addresses =
true;
66 }
else if(arg ==
"-C" ||
starts_with(arg,
"--demangle=")) {
68 }
else if(arg ==
"-e") {
72 std::cerr <<
"Missing argument to -e" << std::endl;
76 filename = arg.substr(6);
77 }
else if(arg ==
"-f" || arg ==
"--functions") {
78 print_functions =
true;
79 }
else if(arg ==
"-s" || arg ==
"--basenames") {
81 }
else if(arg ==
"-i" || arg ==
"--inlines") {
83 }
else if(arg ==
"-p" || arg ==
"--pretty-print") {
85 }
else if(arg[0] !=
'-') {
86 addresses.push_back(arg);
88 std::cerr <<
"unexpected argument: " << arg << std::endl;
93 std::vector<std::string> function_names;
102 for(std::size_t i = 0; i < info.function_offsets.size(); ++i) {
104 function_names.push_back(std::string(
reinterpret_cast<const char*
>(
name->raw()),
name->size()));
106 function_names.push_back(
"fn" + std::to_string( i + mod.get_imported_functions_size()));
111 std::string_view sep = pretty ?
" " :
"\n";
113 auto print_one_address = [&](
const std::string& addr) {
114 unsigned x = std::stoul(addr,
nullptr, 16);
115 if(print_addresses) {
116 std::cout << std::showbase << std::hex << x << sep;
118 if(print_functions) {
119 std::cout << std::hex << function_names[info.get_function(x)] << sep;
121 std::cout <<
"??:0\n";
124 if(!addresses.empty()) {
125 for(
const auto& addr : addresses) {
126 print_one_address(addr);
130 while(std::cin >> addr) {
131 print_one_address(addr);
sysio::vm::guarded_vector< uint8_t > * find_export_name(sysio::vm::module &mod, uint32_t idx)
bool starts_with(std::string_view arg, std::string_view prefix)
module & parse_module(wasm_code &code, module &mod, DebugInfo &debug)
std::vector< uint8_t > read_wasm(const std::string &fname)
void relocate(const void *)
uint32_t get_function(std::uint32_t addr)
void on_code_end(const void *code_addr, const void *wasm_addr)
std::vector< uint32_t > function_offsets
void on_instr_start(const void *code_addr, const void *wasm_addr)
void set(nm_debug_info &&other)
void on_function_start(const void *code_addr, const void *wasm_addr)
void on_code_start(const void *compiled_base, const void *wasm_code_start)
static constexpr bool parse_custom_section_name
Immutable except for fc::from_variant.
guarded_vector< export_entry > exports
guarded_vector< name_assoc > * function_names