gpt4 book ai didi

gdb: Actor 取决于编译的语言

转载 作者:行者123 更新时间:2023-12-04 15:46:45 26 4
gpt4 key购买 nike

我正在调试使用 GDB (arm-none-eabi-gdb) 在 Rust 中编译的程序。有一次,我想写入一个内存地址,如下所示:

(gdb) set *((int *) 0x24040000) = 0x0000CAFE
syntax error in expression, near `) 0x24040000) = 0x0000CAFE'.

经过多次尝试,我发现我正在转换 C 风格,我不得不将其转换为 Rust 风格,如下所示:
set *(0x24040000 as *mut i32) = 0x0000CAFE

我的问题是 GDB 如何解释不同的命令以及为什么会出现此错误。是不是因为符号(int)不被识别,但是在这种情况下,gdb如何加载符号? gdb 是否需要将指令编译为目标上运行的二进制文件的正确语言?

最佳答案

是的,这取决于语言,语言是从加载的源文件的文件名中推导出来的。

报价the manual :

print and many other GDB commands accept an expression and compute its value. Any kind of constant, variable or operator defined by the programming language you are using is valid in an expression in GDB. This includes conditional expressions, function calls, casts, and string constants.



And :

If you are not interested in seeing the value of the assignment, use the set command instead of the print command. set is really the same as print except that the expression’s value is not printed and is not put in the value history (see Value History). The expression is evaluated only for its effects.



And :

Language-specific information is built into GDB for some languages, allowing you to express operations like the above in your program’s native language, and allowing GDB to output values in a manner consistent with the syntax of your program’s native language. The language you use to build expressions is called the working language.



And :

There are two ways to control the working language—either have GDB set it automatically, or select it manually yourself. You can use the set language command for either purpose. On startup, GDB defaults to setting the language automatically.

[..] most of the time GDB infers the language from the name of the file.

关于gdb: Actor 取决于编译的语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55457338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com