Skip to content

Commit

Permalink
[LLDB] wasm: Add execute_command API call
Browse files Browse the repository at this point in the history
  • Loading branch information
jawilk committed Oct 1, 2022
1 parent 5a88e03 commit 12a948e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lldb/tools/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ static void printHelp(LLDBOptTable &table, llvm::StringRef tool_name) {
llvm::outs() << examples << '\n';
}

#ifndef __EMSCRIPTEN__
int main(int argc, char const *argv[]) {
// Editline uses for example iswprint which is dependent on LC_CTYPE.
std::setlocale(LC_ALL, "");
Expand Down Expand Up @@ -817,3 +818,52 @@ int main(int argc, char const *argv[]) {
SBDebugger::Terminate();
return exit_code;
}
#else
#include "/home/wj/projects/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/emscripten.h"
#include <iostream>

using namespace std;

extern "C" {
EMSCRIPTEN_KEEPALIVE const char* execute_command(const char* input);
}

class LLDBSentry {
public:
LLDBSentry() {
// Initialize LLDB
SBDebugger::Initialize();
}
~LLDBSentry() {
// Terminate LLDB
SBDebugger::Terminate();
}
};

static SBDebugger g_debugger;
static LLDBSentry sentry;


int main() {
cout << "LLDB WASM call - " << __FUNCTION__ << "\n";

// Create debugger instance
g_debugger = SBDebugger::Create(false);
if (!g_debugger.IsValid())
fprintf(stderr, "error: failed to create a debugger object\n");
g_debugger.SetAsync(false);

return 0;
}

// API
const char* execute_command(const char* command) {
cout << "LLDB WASM call - " << __FUNCTION__ << " command: " << command << "\n";

SBCommandReturnObject result;
SBCommandInterpreter sb_interpreter = g_debugger.GetCommandInterpreter();
sb_interpreter.HandleCommand(command, result, false);
cout << "result: " << result.GetOutput() << "\n";
return strdup(result.GetOutput());
}
#endif

0 comments on commit 12a948e

Please sign in to comment.