Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Translate memory addresses
@ 2011-03-06 23:53 Michael Eager
  2011-03-08 16:28 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Eager @ 2011-03-06 23:53 UTC (permalink / raw)
  To: gdb

Hi --

I'm working with a target which needs to translate
a virtual memory addresses to a physical address
before accessing the target's memory or the core file.

I added a new field to target_ops to specify the
translation function and added the following to
target_xfer_partial():

   /* Translate address if needed.  */
   if (ops->to_translate_address)
     offset = ops->to_translate_address (ops, offset);

So far, so good.  I can add this to the target definition
for the live targets.  But this doesn't work for core files.

Core_ops is defined in corelow.c, and there doesn't appear
to be an obvious hook for the target code to modify it to
add the translation routine.

Any suggestions on the best way to add a hook or how to specify
a target routine to do address translations for core files?

-- 
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077


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

* Re: Translate memory addresses
  2011-03-06 23:53 Translate memory addresses Michael Eager
@ 2011-03-08 16:28 ` Tom Tromey
  2011-03-08 16:48   ` Michael Eager
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2011-03-08 16:28 UTC (permalink / raw)
  To: Michael Eager; +Cc: gdb

>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:

Michael> I'm working with a target which needs to translate
Michael> a virtual memory addresses to a physical address
Michael> before accessing the target's memory or the core file.

Michael> Core_ops is defined in corelow.c, and there doesn't appear
Michael> to be an obvious hook for the target code to modify it to
Michael> add the translation routine.

Michael> Any suggestions on the best way to add a hook or how to specify
Michael> a target routine to do address translations for core files?

I am not an expert in this area, but couldn't you make a new
arch_stratum target that does the translation?

With this approach maybe you don't even need a hook -- just do the
translation and call the target beneath.

Tom


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

* Re: Translate memory addresses
  2011-03-08 16:28 ` Tom Tromey
@ 2011-03-08 16:48   ` Michael Eager
  2011-03-08 17:04     ` Mark Kettenis
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Eager @ 2011-03-08 16:48 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb

Tom Tromey wrote:
>>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
> 
> Michael> I'm working with a target which needs to translate
> Michael> a virtual memory addresses to a physical address
> Michael> before accessing the target's memory or the core file.
> 
> Michael> Core_ops is defined in corelow.c, and there doesn't appear
> Michael> to be an obvious hook for the target code to modify it to
> Michael> add the translation routine.
> 
> Michael> Any suggestions on the best way to add a hook or how to specify
> Michael> a target routine to do address translations for core files?
> 
> I am not an expert in this area, but couldn't you make a new
> arch_stratum target that does the translation?
> 
> With this approach maybe you don't even need a hook -- just do the
> translation and call the target beneath.

Interesting idea.  I didn't think of adding a stratum for translation.

I took a clue from the way that sol-thread.c prevents corelow.c
from calling add_target to install core_ops.  I added the following
to corelow.c:

   CORE_ADDR (*target_translate_address) (struct target_ops *, CORE_ADDR addr);

and in init_core_ops():

   core_ops.to_translate_address = target_translate_address;

The target code contains a definition for target_translate_address
which is initialized to point to the translation routine.  For other
targets, this will be zero.

It's inelegant, what can I say, but functional.


-- 
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077


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

* Re: Translate memory addresses
  2011-03-08 16:48   ` Michael Eager
@ 2011-03-08 17:04     ` Mark Kettenis
  2011-03-08 17:21       ` Michael Eager
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Kettenis @ 2011-03-08 17:04 UTC (permalink / raw)
  To: eager; +Cc: tromey, gdb

> Date: Tue, 08 Mar 2011 08:47:53 -0800
> From: Michael Eager <eager@eagerm.com>
> 
> Tom Tromey wrote:
> >>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
> > 
> > Michael> I'm working with a target which needs to translate
> > Michael> a virtual memory addresses to a physical address
> > Michael> before accessing the target's memory or the core file.
> > 
> > Michael> Core_ops is defined in corelow.c, and there doesn't appear
> > Michael> to be an obvious hook for the target code to modify it to
> > Michael> add the translation routine.
> > 
> > Michael> Any suggestions on the best way to add a hook or how to specify
> > Michael> a target routine to do address translations for core files?
> > 
> > I am not an expert in this area, but couldn't you make a new
> > arch_stratum target that does the translation?
> > 
> > With this approach maybe you don't even need a hook -- just do the
> > translation and call the target beneath.
> 
> Interesting idea.  I didn't think of adding a stratum for translation.
> 
> I took a clue from the way that sol-thread.c prevents corelow.c
> from calling add_target to install core_ops.  I added the following
> to corelow.c:
> 
>    CORE_ADDR (*target_translate_address) (struct target_ops *, CORE_ADDR addr);
> 
> and in init_core_ops():
> 
>    core_ops.to_translate_address = target_translate_address;
> 
> The target code contains a definition for target_translate_address
> which is initialized to point to the translation routine.  For other
> targets, this will be zero.
> 
> It's inelegant, what can I say, but functional.

Did you look at how the BSD kvm target does things?  It does a
physical to virtual address translation (by using the system-provided
libkvm), and seems to get away with this without having such a hook.


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

* Re: Translate memory addresses
  2011-03-08 17:04     ` Mark Kettenis
@ 2011-03-08 17:21       ` Michael Eager
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Eager @ 2011-03-08 17:21 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: tromey, gdb

Mark Kettenis wrote:
>> Date: Tue, 08 Mar 2011 08:47:53 -0800
>> From: Michael Eager <eager@eagerm.com>
>>
>> Tom Tromey wrote:
>>>>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
>>> Michael> I'm working with a target which needs to translate
>>> Michael> a virtual memory addresses to a physical address
>>> Michael> before accessing the target's memory or the core file.
>>>
>>> Michael> Core_ops is defined in corelow.c, and there doesn't appear
>>> Michael> to be an obvious hook for the target code to modify it to
>>> Michael> add the translation routine.
>>>
>>> Michael> Any suggestions on the best way to add a hook or how to specify
>>> Michael> a target routine to do address translations for core files?
>>>
>>> I am not an expert in this area, but couldn't you make a new
>>> arch_stratum target that does the translation?
>>>
>>> With this approach maybe you don't even need a hook -- just do the
>>> translation and call the target beneath.
>> Interesting idea.  I didn't think of adding a stratum for translation.
>>
>> I took a clue from the way that sol-thread.c prevents corelow.c
>> from calling add_target to install core_ops.  I added the following
>> to corelow.c:
>>
>>    CORE_ADDR (*target_translate_address) (struct target_ops *, CORE_ADDR addr);
>>
>> and in init_core_ops():
>>
>>    core_ops.to_translate_address = target_translate_address;
>>
>> The target code contains a definition for target_translate_address
>> which is initialized to point to the translation routine.  For other
>> targets, this will be zero.
>>
>> It's inelegant, what can I say, but functional.
> 
> Did you look at how the BSD kvm target does things?  It does a
> physical to virtual address translation (by using the system-provided
> libkvm), and seems to get away with this without having such a hook.

How would this help?  The kernel isn't running when debugging
a hardware target and you can't execute target code when debugging
a core file.


-- 
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077


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

end of thread, other threads:[~2011-03-08 17:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-06 23:53 Translate memory addresses Michael Eager
2011-03-08 16:28 ` Tom Tromey
2011-03-08 16:48   ` Michael Eager
2011-03-08 17:04     ` Mark Kettenis
2011-03-08 17:21       ` Michael Eager

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox