如何导入Facebook的Chisel fbchisellldb.py取决于芯片类型(M1/Intel)?

发布于 2025-01-22 18:54:55 字数 820 浏览 1 评论 0原文

我在〜/.lldbinit中添加以下外壳代码。

if [[ $(uname -p) == 'arm' ]]; then
    command script import /opt/homebrew/opt/chisel/libexec/fbchisellldb.py
fi

if [[ $(uname -p) == 'i386' ]]; then
    command script import /usr/local/opt/chisel/libexec/fbchisellldb.py
fi

script fbchisellldb.loadCommandsInDirectory('/path/to/fbchisellldb.py')

但是事实证明,lldbinit不支持壳代码/语法,检测芯片类型并动态导入fbchiselldb.py的正确方法是什么?

error: 'if' is not a valid command.
error: error: No value
error: error: No value
error: error: No value
error: error: No value
Error loading Chisel (errno None)
error: 'if' is not a valid command.
error: module importing failed: invalid pathname
error: error: No value
error: error: No value
error: error: No value
error: error: No value
Error loading Chisel (errno None)

I add the following shell code in the ~/.lldbinit.

if [[ $(uname -p) == 'arm' ]]; then
    command script import /opt/homebrew/opt/chisel/libexec/fbchisellldb.py
fi

if [[ $(uname -p) == 'i386' ]]; then
    command script import /usr/local/opt/chisel/libexec/fbchisellldb.py
fi

script fbchisellldb.loadCommandsInDirectory('/path/to/fbchisellldb.py')

but turns out .lldbinit not support shell code/syntax, what's the correct way to detect chip type and dynamically import fbchiselldb.py.

error: 'if' is not a valid command.
error: error: No value
error: error: No value
error: error: No value
error: error: No value
Error loading Chisel (errno None)
error: 'if' is not a valid command.
error: module importing failed: invalid pathname
error: error: No value
error: error: No value
error: error: No value
error: error: No value
Error loading Chisel (errno None)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他不在意 2025-01-29 18:54:55

LLDB将脚本任务委托给脚本解释器。我们认为Python的人们在制作可用的语言方面会做得更好,而不是我们想出的任何内容,而Python是广为人知的,因此我们不会强迫人们学习另一组Shell的怪癖像测试&循环结构。因此,如果您需要使用逻辑测试&在与LLDB的交互中,您可以使用脚本命令或导入模块在Python中进行此操作。

您可以在您的〜/.lldbinit中使用脚本命令单线,也可以将脚本文本插入在.lldbinit中,但是我通常将.py文件保留在〜/.lldb中i 命令脚本导入在.lldbinit中,并让它完成此类工作。以这种方式更容易添加和调试。

如果将表单的函数列出:

def __lldb_init_module(debugger, dict):

在Python模块中,LLDB将在模块以命令脚本导入导入模块时运行该功能(这是使用命令脚本import之间的最大差异之一和<代码>脚本导入)。这使您可以将命令添加到导入此模块的调试器中。

所以你可以做:

import platform

def __lldb_init_module(debugger, dict):
    if platform.machine() == 'arm64':
        debugger.HandleCommand("command script import <ONE_CHISEL>")
    else
        debugger.HandleCommand("command script import <OTHER_CHISEL>")

lldb delegates scripting tasks to the script interpreter. We figured the Python folks would do a better job at producing a useable language than anything we were going to come up with, and Python is pretty widely known, so we wouldn't be forcing people to learn the quirks of yet another set of shell like if tests & looping constructs. So if you need to use logical tests & looping in your interactions with lldb, you do that in Python using the script command or by importing modules.

You can either use script command one-lines in your ~/.lldbinit, or you can put the script text inline in your .lldbinit, but I generally keep a .py file in ~/.lldb that I command script import in the .lldbinit, and have it do this sort of job. It's easier to add to and debug that way.

If you put a function of the form:

def __lldb_init_module(debugger, dict):

in a Python module, lldb will run that function when the module is imported with command script import (that's one of the big differences between using command script import and script import). That allows you to add commands to the debugger that's importing this module.

So you could do:

import platform

def __lldb_init_module(debugger, dict):
    if platform.machine() == 'arm64':
        debugger.HandleCommand("command script import <ONE_CHISEL>")
    else
        debugger.HandleCommand("command script import <OTHER_CHISEL>")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文