| Issue |
165807
|
| Summary |
[lldb][RFC] add _javascript_ as a supported scripting language
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
cs01
|
https://github.com/llvm/llvm-project/pull/165805 implements support for _javascript_ scripting in lldb. Similar to python and lua, it uses swig to generate C++ bindings for the language. V8 is embedded in lldb and used as a _javascript_ engine. I am sharing here for discussion to see if there is interest in landing support for _javascript_ scripting in lldb. There may be a few gaps in functionality like callback support, but I tried some of the standard scripting bridge functions and they worked.
For instructions to try this out, check out the branch and see the file `lldb/docs/use/_javascript_-reference.md`.
To try this out save the following file
`/tmp/test.js`:
```
let dbg = lldb.SBDebugger.Create();
dbg.SetAsync(false);
let target = dbg.CreateTarget("/bin/ls");
let breakpoint = target.BreakpointCreateByName("main");
console.log("Breakpoint ID:", breakpoint.GetID());
let error = new lldb.SBError();
let proc = target.Launch(target.GetLaunchInfo(), error);
if (error.Fail()) {
console.error("Error:", error.GetCString());
} else {
console.log("PID:", proc.GetProcessID());
let thread = proc.GetSelectedThread();
console.log("Thread:", thread.GetThreadID());
console.log("Stop reason:", thread.GetStopReason());
console.log("\nStack trace:");
for (let i = 0; i < Math.min(thread.GetNumFrames(), 4); i++) {
let frame = thread.GetFrameAtIndex(i);
let pc = frame.GetPCAddress().GetLoadAddress(target);
let pcHex = "0x" + (pc >>> 0).toString(16).padStart(8, '0');
console.log("Frame #" + i + ": " + pcHex);
}
console.log("Registers:");
let frame0 = thread.GetFrameAtIndex(0);
let gprs = frame0.GetRegisters().GetValueAtIndex(0);
for (let i = 0; i < Math.min(gprs.GetNumChildren(), 10); i++) {
let reg = gprs.GetChildAtIndex(i);
console.log(reg.GetName() + " = " + reg.GetValue());
}
proc.Kill();
}
undefined;
```
then run
```
./build/bin/lldb -b -o 'settings set script-lang _javascript_' -o 'command script import /tmp/test.js'
```
which prints
```
bin/lldb -b -o 'settings set script-lang _javascript_' -o 'command script import /tmp/test_process_launch.js'
(lldb) settings set script-lang _javascript_
(lldb) command script import /tmp/test_process_launch.js
Breakpoint ID: 1
PID: 2351277
Thread: 2351277
Stop reason: 3
Stack trace:
Frame #0: 0x55558d80
Frame #1: 0xf7c2a610
Frame #2: 0xf7c2a6c0
Frame #3: 0x5555ab35
Registers:
rax = 0x0000555555558d80
rbx = 0x0000000000000000
rcx = 0x0000555555574f78
rdx = 0x00007fffffffcbf8
rdi = 0x0000000000000001
rsi = 0x00007fffffffcbe8
rbp = 0x0000000000000001
rsp = 0x00007fffffffcad8
r8 = 0x00007ffff7dfc330
r9 = 0x00007ffff7fcb060
>
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs