Reputation: 1351
I was debugging a program compiled in Rust using GDB (arm-none-eabi-gdb). At one point, I wanted to write to a memory address as follow:
(gdb) set *((int *) 0x24040000) = 0x0000CAFE
syntax error in expression, near `) 0x24040000) = 0x0000CAFE'.
After multiple tentative, I found out that I was casting the C style and I had to cast it the Rust style as follow:
set *(0x24040000 as *mut i32) = 0x0000CAFE
My question is how GDB is interpreting the different commands and why I get this error. Is it because the symbol (int) is not recognized, but in this case, how gdb load the symbols? Does gdb need to compile the instruction to the correct language of the binary running on the target?
Upvotes: 5
Views: 1279
Reputation: 385325
Yes, it depends on the language, and the language is deduced from the filename of the loaded source file.
Quoting the manual:
And:
If you are not interested in seeing the value of the assignment, use the
set
command instead of theset
is really the same as
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.
Upvotes: 2