This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: How to recgnize the local varialble
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: éåè <guosheng_gao at realsil dot com dot cn>
- Cc: "gdb at sourceware dot org" <gdb at sourceware dot org>, Phil Muldoon <pmuldoon at redhat dot com>
- Date: Wed, 29 Apr 2015 21:59:31 +0200
- Subject: Re: How to recgnize the local varialble
- Authentication-results: sourceware.org; auth=none
- References: <0CEE46EB9C50E44486A861D738D3E20645F9D0A9 at rsex2 dot realsil dot com dot cn>
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