Re: How to recgnize the local varialble
Jan Kratochvil <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 29 Apr 2015 10:42:07 +0200, 高国胜 wrote:
> Accord to the red part,
Please do not depend on the HTML part of mail, it is difficult to display.
> we can get the memory address of the variable i, but how can the injected
> code identify the symbol i ?
So it looks like:
------------------------------------------------------------------------------
void _gdb_expr (struct __gdb_regs *__regs) {
__attribute__ ((unused)) __gdb_uintptr __i_ptr; {
[...]
__i_ptr = __gdb_stack[__gdb_tos];
}
#pragma GCC user_expression
{
#line 1 "gdb command line"
i=20
; } }
------------------------------------------------------------------------------
Starting at that line
#pragma GCC user_expression
GCC starts to ask GDB about any unknown symbols. With
(gdb) set debug compile 1
you can see it as line:
gcc_convert_symbol "i": local symbol
It is the GDB line:
decl = C_CTX (context)->c_ops->build_decl (C_CTX (context),
SYMBOL_NATURAL_NAME (sym),
kind,
sym_type,
symbol_name, addr,
filename, line);
and 'symbol_name' is "__i_ptr" in this case passed as parameter
const char *, /* Argument SUBSTITUTION_NAME. */
How GCC binds the created symbol "i"'s address to the value of the "__i_ptr"
variable is GCC's magic beyond my knowledge.
Jan