public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Convenience variable for filename in add-symbol-file not expanded
@ 2005-09-29 10:22 David Lamy-Charrier
  0 siblings, 0 replies; 6+ messages in thread
From: David Lamy-Charrier @ 2005-09-29 10:22 UTC (permalink / raw)
  To: GDB List

I am using the add-symbol-file command from a gdb script to
dynamically add symbols at runtime.
So I want to use a convenience variable for the filename parameter of
add-symbol-file, I tested with gdb 6.3.1 for mingw and looked in the
code but convenience variables as filename are not expanded.

I found this thread:
http://www.cygwin.com/ml/gdb/2002-11/msg00275.html
But I do not know the current status of it.

Does anyone know if a patch exists for that ?
If not, could you give me some hints to implement it (any
parse_and_eval_string or equivalent i can use...) ?

Thanks in advance,
David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Convenience variable for filename in add-symbol-file not expanded
  2005-09-29 13:38     ` David Lamy-Charrier
@ 2005-09-29 14:04       ` Andrew STUBBS
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew STUBBS @ 2005-09-29 14:04 UTC (permalink / raw)
  To: David Lamy-Charrier; +Cc: gdb

David Lamy-Charrier wrote:
> Thanks Andrew,
> 
> I already have a static buffer in the inferior program containing the
> path to the file I want to use.
> You mean that I should declare a pointer to the variable in the
> inferior program too ?
> And then how can I access the pointed value in gdb, using
> value_of_internalvar() or parse_and_eval_address() or anything else) ?

No, I mean you can create a convenience variable with type char*. The 
command language can be made to substitute convenience variables 
starting with $, but it seems a little much to expect it to unpick 
program variables as well.

So, if your string were referenced by an inferior variable 'filename', 
it would look like:
(gdb) set $name = filename
(gdb) set $address = 0x.....
(gdb) add-symbol-file $name $address

You can then use lookup_internalvar() to get the address and then read 
the string from memory somehow, get_target_memory() probably (look in 
target.h for the various options). Of course, there may be a better way 
... anyone?

HTH

Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Convenience variable for filename in add-symbol-file not expanded
  2005-09-29 13:00   ` Andrew STUBBS
@ 2005-09-29 13:38     ` David Lamy-Charrier
  2005-09-29 14:04       ` Andrew STUBBS
  0 siblings, 1 reply; 6+ messages in thread
From: David Lamy-Charrier @ 2005-09-29 13:38 UTC (permalink / raw)
  To: gdb

Thanks Andrew,

I already have a static buffer in the inferior program containing the
path to the file I want to use.
You mean that I should declare a pointer to the variable in the
inferior program too ?
And then how can I access the pointed value in gdb, using
value_of_internalvar() or parse_and_eval_address() or anything else) ?

Thanks,
David



> I wanted to do much the same thing a while back.
>
> Unless I am very much mistaken, there is no way to assign a string to a
> convenience variable. The nearest you can get is to place it in the
> inferior program's memory somewhere (perhaps using malloc, or some fixed
> location) and then assign a pointer to the variable. Obviously you can't
> do this until there is some memory to write to. However, you could
> extend the patch to expect a 'char *' variable for the name.
>
> Also, all convenience variables are wiped by the file and symbol-file
> commands (because their types disappear along with the old symbol
> table), so they aren't that convenient for scripting this kind of thing.
>
> Andrew
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Convenience variable for filename in add-symbol-file not expanded
  2005-09-29 12:50 ` David Lamy-Charrier
@ 2005-09-29 13:00   ` Andrew STUBBS
  2005-09-29 13:38     ` David Lamy-Charrier
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew STUBBS @ 2005-09-29 13:00 UTC (permalink / raw)
  To: David Lamy-Charrier; +Cc: gdb

David Lamy-Charrier wrote:
> Dieter,
> 
> Thanks for your response, but your solution allows to expand
> convenience variable used
> for section address parameter, I want to expand a convenience variable
> for the filename parameter, so instead of value_as_address() it should
> be a kind of value_as_string...

I wanted to do much the same thing a while back.

Unless I am very much mistaken, there is no way to assign a string to a 
convenience variable. The nearest you can get is to place it in the 
inferior program's memory somewhere (perhaps using malloc, or some fixed 
location) and then assign a pointer to the variable. Obviously you can't 
do this until there is some memory to write to. However, you could 
extend the patch to expect a 'char *' variable for the name.

Also, all convenience variables are wiped by the file and symbol-file 
commands (because their types disappear along with the old symbol 
table), so they aren't that convenient for scripting this kind of thing.

Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Convenience variable for filename in add-symbol-file not expanded
  2005-09-29 12:36 Ruppert
@ 2005-09-29 12:50 ` David Lamy-Charrier
  2005-09-29 13:00   ` Andrew STUBBS
  0 siblings, 1 reply; 6+ messages in thread
From: David Lamy-Charrier @ 2005-09-29 12:50 UTC (permalink / raw)
  To: gdb

Dieter,

Thanks for your response, but your solution allows to expand
convenience variable used
for section address parameter, I want to expand a convenience variable
for the filename parameter, so instead of value_as_address() it should
be a kind of value_as_string...

Regards,
David


On 9/29/05, Ruppert <dieter_ruppert@siemens.com> wrote:
>
>
> >Does anyone know if a patch exists for that ?
> >If not, could you give me some hints to implement it (any
> >parse_and_eval_string or equivalent i can use...) ?
> >
>
> If you can't find a more general solution:
> I got this working with the following local hack in
> parse-and_eval_address (this was gdb-6.1):
>
>     CORE_ADDR addr;
>     if (exp[0] == '$')
>     {
>
>         struct value* valx;
>         valx = value_of_internalvar(lookup_internalvar(&exp[1]));
>         if (TYPE_CODE( VALUE_TYPE(valx)) != TYPE_CODE_INT)
>           error("Invalid type given as section address.");
>         addr = value_as_address(valx);
>     }
>     else
>     {
>
>      ... the current code goes here
>
>
> HTH
>
> regards
> d.ruppert
> dieter_ruppert@siemens.com
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Convenience variable for filename in add-symbol-file not expanded
@ 2005-09-29 12:36 Ruppert
  2005-09-29 12:50 ` David Lamy-Charrier
  0 siblings, 1 reply; 6+ messages in thread
From: Ruppert @ 2005-09-29 12:36 UTC (permalink / raw)
  To: gdb



>Does anyone know if a patch exists for that ?
>If not, could you give me some hints to implement it (any
>parse_and_eval_string or equivalent i can use...) ?
>

If you can't find a more general solution:
I got this working with the following local hack in 
parse-and_eval_address (this was gdb-6.1):

    CORE_ADDR addr;
    if (exp[0] == '$')
    {
	
	struct value* valx;
	valx = value_of_internalvar(lookup_internalvar(&exp[1]));
	if (TYPE_CODE( VALUE_TYPE(valx)) != TYPE_CODE_INT)
	  error("Invalid type given as section address.");
	addr = value_as_address(valx);
    }
    else
    {

     ... the current code goes here


HTH

regards
d.ruppert
dieter_ruppert@siemens.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-09-29 14:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-29 10:22 Convenience variable for filename in add-symbol-file not expanded David Lamy-Charrier
2005-09-29 12:36 Ruppert
2005-09-29 12:50 ` David Lamy-Charrier
2005-09-29 13:00   ` Andrew STUBBS
2005-09-29 13:38     ` David Lamy-Charrier
2005-09-29 14:04       ` Andrew STUBBS

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).